Subversion Repositories eFlore/Applications.coel

Compare Revisions

No changes between revisions

Ignore whitespace Rev 1764 → Rev 1812

/tags/v1.6-muscardin/src/org/tela_botanica/client/modeles/publication/PublicationAPersonne.java
New file
0,0 → 1,248
package org.tela_botanica.client.modeles.publication;
 
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
 
import org.tela_botanica.client.modeles.aDonnee;
import org.tela_botanica.client.modeles.personne.Personne;
import org.tela_botanica.client.util.Log;
import org.tela_botanica.client.util.UtilString;
 
import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.json.client.JSONObject;
 
public class PublicationAPersonne extends aDonnee {
 
private static final long serialVersionUID = 7769105365939978129L;
public static final String PREFIXE = "cpuap";
public static final String ROLE_AUTEUR = "2360";
//FIXME: insérer en base de données une valeur cohérente pour l'identifiant ci-dessous
public static final String ROLE_SUJET = "30762";
private Personne personneLiee = null;
private Publication publicationLiee = null;
public static String[] champsObligatoires = {"cpuap_id_personne", "cpuap_id_publication", "cpuap_id_role"};
public PublicationAPersonne() {
new PublicationAPersonne(new JSONObject());
}
public PublicationAPersonne(boolean removePrefix) {
this.removePrefix = removePrefix;
new PublicationAPersonne(new JSONObject());
}
public PublicationAPersonne(JSONObject pubAPersListe) {
Personne personne = new Personne(pubAPersListe);
setPersonne(personne);
publicationLiee = new Publication(pubAPersListe);
// l'objet JSON est une table de hachage
Set<String> im = pubAPersListe.keySet();
 
// Parcourt pour chaque clé
for (Iterator<String> it = im.iterator(); it.hasNext();) {
// Si elle est associée à une valeur, nous l'ajoutons
String cle = it.next();
String cleObjet = "";
if (removePrefix) {
cleObjet = cle.replaceFirst("^"+getPrefixe()+"_", "");
} else {
cleObjet = cle;
}
// Valeur vide par défaut
String valeur = "";
if (pubAPersListe.get(cle).isString() != null) {
valeur = pubAPersListe.get(cle).isString().stringValue();
}
this.set(cleObjet, valeur);
}
initialiserChampsPourGrille();
}
public PublicationAPersonne(ModelData modele, boolean removePrefix) {
this.removePrefix = removePrefix;
if (modele != null) {
Map<String, Object> modeleProprietes = modele.getProperties();
Set<String> cles = modeleProprietes.keySet();
Iterator<String> it = cles.iterator();
while (it.hasNext()) {
String cle = it.next();
Object valeur = modeleProprietes.get(cle);
if (modeleProprietes.get(cle) != null) {
String cleObjet = "";
if (removePrefix) {
cleObjet = cleObjet.replaceFirst("^"+getPrefixe()+"_", "");
} else {
cleObjet = cle;
}
this.set(cleObjet, valeur);
}
}
setPersonne(new Personne(modele, removePrefix));
setPublicationLiee(new Publication(modele, removePrefix));
initialiserChampsPourGrille();
this.set("_role_", modeleProprietes.get("_role_"));
this.set("_etat_", modeleProprietes.get("_etat_"));
} else {
Log.debug("Le modèle passé en paramètre ne doit pas être vide");
}
}
private void initialiserChampsPourGrille() {
if (removePrefix) {
set("fmt_auteur", publicationLiee.getAuteur());
set("titre", publicationLiee.getTitre());
set("collection", publicationLiee.getCollection());
set("_editeur_", "");
set("_annee_", "");
set("indication_nvt", publicationLiee.getIndicationNvt());
set("fascicule", publicationLiee.getFascicule());
set("truk_pages", publicationLiee.getPages());
set("_etat_", "");
set("_role_", this.getIdRole());
} else {
set("cpu_fmt_auteur", publicationLiee.getAuteur());
set("cpu_titre", publicationLiee.getTitre());
set("cpu_collection", publicationLiee.getCollection());
set("_editeur_", "");
set("_annee_", "");
set("cpu_indication_nvt", publicationLiee.getIndicationNvt());
set("cpu_fascicule", publicationLiee.getFascicule());
set("cpu_truk_pages", publicationLiee.getPages());
set("_etat_", "");
set("_role_", this.getIdRole());
}
}
@Override
protected String getPrefixe() {
return PREFIXE;
}
 
protected String[] getChampsObligatoires() {
return champsObligatoires;
}
public Personne getPersonne() {
return personneLiee;
}
public void setPersonne(Personne personne) {
setPersonne(personne, false);
}
public void setPersonne(Personne personne, boolean integrerProprietes) {
personneLiee = personne;
if (personne != null) {
Log.debug("Tentative ajout id personne : "+personne.getId());
setIdPersonne(personne.getId());
}
if (integrerProprietes) {
Map<String, Object> a = personne.getProperties();
Set<String> cles = a.keySet();
Iterator<String> it = cles.iterator();
while (it.hasNext()) {
String cle = it.next();
if (a.get(cle) != null) {
String cleObjet = "";
if (removePrefix) {
cleObjet = cle.replaceFirst("^"+Personne.PREFIXE+"_", "");
} else {
cleObjet = cle;
}
this.set(cleObjet, a.get(cle));
}
}
}
}
// ID
public String getId() {
String idPublication = getIdPublication();
String idPersonne = getIdPersonne();
String idRole = getIdRole();
if (idPublication.equals("") && idPersonne.equals("") && idRole.equals("")) {
return null;
} else {
return (idPublication+"-"+idPersonne+"-"+idRole);
}
}
// ID PUBLICATION
public String getIdPublication() {
String valeur = renvoyerValeurCorrecte("id_publication");
return UtilString.isEmpty(valeur) ? "0" : valeur;
}
public void setIdPublication(String id) {
setValeurCorrecte("id_publication", id);
}
// PUBLICATION LIEE
public Publication getPublicationLiee() {
return this.publicationLiee;
}
// LIER PUBLICATION
public void setPublicationLiee(Publication publication) {
this.publicationLiee = publication;
initialiserChampsPourGrille();
}
// ID PERSONNE
public String getIdPersonne() {
String valeur = renvoyerValeurCorrecte("id_personne");
return UtilString.isEmpty(valeur) ? "0" : valeur;
}
public void setIdPersonne(String id) {
setValeurCorrecte("id_personne", id);
}
// ID RôLE
public String getIdRole() {
String valeur = renvoyerValeurCorrecte("id_role");
return UtilString.isEmpty(valeur) ? "0" : valeur;
}
public void setIdRole(String id) {
setValeurCorrecte("id_role", id);
this.set("_role_", id);
}
// ROLE
public String getRole() {
String role = this.get("_role_");
if (role != null) {
return role;
} else {
return "";
}
}
// TYPE
public String getType() {
return renvoyerValeurCorrecte("ce_truk_type");
}
public void setType(String type) {
setValeurCorrecte("ce_truk_type", type);
}
public void setFonction(String type, String valeur) {
setChaineDenormaliseUnique("ce_truk_type", type, valeur);
}
// ORDRE DES AUTEURS
public String getOrdreAuteurs() {
return renvoyerValeurCorrecte("ordre");
}
public void setOrdreAuteurs(String ordre) {
if (ordre.matches("[0-9]+")) {
setValeurCorrecte("ordre", ordre);
this.set("_ordre_", ordre);
}
}
}
Property changes:
Added: svn:mergeinfo
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/modeles/publication/PublicationAPersonne.java:r1136-1368
Merged /trunk/src/org/tela_botanica/client/modeles/publication/PublicationAPersonne.java:r11-934,1209-1382
Merged /branches/v1.1-aramon/src/org/tela_botanica/client/modeles/publication/PublicationAPersonne.java:r1383-1511
/tags/v1.6-muscardin/src/org/tela_botanica/client/modeles/publication/PublicationAPersonneListe.java
New file
0,0 → 1,32
package org.tela_botanica.client.modeles.publication;
 
import org.tela_botanica.client.modeles.aDonneeListe;
 
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
 
public class PublicationAPersonneListe extends aDonneeListe<PublicationAPersonne> {
 
private static final long serialVersionUID = -5950583940829919577L;
 
public PublicationAPersonneListe() {
super();
}
public PublicationAPersonneListe(int i) {
super(i);
}
public PublicationAPersonneListe(JSONArray auteurs) {
super(auteurs.size()) ;
final int taillemax = auteurs.size();
for (int i = 0; i < taillemax; i++) {
JSONObject publicationAPersonneCourante = auteurs.get(i).isObject() ;
if (publicationAPersonneCourante != null) {
PublicationAPersonne publicationAPersonne = new PublicationAPersonne(publicationAPersonneCourante);
this.put(publicationAPersonne.getId(), publicationAPersonne);
}
}
}
}
Property changes:
Added: svn:mergeinfo
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/modeles/publication/PublicationAPersonneListe.java:r1136-1368
Merged /trunk/src/org/tela_botanica/client/modeles/publication/PublicationAPersonneListe.java:r11-934,1209-1382
Merged /branches/v1.1-aramon/src/org/tela_botanica/client/modeles/publication/PublicationAPersonneListe.java:r1383-1511
/tags/v1.6-muscardin/src/org/tela_botanica/client/modeles/publication/PublicationAPersonneAsyncDao.java
New file
0,0 → 1,195
package org.tela_botanica.client.modeles.publication;
 
import java.util.HashMap;
 
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.http.JsonRestRequestBuilder;
import org.tela_botanica.client.http.JsonRestRequestCallback;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.Information;
import org.tela_botanica.client.synchronisation.Reponse;
import org.tela_botanica.client.util.Log;
import org.tela_botanica.client.util.UtilDAO;
 
import com.extjs.gxt.ui.client.Registry;
import com.google.gwt.http.client.URL;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONValue;
 
public class PublicationAPersonneAsyncDao {
 
private static final String SERVICE_NOM = "CoelPublicationAPersonne";
private String utilisateurId = null;
private Rafraichissable vueARafraichir = null;
public PublicationAPersonneAsyncDao(Rafraichissable vueARafraichirCourrante) {
Log.trace("|| PublicationAPersonneAsyncDao > vueARafraichir = "+vueARafraichirCourrante.getClass().toString());
vueARafraichir = vueARafraichirCourrante;
utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
}
public void selectionner(final boolean paginationProgressive, String publicationId, String personnesId, String roleId, final String recherche, final int start, final int nbElements, final Integer seqId) {
 
String[] parametres = {publicationId, personnesId, roleId};
HashMap<String, String> restrictions = new HashMap<String, String>();
if (nbElements != -1) {
restrictions.put("limit", String.valueOf(nbElements));
}
restrictions.put("orderby", "cpuap_ordre");
 
if (paginationProgressive) {// GESTION DE LA REQUETE dans le cas d'une liste paginée progressive
restrictions.put("start", String.valueOf(start));// DEFINITION DU TUPLE DE DEPART
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
rb.envoyerRequete(null, new JsonRestRequestCallback() {
/** RECEPTION DE LA REPONSE **/
public void surReponse(JSONValue responseValue) {
/** Dans le cas d'une liste paginée, vueARafraichir est un objet Proxy.
* On retourne l'objet JSON au proxy afin que ce soit lui qui le traite **/
if (seqId != null) {
Log.trace("<-- PublicationAPersonneAsyncDao > Liste paginée, retour au sequenceur");
Reponse reponseRequete = new Reponse(responseValue, seqId);
vueARafraichir.rafraichir(reponseRequete);
} else {
Log.trace("<-- PublicationAPersonneAsyncDao > Liste paginée, retour à "+vueARafraichir.getClass().toString());
vueARafraichir.rafraichir(responseValue);
}
}
});
} else { // GESTION DE LA REQUETE dans le cas d'une liste NON paginée progressive
restrictions.put("start", String.valueOf(start*nbElements));
 
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
rb.envoyerRequete(null, new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue responseValue) {
if (responseValue != null) {
JSONObject responseObject = responseValue.isObject();
if (responseObject != null) {
// Si la réponse est un tableau, alors c'est une liste de collections qui a été retournée
if (responseObject.get("publicationsAPersonne").isArray() != null) {
final JSONArray reponse = responseObject.get("publicationsAPersonne").isArray();
// Transformation du tableau JSON réponse en ListeInstitution
PublicationAPersonneListe publicationsAPersonneListe = new PublicationAPersonneListe(reponse);
// et on met à jour le demandeur des données
if (seqId != null) {
Log.trace("<-- PublicationAPersonneAsyncDao > Liste non paginée, retour au sequenceur");
Reponse reponseRequete = new Reponse(publicationsAPersonneListe, seqId);
vueARafraichir.rafraichir(reponseRequete);
} else {
Log.trace("<-- PublicationAPersonneAsyncDao > Liste non paginée, retour au sequenceur");
vueARafraichir.rafraichir(publicationsAPersonneListe);
}
} else if (responseObject.get("publicationsAPersonne").isObject() != null) {
// Si la réponse est un objet, alors c'est une unique collection qui a été retournée
final JSONObject reponse = responseObject.get("publicationsAPersonne").isObject();
// Transformation du tableau JSON réponse en ListeInstitution
PublicationAPersonne publicationAPersonne = new PublicationAPersonne(reponse);
// et on met à jour le demandeur des données
if (seqId!=null) {
Reponse reponseRequete = new Reponse(publicationAPersonne, seqId);
vueARafraichir.rafraichir(reponseRequete);
} else {
vueARafraichir.rafraichir(publicationAPersonne);
}
} else {
Log.warn("La réponse n'est pas un objet ou un tableau JSON et vaut : "+responseValue.toString());
}
}
} else {
// Dans le cas, où nous demandons toutes les publication et qu'il n'y en a pas, nous retournons un objet vide
PublicationAPersonneListe publicationAPersonneListe = new PublicationAPersonneListe(0);
if (seqId!=null) {
Reponse reponseRequete = new Reponse(publicationAPersonneListe, seqId);
vueARafraichir.rafraichir(reponseRequete);
} else {
vueARafraichir.rafraichir(publicationAPersonneListe);
}
}
}
});
}
}
public void ajouter(String publicationId, String personnesId, String ordreAuteurs, String roleId, final Integer seqId) {
String postDonneesEncodees = "cpuap_id_publication="+URL.encodeQueryString(publicationId)
+"&cpuap_id_auteur="+URL.encodeQueryString(personnesId)
+"&cpuap_ordre="+URL.encodeQueryString(ordreAuteurs)
+"&cpuap_id_role="+URL.encodeQueryString(roleId)
+"&cmhl_ce_modifier_par="+utilisateurId;
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue reponseValeur) {
traiterReponse(reponseValeur, "ajout_publication_a_personne", seqId);
}
});
}
 
public void modifier(String publicationId, String personnesId, String ordreAuteurs, String roleId, final Integer seqId) {
String[] parametres = {publicationId, personnesId, roleId};
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
String postDonneesEncodees = "cpuap_id_publication="+URL.encodeQueryString(publicationId)
+"&cpuap_id_auteur="+URL.encodeQueryString(personnesId)
+"&cpuap_id_role="+URL.encodeQueryString(roleId)
+"&cpuap_ordre="+URL.encodeQueryString(ordreAuteurs)
+"&cmhl_ce_modifier_par="+utilisateurId;
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue reponseValeur) {
traiterReponse(reponseValeur, "modif_publication_a_personne", seqId);
}
});
}
public void supprimer(String idPublicationAPersonne) {
String[] parametres = {utilisateurId, idPublicationAPersonne};
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue responseValue) {
if (responseValue.isString() != null) {
Information info = new Information("suppression_publication_a_personne");
info.setMessage(responseValue.isString().stringValue());
vueARafraichir.rafraichir(info);
} else {
Log.warn(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.");
}
}
});
}
private void traiterReponse(JSONValue reponseValeur, String type, Integer seqId) {
Information info = new Information(type);
// Si la requête est un succès, réception d'une chaîne
if (reponseValeur.isBoolean() != null) {
info.setDonnee(reponseValeur.isBoolean().booleanValue());
} else if (reponseValeur.isString() != null) {
info.setDonnee(reponseValeur.isString().stringValue());
} else {
info.setDeboguage("La réponse n'est pas une chaine JSON.");
}
if (seqId != null) {
Reponse retourRequete = new Reponse(info, seqId);
vueARafraichir.rafraichir(retourRequete);
} else {
vueARafraichir.rafraichir(info);
}
}
}
Property changes:
Added: svn:mergeinfo
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/modeles/publication/PublicationAPersonneAsyncDao.java:r1136-1368
Merged /trunk/src/org/tela_botanica/client/modeles/publication/PublicationAPersonneAsyncDao.java:r11-934,1209-1382
Merged /branches/v1.1-aramon/src/org/tela_botanica/client/modeles/publication/PublicationAPersonneAsyncDao.java:r1383-1511
/tags/v1.6-muscardin/src/org/tela_botanica/client/modeles/publication/Publication.java
New file
0,0 → 1,224
package org.tela_botanica.client.modeles.publication;
 
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
 
import org.tela_botanica.client.modeles.aDonnee;
import org.tela_botanica.client.modeles.structure.Structure;
import org.tela_botanica.client.util.UtilString;
 
import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.json.client.JSONObject;
 
public class Publication extends aDonnee {
 
private static final long serialVersionUID = 4142843068041690126L;
public static final String PREFIXE = "cpu";
public static String[] champsObligatoires = {"cpu_id_publication"};
 
private Structure editeur = null;
public ArrayList<String> cles = null;
public Publication() {}
public Publication(boolean removePrefix) {
this.removePrefix = removePrefix;
cles = new ArrayList<String>();
cles.add("id_publication");
}
public Publication(JSONObject publication) {
initialiserModele(publication);
editeur = new Structure(publication);
cles = new ArrayList<String>();
cles.add("id_publication");
}
public Publication(ModelData model, boolean removePrefix) {
this.removePrefix = removePrefix;
cles = new ArrayList<String>();
cles.add("id_publication");
Map<String, Object> a = model.getProperties();
 
Set<String> cles = a.keySet();
Iterator<String> it = cles.iterator();
while (it.hasNext()) {
String cle = it.next();
if (a.get(cle) != null) {
String cleObjet = "";
if (removePrefix) {
cleObjet = cle.replaceFirst("^"+getPrefixe()+"_", "");
}
else {
cleObjet = cle;
String valeur = "";
if (a.get(cle) instanceof Integer) {
valeur = String.valueOf(a.get(cle));
} else if (a.get(cle) instanceof String) {
valeur = (String) a.get(cle);
}
traiterClesEtrangeres(cle, valeur);
}
this.set(cleObjet, a.get(cle));
}
}
}
// Action
//--------
// cette méthode sert dans le cas suivant : le contructeur reçoit un object ModelData
// qui contient cpuap_id_publication mais pas cpu_id_publication ou id_publication. Sans
// la méthode ci-dessous, on aurait des problèmes. Celle-ci affecte à id_publication la
// valeur des clés étrangères rencontrées (cpuap_id_publication, cpuac_id_publication, etc.)
private void traiterClesEtrangeres(String cle, String valeur) {
// on recupere le nom de la clé de la propriété (sans son prefixe)
String nomSansPrefixe = cle.replaceFirst("^[a-zA-Z]+_", "");
// on regarde si cette clé est une clé primaire de la table Publication
if (cles.contains(nomSansPrefixe)) {
// si c'est le cas et que la valeur est non nulle
if (valeur != null && !UtilString.isEmpty(valeur)) {
// on affecte la valeur de la clés étrangère à la clé primaire
if (removePrefix) {
this.set(nomSansPrefixe, valeur);
} else {
this.set(getPrefixe()+"_"+nomSansPrefixe, valeur);
}
}
}
}
protected String getPrefixe() {
return PREFIXE;
}
protected String[] getChampsObligatoires() {
return champsObligatoires;
}
public void setStructureEditeur(Structure structure) {
editeur = structure;
}
public String getId() {
return renvoyerValeurCorrecte("id_publication");
}
public void setId(String idPublication) {
setValeurCorrecte("id_publication", idPublication);
}
public String getNomComplet() {
return renvoyerValeurCorrecte("fmt_nom_complet");
}
public void setNomComplet(String nomComplet) {
setValeurCorrecte("fmt_nom_complet", nomComplet);
}
public String getURI() {
return renvoyerValeurCorrecte("uri");
}
public void setUri(String uri) {
setValeurCorrecte("uri", uri);
}
 
public String getAuteur() {
return renvoyerValeurCorrecte("fmt_auteur");
}
public void setAuteur(String auteurFormate) {
setValeurCorrecte("fmt_auteur", auteurFormate);
}
 
public String getCollection() {
return renvoyerValeurCorrecte("collection");
}
public void setCollection(String collection) {
setValeurCorrecte("collection", collection);
}
public String getTitre() {
return renvoyerValeurCorrecte("titre");
}
public void setTitre(String titre) {
setValeurCorrecte("titre", UtilString.ucFirst(titre));
}
 
public String getNomEditeur() {
String editeurNom = getEditeur();
if (editeurNom.matches("[0-9]+")) {
editeurNom = editeur.getNom();
}
return editeurNom;
}
public String getEditeur() {
return getChaineDenormaliseUnique("ce_truk_editeur");
}
public void setEditeur(String editeur) {
setChaineDenormaliseUnique("ce_truk_editeur", "AUTRE", editeur);
}
 
public String getAnneeParution() {
String annee = "";
String dateParution = this.getDateParution();
if (dateParution.matches("^[0-2][0-9]{3}(-[0-9]{2}){2}$")) {// AAAA-MM-JJ
annee = dateParution.split("-")[0];
} else if (dateParution.matches("^[0-2][0-9]{3}-[0-2][0-9]{3}$")) {// AAAA-AAAA
annee = dateParution;
} else if (dateParution.matches("^[0-2][0-9]{3}$")) {// AAAA
annee = dateParution;
} else {
annee = "";
}
return annee;
}
public void setAnneeParution(String annee) {
if (annee.matches("^[0-2][0-9]{3}(-[0-9]{2}){2}$")) {// AAAA-MM-JJ
this.setDateParution(annee);
} else if (annee.matches("^[0-2][0-9]{3}-[0-2][0-9]{3}$")) {// AAAA-AAAA
this.setDateParution(annee);
} else if (annee.matches("^[0-2][0-9]{3}$")) {// AAAA
this.setDateParution(annee);
} else {
this.setDateParution("");
}
}
public static boolean etreAnneeParutionValide(String annee) {
boolean valide = false;
if (annee.matches("^[0-2][0-9]{3}$")) {// AAAA
valide = true;
} else if (annee.matches("^[0-2][0-9]{3}-[0-2][0-9]{3}$")) {// AAAA-AAAA
valide = true;
}
return valide;
}
public String getDateParution() {
return renvoyerValeurCorrecte("date_parution");
}
public void setDateParution(String date) {
setValeurCorrecte("date_parution", date);
}
 
public String getIndicationNvt() {
return renvoyerValeurCorrecte("indication_nvt");
}
public void setIndicationNvt(String nvt) {
setValeurCorrecte("indication_nvt", nvt);
}
public String getFascicule() {
return renvoyerValeurCorrecte("fascicule");
}
public void setFascicule(String fascicule) {
setValeurCorrecte("fascicule", fascicule);
}
public String getPages() {
return renvoyerValeurCorrecte("truk_pages");
}
public void setPages(String pages) {
setValeurCorrecte("truk_pages", pages);
}
}
Property changes:
Added: svn:mergeinfo
Merged /branches/v1.1-aramon/src/org/tela_botanica/client/modeles/publication/Publication.java:r1383-1511
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/modeles/publication/Publication.java:r1136-1368
Merged /trunk/src/org/tela_botanica/client/modeles/publication/Publication.java:r11-934,1209-1382
/tags/v1.6-muscardin/src/org/tela_botanica/client/modeles/publication/PublicationListe.java
New file
0,0 → 1,129
package org.tela_botanica.client.modeles.publication;
 
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import com.google.gwt.i18n.client.Dictionary;
import org.tela_botanica.client.interfaces.ListePaginable;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.aDonneeListe;
 
import com.extjs.gxt.ui.client.Registry;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONObject;
 
/**
* Classe contenant les informations sur les Publications renvoyées par un objet de type DAO.
*
* @author Aurélien PERONNET
*
*/
public class PublicationListe extends aDonneeListe<Publication> implements ListePaginable {
 
private static final long serialVersionUID = 2600314321196345072L;
private int currentPage = 0;
private int nbElementsPage = Integer.valueOf(((Dictionary) Dictionary.getDictionary("configuration")).get("nbElementsPage"));
private int nbElementsTotal;
private Rafraichissable vueARafraichir;
public PublicationListe() {
super();
}
public PublicationListe(int taille) {
super(taille);
}
public PublicationListe(JSONArray ListeDePublications) {
super(ListeDePublications.size());
initialiserPublicationListe(ListeDePublications);
}
public PublicationListe(JSONArray ListeDePublications, JSONNumber nbElements, Rafraichissable vueARafraichir) {
super(ListeDePublications.size());
this.nbElementsTotal = Integer.valueOf(nbElements.toString());
this.vueARafraichir = vueARafraichir;
initialiserPublicationListe(ListeDePublications);
}
 
private void initialiserPublicationListe(JSONArray ListeDePublications) {
int taille = ListeDePublications.size();
for (int i = 0; i < taille; i++) {
JSONObject publicationCourante = ListeDePublications.get(i).isObject() ;
if (publicationCourante != null) {
Publication publication = new Publication(publicationCourante);
this.put(publication.getId(), publication);
}
}
}
public void changerNumeroPage(int pageCourante) {
currentPage = pageCourante;
selectionnerPublication();
}
 
public void changerTaillePage(int nouvelleTaillePage) {
nbElementsPage = nouvelleTaillePage;
selectionnerPublication();
}
public void recharger() {
selectionnerPublication();
}
public void setPageCourante(int pageCourante) {
this.currentPage = pageCourante;
}
 
public void setTaillePage(int taillePage) {
this.nbElementsPage = taillePage;
}
public int[] getPageTable() {
int[] page = new int[4];
// nombre de pages au total
page[0] = calculerNbPages();
// Page En Cours
page[1] = currentPage;
// nbElementsParPage
page[2] = nbElementsPage;
// et le dernier le nombre total d'éléments
page[3] = nbElementsTotal;
return page;
}
/**
* Calcule le nombre de pages nécessaires pour afficher un nombre d'élements
* donnés en fonction de la taille de page en cours
*
* @return le nombre de pages
*/
public int calculerNbPages() {
// À cause de la bétise de java pour les conversion implicite, on fait quelques conversions manuellement
// pour eviter qu'il arrondisse mal la division nombre de pages = (nombre d'element / taille de la page)
// arrondie à l'entier supérieur.
double nPage = (1.0 * nbElementsTotal) / (1.0 * nbElementsPage);
double nPageRound = Math.ceil(nPage);
Double nPageInt = new Double(nPageRound);
 
// Convertion en entier
return nPageInt.intValue();
}
public void selectionnerPublication() {
Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
mediateur.selectionnerPublication(vueARafraichir, null, null, currentPage, nbElementsPage, null);
}
public void filtrerParNom(String nom) {
Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
mediateur.selectionnerPublicationParNomComplet(vueARafraichir, "%" + nom + "%");
}
 
public void filtrerParNomEtPage(String nom, int pageCourante) {
currentPage = pageCourante;
Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
mediateur.selectionnerPublication(vueARafraichir, null, "%" + nom + "%", currentPage, nbElementsPage, null);
}
}
Property changes:
Added: svn:mergeinfo
Merged /branches/v1.1-aramon/src/org/tela_botanica/client/modeles/publication/PublicationListe.java:r1383-1511
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/modeles/publication/PublicationListe.java:r1136-1368
Merged /trunk/src/org/tela_botanica/client/modeles/publication/PublicationListe.java:r11-934,1209-1382
/tags/v1.6-muscardin/src/org/tela_botanica/client/modeles/publication/PublicationAsyncDao.java
New file
0,0 → 1,199
package org.tela_botanica.client.modeles.publication;
 
import java.util.HashMap;
 
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.http.JsonRestRequestBuilder;
import org.tela_botanica.client.http.JsonRestRequestCallback;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.Information;
import org.tela_botanica.client.synchronisation.Reponse;
import org.tela_botanica.client.util.Log;
import org.tela_botanica.client.util.UtilDAO;
 
import com.extjs.gxt.ui.client.Registry;
import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONValue;
 
public class PublicationAsyncDao {
private static final String SERVICE_NOM = "CoelPublication";
public static String tri = null;
private String utilisateurId = null;
private Rafraichissable vueARafraichir = null;
public PublicationAsyncDao(Rafraichissable vueARafraichirCourrante) {
Log.trace("|| PublicationAsyncDao > vueARafraichir = "+vueARafraichirCourrante.getClass().toString());
vueARafraichir = vueARafraichirCourrante ;
utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
}
 
/**
* @param paginationProgressive : définit le mode de consultation de la base de données
* - True : la consultation des données est progressive, ce qui signifie que la liste est chargée (paginée) au
* fur et à mesure de la consultation des données par l'utilisateur.
* - False : la consultation des données est classique : un seul appel à la base de données est effectué, le retour
* est renvoyé à l'appelant
* // FIXME : si la taille de la liste est supérieure à la limite du JREST (150), ce deuxieme mode ne fonctionne pas efficacement (on ne voit pas les enregistrement suivants)
*/
public void selectionner(final boolean paginationProgressive, final String publicationId, String nomComplet, final int start, final int nbElements, final Integer seqId) {
String nom = (nomComplet == null) ? "%" : nomComplet+"%";
String[] param = {publicationId, nom};
HashMap<String, String> restrictions = new HashMap<String, String>();
if (nbElements != -1) {
restrictions.put("limit", String.valueOf(nbElements));
}
 
if(tri != null) {
restrictions.put("orderby", tri);
} else {
restrictions.put("orderby", "cpu_fmt_nom_complet");
}
if (paginationProgressive) {
// GESTION DE LA REQUETE dans le cas d'une liste paginée progressive
restrictions.put("start", String.valueOf(start));
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, param, restrictions);
rb.envoyerRequete(null, new JsonRestRequestCallback() {
/** RECEPTION DE LA REPONSE **/
public void surReponse(JSONValue responseValue) {
/** Dans le cas d'une liste paginée, vueARafraichir est un objet Proxy.
* On retourne l'objet JSON au proxy afin que ce soit lui qui le traite **/
if (seqId != null) {
Log.trace("<-- PublicationAsyncDao > Liste paginée, retour au sequenceur");
Reponse reponseRequete = new Reponse(responseValue, seqId);
vueARafraichir.rafraichir(reponseRequete);
} else {
Log.trace("<-- PublicationAsyncDao > Liste paginée, retour à "+vueARafraichir.getClass().toString());
vueARafraichir.rafraichir(responseValue);
}
}
});
} else {
// GESTION DE LA REQUETE dans le cas d'une liste NON paginée progressive
restrictions.put("start", String.valueOf(start*nbElements));
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, param, restrictions);
rb.envoyerRequete(null, new JsonRestRequestCallback() {
public void surReponse(JSONValue responseValue) {
if (responseValue != null) {
JSONObject responseObject = responseValue.isObject();
if (responseObject != null) {
// Si la réponse est un tableau, alors c'est une liste de publications qui a été retournée
if (responseObject.get("publications").isArray() != null) {
JSONArray reponse = responseObject.get("publications").isArray();
PublicationListe publications;
publications = new PublicationListe(reponse, responseObject.get("nbElements").isNumber(), vueARafraichir);
publications.setTaillePage(nbElements);
publications.setPageCourante(start);
 
if (seqId != null) {
if (Mediateur.DEBUG) System.out.println("<-- PublicationAsyncDao > Liste non paginée, retour au sequenceur");
Reponse retourRequete = new Reponse(publications, seqId);
vueARafraichir.rafraichir(retourRequete);
} else {
if (Mediateur.DEBUG) System.out.println("<-- PublicationAsyncDao > Liste non paginée, retour à "+vueARafraichir.getClass().toString());
vueARafraichir.rafraichir(publications);
}
// Si la réponse est un objet, alors c'est une unique publication qui a été retournée
} else if (responseObject.get("publications").isObject() != null) {
JSONObject reponse = responseObject.get("publications").isObject();
// Transformation du tableau JSON réponse en ListeInstitution
Publication publication = new Publication(reponse);
// et on met à jour le demandeur des données
if (seqId!=null) {
Reponse reponseRequete = new Reponse(publication, seqId);
vueARafraichir.rafraichir(reponseRequete);
} else {
vueARafraichir.rafraichir(publication);
}
}
} else {
Log.warn(rb.getUrl()+"\n\tLa réponse n'est pas un objet ou un tableau JSON et vaut : "+responseValue.toString());
}
} else {
if (publicationId == null) {
PublicationListe publications = new PublicationListe(0);
vueARafraichir.rafraichir(publications);
}
}
}
});
}
}
 
public void ajouter(Publication publication, final Integer seqId) {
String postDonneesEncodees = publication.obtenirChainePOST()+"&cmhl_ce_modifier_par="+utilisateurId;
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);
 
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue reponseValeur) {
traiterReponse(reponseValeur, "ajout_publication", seqId);
}
}) ;
}
public void modifier(Publication publication, final Integer seqId) {
String[] parametres = {publication.getId()};
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
String postDonneesEncodees = publication.obtenirChainePOST()+"&cmhl_ce_modifier_par="+utilisateurId;
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue reponseValeur) {
traiterReponse(reponseValeur, "modif_publication", seqId);
}
});
}
 
public void supprimer(String publicationsId) {
String[] parametres = {utilisateurId, publicationsId};
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue reponseValeur) {
traiterReponse(reponseValeur, "suppression_publication", null);
}
});
}
private void traiterReponse(JSONValue reponseValeur, String type, Integer seqId) {
Information info = new Information(type);
 
// Si la requête est un succès, réception d'une chaîne
if (reponseValeur.isString() != null) {
String idOuMessage = reponseValeur.isString().stringValue();
if (idOuMessage.matches("^[0-9]+$")) {
info.setDonnee(idOuMessage);
} else {
info.setMessage(idOuMessage);
}
} else {
info.setDeboguage("La réponse n'est pas une chaine JSON.");
}
if (seqId != null) {
Reponse retourRequete = new Reponse(info, seqId);
vueARafraichir.rafraichir(retourRequete);
} else {
vueARafraichir.rafraichir(info);
}
}
 
}
Property changes:
Added: svn:mergeinfo
Merged /trunk/src/org/tela_botanica/client/modeles/publication/PublicationAsyncDao.java:r11-934,1209-1382
Merged /branches/v1.1-aramon/src/org/tela_botanica/client/modeles/publication/PublicationAsyncDao.java:r1383-1511
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/modeles/publication/PublicationAsyncDao.java:r1136-1368