--- /dev/null
+package com.liferay.contacts.util;
+
+import com.liferay.portal.kernel.json.JSONObject;
+import com.liferay.portal.kernel.util.Validator;
+import com.liferay.portal.model.User;
+import com.liferay.portal.service.UserLocalServiceUtil;
+import com.pentila.entSavoie.ENTDisplayUtil;
+import com.pentila.entSavoie.carnetDAdresses.FicheConstant;
+import com.pentila.entSavoie.carnetDAdresses.model.Fiche;
+import com.pentila.entSavoie.carnetDAdresses.service.FicheLocalServiceUtil;
+
+public class ProxyFiche implements Comparable<ProxyFiche> {
+
+ private String nom = "";
+ private String prenom = "";
+ private String screenName = "";
+ private String statut = "";
+ private String type = "";
+ private String id = "";
+ private String relUserId = "";
+ private String mail = "";
+
+ public ProxyFiche(User currentUser, User u) {
+ this(currentUser, u, true);
+ }
+
+ //Add a boolean that indicates if the status is needed to win some perf
+ public ProxyFiche(User currentUser, User u, boolean processStatut) {
+ super();
+ this.setNom(u.getLastName());
+ this.setPrenom(u.getFirstName());
+ this.setScreenName(u.getScreenName());
+ this.setMail(u.getEmailAddress());
+
+ if (processStatut) {
+ String statut = ENTDisplayUtil.displayUserRoles(currentUser, u);
+ this.setStatut(statut);
+ }
+
+ this.setType("user");
+ this.setId(String.valueOf(u.getUserId()));
+ this.setRelUserId(String.valueOf(""));
+ }
+
+ /**
+ * @param f
+ * @param user Le user est celui qui genere la page
+ */
+ public ProxyFiche(User currentUser, Fiche f) {
+ this(currentUser, f, true);
+ }
+
+ //Add a boolean that indicates if the status is needed to win some perf
+ public ProxyFiche(User currentUser, Fiche f, boolean processStatut) {
+ super();
+
+ try {
+ JSONObject jsonProperties = FicheLocalServiceUtil.getProperties(f.getFicheId());
+
+ if (Validator.isNotNull(jsonProperties.getString(FicheConstant.LASTNAME))){
+ this.setNom(jsonProperties.getString(FicheConstant.LASTNAME));
+ }
+
+ if (Validator.isNotNull(jsonProperties.getString(FicheConstant.FIRSTNAME))){
+ this.setPrenom(jsonProperties.getString(FicheConstant.FIRSTNAME));
+ }
+
+ if (Validator.isNotNull(jsonProperties.getString(FicheConstant.EMAIL))){
+ this.setMail(jsonProperties.getString(FicheConstant.EMAIL));
+ }
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+
+
+ String statut = "Utilisateur local";
+ if (processStatut) {
+ try {
+ statut = ENTDisplayUtil.displayUserRoles(currentUser, UserLocalServiceUtil.getUser(f.getRelUserId()));
+ }
+ catch (Exception e) {}
+ }
+ this.setStatut(statut);
+ this.setType("fiche");
+ this.setId(String.valueOf(f.getFicheId()));
+ this.setRelUserId(String.valueOf(f.getRelUserId()));
+
+ }
+
+
+ public String getMail() {
+ return mail;
+ }
+ public void setMail(String mail) {
+ this.mail = mail;
+ }
+ public String getNom() {
+ return nom;
+ }
+ public void setNom(String nom) {
+ this.nom = nom;
+ }
+ public String getScreenName() {
+ return screenName;
+ }
+ public void setScreenName(String screenName) {
+ this.screenName = screenName;
+ }
+ public String getPrenom() {
+ return prenom;
+ }
+ public void setPrenom(String prenom) {
+ this.prenom = prenom;
+ }
+ public String getStatut() {
+ return statut;
+ }
+ public void setStatut(String statut) {
+ this.statut = statut;
+ }
+ public String getType() {
+ return type;
+ }
+ public void setType(String type) {
+ this.type = type;
+ }
+ public String getId() {
+ return id;
+ }
+ public void setId(String id) {
+ this.id = id;
+ }
+ public String getRelUserId() {
+ return relUserId;
+ }
+ public void setRelUserId(String relUserId) {
+ this.relUserId = relUserId;
+ }
+
+ @Override
+ public boolean equals(Object anObj) {
+ if ( this == anObj ) {
+ return true;
+ }
+ if ( !(anObj instanceof ProxyFiche) ) {
+ return false;
+ }
+
+ //cast to native object is now safe
+ ProxyFiche obj = (ProxyFiche)anObj;
+ if ( this.getType().equals("user") &&
+ obj.getType().equals("user") &&
+ this.getId().equals(obj.getId())) {
+ return true;
+ }
+
+ if ( this.getType().equals("user") &&
+ obj.getType().equals("fiche") &&
+ this.getId().equals(obj.getRelUserId())) {
+ return true;
+ }
+
+ if ( this.getType().equals("fiche") &&
+ obj.getType().equals("user") &&
+ this.getRelUserId().equals(obj.getId())) {
+ return true;
+ }
+
+ if ( this.getType().equals("fiche") &&
+ obj.getType().equals("fiche") &&
+ this.getRelUserId().equals(obj.getRelUserId()) ) {
+ if (!this.getRelUserId().equals("")) {
+ return true;
+ }
+ else {
+ if ( this.getNom().equals(obj.getNom()) &&
+ this.getPrenom().equals(obj.getPrenom()) &&
+ this.getStatut().equals(obj.getStatut())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public int compareTo(ProxyFiche o) {
+ String s1 = this.getNom()+this.getPrenom();
+ String s2 = o.getNom()+o.getPrenom();
+ return s1.compareTo(s2);
+ }
+
+ @Override
+ public int hashCode() {
+ if ( this.getType().equals("user") ) {
+ return 31 + ("userRelated" + this.getId() ).hashCode();
+ }
+ else {
+ // cas d'une fiche
+ if ( !this.getRelUserId().equals("") ) {
+ return 31 + ("userRelated" + this.getRelUserId() ).hashCode();
+ }
+ else {
+ return 31 + ("fiche" + this.getNom() + this.getPrenom() + this.getStatut() ).hashCode();
+ }
+
+ }
+ }
+
+}