/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); |
} |
} |