New file |
0,0 → 1,210 |
package org.tela_botanica.client.modeles.structure; |
|
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.Debug; |
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.http.client.URL; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONObject; |
import com.google.gwt.json.client.JSONValue; |
|
public class StructureAPersonneAsyncDao { |
private static final String SERVICE_NOM = "CoelStructureAPersonne"; |
|
private String utilisateurId = null; |
private Rafraichissable vueARafraichir = null; |
|
public StructureAPersonneAsyncDao(Rafraichissable vueARafraichirCourrante) { |
if (Mediateur.DEBUG) System.out.println("|| StructureAPersonneAsyncDao > vueARafraichir = "+vueARafraichirCourrante.getClass().toString()); |
vueARafraichir = vueARafraichirCourrante; |
utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId(); |
} |
|
|
public void selectionner(final boolean paginationProgressive, final String structureId, final String roleId, final String recherche, final int start, final int nbElements, final Integer seqId) { |
|
String[] parametres = {structureId, roleId}; |
|
HashMap<String, String> restrictions = new HashMap<String, String>(); |
|
if (nbElements != -1) { |
restrictions.put("limit", String.valueOf(nbElements)); |
} |
|
restrictions.put("orderby", "cp_nom"); |
|
/** GESTION DE LA REQUETE dans le cas d'une liste paginée progressive **/ |
if (paginationProgressive) { |
|
/** DEFINITION DU TUPLE DE DEPART **/ |
restrictions.put("start", String.valueOf(start)); |
|
/** CONSTRUCTION DE LA REQUETE **/ |
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions); |
|
/** ENVOI DE LA REQUETE **/ |
rb.envoyerRequete(null, new JsonRestRequestCallback() |
{ |
/** RECEPTION DE LA REPONSE **/ |
public void surReponse(JSONValue responseValue) |
{ |
/** Dans le cas d'une liste paginée, vueARafraichir est un objet Proxy. |
* On retourne l'objet JSON au proxy afin que ce soit lui qui le traite **/ |
if (seqId != null) { |
if (Mediateur.DEBUG) System.out.println("<-- StructureAPersonneAsyncDao > Liste paginée, retour au sequenceur"); |
Reponse reponseRequete = new Reponse(responseValue, seqId); |
vueARafraichir.rafraichir(reponseRequete); |
} |
else { |
if (Mediateur.DEBUG) System.out.println("<-- StructureAPersonneAsyncDao > Liste paginée, retour à "+vueARafraichir.getClass().toString()); |
vueARafraichir.rafraichir(responseValue); |
} |
} |
}); |
} |
/** GESTION DE LA REQUETE dans le cas d'une liste NON paginée progressive **/ |
else { |
|
/** DEFINITION DU TUPLE DE DEPART **/ |
restrictions.put("start", String.valueOf(start*nbElements)); |
|
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions); |
|
rb.envoyerRequete(null, new JsonRestRequestCallback() { |
@Override |
public void surReponse(JSONValue responseValue) { |
|
Information info = new Information("liste_structure_a_personne"); |
|
if (responseValue != null) { |
|
JSONObject responseObject = responseValue.isObject(); |
|
if (responseObject != null) { |
|
// Si la réponse est un tableau, alors c'est une liste de Structures qui a été retournée |
if (responseObject.get("structuresAPersonne").isArray() != null) { |
|
final JSONArray reponse = responseObject.get("structuresAPersonne").isArray(); |
// Transformation du tableau JSON réponse en ListeInstitution |
StructureAPersonneListe personnes = new StructureAPersonneListe(reponse); |
info.setDonnee(0, personnes); |
// et on met à jour le demandeur des données |
if (seqId != null) { |
Reponse reponseRequete = new Reponse(info, seqId); |
vueARafraichir.rafraichir(reponseRequete); |
} |
else { |
vueARafraichir.rafraichir(info); |
} |
|
// Si la réponse est un objet, alors c'est une unique Structure qui a été retournée |
} else if (responseObject.get("structuresAPersonne").isObject() != null) { |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un tableau JSON et vaut : "+responseValue.toString(), null); |
} |
} |
} else { |
// Dans le cas, où nous demandons toutes les institutions et qu'il n'y en a pas, nous retournons un objet vide |
if (structureId == null) { |
// Dans le cas, où nous demandons toutes les relations Structure à Personne et qu'il n'y en a pas, nous retournons un message d'information |
info.setMessage("Aucun personnel"); |
vueARafraichir.rafraichir(info); |
} |
} |
} |
}); |
} |
} |
|
|
public void ajouter(String structureId, StructureAPersonne personnel) { |
String postDonneesEncodees = construirePost(structureId, personnel); |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM); |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() { |
@Override |
public void surReponse(JSONValue responseValue) { |
// Si la requête est un succès, reception d'une chaine |
if (responseValue.isString() != null) { |
Information info = new Information("ajout_structure_a_personne"); |
info.setMessage(responseValue.isString().stringValue()); |
vueARafraichir.rafraichir(info); |
} else { |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null); |
} |
} |
}); |
} |
|
public void modifier(StructureAPersonne personnel) { |
String[] parametres = {personnel.getIdStructure(), personnel.getIdPersonne(), personnel.getIdRole()}; |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres); |
|
String postDonneesEncodees = construirePost(personnel.getIdStructure(), personnel); |
|
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() { |
@Override |
public void surReponse(JSONValue responseValue) { |
Information info = new Information("modif_structure_a_personne"); |
// Si la requête est un succès, reception d'une chaine |
if (responseValue.isString() != null) { |
info.setMessage(responseValue.isString().stringValue()); |
vueARafraichir.rafraichir(info); |
} else { |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null); |
} |
} |
}); |
} |
|
public void supprimer(String idStrAPer) { |
String[] parametres = {utilisateurId, idStrAPer}; |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres); |
rb.envoyerRequeteSuppression(new JsonRestRequestCallback() { |
@Override |
public void surReponse(JSONValue responseValue) { |
if (responseValue.isString() != null) { |
Information info = new Information("suppression_structure_a_personne"); |
info.setMessage(responseValue.isString().stringValue()); |
vueARafraichir.rafraichir(info); |
} else { |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null); |
} |
} |
}); |
} |
|
private String construirePost(String structureId, StructureAPersonne personnel) { |
String postDonnees = "cmhl_ce_modifier_par=" + URL.encodeComponent(utilisateurId); |
if (!personnel.getIdPersonne().equals("")) { |
postDonnees += "&csap_id_personne=" + URL.encodeComponent(personnel.getIdPersonne()) + |
"&cp_id_personne=" + URL.encodeComponent(personnel.getIdPersonne()); |
} |
postDonnees += "&csap_id_structure=" + URL.encodeComponent(structureId) + |
"&csap_id_role=" + URL.encodeComponent(personnel.getIdRole()) + |
"&csap_ce_truk_fonction=" + URL.encodeComponent(personnel.getFonction()) + |
"&csap_service=" + URL.encodeComponent(personnel.getService()) + |
"&csap_ce_truk_statut=" + URL.encodeComponent(personnel.getStatut()) + |
"&csap_mark_contact=" + URL.encodeComponent(personnel.getContact()) + |
"&csap_bota_travail_hebdo_tps=" + URL.encodeComponent(personnel.getBotaTravailHebdoTps()) + |
"&cp_prenom=" + URL.encodeComponent(personnel.getPrenom()) + |
"&cp_nom=" + URL.encodeComponent(personnel.getNom()) + |
"&cp_fmt_nom_complet=" + URL.encodeComponent(personnel.getNomComplet()) + |
"&cp_truk_telephone=" + URL.encodeComponent(personnel.getTelephone()) + |
"&cp_truk_courriel=" + URL.encodeComponent(personnel.getCourriel()) + |
"&cp_ce_truk_specialite=" + URL.encodeComponent(personnel.getSpecialite()) + |
"&cp_ce_deces=" + URL.encodeComponent(personnel.getDeces()) + |
""; |
return postDonnees; |
} |
} |
Property changes: |
Added: svn:mergeinfo |
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/modeles/structure/StructureAPersonneAsyncDao.java:r1136-1368 |
Merged /trunk/src/org/tela_botanica/client/modeles/structure/StructureAPersonneAsyncDao.java:r11-934,1209-1382 |
Merged /branches/v1.1-aramon/src/org/tela_botanica/client/modeles/structure/StructureAPersonneAsyncDao.java:r1383-1511 |