1 package com.liferay.contacts.util;
3 import com.liferay.portal.kernel.json.JSONObject;
4 import com.liferay.portal.kernel.util.Validator;
5 import com.liferay.portal.model.User;
6 import com.liferay.portal.service.UserLocalServiceUtil;
7 import com.pentila.entSavoie.ENTDisplayUtil;
8 import com.pentila.entSavoie.carnetDAdresses.FicheConstant;
9 import com.pentila.entSavoie.carnetDAdresses.model.Fiche;
10 import com.pentila.entSavoie.carnetDAdresses.service.FicheLocalServiceUtil;
12 public class ProxyFiche implements Comparable<ProxyFiche> {
14 private String nom = "";
15 private String prenom = "";
16 private String screenName = "";
17 private String statut = "";
18 private String type = "";
19 private String id = "";
20 private String relUserId = "";
21 private String mail = "";
23 public ProxyFiche(User currentUser, User u) {
24 this(currentUser, u, true);
27 //Add a boolean that indicates if the status is needed to win some perf
28 public ProxyFiche(User currentUser, User u, boolean processStatut) {
30 this.setNom(u.getLastName());
31 this.setPrenom(u.getFirstName());
32 this.setScreenName(u.getScreenName());
33 this.setMail(u.getEmailAddress());
36 String statut = ENTDisplayUtil.displayUserRoles(currentUser, u);
37 this.setStatut(statut);
41 this.setId(String.valueOf(u.getUserId()));
42 this.setRelUserId(String.valueOf(""));
47 * @param user Le user est celui qui genere la page
49 public ProxyFiche(User currentUser, Fiche f) {
50 this(currentUser, f, true);
53 //Add a boolean that indicates if the status is needed to win some perf
54 public ProxyFiche(User currentUser, Fiche f, boolean processStatut) {
58 JSONObject jsonProperties = FicheLocalServiceUtil.getProperties(f.getFicheId());
60 if (Validator.isNotNull(jsonProperties.getString(FicheConstant.LASTNAME))){
61 this.setNom(jsonProperties.getString(FicheConstant.LASTNAME));
64 if (Validator.isNotNull(jsonProperties.getString(FicheConstant.FIRSTNAME))){
65 this.setPrenom(jsonProperties.getString(FicheConstant.FIRSTNAME));
68 if (Validator.isNotNull(jsonProperties.getString(FicheConstant.EMAIL))){
69 this.setMail(jsonProperties.getString(FicheConstant.EMAIL));
71 } catch (Exception e1) {
76 String statut = "Utilisateur local";
79 statut = ENTDisplayUtil.displayUserRoles(currentUser, UserLocalServiceUtil.getUser(f.getRelUserId()));
81 catch (Exception e) {}
83 this.setStatut(statut);
84 this.setType("fiche");
85 this.setId(String.valueOf(f.getFicheId()));
86 this.setRelUserId(String.valueOf(f.getRelUserId()));
91 public String getMail() {
94 public void setMail(String mail) {
97 public String getNom() {
100 public void setNom(String nom) {
103 public String getScreenName() {
106 public void setScreenName(String screenName) {
107 this.screenName = screenName;
109 public String getPrenom() {
112 public void setPrenom(String prenom) {
113 this.prenom = prenom;
115 public String getStatut() {
118 public void setStatut(String statut) {
119 this.statut = statut;
121 public String getType() {
124 public void setType(String type) {
127 public String getId() {
130 public void setId(String id) {
133 public String getRelUserId() {
136 public void setRelUserId(String relUserId) {
137 this.relUserId = relUserId;
141 public boolean equals(Object anObj) {
142 if ( this == anObj ) {
145 if ( !(anObj instanceof ProxyFiche) ) {
149 //cast to native object is now safe
150 ProxyFiche obj = (ProxyFiche)anObj;
151 if ( this.getType().equals("user") &&
152 obj.getType().equals("user") &&
153 this.getId().equals(obj.getId())) {
157 if ( this.getType().equals("user") &&
158 obj.getType().equals("fiche") &&
159 this.getId().equals(obj.getRelUserId())) {
163 if ( this.getType().equals("fiche") &&
164 obj.getType().equals("user") &&
165 this.getRelUserId().equals(obj.getId())) {
169 if ( this.getType().equals("fiche") &&
170 obj.getType().equals("fiche") &&
171 this.getRelUserId().equals(obj.getRelUserId()) ) {
172 if (!this.getRelUserId().equals("")) {
176 if ( this.getNom().equals(obj.getNom()) &&
177 this.getPrenom().equals(obj.getPrenom()) &&
178 this.getStatut().equals(obj.getStatut())) {
186 public int compareTo(ProxyFiche o) {
187 String s1 = this.getNom()+this.getPrenom();
188 String s2 = o.getNom()+o.getPrenom();
189 return s1.compareTo(s2);
193 public int hashCode() {
194 if ( this.getType().equals("user") ) {
195 return 31 + ("userRelated" + this.getId() ).hashCode();
199 if ( !this.getRelUserId().equals("") ) {
200 return 31 + ("userRelated" + this.getRelUserId() ).hashCode();
203 return 31 + ("fiche" + this.getNom() + this.getPrenom() + this.getStatut() ).hashCode();