Subversion Repositories eFlore/Applications.coel

Compare Revisions

No changes between revisions

Ignore whitespace Rev 1414 → Rev 1415

/trunk/src/org/tela_botanica/client/modeles/commentaire/Commentaire.java
New file
0,0 → 1,141
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 org.tela_botanica.client.util.Debug;
 
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 static String[] champsObligatoires = {"ccm_id_commentaire"};
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;
}
protected String[] getChampsObligatoires() {
return champsObligatoires;
}
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("mark_public");
}
public void setPublic(String publique) {
this.set("mark_public", publique);
}
}
Property changes:
Added: svn:mergeinfo
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/modeles/commentaire/Commentaire.java:r1136-1368
/trunk/src/org/tela_botanica/client/modeles/commentaire/CommentaireListe.java
New file
0,0 → 1,135
package org.tela_botanica.client.modeles.commentaire;
 
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.interfaces.ListePaginable;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.aDonneeListe;
import org.tela_botanica.client.util.UtilString;
 
import com.extjs.gxt.ui.client.Registry;
import com.google.gwt.i18n.client.Dictionary;
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 Commentaires renvoyées par un objet de type DAO.
*
* @author Jean-Pascal MILCENT
*
*/
public class CommentaireListe extends aDonneeListe<Commentaire> 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 CommentaireListe() {
super();
}
public CommentaireListe(int taille) {
super(taille);
}
/**
* Constructeur pour une liste de commentaires
* @param dates
*/
public CommentaireListe(JSONArray ListeDeCommentaires) {
super(ListeDeCommentaires.size());
initialiserCommentaireListe(ListeDeCommentaires);
}
public CommentaireListe(JSONArray ListeDeCommentaires, JSONNumber nbElements, Rafraichissable vueARafraichir) {
super(ListeDeCommentaires.size());
this.nbElementsTotal = Integer.valueOf(nbElements.toString());
this.vueARafraichir = vueARafraichir;
initialiserCommentaireListe(ListeDeCommentaires);
}
private void initialiserCommentaireListe(JSONArray ListeDeCommentaires) {
boolean chargerCollectionACommentaire = true;
final int taillemax = ListeDeCommentaires.size();
for (int i = 0; i < taillemax; i++) {
JSONObject commentaireCourant = ListeDeCommentaires.get(i).isObject() ;
if (commentaireCourant != null) {
Commentaire commentaire = new Commentaire(commentaireCourant, chargerCollectionACommentaire);
if (!UtilString.isEmpty(commentaire.getCollectionACommentaire().getId())) {
this.put(commentaire.getCollectionACommentaire().getId(), commentaire);
}
else {
this.put(commentaire.getId(), commentaire);
}
}
}
}
public void changerNumeroPage(int pageCourante) {
currentPage = pageCourante;
selectionnerCommentaire();
}
 
public void changerTaillePage(int nouvelleTaillePage) {
nbElementsPage = nouvelleTaillePage;
selectionnerCommentaire();
}
public void recharger() {
selectionnerCommentaire();
}
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 selectionnerCommentaire() {
Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
mediateur.selectionnerCommentaire(vueARafraichir, null, null, currentPage, nbElementsPage, null);
}
public void filtrerParNom(String nom) {
Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
mediateur.selectionnerCommentaireParTitre(vueARafraichir, "%" + nom + "%", null);
}
}
Property changes:
Added: svn:mergeinfo
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/modeles/commentaire/CommentaireListe.java:r1136-1368
/trunk/src/org/tela_botanica/client/modeles/commentaire/CommentaireAsyncDao.java
New file
0,0 → 1,154
package org.tela_botanica.client.modeles.commentaire;
 
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.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) {
if (Mediateur.DEBUG) System.out.println("|| CommentaireAsyncDao > vueARafraichir = "+vueARafraichirCourrante.getClass().toString());
vueARafraichir = vueARafraichirCourrante ;
utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
}
 
public void selectionner(final String commentaireId, String projetId, String titre, final int pageCourante, final int nbElements, final Integer seqId) {
String[] parametres = {projetId, commentaireId, titre};
HashMap<String, String> restrictions = new HashMap<String, String>();
restrictions.put("start", String.valueOf(pageCourante*nbElements));
if (nbElements != -1) {
restrictions.put("limit", String.valueOf(nbElements));
}
restrictions.put("orderby", "cc_nom ASC");
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
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
JSONArray responseArray = responseValue.isArray();
if (responseArray.get(1).isObject() != null) {
final JSONObject reponse = responseArray.get(1).isObject();
// Transformation du tableau JSON réponse en ListeInstitution
Commentaire commentaire = new Commentaire(reponse);
// et on met à jour le demandeur des données
if (seqId != null) {
Reponse reponseRequete = new Reponse(commentaire, seqId);
vueARafraichir.rafraichir(reponseRequete);
}
else {
vueARafraichir.rafraichir(commentaire);
}
} else if (responseValue.isArray() != null) {
final JSONArray reponse = responseValue.isArray();
CommentaireListe commentaires;
if (reponse.get(1).isObject() != null) {
commentaires = new CommentaireListe(reponse.get(1).isArray());
} else {
commentaires = new CommentaireListe(reponse.get(1).isArray(), reponse.get(0).isNumber(), vueARafraichir);
}
commentaires.setTaillePage(nbElements);
commentaires.setPageCourante(pageCourante);
 
if (seqId != null) {
Reponse reponseRequete = new Reponse(commentaires, seqId);
vueARafraichir.rafraichir(reponseRequete);
}
else {
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);
if (seqId != null) {
Reponse reponseRequete = new Reponse(commentaires, seqId);
vueARafraichir.rafraichir(reponseRequete);
}
else {
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) {
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);
}
 
}
Property changes:
Added: svn:mergeinfo
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/modeles/commentaire/CommentaireAsyncDao.java:r1136-1368