1 package com.pentila.entSavoie.utils;
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.LinkedHashMap;
8 import javax.portlet.RenderRequest;
9 import javax.portlet.ResourceRequest;
11 import com.liferay.contacts.util.ListFicheFactory;
12 import com.liferay.contacts.util.ProxyFiche;
13 import com.liferay.portal.kernel.dao.orm.QueryUtil;
14 import com.liferay.portal.kernel.exception.SystemException;
15 import com.liferay.portal.kernel.json.JSONArray;
16 import com.liferay.portal.kernel.json.JSONFactoryUtil;
17 import com.liferay.portal.kernel.json.JSONObject;
18 import com.liferay.portal.kernel.log.Log;
19 import com.liferay.portal.kernel.log.LogFactoryUtil;
20 import com.liferay.portal.kernel.util.OrderByComparator;
21 import com.liferay.portal.kernel.util.ParamUtil;
22 import com.liferay.portal.kernel.workflow.WorkflowConstants;
23 import com.liferay.portal.model.Organization;
24 import com.liferay.portal.model.Role;
25 import com.liferay.portal.model.User;
26 import com.liferay.portal.service.ExtUserLocalServiceUtil;
27 import com.liferay.portal.service.RoleLocalServiceUtil;
28 import com.liferay.portal.service.UserLocalServiceUtil;
29 import com.liferay.portal.util.comparator.UserFirstNameComparator;
30 import com.liferay.portal.util.comparator.UserLastNameComparator;
31 import com.liferay.portal.util.comparator.UserScreenNameComparator;
32 import com.pentila.entSavoie.ENTRoleUtilFactory;
33 import com.pentila.entSavoie.ENTRolesConstants;
34 import com.pentila.entSavoie.amis.model.Relationship;
35 import com.pentila.entSavoie.amis.service.RelationshipLocalServiceUtil;
36 import com.pentila.entSavoie.carnetDAdresses.CANameComparator;
37 import com.pentila.entSavoie.carnetDAdresses.CAStatusComparator;
38 import com.pentila.entSavoie.carnetDAdresses.CAfirstNameComparator;
39 import com.pentila.entSavoie.carnetDAdresses.model.Liste;
40 import com.pentila.entSavoie.carnetDAdresses.service.ListeLocalServiceUtil;
41 import com.pentila.entSavoie.directory.OrganizationFinderServiceUtil;
42 import com.pentila.entSavoie.userProperties.model.UserProperties;
43 import com.pentila.entSavoie.userProperties.model.UserRelationship;
44 import com.pentila.entSavoie.userProperties.service.UserPropertiesLocalServiceUtil;
45 import com.pentila.entSavoie.userProperties.service.UserRelationshipLocalServiceUtil;
46 import com.pentila.entSavoie.userRelationship.UserRelationshipConstants;
48 import edu.emory.mathcs.backport.java.util.Arrays;
50 public class ENTUserListUtil {
52 private static Log logger = LogFactoryUtil.getLog(ENTUserListUtil.class);
53 private final static int COMPARE_ON_USER = 0;
54 private final static int COMPARE_ON_PROXYLIST = 1;
57 * Return a JSONObject that contains a users list which is the result of the search
58 * @param renderRequest The request containing all the parameters
59 * @param user The user currently searching
60 * @return a JSONObject with all the search results
62 public static JSONObject getUserListFromSearch(RenderRequest renderRequest, User user) {
63 return getUserListFromSearch(renderRequest, user, JsonUserProxyFactory.SIMPLE_USER_SEARCH, "");
67 * Return a JSONObject that contains a users list which is the result of the search
68 * @param renderRequest The request containing all the parameters
69 * @param user The user currently searching
70 * @return a JSONObject with all the search results
72 public static JSONObject getUserListFromSearch(ResourceRequest resourceRequest, User user) {
73 return getUserListFromSearch(resourceRequest, user, JsonUserProxyFactory.SIMPLE_USER_SEARCH, "");
77 * Return a JSONObject that contains a users list which is the result of the search
78 * @param renderRequest The request containing all the parameters
79 * @param user The user currently searching
81 * @param themeImagesUrl
82 * @return a JSONObject with all the search results
84 public static JSONObject getUserListFromSearch(RenderRequest renderRequest, User user, String typeSearch, String themeImagesUrl) {
85 JSONObject ret = JSONFactoryUtil.createJSONObject();
87 final int start = ParamUtil.getInteger(renderRequest, "start", 0);
88 final int limit = ParamUtil.getInteger(renderRequest, "limit", 0);
89 final int stop = start+limit;
91 //Get the request parameters
92 String firstName = renderRequest.getParameter("firstName");
93 if (firstName != null) {
94 firstName = firstName.trim();
95 firstName = firstName.toLowerCase();
98 String lastName = renderRequest.getParameter("lastName");
99 if (lastName != null) {
100 lastName = lastName.trim();
101 lastName = lastName.toLowerCase();
103 final String middleName = null;
104 final String screenName = null;
105 final String email = null;
107 LinkedHashMap<String, Object> userParams = buildUserParams(renderRequest, user);
109 OrderByComparator obc = buildComparator(renderRequest, COMPARE_ON_USER);
111 List<User> usersList = new ArrayList<User>();
113 usersList = ExtUserLocalServiceUtil.search(
120 WorkflowConstants.STATUS_APPROVED,
126 } catch (SystemException e) {
130 usersList = userListFilter(usersList);
132 long nbTotalResults = 0;
134 nbTotalResults = ExtUserLocalServiceUtil.searchCount(
141 WorkflowConstants.STATUS_APPROVED,
144 } catch (SystemException e) {
148 ret.put("users", (new JsonUserProxyFactory()).format(user, usersList, typeSearch, themeImagesUrl));
149 ret.put("nombreTotal", nbTotalResults);
155 * Return a JSONObject that contains a users list which is the result of the search
156 * @param renderRequest The request containing all the parameters
157 * @param user The user currently searching
159 * @param themeImagesUrl
160 * @return a JSONObject with all the search results
162 public static JSONObject getUserListFromSearch(ResourceRequest resourceRequest, User user, String typeSearch, String themeImagesUrl) {
163 JSONObject ret = JSONFactoryUtil.createJSONObject();
165 final int start = ParamUtil.getInteger(resourceRequest, "start", QueryUtil.ALL_POS);
166 final int limit = ParamUtil.getInteger(resourceRequest, "limit", 0);
167 final int stop = start+limit;
169 // Get the request parameters
170 String name = ParamUtil.getString(resourceRequest, "name", "");
171 String firstName = null;
172 String lastName = null;
173 if (!name.equals("")) {
174 firstName = name.trim();
175 firstName = name.toLowerCase();
176 lastName = name.trim();
177 lastName = name.toLowerCase();
180 final String middleName = null;
181 final String screenName = null;
182 final String email = null;
184 LinkedHashMap<String, Object> userParams = buildUserParams(resourceRequest, user);
186 OrderByComparator obc = buildComparator(resourceRequest, COMPARE_ON_USER);
188 List<User> usersList = new ArrayList<User>();
190 usersList = ExtUserLocalServiceUtil.search(
197 WorkflowConstants.STATUS_APPROVED,
203 } catch (SystemException e) {
207 String scholarship = ParamUtil.getString(resourceRequest, "scholarship", "");
208 int grant = ParamUtil.getInteger(resourceRequest, "grant", -1);
209 int transport = ParamUtil.getInteger(resourceRequest, "transport", -1);
211 // Filter over scholarship and grant
212 if (!scholarship.equals("") || grant > -1 || transport > -1) {
213 List<UserProperties> userPropertiesList = UserPropertiesLocalServiceUtil.filterScholarshipAndGrant(usersList, scholarship, grant, transport);
214 List<User> filteredList = new ArrayList<User>();
215 for (User resultUser : usersList) {
216 for (UserProperties userProperties : userPropertiesList) {
217 if (resultUser.getUserId() == userProperties.getUserId()) {
218 filteredList.add(resultUser);
222 usersList = filteredList;
225 usersList = userListFilter(usersList);
227 long nbTotalResults = 0;
229 nbTotalResults = ExtUserLocalServiceUtil.searchCount(
236 WorkflowConstants.STATUS_APPROVED,
239 } catch (SystemException e) {
243 ret.put("users", (new JsonUserProxyFactory()).format(user, usersList, typeSearch, themeImagesUrl));
244 ret.put("nombreTotal", nbTotalResults);
249 public static JSONObject getContactsFromSearch(ResourceRequest resourceRequest, User user) {
250 JSONObject result = JSONFactoryUtil.createJSONObject();
252 final int start = ParamUtil.getInteger(resourceRequest, "start", QueryUtil.ALL_POS);
254 JSONArray jsonContactList = JSONFactoryUtil.createJSONArray();
256 // Get the request parameters
257 Boolean myChildren = ParamUtil.getBoolean(resourceRequest, "myChildren", false);
258 Boolean myParents = ParamUtil.getBoolean(resourceRequest, "myParents", false);
260 logger.info("Fetch myChildren list elements");
262 List<UserRelationship> parentRelationships = UserRelationshipLocalServiceUtil.getUserRelationshipByFromUserIdRelationType(user.getUserId(), UserRelationshipConstants.PARENT_RELATION);
263 for (UserRelationship parentRelationship : parentRelationships) {
264 jsonContactList.put(JsonUserFactory.convertUserToJson(UserLocalServiceUtil.getUser(parentRelationship.getToUserId())));
266 result.put("nbResults", jsonContactList.length());
267 } catch (Exception e) {
268 logger.error("Error when fetching user "+user.getFullName()+" children", e);
271 else if (myParents) {
272 logger.info("Fetch myParents list elements");
274 List<UserRelationship> parentRelationships = UserRelationshipLocalServiceUtil.getUserRelationshipByToUserIdRelationType(user.getUserId(), UserRelationshipConstants.PARENT_RELATION);
275 for (UserRelationship parentRelationship : parentRelationships) {
276 jsonContactList.put(JsonUserFactory.convertUserToJson(UserLocalServiceUtil.getUser(parentRelationship.getFromUserId())));
278 result.put("nbResults", jsonContactList.length());
279 } catch (Exception e) {
280 logger.error("Error when fetching user "+user.getFullName()+" parents", e);
284 String name = ParamUtil.getString(resourceRequest, "name", "");
286 Long[] usersOrgs = getUsersOrgs(resourceRequest, user);
287 List<Long> orgIds = null;
288 if (usersOrgs != null) {
289 orgIds = Arrays.asList(usersOrgs);
292 Long[] usersRoles = getUsersRoles(resourceRequest, user);
293 List<Long> roleIds = null;
294 if (usersRoles != null) {
295 roleIds = Arrays.asList(usersRoles);
298 String scholarship = ParamUtil.getString(resourceRequest, "scholarship", "");
300 List<String> scholarshipLabels = getScholarshipLabels(scholarship);
303 // 0 -> value is false
304 // 1 -> value is true
305 int grant = ParamUtil.getInteger(resourceRequest, "grant", -1);
306 int transport = ParamUtil.getInteger(resourceRequest, "transport", -1);
308 List<User> contacts = getUserListFromContactSearch(resourceRequest, name, orgIds, roleIds, scholarshipLabels, grant, transport);
310 // convert result to JSON
311 long timer = System.currentTimeMillis();
312 for (User u : contacts) {
313 jsonContactList.put(JsonUserFactory.convertUserToJson(u));
315 System.out.println("convert to json took "+(System.currentTimeMillis() - timer)+" ms");
319 Long nbTotalResults = new Long(0);
320 timer = System.currentTimeMillis();
321 nbTotalResults = UserPropertiesLocalServiceUtil.getUserCountFromContactSearch(name, orgIds, roleIds, scholarshipLabels, grant, transport);
322 System.out.println("count query users (" + nbTotalResults + ") took "+(System.currentTimeMillis() - timer)+" ms");
323 result.put("nbResults", nbTotalResults);
324 } catch (Exception e) {
329 result.put("contacts", jsonContactList);
336 public static List<User> getUserListFromContactSearch(ResourceRequest resourceRequest, String name,
337 List<Long> orgIds, List<Long> roleIds, List<String> scholarshipLabels, int grant, int transport) {
339 final int start = ParamUtil.getInteger(resourceRequest, "start", QueryUtil.ALL_POS);
340 final int limit = ParamUtil.getInteger(resourceRequest, "limit", 0);
341 final int stop = start + limit;
343 OrderByComparator obc = buildComparator(resourceRequest, COMPARE_ON_USER);
345 List<User> usersList = new ArrayList<User>();
349 long timer = System.currentTimeMillis();
350 usersList = UserPropertiesLocalServiceUtil.getUserFromContactSearch(name, orgIds, roleIds, scholarshipLabels, grant, transport, start, stop, obc);
351 System.out.println("query users took "+(System.currentTimeMillis() - timer)+" ms");
353 } catch (Exception e) {
356 System.out.println("Returned " + usersList.size() + " users");
358 //Check if we still found double. TODO Do we still need to check ?
359 //usersList = userListFilter(usersList);
364 private static List<String> getScholarshipLabels(String scholarship) {
365 if (scholarship.equals("internal")) {
366 return UserInformationsUtil.getInternalScholarshipLabels();
367 } else if (scholarship.equals("external")) {
368 return UserInformationsUtil.getExternalScholarshipLabels();
369 } else if (scholarship.equals("semi")) {
370 return UserInformationsUtil.getSemiPensionScholarshipLabels();
373 return new ArrayList<String>();
377 * Get the users from a list and apply a filter if a search is entered
378 * @param renderRequest Request which contains the list and search parameters
379 * @param user User who currently displays the list
380 * @return a ProxyFiche list containing all the users that matches the search
382 public static List<ProxyFiche> getUsersFromList(RenderRequest renderRequest, User user) {
383 final String query = ParamUtil.getString(renderRequest, "recherche", "").toLowerCase();
385 OrderByComparator obc = buildComparator(renderRequest, COMPARE_ON_PROXYLIST);
387 List<ProxyFiche> fullListResult = getListFromType(renderRequest, user);
389 List<ProxyFiche> usersPFList = ENTAutoCompletionUtil.getFilteredListFromProxyFicheList(fullListResult, query);
390 Collections.sort(usersPFList, obc);
396 * Get a sub list from the one in parameter (used for pagination)
397 * @param pfList ProxyFiche List to cut
398 * @param start The first element from the list to get
399 * @param limit The number of element we want
400 * @return a ProxyFiche List which is a sub list from the one received
402 public static List<ProxyFiche> getSubList(List<ProxyFiche> pfList, int start, int limit) {
403 int stop = start + limit;
405 if (stop > pfList.size()) {
406 stop = pfList.size();
409 pfList = pfList.subList(start, stop);
415 * Build a LinkedHashMap which will be use as a parameter container in the search
416 * @param renderRequest The request with the parameters
417 * @param user The user currently searching
418 * @return LinkedHashMap with the parameters set for the search
420 private static LinkedHashMap<String, Object> buildUserParams(RenderRequest renderRequest, User user) {
421 LinkedHashMap<String, Object> userParams = new LinkedHashMap<String, Object>();
423 //Get searching parameters
424 long roleId = ParamUtil.getLong(renderRequest, "statut", 0);
425 long organizationId = ParamUtil.getLong(renderRequest, "organizationId", 0);
426 long etabId = ParamUtil.getLong(renderRequest, "etabId", 0);
427 long matiereId = ParamUtil.getLong(renderRequest, "matiereId", 0);
428 long[] etabStore = ParamUtil.getLongValues(renderRequest, "etabStore", null);
430 //User has restrictions : we search only on his school and students can only see other students
432 if (OrganizationFinderServiceUtil.hasRestriction(user)) {
433 final Organization etabRattach = OrganizationFinderServiceUtil.getEtabRatachement(user);
434 etabId = etabRattach.getOrganizationId();
436 } catch (Exception e) {
441 if (RoleLocalServiceUtil.hasUserRole(user.getUserId(), user.getCompanyId(), ENTRolesConstants.NATIONAL_1, false)) {
442 roleId = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(ENTRolesConstants.NATIONAL_1).getRoleId();
444 } catch (Exception e) {
448 // Check organizations : We search in the one selected, or in the restricted one,
449 //or in all schools of the list (after removing first empty value)
450 if (organizationId > 0) {
451 userParams.put("usersOrgs", new Long(organizationId));
452 } else if (etabId > 0) {
453 userParams.put("usersOrgs", new Long(etabId));
454 } else if (etabStore != null && etabStore.length < 5){
455 Long[] etabList = new Long[etabStore.length-1];
456 for (int i=1 ; i<etabStore.length ; ++i) {
457 etabList[i-1] = etabStore[i];
459 userParams.put("usersOrgs", etabList);
462 // Add role criterion if selected (or restriction)
464 userParams.put("usersRoles", new Long(roleId));
467 // Add courses filter
469 userParams.put("userEnseignement", new Long(matiereId));
476 * Build a LinkedHashMap which will be use as a parameter container in the search
477 * @param renderRequest The request with the parameters
478 * @param user The user currently searching
479 * @return LinkedHashMap with the parameters set for the search
481 private static LinkedHashMap<String, Object> buildUserParams(ResourceRequest resourceRequest, User user) {
482 LinkedHashMap<String, Object> userParams = new LinkedHashMap<String, Object>();
484 System.out.println("ENTUserListUtil - buildUserParams over ResourceRequest");
486 Long[] usersOrgsList = getUsersOrgs(resourceRequest, user);
487 if (usersOrgsList != null) {
488 userParams.put("usersOrgs", usersOrgsList);
491 Long[] usersRolesList = getUsersRoles(resourceRequest, user);
493 if (usersRolesList != null && usersRolesList.length > 0){
494 // TODO : manage multipe roles
495 userParams.put("usersRoles", usersRolesList[0]);
501 private static Long[] getUsersRoles(ResourceRequest resourceRequest, User user) {
502 // Get searching parameters
503 long[] roleIds = ParamUtil.getLongValues(resourceRequest, "roleIds");
505 Long[] longRoleIds = new Long[roleIds.length];
506 for (int i = 0 ; i < roleIds.length ; i++) {
507 long roleId = roleIds[i];
508 System.out.println(" > roleId="+roleId);
509 longRoleIds[i] = roleId;
512 // Students are only allowed to search among students
514 if (RoleLocalServiceUtil.hasUserRole(user.getUserId(), user.getCompanyId(), ENTRolesConstants.NATIONAL_1, false)) {
515 roleIds = new long[1];
516 roleIds[0] = ENTRoleUtilFactory.getInstance(user.getCompanyId()).getRole(ENTRolesConstants.NATIONAL_1).getRoleId();
518 } catch (Exception e) {
523 if (longRoleIds.length > 0){
524 // TODO : manage multipe roles
531 private static Long[] getUsersOrgs(ResourceRequest resourceRequest, User user) {
532 // Get searching parameters
533 long[] organizationIds = ParamUtil.getLongValues(resourceRequest, "classIds");
534 long[] schoolIds = ParamUtil.getLongValues(resourceRequest, "schoolIds");
536 Long[] longSchoolIds = new Long[schoolIds.length];
537 for (int i = 0 ; i < schoolIds.length ; i++) {
538 long schoolId = schoolIds[i];
539 longSchoolIds[i] = schoolId;
542 Long[] longOrgIds = new Long[organizationIds.length];
543 for (int i = 0 ; i < organizationIds.length ; i++) {
544 long orgId = organizationIds[i];
545 longOrgIds[i] = orgId;
548 //User has restrictions : we search only on his school and students can only see other students
550 if (OrganizationFinderServiceUtil.hasRestriction(user)) {
551 final Organization etabRattach = OrganizationFinderServiceUtil.getEtabRatachement(user);
552 longSchoolIds = new Long[1];
553 longSchoolIds[0] = etabRattach.getOrganizationId();
555 } catch (Exception e) {
559 // Check organizations : We search in the one selected, or in the restricted one,
560 //or in all schools of the list (after removing first empty value)
561 if (longOrgIds.length > 0) {
563 } else if (longSchoolIds.length > 0) {
564 return longSchoolIds;
568 if (!ENTRolesConstants.hasGlobalVisibilityOnGroupClassOnItsSchool(user)) {
569 // If no org filter then we check if the user is admin or limit him to his schools
570 JSONArray schools = GroupCacheUtil.getUserSchools(user);
571 longSchoolIds = new Long[schools.length()];
573 for (int i = 0 ; i < schools.length() ; ++i) {
574 long schoolId = schools.getJSONObject(i).getLong(GroupCacheUtil.GROUP_ORG_ID);
575 longSchoolIds[i] = schoolId;
578 return longSchoolIds;
580 } catch (Exception e) {
589 * Build an OrderByComparator which will serve to sort list thanks to parameters in request
590 * @param renderRequest The request with the parameters
591 * @return an OrderByComparator to sort the search results
593 private static OrderByComparator buildComparator(RenderRequest renderRequest, int typeComparator) {
594 //Handle result sorting
595 final boolean asc = ParamUtil.getString(renderRequest, "dir", "ASC").equals("ASC")?true:false;
596 final String sort = ParamUtil.getString(renderRequest, "sort", "nom");
598 OrderByComparator obc;
600 //Use custom comparator for ProxyList, the default case is to compare users
601 if (typeComparator == COMPARE_ON_PROXYLIST) {
602 if (sort.equals("prenom")) {
603 obc = new CAfirstNameComparator(asc);
604 } else if (sort.equals("statut")) {
605 obc = new CAStatusComparator(asc);
607 obc = new CANameComparator(asc);
610 if (sort.equals("prenom")) {
611 obc = new UserFirstNameComparator(asc);
612 } else if (sort.equals("login")) {
613 obc = new UserScreenNameComparator(asc);
615 obc = new UserLastNameComparator(asc);
623 * Build an OrderByComparator which will serve to sort list thanks to parameters in request
624 * @param renderRequest The request with the parameters
625 * @return an OrderByComparator to sort the search results
627 private static OrderByComparator buildComparator(ResourceRequest resourceRequest, int typeComparator) {
628 //Handle result sorting
629 final boolean asc = ParamUtil.getString(resourceRequest, "dir", "ASC").equals("ASC")?true:false;
630 final String sort = ParamUtil.getString(resourceRequest, "sort", "nom");
632 OrderByComparator obc;
634 //Use custom comparator for ProxyList, the default case is to compare users
635 if (typeComparator == COMPARE_ON_PROXYLIST) {
636 if (sort.equals("prenom")) {
637 obc = new CAfirstNameComparator(asc);
638 } else if (sort.equals("statut")) {
639 obc = new CAStatusComparator(asc);
641 obc = new CANameComparator(asc);
644 if (sort.equals("prenom")) {
645 obc = new UserFirstNameComparator(asc);
646 } else if (sort.equals("login")) {
647 obc = new UserScreenNameComparator(asc);
649 obc = new UserLastNameComparator(asc);
657 * Remove double from a users list and return the filtered list
658 * @param usersList The users list which possibly contains double
659 * @return a User's List without double left
661 private static List<User> userListFilter(List<User> usersList) {
662 // Avoid duplicate user
663 List<Long> listExistingUserId = new ArrayList<Long>();
664 List<User> filteredUsers = new ArrayList<User>();
665 for(User u : usersList){
666 if(!listExistingUserId.contains(u.getUserId())){
667 filteredUsers.add(u);
668 listExistingUserId.add(u.getUserId());
672 return filteredUsers;
676 * Return the users from the selected list
677 * @param renderRequest Request that contains all the parameters which describe the list
678 * @param user The owner of the list
679 * @return a ProxyFiche list with all the list users
681 private static List<ProxyFiche> getListFromType(RenderRequest renderRequest, User user) {
682 List<ProxyFiche> userListFromType = new ArrayList<ProxyFiche>();
684 final Long listId = ParamUtil.getLong(renderRequest, "listId", 0);
685 final Long roleId = ParamUtil.getLong(renderRequest, "roleId", 0);
686 final Long orgId = ParamUtil.getLong(renderRequest, "orgId", 0);
687 final String type = ParamUtil.getString(renderRequest, "type", "");
688 final String parentList = ParamUtil.getString(renderRequest, "parentList", "");
689 final String childrenList = ParamUtil.getString(renderRequest, "childrenList", "");
691 if (type.equals("local")) {
692 // personal lists (created by user)
694 Liste userListe = ListeLocalServiceUtil.getListe(listId);
695 userListFromType = ListFicheFactory.createUserListContacts(user, userListe);
696 } catch (Exception e) {
700 else if (type.equals("search")) {
701 // organizations lists / groups lists
703 userListFromType = ListFicheFactory.createSearchContacts(user, orgId, roleId, listId, parentList, childrenList, true);
704 } catch (SystemException e) {
708 // Global and friends lists
709 else if (type.equals("perso")) {
710 userListFromType = ListFicheFactory.createPersoContacts(user);
712 else if (type.equals("inst")) {
713 userListFromType = ListFicheFactory.createInstContacts(user);
715 else if (type.equals("all")) {
716 userListFromType = ListFicheFactory.createAllContacts(user);
718 else if (type.equals("allAmis")) {
720 List<Relationship> listAllRel = RelationshipLocalServiceUtil.getRelationshipByUserIdStateId(user.getUserId(), 2, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
722 List<Long> lesAmis = new ArrayList<Long>();
723 for(Relationship rel : listAllRel){
724 lesAmis.add(rel.getFriendId());
726 userListFromType = ListFicheFactory.createAmisContacts(user, lesAmis);
727 } catch (Exception e) {
732 else if (type.equals("amis")) {
734 List<Relationship> listRel = RelationshipLocalServiceUtil.getRelationshipByUserIdFriendFolderIdStateId(user.getUserId(), listId, 2, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
735 List<Long> lesAmis = new ArrayList<Long>();
736 for(Relationship rel : listRel){
737 lesAmis.add(rel.getFriendId());
739 userListFromType = ListFicheFactory.createAmisContacts(user, lesAmis);
740 } catch (Exception e) {
745 return userListFromType;
749 * Method which get all user from an organization
751 * @param organizationId
752 * @return List<User> representing the list of user of the organization, return empty list in error case
754 public static List<User> getUserFromAnOrganization(long companyId, long organizationId){
755 List<User> usersList = new ArrayList<User>();
758 LinkedHashMap<String, Object> userParams = new LinkedHashMap<String, Object>();
759 userParams.put("usersOrgs", new Long(organizationId));
760 usersList = ExtUserLocalServiceUtil.search(
767 WorkflowConstants.STATUS_APPROVED,
772 (OrderByComparator) null);
774 } catch (SystemException e) {
781 * Method which get all user with role from an organization
783 * @param userRoleFilter the role it filter on
784 * @param organizationId
785 * @param comparator the comparator to order the
786 * @return List<User> representing the list of specific role user of the organization, return empty list in error case
788 public static List<User> getUserWithSpecificRoleForOrganization(long companyId, Role userRoleFilter,
789 long organizationId, OrderByComparator comparator){
790 List<User> usersList = new ArrayList<User>();
793 LinkedHashMap<String, Object> userParams = new LinkedHashMap<String, Object>();
794 userParams.put("usersRoles", new Long(userRoleFilter.getRoleId()));
795 userParams.put("usersOrgs", new Long(organizationId));
797 usersList = ExtUserLocalServiceUtil.search(
804 WorkflowConstants.STATUS_APPROVED,
809 (OrderByComparator) null);
811 } catch (SystemException e) {
818 * Method which get all user with role from a group
820 * @param userRoleFilter the role it filter on
822 * @return List<User> representing the list of specific role user of the organization, return empty list in error case
824 public static List<User> getUserWithSpecificRoleForGroup(long companyId, Role userRoleFilter,
826 List<User> usersList = new ArrayList<User>();
829 LinkedHashMap<String, Object> userParams = new LinkedHashMap<String, Object>();
830 userParams.put("usersRoles", new Long(userRoleFilter.getRoleId()));
831 userParams.put("usersGroups", new Long(groupId));
833 usersList = ExtUserLocalServiceUtil.search(
840 WorkflowConstants.STATUS_APPROVED,
845 (OrderByComparator) null);
847 } catch (SystemException e) {