/trunk/src/org/tela_botanica/client/modeles/MenuApplicationId.java |
---|
8,4 → 8,5 |
public static final String COLLECTION = "Collections"; |
public static final String PERSONNE = "Personnes"; |
public static final String PUBLICATION = "Publications"; |
public static final String COMMENTAIRE = "Commentaires"; |
} |
/trunk/src/org/tela_botanica/client/modeles/collection/CollectionACommentaire.java |
---|
New file |
0,0 → 1,105 |
package org.tela_botanica.client.modeles.collection; |
import org.tela_botanica.client.modeles.aDonnee; |
import org.tela_botanica.client.modeles.commentaire.Commentaire; |
import com.google.gwt.json.client.JSONObject; |
public class CollectionACommentaire extends aDonnee { |
private static final long serialVersionUID = 8751553802444398035L; |
public static final String PREFIXE = "ccac"; |
private Commentaire commentaireLiee = null; |
public CollectionACommentaire() { |
initialiser(new JSONObject(), false); |
} |
public CollectionACommentaire(JSONObject collectionACommentaireListe) { |
initialiser(collectionACommentaireListe, false); |
} |
public CollectionACommentaire(JSONObject collectionACommentaireListe, boolean chargerCommentaire) { |
initialiser(collectionACommentaireListe, chargerCommentaire); |
} |
@Override |
protected String getPrefixe() { |
return PREFIXE; |
} |
private void initialiser(JSONObject collectionACommentaireListe, boolean chargerCommentaire) { |
if (chargerCommentaire) { |
setCommentaire(new Commentaire(collectionACommentaireListe, false)); |
} else { |
setCommentaire(new Commentaire()); |
} |
initialiserModele(collectionACommentaireListe); |
initialiserChampsPourGrille(); |
} |
// COMMENTAIRE |
public Commentaire getCommentaire() { |
return commentaireLiee; |
} |
public void setCommentaire(Commentaire commentaire) { |
commentaireLiee = commentaire; |
initialiserChampsPourGrille(); |
if (commentaire != null) { |
setIdCommentaire(commentaire.getId()); |
} |
} |
private void initialiserChampsPourGrille() { |
set("_type_", getType()); |
set("_titre_", getCommentaire().getTitre()); |
set("_texte_", getCommentaire().getTexte()); |
set("_ponderation_", getCommentaire().getPonderation()); |
set("_public_", getCommentaire().getPublic()); |
set("_etat_", ""); |
} |
// ID |
/** Génère un identifiant de CollectionACommentaire. |
* |
* C'est une concaténation des clés primaires de la table coel_collection_a_commentaire séparées par un tiret "-". |
* |
* @return identifiant unique d'une relation "collection à commentaire". |
*/ |
public String getId() { |
String idCollection = getIdCollection(); |
String idCommentaire = getIdCommentaire(); |
if (idCollection.equals("") && idCommentaire.equals("")) { |
return null; |
} else { |
return (idCollection+"-"+idCommentaire); |
} |
} |
//+---------------------------------------------------------------------------------------------------------------+ |
// CHAMPS PROVENANT de la TABLE COEL_COLLECTION_A_COMMENTAIRE |
// ID COLLECTION |
public String getIdCollection() { |
return renvoyerValeurCorrecte("id_collection"); |
} |
public void setIdCollection(String idCollection) { |
set("id_collection", idCollection); |
} |
// ID COMENTAIRE |
public String getIdCommentaire() { |
return renvoyerValeurCorrecte("id_commentaire"); |
} |
public void setIdCommentaire(String ic) { |
set("id_commentaire", ic); |
} |
// TRUCK TYPE |
public String getType() { |
return renvoyerValeurCorrecte("truk_type"); |
} |
public void setType(String type) { |
set("truk_type", type); |
} |
} |
/trunk/src/org/tela_botanica/client/modeles/collection/CollectionACommentaireListe.java |
---|
New file |
0,0 → 1,34 |
package org.tela_botanica.client.modeles.collection; |
import org.tela_botanica.client.modeles.aDonneeListe; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONObject; |
public class CollectionACommentaireListe extends aDonneeListe<CollectionACommentaire> { |
private static final long serialVersionUID = 1L; |
public CollectionACommentaireListe() { |
super(); |
} |
public CollectionACommentaireListe(int taille) { |
super(taille); |
} |
public CollectionACommentaireListe(JSONArray collectionACommentaires) { |
super(collectionACommentaires.size()) ; |
final int taillemax = collectionACommentaires.size(); |
for (int i = 0; i < taillemax; i++) { |
JSONObject collectionACommentaireCourant = collectionACommentaires.get(i).isObject() ; |
if (collectionACommentaireCourant != null) { |
CollectionACommentaire collectionACommentaire = new CollectionACommentaire(collectionACommentaireCourant); |
this.put(collectionACommentaire.getId(), collectionACommentaire); |
} |
} |
} |
} |
/trunk/src/org/tela_botanica/client/modeles/commentaire/Commentaire.java |
---|
New file |
0,0 → 1,133 |
package org.tela_botanica.client.modeles.commentaire; |
import org.tela_botanica.client.Mediateur; |
import org.tela_botanica.client.modeles.aDonnee; |
import org.tela_botanica.client.modeles.collection.Collection; |
import org.tela_botanica.client.modeles.collection.CollectionACommentaire; |
import com.google.gwt.json.client.JSONObject; |
public class Commentaire extends aDonnee { |
private static final long serialVersionUID = 7216356814682582569L; |
private static final String PREFIXE = "ccm"; |
private Collection collection = null; |
private CollectionACommentaire collectionACommentaire = null; |
public Commentaire() { |
} |
public Commentaire(JSONObject commentaire) { |
initialiserCommentaire(commentaire, false); |
} |
public Commentaire(JSONObject commentaire, boolean chargerCollectionACommentaire) { |
initialiserCommentaire(commentaire, chargerCollectionACommentaire); |
} |
public void initialiserCommentaire(JSONObject commentaire, boolean chargerCollectionACommentaire) { |
initialiserModele(commentaire); |
collection = new Collection(commentaire); |
if (chargerCollectionACommentaire) { |
collectionACommentaire = new CollectionACommentaire(commentaire); |
} else { |
collectionACommentaire = new CollectionACommentaire(); |
} |
initialiserChampsPourGrille(); |
} |
@Override |
protected String getPrefixe() { |
return PREFIXE; |
} |
private void initialiserChampsPourGrille() { |
set("_collection_nom_", getCollection().getNom()); |
set("_type_", getCollectionACommentaire().getType()); |
set("_titre_", getTitre()); |
set("_texte_", getTexteResume()); |
set("_ponderation_", getPonderation()); |
set("_public_", getPublic()); |
set("_etat_", ""); |
} |
public Collection getCollection() { |
if (collection == null) { |
collection = new Collection(); |
} |
return collection; |
} |
public void setCollection(Collection collectionAStocker) { |
collection = collectionAStocker; |
} |
public CollectionACommentaire getCollectionACommentaire() { |
if (collectionACommentaire == null) { |
collectionACommentaire = new CollectionACommentaire(); |
} |
return collectionACommentaire; |
} |
public void setCollectionACommentaire(CollectionACommentaire collectionACommentaireAStocker) { |
collectionACommentaire = collectionACommentaireAStocker; |
} |
public String getId() { |
return renvoyerValeurCorrecte("id_commentaire"); |
} |
public void setId(String idCommentaire) { |
this.set("id_commentaire", idCommentaire); |
} |
public String getIdProjet() { |
return renvoyerValeurCorrecte("ce_projet"); |
} |
public void setIdProjet(String idProjet) { |
this.set("ce_projet", idProjet); |
} |
public String getCommentairePereId() { |
return renvoyerValeurCorrecte("ce_pere"); |
} |
public void setCommentairePereId(String idPere) { |
this.set("ce_pere", idPere); |
} |
public String getTitre() { |
return renvoyerValeurCorrecte("titre"); |
} |
public void setTitre(String titre) { |
this.set("titre", titre); |
} |
public String getTexteResume() { |
String resume = getTexte(); |
if (getTexte().length() > 100) { |
resume = getTexte().substring(0, 100); |
} |
return resume; |
} |
public String getTexte() { |
return renvoyerValeurCorrecte("texte"); |
} |
public void setTexte(String texte) { |
this.set("texte", texte); |
} |
public String getPonderation() { |
return renvoyerValeurCorrecte("ponderation"); |
} |
public void setPonderation(String ponderation) { |
this.set("ponderation", ponderation); |
} |
public boolean etrePublic() { |
return (getPublic().equals("1") ? true : false); |
} |
public String getPublic() { |
return renvoyerValeurCorrecte("public"); |
} |
public void setPublic(String publique) { |
this.set("public", publique); |
} |
} |
/trunk/src/org/tela_botanica/client/modeles/commentaire/CommentaireListe.java |
---|
New file |
0,0 → 1,38 |
package org.tela_botanica.client.modeles.commentaire; |
import org.tela_botanica.client.modeles.aDonneeListe; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONObject; |
public class CommentaireListe extends aDonneeListe<Commentaire> { |
private static final long serialVersionUID = 2600314321196345072L; |
public CommentaireListe() { |
super(); |
} |
public CommentaireListe(int taille) { |
super(taille); |
} |
/** |
* Constructeur pour une liste de commentaires |
* @param dates |
*/ |
public CommentaireListe(JSONArray commentaires) { |
super(commentaires.size()); |
boolean chargerCollectionACommentaire = true; |
int taille = commentaires.size(); |
for (int i = 0; i < taille; i++) { |
JSONObject commentaireCourant = commentaires.get(i).isObject() ; |
if (commentaireCourant != null) { |
Commentaire commentaire = new Commentaire(commentaireCourant, chargerCollectionACommentaire); |
this.put(commentaire.getId(), commentaire); |
} |
} |
} |
} |
/trunk/src/org/tela_botanica/client/modeles/commentaire/CommentaireAsyncDao.java |
---|
New file |
0,0 → 1,115 |
package org.tela_botanica.client.modeles.commentaire; |
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.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 CommentaireAsyncDao { |
private static final String SERVICE_NOM = "CoelCommentaire"; |
private String utilisateurId = null; |
private Rafraichissable vueARafraichir = null; |
public CommentaireAsyncDao(Rafraichissable vueARafraichirCourrante) { |
vueARafraichir = vueARafraichirCourrante ; |
utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId(); |
} |
public void selectionner(final String commentaireId, String projetId) { |
String[] parametres = {projetId, commentaireId}; |
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres); |
rb.envoyerRequete(null, new JsonRestRequestCallback() { |
@Override |
public void surReponse(JSONValue responseValue) { |
if (responseValue != null) { |
// Si la requête est un succès, réception d'un objet ou d'un tableau |
if (responseValue.isObject() != null) { |
final JSONObject reponse = responseValue.isObject(); |
// Transformation du tableau JSON réponse en ListeInstitution |
Commentaire commentaire = new Commentaire(reponse); |
// et on met à jour le demandeur des données |
vueARafraichir.rafraichir(commentaire); |
} else if (responseValue.isArray() != null) { |
final JSONArray reponse = responseValue.isArray(); |
CommentaireListe commentaires = new CommentaireListe(reponse); |
vueARafraichir.rafraichir(commentaires); |
} else { |
GWT.log("La réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null); |
} |
} else { |
// Dans le cas, où nous demandons toutes les publication et qu'il n'y en a pas, nous retournons un objet vide |
if (commentaireId == null) { |
CommentaireListe commentaires = new CommentaireListe(0); |
vueARafraichir.rafraichir(commentaires); |
} |
} |
} |
}); |
} |
public void ajouter(Commentaire commentaire) { |
String postDonneesEncodees = commentaire.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_commentaire"); |
} |
}) ; |
} |
public void modifier(Commentaire commentaire) { |
String[] parametres = {commentaire.getId()}; |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres); |
String postDonneesEncodees = commentaire.obtenirChainePOST()+"&cmhl_ce_modifier_par="+utilisateurId; |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() { |
@Override |
public void surReponse(JSONValue reponseValeur) { |
traiterReponse(reponseValeur, "modif_commentaire"); |
} |
}); |
} |
public void supprimer(String commentairesId) { |
String[] parametres = {utilisateurId, commentairesId}; |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres); |
rb.envoyerRequeteSuppression(new JsonRestRequestCallback() { |
@Override |
public void surReponse(JSONValue reponseValeur) { |
traiterReponse(reponseValeur, "suppression_commentaire"); |
} |
}); |
} |
private void traiterReponse(JSONValue reponseValeur, String type) { |
Information info = new Information(type); |
// Si la requête est un succès, réception d'une chaîne |
if (reponseValeur.isString() != null) { |
info.setDonnee(reponseValeur.isString().stringValue()); |
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."); |
} |
vueARafraichir.rafraichir(info); |
} |
} |