1 package com.pentila.entSavoie.utils;
3 import java.text.Normalizer;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.LinkedHashMap;
10 import javax.portlet.PortletPreferences;
12 import com.liferay.contacts.util.InstitutionalListsFactory;
13 import com.liferay.contacts.util.OrganizationFilter;
14 import com.liferay.portal.kernel.dao.orm.QueryUtil;
15 import com.liferay.portal.kernel.exception.SystemException;
16 import com.liferay.portal.kernel.json.JSONArray;
17 import com.liferay.portal.kernel.json.JSONFactoryUtil;
18 import com.liferay.portal.kernel.json.JSONObject;
19 import com.liferay.portal.kernel.language.LanguageUtil;
20 import com.liferay.portal.kernel.log.Log;
21 import com.liferay.portal.kernel.log.LogFactoryUtil;
22 import com.liferay.portal.kernel.util.OrderByComparator;
23 import com.liferay.portal.model.Group;
24 import com.liferay.portal.model.Organization;
25 import com.liferay.portal.model.Role;
26 import com.liferay.portal.model.User;
27 import com.liferay.portal.service.GroupLocalServiceUtil;
28 import com.liferay.portal.service.OrganizationLocalServiceUtil;
29 import com.liferay.portal.service.RoleLocalServiceUtil;
30 import com.liferay.portal.service.UserLocalServiceUtil;
31 import com.liferay.portal.util.comparator.GroupNameComparator;
32 import com.pentila.entSavoie.ENTDisplayUtil;
33 import com.pentila.entSavoie.ENTRolesConstants;
34 import com.pentila.entSavoie.administrationTools.model.CommunicationPrefs;
35 import com.pentila.entSavoie.administrationTools.service.CommunicationPrefsLocalServiceUtil;
36 import com.pentila.entSavoie.amis.model.FriendFolder;
37 import com.pentila.entSavoie.amis.service.FriendFolderLocalServiceUtil;
38 import com.pentila.entSavoie.carnetDAdresses.model.ListProperty;
39 import com.pentila.entSavoie.carnetDAdresses.model.Liste;
40 import com.pentila.entSavoie.carnetDAdresses.service.ListeLocalServiceUtil;
41 import com.pentila.entSavoie.communityInfos.model.CommunityInfos;
42 import com.pentila.entSavoie.communityInfos.service.CommunityInfosLocalServiceUtil;
43 import com.pentila.entSavoie.directory.OrganizationFinderServiceUtil;
44 import com.pentila.entSavoie.institutionalList.model.ListeInstDetails;
45 import com.pentila.entSavoie.userProperties.model.UserRelationship;
46 import com.pentila.entSavoie.userProperties.service.UserPropertiesLocalServiceUtil;
47 import com.pentila.entSavoie.userProperties.service.UserRelationshipLocalServiceUtil;
48 import com.pentila.entSavoie.userRelationship.UserRelationshipConstants;
50 import edu.emory.mathcs.backport.java.util.Collections;
52 public class ENTAddressBookListsManager {
54 public static final String USER_MIGRATE_LISTS = "migrate";
55 public static final String USER_CURRENT_LISTS = "current";
57 private static Log logger = LogFactoryUtil.getLog(ENTAddressBookListsManager.class);
61 public static JSONArray getUserAdressBookLists(User user) {
63 JSONArray userLists = JSONFactoryUtil.createJSONArray();
65 // Get user's roleType
66 int roleType = getUsersRoleType(user);
68 boolean isAdmin = false;
69 Organization rattachSchool = null;
71 isAdmin = RoleLocalServiceUtil.hasUserRole(user.getUserId(), user.getCompanyId(), ENTRolesConstants.GROUP_ADMIN, false);
72 rattachSchool = OrganizationFinderServiceUtil.getEtabRatachement(user);
73 } catch (Exception e) {}
75 // Loop over user's schools
76 List<Organization> userSchools = OrganizationFilter.getUserSchools(user);
77 for (Organization school : userSchools) {
79 JSONObject orgJson = JSONFactoryUtil.createJSONObject();
80 orgJson.put("categoryName", ENTDisplayUtil.formatSCONETName(school.getName(), true));
81 orgJson.put("schoolId", school.getOrganizationId());
82 orgJson.put("isInstitutionalCategory", true);
84 JSONArray orgListsJson = getSchoolListsForRoleType(user, school, roleType, isAdmin);
86 orgJson.put("categoryList", orgListsJson);
87 if (rattachSchool != null && rattachSchool.getOrganizationId() == school.getOrganizationId()) {
88 orgJson.put("isSelected", true);
90 orgJson.put("isSelected", false);
92 userLists.put(orgJson);
98 public static JSONObject getSchoolContactsForRoleType(String search, User user, Organization school, int roleType, int start, int limit, OrderByComparator comparator) {
100 JSONObject result = JSONFactoryUtil.createJSONObject();
101 JSONArray schoolContacts = JSONFactoryUtil.createJSONArray();
102 logger.info("Searching contacts in school "+school.getName()+" for user "+user.getFullName()+" with search '"+search+"' and limited between "+start+" and "+limit);
104 long _start = System.currentTimeMillis();
105 CommunicationPrefs communicationPrefs = CommunicationPrefsLocalServiceUtil.getCommunicationPrefs(school.getOrganizationId(), roleType);
107 Role studentRole = RoleLocalServiceUtil.getRole(school.getCompanyId(), ENTRolesConstants.NATIONAL_1);
108 Role parentRole = RoleLocalServiceUtil.getRole(school.getCompanyId(), ENTRolesConstants.NATIONAL_2);
109 Role teacherRole = RoleLocalServiceUtil.getRole(school.getCompanyId(), ENTRolesConstants.NATIONAL_3);
110 Role otherRole = RoleLocalServiceUtil.getRole(school.getCompanyId(), ENTRolesConstants.NATIONAL_7);
111 Role adminRole = RoleLocalServiceUtil.getRole(school.getCompanyId(), ENTRolesConstants.GROUP_ADMIN);
112 boolean isAdmin = RoleLocalServiceUtil.hasUserRole(user.getUserId(), adminRole.getRoleId());
114 List<User> resultUsers = new ArrayList<User>();
116 // 1. Fetch users at school-level if needed, from start to limit, ordered by given comparator, with given search keyword
117 // 2. Fetch users at class-level if needed, from start to limit, ordered by given comparator, with given search keyword
118 // 3. Fetch myChildren or myParents if needed
119 // 4. Aggregate, sort and limit from start to limit
120 // 5. Convert to JSON
122 List<Organization> userClasses = new ArrayList<Organization>();
123 if (isAdmin || communicationPrefs.getAllStudents() || communicationPrefs.getAllParents() || communicationPrefs.getAllTeachers() || communicationPrefs.getAllPersonals() || communicationPrefs.getAllOthers()) {
125 logger.info("Searching at school-level scope");
126 // Scope is the whole school
127 List<Long> orgIds = new ArrayList<Long>();
128 orgIds.add(school.getOrganizationId());
130 long time0 = System.currentTimeMillis();
131 List<Long> roleIds = new ArrayList<Long>();
132 if (!isAdmin && communicationPrefs.getAllStudents()) {
133 roleIds.add(studentRole.getRoleId());
135 if (!isAdmin && communicationPrefs.getAllParents()) {
136 roleIds.add(parentRole.getRoleId());
138 if (!isAdmin && communicationPrefs.getAllTeachers()) {
139 roleIds.add(teacherRole.getRoleId());
141 if (!isAdmin && communicationPrefs.getAllPersonals()) {
142 for (String personalRoleNat : CommunicationPrefsConstants.PERSONAL_ROLES.keySet()) {
144 Role role = RoleLocalServiceUtil.getRole(school.getCompanyId(), personalRoleNat);
145 roleIds.add(role.getRoleId());
146 } catch (Exception e) {
150 if (!isAdmin && communicationPrefs.getAllOthers()) {
151 roleIds.add(otherRole.getRoleId());
153 List<User> schoolUsers = UserPropertiesLocalServiceUtil.getUserFromContactSearch(search, orgIds, roleIds, new ArrayList<String>(), -1, -1, start, limit, comparator);
156 nbResults += UserPropertiesLocalServiceUtil.getUserCountFromContactSearch(search, orgIds, roleIds, new ArrayList<String>(), -1, -1);
157 logger.info("First call : got a total of "+nbResults+" users");
160 long time1 = System.currentTimeMillis();
161 logger.info(" >> School-level search on "+roleIds.size()+" roles fetched "+schoolUsers.size()+" results in "+(time1 - time0)+" ms");
162 resultUsers.addAll(schoolUsers);
165 if (communicationPrefs.getClassStudents() || communicationPrefs.getClassParents() || communicationPrefs.getClassTeachers()) {
166 long time0 = System.currentTimeMillis();
167 // Scope is the user's classes only
168 userClasses = OrganizationFilter.getUserClassesAndGroups(user);
169 logger.info("Fetched "+userClasses.size()+" classes for standard user and school "+school.getName());
171 List<Long> roleIds = new ArrayList<Long>();
172 if (communicationPrefs.getClassStudents() && !communicationPrefs.getAllStudents()) {
173 roleIds.add(studentRole.getRoleId());
175 if (communicationPrefs.getClassParents() && !communicationPrefs.getAllParents()) {
176 roleIds.add(parentRole.getRoleId());
178 if (communicationPrefs.getClassTeachers() && !communicationPrefs.getAllTeachers()) {
179 roleIds.add(teacherRole.getRoleId());
181 List<Long> orgIds = new ArrayList<Long>();
182 for (Organization userClass : userClasses) {
183 orgIds.add(userClass.getOrganizationId());
185 List<User> classUsers = UserPropertiesLocalServiceUtil.getUserFromContactSearch(search, orgIds, roleIds, new ArrayList<String>(), -1, -1, start, limit, comparator);
186 long time1 = System.currentTimeMillis();
188 nbResults += UserPropertiesLocalServiceUtil.getUserCountFromContactSearch(search, orgIds, roleIds, new ArrayList<String>(), -1, -1);
189 logger.info("First call : got a total of "+nbResults+" users");
191 logger.info(" >> Class-level search on "+roleIds.size()+" roles and "+orgIds.size()+" classes fetched "+classUsers.size()+" results in "+(time1 - time0)+" ms");
192 resultUsers.addAll(classUsers);
196 // Add myChildren if needed
197 if (communicationPrefs.getMyChildren()) {
198 List<UserRelationship> parentRelationships = UserRelationshipLocalServiceUtil.getUserRelationshipByToUserIdRelationType(user.getUserId(), UserRelationshipConstants.PARENT_RELATION);
199 for (UserRelationship parentRelationship : parentRelationships) {
200 resultUsers.add(UserLocalServiceUtil.getUser(parentRelationship.getFromUserId()));
205 // Add myParents if needed
206 if (communicationPrefs.getMyParents()) {
207 List<UserRelationship> parentRelationships = UserRelationshipLocalServiceUtil.getUserRelationshipByFromUserIdRelationType(user.getUserId(), UserRelationshipConstants.PARENT_RELATION);
208 for (UserRelationship parentRelationship : parentRelationships) {
209 resultUsers.add(UserLocalServiceUtil.getUser(parentRelationship.getToUserId()));
214 logger.info("Found a total of "+resultUsers.size()+" users");
215 result.put("nbResults", nbResults);
218 List<User> uniqueList = new ArrayList<User>();
219 List<Long> uniqueIdsList = new ArrayList<Long>();
220 for (User _user : resultUsers) {
221 if (!uniqueIdsList.contains(_user.getUserId())) {
222 uniqueList.add(_user);
223 uniqueIdsList.add(_user.getUserId());
226 logger.info("After unification: "+uniqueList.size()+" users");
229 // Now loop over aggregated list resultUsers and sort it with given comparator
230 Collections.sort(uniqueList, comparator);
232 // TODO : better manage start and limit
233 List<User> sortedUserList = uniqueList.subList(start, ((uniqueList.size() < limit) ? uniqueList.size() : limit));
236 for (User sortedUser : sortedUserList) {
237 JSONObject jsonUser = JsonUserFactory.convertUserToJson(sortedUser);
238 schoolContacts.put(jsonUser);
241 } catch (Exception e) {
242 logger.error("Error when fetching all school's classes for "+school.getName(), e);
245 long end = System.currentTimeMillis();
246 logger.info("Full getSchool contacts for user "+user.getFullName()+" and school "+school.getName()+" took "+(end - _start)+" ms");
247 result.put("contacts", schoolContacts);
252 private static JSONArray getSchoolListsForRoleType(User user, Organization school, int roleType, boolean isAdmin) {
254 JSONArray orgLists = JSONFactoryUtil.createJSONArray();
256 long start = System.currentTimeMillis();
257 CommunicationPrefs communicationPrefs = CommunicationPrefsLocalServiceUtil.getCommunicationPrefs(school.getOrganizationId(), roleType);
260 // The list of all school classes and groups
261 List<Organization> userClasses = new ArrayList<Organization>();
263 userClasses = OrganizationFilter.filterNotArchivedOrganizations(OrganizationFilter.filterNotSuffixedOrganizations(OrganizationLocalServiceUtil.getOrganizations(school.getCompanyId(), school.getOrganizationId())));
264 logger.info("Fetched "+userClasses.size()+" classes for admin user and school "+school.getName());
266 userClasses = OrganizationFilter.getUserClassesAndGroups(user);
267 logger.info("Fetched "+userClasses.size()+" classes for standard user and school "+school.getName());
270 Role studentRole = RoleLocalServiceUtil.getRole(school.getCompanyId(), ENTRolesConstants.NATIONAL_1);
271 Role parentRole = RoleLocalServiceUtil.getRole(school.getCompanyId(), ENTRolesConstants.NATIONAL_2);
272 Role teacherRole = RoleLocalServiceUtil.getRole(school.getCompanyId(), ENTRolesConstants.NATIONAL_3);
273 Role otherRole = RoleLocalServiceUtil.getRole(school.getCompanyId(), ENTRolesConstants.NATIONAL_7);
275 if (communicationPrefs.getAllStudents()) {
276 JSONObject classJson = buildJson("Eleves de l'etablissement", studentRole.getRoleId(), 0, school.getOrganizationId(), false, false);
277 orgLists.put(classJson);
280 if (communicationPrefs.getClassStudents()) {
281 for (Organization userClass : userClasses) {
282 JSONObject classJson = buildJson("Eleves de "+ ENTDisplayUtil.formatSCONETName(userClass.getName(), false), studentRole.getRoleId(), userClass.getOrganizationId(), school.getOrganizationId(), false, false);
283 orgLists.put(classJson);
287 if (communicationPrefs.getAllParents()) {
288 JSONObject classJson = buildJson("Parents de l'etablissement", parentRole.getRoleId(), 0, school.getOrganizationId(), false, false);
289 orgLists.put(classJson);
292 if (communicationPrefs.getClassParents()) {
293 for (Organization userClass : userClasses) {
294 JSONObject classJson = buildJson("Parents de "+ ENTDisplayUtil.formatSCONETName(userClass.getName(), false), parentRole.getRoleId(), userClass.getOrganizationId(), school.getOrganizationId(), false, false);
295 orgLists.put(classJson);
299 if (communicationPrefs.getAllTeachers()) {
300 JSONObject classJson = buildJson("Enseignants de l'etablissement", teacherRole.getRoleId(), 0, school.getOrganizationId(), false, false);
301 orgLists.put(classJson);
304 if (communicationPrefs.getClassTeachers()) {
305 for (Organization userClass : userClasses) {
306 JSONObject classJson = buildJson("Enseignants de "+ ENTDisplayUtil.formatSCONETName(userClass.getName(), false), teacherRole.getRoleId(), userClass.getOrganizationId(), school.getOrganizationId(), false, false);
307 orgLists.put(classJson);
311 if (communicationPrefs.getAllPersonals()) {
312 // Build over all roles included in 'Personal'
313 for (String personalRoleNat : CommunicationPrefsConstants.PERSONAL_ROLES.keySet()) {
315 Role role = RoleLocalServiceUtil.getRole(school.getCompanyId(), personalRoleNat);
316 JSONObject classJson = buildJson(CommunicationPrefsConstants.PERSONAL_ROLES.get(personalRoleNat), role.getRoleId(), 0, school.getOrganizationId(), false, false);
317 orgLists.put(classJson);
318 } catch (Exception e) {
323 if (communicationPrefs.getAllOthers()) {
324 JSONObject classJson = buildJson("Personnels de la collectivité", otherRole.getRoleId(), 0, school.getOrganizationId(), false, false);
325 orgLists.put(classJson);
328 if (communicationPrefs.getMyChildren()) {
329 JSONObject classJson = buildJson("Mes enfants", studentRole.getRoleId(), 0, school.getOrganizationId(), true, false);
330 orgLists.put(classJson);
333 if (communicationPrefs.getMyParents()) {
334 JSONObject classJson = buildJson("Mes parents", parentRole.getRoleId(), 0, school.getOrganizationId(), false, true);
335 orgLists.put(classJson);
338 } catch (Exception e) {
339 logger.error("Error when fetching all school's classes for "+school.getName(), e);
342 long end = System.currentTimeMillis();
343 logger.info("Full getSchoolList for user "+user.getFullName()+" and school "+school.getName()+" took "+(end - start)+" ms");
348 private static JSONObject buildJson(String name, long roleId, long organizationId, long schoolId, boolean myChildren, boolean myParents) {
350 JSONObject classJson = JSONFactoryUtil.createJSONObject();
351 classJson.put("listName", name);
352 classJson.put("roleId", roleId);
353 classJson.put("orgId", organizationId);
354 classJson.put("schoolId", schoolId);
355 classJson.put("myChildren", myChildren);
356 classJson.put("myParents", myParents);
357 classJson.put("isDisplayed", true);
362 public static int getUsersRoleType(User user) {
365 if (ENTRolesConstants.isStudent(user)) {
367 } else if (ENTRolesConstants.isParent(user)) {
369 } else if (ENTRolesConstants.isTeacher(user)) {
371 } else if (ENTRolesConstants.isPersonal(user)) {
376 } catch (Exception e) {
377 logger.error("Error when determinig user's roleType for "+user.getFullName(), e);
386 * Get the menu list name for institutional lists (usually the school name)
387 * @param user The user currently getting his lists
388 * @param lid The list we want the menu for
389 * @return the menu name for the list received
391 public static String getListMenuName(User user, ListeInstDetails lid) {
392 String listMenuName = "";
395 Organization org = OrganizationLocalServiceUtil.getOrganization(lid.getOrgId());
396 listMenuName = org.getName();
397 } catch (Exception e) {
401 // If no grouping name is found use the default one
402 if(listMenuName.equals("")){
403 listMenuName = LanguageUtil.get(user.getLocale(), "institutionnelles");
410 * NB: The archives are not displayed for the moment
411 * Get the user's institutional lists (Current lists and archives)
412 * @param user The user currently getting his institutional list
413 * @param search The searching term to match
414 * @return a HashMap which link a string with a ListInstDetails List. These lists contains the user's institutional lists to display.
416 public static HashMap<String, List<ListeInstDetails> > getUserInstitutionalLists(User user, String search) {
417 HashMap<String, List<ListeInstDetails> > userInstitutionalLists = new HashMap<String, List<ListeInstDetails>>();
418 List<ListeInstDetails> userCurrentInstistutionalLists = new ArrayList<ListeInstDetails>();
419 List<ListeInstDetails> userArchiveLists = new ArrayList<ListeInstDetails>();
421 InstitutionalListsFactory ilf = new InstitutionalListsFactory(user);
422 List<ListeInstDetails> lids = new ArrayList<ListeInstDetails>();
424 lids = ilf.getInstitutionnalLists();
425 } catch (Exception e) {
429 String searchQuery = getStringReadyForSearch(search);
430 //We cut the list in two : archives and actual lists
431 for (ListeInstDetails lid : lids) {
433 //Apply search filter and check if search matches
434 String listName = getStringReadyForSearch(lid.getListeInstDetailsName());
435 boolean isPositiveToSearch = (listName.length() >= searchQuery.length() && listName.contains(searchQuery));
437 if (search.equals("") || isPositiveToSearch) {
439 long subOrgId = Long.valueOf(lid.getSubOrgId());
440 Organization org = OrganizationLocalServiceUtil.getOrganization(subOrgId);
441 // Get preferences to recognize migrate organization. We do not display them anymore so just continue when finding one
442 PortletPreferences prefs = org.getPreferences();
444 if (prefs.getValue("migrate", "none").equals("done")) {
445 //userArchiveLists.add(lid);
449 String instGroupName = lid.getListeInstDetailsName().trim();
451 String suffixToRemove = " - Parents";
452 if(instGroupName.endsWith(suffixToRemove)){
454 //instGroupName = instGroupName.substring(0 , (instGroupName.length()-suffixToRemove.length()));
457 userCurrentInstistutionalLists.add(lid);
459 } catch (Exception e) {
465 userInstitutionalLists.put(USER_CURRENT_LISTS, userCurrentInstistutionalLists);
466 userInstitutionalLists.put(USER_MIGRATE_LISTS, userArchiveLists);
468 return userInstitutionalLists;
472 * Get the user's personal lists (The ones he has created)
473 * @param group The group of the user current
474 * @param search The searching term to match
475 * @return a Liste List which contains the user's personal lists
477 public static List<Liste> getUserPersonalLists(Group group, String search) {
478 List<Liste> listPersoResult = new ArrayList<Liste>();
480 //Get all users personnal list
482 List<Liste> lesListes = ListeLocalServiceUtil.findByGroupId(group.getGroupId());
484 String searchQuery = getStringReadyForSearch(search);
486 for (Liste list : lesListes) {
487 String listName = "";
488 Map<String, List<ListProperty>> propsMap = ListeLocalServiceUtil.getPropertiesMap(list.getListeId());
489 if (propsMap.containsKey("name") && !propsMap.get("name").isEmpty()){
490 listName = propsMap.get("name").get(0).getValue_();
493 if (!listName.contains("LFR_ORGANIZATION"))
495 //Apply search filter
496 listName = getStringReadyForSearch(listName);
497 boolean isPositiveToSearch = (listName.length() >= searchQuery.length() && listName.contains(searchQuery));
499 if (search.equals("") || isPositiveToSearch) {
500 listPersoResult.add(list);
504 } catch (SystemException e) {
508 return listPersoResult;
512 * Get the user's friends lists
513 * @param user The user currently getting his friends list
514 * @param search The searching term to match
515 * @return a FriendFolder List which contains the user's friends lists
517 public static List<FriendFolder> getUserFriendsLists(User user, String search) {
518 List<FriendFolder> listAmisResult = new ArrayList<FriendFolder>();
519 List<FriendFolder> listesAmis;
522 listesAmis = FriendFolderLocalServiceUtil.getFriendFolderByUserIDParentFolderId(user.getUserId(), 0);
524 String searchQuery = getStringReadyForSearch(search);
526 for (FriendFolder ff : listesAmis) {
527 //Apply search filter
528 String friendsListNameNormalized = getStringReadyForSearch(ff.getName());
529 boolean isPositiveToSearch = (friendsListNameNormalized.length() >= searchQuery.length() && friendsListNameNormalized.contains(searchQuery));
531 if (search.equals("") || isPositiveToSearch) {
532 listAmisResult.add(ff);
535 } catch (SystemException e) {
539 return listAmisResult;
543 * Get the user's groups lists (without institutional ones)
544 * @param user The user currently getting his groups list
545 * @param search The searching term to match
546 * @return a Group List which contains the user's groups
548 public static List<Group> getUserGroupsLists(User user, String search) {
549 List<Group> groupListResult = new ArrayList<Group>();
551 LinkedHashMap<String, Object> groupParams = new LinkedHashMap<String, Object>();
552 groupParams.put("usersGroups", new Long(user.getUserId()));
553 groupParams.put("active", Boolean.TRUE);
554 GroupNameComparator gnc = new GroupNameComparator();
557 List<Group> userAllGroups = GroupLocalServiceUtil.search(user.getCompanyId(), null, null, groupParams, QueryUtil.ALL_POS, QueryUtil.ALL_POS, gnc);
559 String searchQuery = getStringReadyForSearch(search);
561 for (Group group: userAllGroups) {
562 if (group.getName().contains("LFR_ORGANIZATION")) {
566 //Apply search filter
567 String groupNameNormalized = getStringReadyForSearch(group.getName());
568 boolean isPositiveToSearch = (groupNameNormalized.length() >= searchQuery.length() && groupNameNormalized.contains(searchQuery));
570 if (search.equals("") || isPositiveToSearch) {
571 CommunityInfos ci = CommunityInfosLocalServiceUtil.getCommunityInfosByGroupId(group.getGroupId());
572 if (ci.getStatus() == 0 && ci.isGroupContactList()) {
573 groupListResult.add(group);
577 } catch (Exception e) {
581 return groupListResult;
585 * Lower and normalize a search term (the goal is to ignore case and accented characters)
586 * @param term A word to translate into normalized form
587 * @return the term ready for search
589 private static String getStringReadyForSearch(String term) {
590 term = term.toLowerCase();
591 term = Normalizer.normalize(term, Normalizer.Form.NFD);
592 term = term.replaceAll("[^\\p{ASCII}]","");