| 935 | jpm | 1 | package org.tela_botanica.client.modeles.publication;
 | 
        
           | 741 | aurelien | 2 |   | 
        
           |  |  | 3 | import java.util.Iterator;
 | 
        
           | 1428 | cyprien | 4 | import java.util.Map;
 | 
        
           | 741 | aurelien | 5 | import java.util.Set;
 | 
        
           |  |  | 6 |   | 
        
           | 935 | jpm | 7 | import org.tela_botanica.client.modeles.aDonnee;
 | 
        
           |  |  | 8 | import org.tela_botanica.client.modeles.personne.Personne;
 | 
        
           | 1561 | jpm | 9 | import org.tela_botanica.client.util.Log;
 | 
        
           | 1573 | jpm | 10 | import org.tela_botanica.client.util.UtilString;
 | 
        
           | 935 | jpm | 11 |   | 
        
           | 1513 | jpm | 12 | import com.extjs.gxt.ui.client.data.ModelData;
 | 
        
           | 741 | aurelien | 13 | import com.google.gwt.json.client.JSONObject;
 | 
        
           |  |  | 14 |   | 
        
           |  |  | 15 | public class PublicationAPersonne extends aDonnee {
 | 
        
           |  |  | 16 |   | 
        
           |  |  | 17 | 	private static final long serialVersionUID = 7769105365939978129L;
 | 
        
           | 748 | jpm | 18 |   | 
        
           | 751 | jpm | 19 | 	public static final String PREFIXE = "cpuap";
 | 
        
           |  |  | 20 | 	public static final String ROLE_AUTEUR = "2360";
 | 
        
           | 992 | gduche | 21 | 	//FIXME: insérer en base de données une valeur cohérente pour l'identifiant ci-dessous
 | 
        
           |  |  | 22 | 	public static final String ROLE_SUJET = "30762";
 | 
        
           |  |  | 23 |   | 
        
           | 775 | jpm | 24 | 	private Personne personneLiee = null;
 | 
        
           | 992 | gduche | 25 | 	private Publication publicationLiee = null;
 | 
        
           | 1173 | jpm | 26 | 	public static String[] champsObligatoires = {"cpuap_id_personne", "cpuap_id_publication", "cpuap_id_role"};
 | 
        
           | 775 | jpm | 27 |   | 
        
           | 992 | gduche | 28 | 	public PublicationAPersonne() {
 | 
        
           |  |  | 29 | 		new PublicationAPersonne(new JSONObject());
 | 
        
           |  |  | 30 | 	}
 | 
        
           | 901 | jpm | 31 |   | 
        
           | 1513 | jpm | 32 | 	public PublicationAPersonne(boolean removePrefix) {
 | 
        
           |  |  | 33 | 		this.removePrefix = removePrefix;
 | 
        
           |  |  | 34 | 		new PublicationAPersonne(new JSONObject());
 | 
        
           |  |  | 35 | 	}
 | 
        
           |  |  | 36 |   | 
        
           | 741 | aurelien | 37 | 	public PublicationAPersonne(JSONObject pubAPersListe) {
 | 
        
           | 1428 | cyprien | 38 | 		Personne personne = new Personne(pubAPersListe);
 | 
        
           |  |  | 39 | 		setPersonne(personne);
 | 
        
           | 992 | gduche | 40 | 		publicationLiee = new Publication(pubAPersListe);
 | 
        
           | 775 | jpm | 41 |   | 
        
           | 741 | aurelien | 42 | 		// l'objet JSON est une table de hachage
 | 
        
           |  |  | 43 | 		Set<String> im = pubAPersListe.keySet();
 | 
        
           |  |  | 44 |   | 
        
           |  |  | 45 | 		// Parcourt pour chaque clé
 | 
        
           |  |  | 46 | 		for (Iterator<String> it = im.iterator(); it.hasNext();) {
 | 
        
           |  |  | 47 | 			// Si elle est associée à une valeur, nous l'ajoutons
 | 
        
           |  |  | 48 | 			String cle = it.next();
 | 
        
           | 1513 | jpm | 49 | 			String cleObjet = "";
 | 
        
           | 1561 | jpm | 50 | 			if (removePrefix) {
 | 
        
           |  |  | 51 | 				cleObjet = cle.replaceFirst("^"+getPrefixe()+"_", "");
 | 
        
           |  |  | 52 | 			} else {
 | 
        
           |  |  | 53 | 				cleObjet = cle;
 | 
        
           |  |  | 54 | 			}
 | 
        
           | 748 | jpm | 55 | 			// Valeur vide par défaut
 | 
        
           |  |  | 56 | 			String valeur = "";
 | 
        
           | 741 | aurelien | 57 | 			if (pubAPersListe.get(cle).isString() != null) {
 | 
        
           | 748 | jpm | 58 | 				valeur = pubAPersListe.get(cle).isString().stringValue();
 | 
        
           | 1513 | jpm | 59 | 			}
 | 
        
           |  |  | 60 | 			this.set(cleObjet, valeur);
 | 
        
           | 741 | aurelien | 61 | 		}
 | 
        
           | 992 | gduche | 62 |   | 
        
           |  |  | 63 | 		initialiserChampsPourGrille();
 | 
        
           | 741 | aurelien | 64 | 	}
 | 
        
           |  |  | 65 |   | 
        
           | 1561 | jpm | 66 | 	public PublicationAPersonne(ModelData modele, boolean removePrefix) {
 | 
        
           | 1513 | jpm | 67 | 		this.removePrefix = removePrefix;
 | 
        
           | 1561 | jpm | 68 | 		if (modele != null) {
 | 
        
           |  |  | 69 | 			Map<String, Object> modeleProprietes = modele.getProperties();
 | 
        
           |  |  | 70 |   | 
        
           |  |  | 71 | 			Set<String> cles = modeleProprietes.keySet();
 | 
        
           |  |  | 72 | 			Iterator<String> it = cles.iterator();
 | 
        
           |  |  | 73 | 			while (it.hasNext()) {
 | 
        
           |  |  | 74 | 				String cle = it.next();
 | 
        
           | 1573 | jpm | 75 | 				Object valeur = modeleProprietes.get(cle);
 | 
        
           | 1561 | jpm | 76 | 				if (modeleProprietes.get(cle) != null) {
 | 
        
           |  |  | 77 | 					String cleObjet = "";
 | 
        
           |  |  | 78 | 					if (removePrefix) {
 | 
        
           | 1568 | jpm | 79 | 						cleObjet = cleObjet.replaceFirst("^"+getPrefixe()+"_", "");
 | 
        
           | 1561 | jpm | 80 | 					} else {
 | 
        
           |  |  | 81 | 						cleObjet = cle;
 | 
        
           |  |  | 82 | 					}
 | 
        
           | 1573 | jpm | 83 | 					this.set(cleObjet, valeur);
 | 
        
           | 1513 | jpm | 84 | 				}
 | 
        
           |  |  | 85 | 			}
 | 
        
           | 1561 | jpm | 86 | 			setPersonne(new Personne(modele, removePrefix));
 | 
        
           |  |  | 87 | 			setPublicationLiee(new Publication(modele, removePrefix));
 | 
        
           | 1573 | jpm | 88 | 			initialiserChampsPourGrille();
 | 
        
           | 1561 | jpm | 89 | 			this.set("_role_", modeleProprietes.get("_role_"));
 | 
        
           |  |  | 90 | 			this.set("_etat_", modeleProprietes.get("_etat_"));
 | 
        
           |  |  | 91 | 		} else {
 | 
        
           |  |  | 92 | 			Log.debug("Le modèle passé en paramètre ne doit pas être vide");
 | 
        
           | 1513 | jpm | 93 | 		}
 | 
        
           |  |  | 94 | 	}
 | 
        
           | 992 | gduche | 95 |   | 
        
           |  |  | 96 | 	private void initialiserChampsPourGrille() {
 | 
        
           | 1513 | jpm | 97 | 		if (removePrefix) {
 | 
        
           |  |  | 98 | 			set("fmt_auteur", publicationLiee.getAuteur());
 | 
        
           |  |  | 99 | 			set("titre", publicationLiee.getTitre());
 | 
        
           |  |  | 100 | 			set("collection", publicationLiee.getCollection());
 | 
        
           |  |  | 101 | 			set("_editeur_", "");
 | 
        
           |  |  | 102 | 			set("_annee_", "");
 | 
        
           |  |  | 103 | 			set("indication_nvt", publicationLiee.getIndicationNvt());
 | 
        
           |  |  | 104 | 			set("fascicule", publicationLiee.getFascicule());
 | 
        
           |  |  | 105 | 			set("truk_pages", publicationLiee.getPages());
 | 
        
           |  |  | 106 | 			set("_etat_", "");
 | 
        
           | 1561 | jpm | 107 | 			set("_role_", this.getIdRole());
 | 
        
           | 1513 | jpm | 108 | 		} else {
 | 
        
           |  |  | 109 | 			set("cpu_fmt_auteur", publicationLiee.getAuteur());
 | 
        
           |  |  | 110 | 			set("cpu_titre", publicationLiee.getTitre());
 | 
        
           |  |  | 111 | 			set("cpu_collection", publicationLiee.getCollection());
 | 
        
           |  |  | 112 | 			set("_editeur_", "");
 | 
        
           |  |  | 113 | 			set("_annee_", "");
 | 
        
           |  |  | 114 | 			set("cpu_indication_nvt", publicationLiee.getIndicationNvt());
 | 
        
           |  |  | 115 | 			set("cpu_fascicule", publicationLiee.getFascicule());
 | 
        
           |  |  | 116 | 			set("cpu_truk_pages", publicationLiee.getPages());
 | 
        
           |  |  | 117 | 			set("_etat_", "");
 | 
        
           | 1561 | jpm | 118 | 			set("_role_", this.getIdRole());
 | 
        
           | 1513 | jpm | 119 | 		}
 | 
        
           | 992 | gduche | 120 | 	}
 | 
        
           |  |  | 121 |   | 
        
           | 748 | jpm | 122 | 	@Override
 | 
        
           |  |  | 123 | 	protected String getPrefixe() {
 | 
        
           |  |  | 124 | 		return PREFIXE;
 | 
        
           |  |  | 125 | 	}
 | 
        
           |  |  | 126 |   | 
        
           | 1173 | jpm | 127 | 	protected String[] getChampsObligatoires()	{
 | 
        
           |  |  | 128 | 		return champsObligatoires;
 | 
        
           |  |  | 129 | 	}
 | 
        
           |  |  | 130 |   | 
        
           | 775 | jpm | 131 | 	public Personne getPersonne() {
 | 
        
           |  |  | 132 | 		return personneLiee;
 | 
        
           | 748 | jpm | 133 | 	}
 | 
        
           | 1513 | jpm | 134 |   | 
        
           | 775 | jpm | 135 | 	public void setPersonne(Personne personne) {
 | 
        
           | 1513 | jpm | 136 | 		setPersonne(personne, false);
 | 
        
           |  |  | 137 | 	}
 | 
        
           |  |  | 138 |   | 
        
           |  |  | 139 | 	public void setPersonne(Personne personne, boolean integrerProprietes) {
 | 
        
           | 775 | jpm | 140 | 		personneLiee = personne;
 | 
        
           | 901 | jpm | 141 | 		if (personne != null) {
 | 
        
           | 1573 | jpm | 142 | 			Log.debug("Tentative ajout id personne : "+personne.getId());
 | 
        
           | 901 | jpm | 143 | 			setIdPersonne(personne.getId());
 | 
        
           |  |  | 144 | 		}
 | 
        
           | 1428 | cyprien | 145 |   | 
        
           | 1513 | jpm | 146 | 		if (integrerProprietes) {
 | 
        
           |  |  | 147 | 			Map<String, Object> a = personne.getProperties();
 | 
        
           |  |  | 148 |   | 
        
           |  |  | 149 | 			Set<String> cles = a.keySet();
 | 
        
           |  |  | 150 | 			Iterator<String> it = cles.iterator();
 | 
        
           |  |  | 151 | 			while (it.hasNext()) {
 | 
        
           |  |  | 152 | 				String cle = it.next();
 | 
        
           |  |  | 153 | 				if (a.get(cle) != null) {
 | 
        
           |  |  | 154 | 					String cleObjet = "";
 | 
        
           |  |  | 155 | 					if (removePrefix) {
 | 
        
           |  |  | 156 | 						cleObjet = cle.replaceFirst("^"+Personne.PREFIXE+"_", "");
 | 
        
           | 1568 | jpm | 157 | 					} else {
 | 
        
           | 1513 | jpm | 158 | 						cleObjet = cle;
 | 
        
           |  |  | 159 | 					}
 | 
        
           |  |  | 160 | 					this.set(cleObjet, a.get(cle));
 | 
        
           |  |  | 161 | 				}
 | 
        
           | 1428 | cyprien | 162 | 			}
 | 
        
           |  |  | 163 | 		}
 | 
        
           | 741 | aurelien | 164 | 	}
 | 
        
           |  |  | 165 |   | 
        
           | 901 | jpm | 166 | 	// ID
 | 
        
           |  |  | 167 | 	public String getId() {
 | 
        
           |  |  | 168 | 		String idPublication = getIdPublication();
 | 
        
           |  |  | 169 | 		String idPersonne = getIdPersonne();
 | 
        
           |  |  | 170 | 		String idRole = getIdRole();
 | 
        
           |  |  | 171 | 		if (idPublication.equals("") && idPersonne.equals("") && idRole.equals("")) {
 | 
        
           |  |  | 172 | 			return null;
 | 
        
           |  |  | 173 | 		} else {
 | 
        
           |  |  | 174 | 			return (idPublication+"-"+idPersonne+"-"+idRole);
 | 
        
           |  |  | 175 | 		}
 | 
        
           |  |  | 176 | 	}
 | 
        
           |  |  | 177 |   | 
        
           |  |  | 178 | 	// ID PUBLICATION
 | 
        
           |  |  | 179 | 	public String getIdPublication() {
 | 
        
           | 1573 | jpm | 180 | 		String valeur =  renvoyerValeurCorrecte("id_publication");
 | 
        
           |  |  | 181 | 		return UtilString.isEmpty(valeur) ? "0" : valeur;
 | 
        
           | 901 | jpm | 182 | 	}
 | 
        
           |  |  | 183 | 	public void setIdPublication(String id) {
 | 
        
           | 1561 | jpm | 184 | 		setValeurCorrecte("id_publication", id);
 | 
        
           | 901 | jpm | 185 | 	}
 | 
        
           |  |  | 186 |   | 
        
           | 992 | gduche | 187 | 	// PUBLICATION LIEE
 | 
        
           | 1561 | jpm | 188 | 	public Publication getPublicationLiee() {
 | 
        
           | 992 | gduche | 189 | 		return this.publicationLiee;
 | 
        
           |  |  | 190 | 	}
 | 
        
           |  |  | 191 |   | 
        
           |  |  | 192 | 	// LIER PUBLICATION
 | 
        
           |  |  | 193 | 	public void setPublicationLiee(Publication publication)	{
 | 
        
           |  |  | 194 | 		this.publicationLiee = publication;
 | 
        
           |  |  | 195 | 		initialiserChampsPourGrille();
 | 
        
           |  |  | 196 | 	}
 | 
        
           |  |  | 197 |   | 
        
           | 901 | jpm | 198 | 	// ID PERSONNE
 | 
        
           |  |  | 199 | 	public String getIdPersonne() {
 | 
        
           | 1573 | jpm | 200 | 		String valeur = renvoyerValeurCorrecte("id_personne");
 | 
        
           |  |  | 201 | 		return UtilString.isEmpty(valeur) ? "0" : valeur;
 | 
        
           | 901 | jpm | 202 | 	}
 | 
        
           |  |  | 203 | 	public void setIdPersonne(String id) {
 | 
        
           | 1561 | jpm | 204 | 		setValeurCorrecte("id_personne", id);
 | 
        
           | 901 | jpm | 205 | 	}
 | 
        
           |  |  | 206 |   | 
        
           |  |  | 207 | 	// ID RôLE
 | 
        
           |  |  | 208 | 	public String getIdRole() {
 | 
        
           | 1573 | jpm | 209 | 		String valeur = renvoyerValeurCorrecte("id_role");
 | 
        
           |  |  | 210 | 		return UtilString.isEmpty(valeur) ? "0" : valeur;
 | 
        
           | 901 | jpm | 211 | 	}
 | 
        
           |  |  | 212 | 	public void setIdRole(String id) {
 | 
        
           | 1561 | jpm | 213 | 		setValeurCorrecte("id_role", id);
 | 
        
           |  |  | 214 | 		this.set("_role_", id);
 | 
        
           | 901 | jpm | 215 | 	}
 | 
        
           | 1561 | jpm | 216 |   | 
        
           |  |  | 217 | 	// ROLE
 | 
        
           |  |  | 218 | 	public String getRole() {
 | 
        
           |  |  | 219 | 		String role = this.get("_role_");
 | 
        
           |  |  | 220 | 		if (role != null)	{
 | 
        
           |  |  | 221 | 			return role;
 | 
        
           |  |  | 222 | 		} else 	{
 | 
        
           |  |  | 223 | 			return "";
 | 
        
           |  |  | 224 | 		}
 | 
        
           |  |  | 225 | 	}
 | 
        
           | 901 | jpm | 226 |   | 
        
           |  |  | 227 | 	// TYPE
 | 
        
           |  |  | 228 | 	public String getType() {
 | 
        
           |  |  | 229 | 		return renvoyerValeurCorrecte("ce_truk_type");
 | 
        
           |  |  | 230 | 	}
 | 
        
           |  |  | 231 | 	public void setType(String type) {
 | 
        
           | 1561 | jpm | 232 | 		setValeurCorrecte("ce_truk_type", type);
 | 
        
           | 901 | jpm | 233 | 	}
 | 
        
           |  |  | 234 | 	public void setFonction(String type, String valeur) {
 | 
        
           |  |  | 235 | 		setChaineDenormaliseUnique("ce_truk_type", type, valeur);
 | 
        
           |  |  | 236 | 	}
 | 
        
           | 1428 | cyprien | 237 |   | 
        
           |  |  | 238 | 	// ORDRE DES AUTEURS
 | 
        
           |  |  | 239 | 	public String getOrdreAuteurs() {
 | 
        
           | 1561 | jpm | 240 | 		return renvoyerValeurCorrecte("ordre");
 | 
        
           | 1428 | cyprien | 241 | 	}
 | 
        
           |  |  | 242 | 	public void setOrdreAuteurs(String ordre) {
 | 
        
           |  |  | 243 | 		if (ordre.matches("[0-9]+")) {
 | 
        
           | 1561 | jpm | 244 | 			setValeurCorrecte("ordre", ordre);
 | 
        
           | 1513 | jpm | 245 | 			this.set("_ordre_", ordre);
 | 
        
           | 1428 | cyprien | 246 | 		}
 | 
        
           |  |  | 247 | 	}
 | 
        
           | 775 | jpm | 248 | }
 |