Rev 767 | Rev 1262 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package org.tela_botanica.client.modeles.structure;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.http.client.URL;import com.google.gwt.json.client.JSONArray;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) {vueARafraichir = vueARafraichirCourrante;utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();}public void selectionner(final String structureId, final String roleId) {String[] parametres = {structureId, roleId};final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);rb.envoyerRequete(null, new JsonRestRequestCallback() {@Overridepublic void surReponse(JSONValue responseValue) {Information info = new Information("liste_structure_a_personne");if (responseValue != null) {// Si la requête est un succès, reception d'un tableauif (responseValue.isArray() != null) {final JSONArray reponse = responseValue.isArray();// Transformation du tableau JSON réponse en ListeInstitutionStructureAPersonneListe personnel = new StructureAPersonneListe(reponse);info.setDonnee(0, personnel);// et on met à jour le demandeur des donnéesvueARafraichir.rafraichir(info);} else {GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un talbeau JSON et vaut : "+responseValue.toString(), null);}} else {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'informationinfo.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() {@Overridepublic void surReponse(JSONValue responseValue) {// Si la requête est un succès, reception d'une chaineif (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() {@Overridepublic void surReponse(JSONValue responseValue) {Information info = new Information("modif_structure_a_personne");// Si la requête est un succès, reception d'une chaineif (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() {@Overridepublic 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_ce_projet=" + URL.encodeComponent(personnel.getIdProjetPersonne()) +"&cp_prenom=" + URL.encodeComponent(personnel.getPrenom()) +"&cp_nom=" + URL.encodeComponent(personnel.getNom()) +"&cp_truk_telephone=" + URL.encodeComponent(personnel.getTelephone()) +"&cp_truk_courriel=" + URL.encodeComponent(personnel.getCourriel()) +"&cp_ce_truk_specialite=" + URL.encodeComponent(personnel.getSpecialite()) +"";return postDonnees;}}