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 |