--- /dev/null
+<% /**
+*Copyright © Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+*
+*This file is part of the work and learning management system Pentila Nero.
+*
+*Pentila Nero is free software. You can redistribute it and/or modify since
+*you respect the terms of either (at least one of the both license) :
+*- under the terms of the GNU Affero General Public License as
+*published by the Free Software Foundation, either version 3 of the
+*License, or (at your option) any later version.
+*- the CeCILL-C as published by CeCILL-C; either version 1 of the
+*License, or any later version
+*- the GNU Lesser General Public License as published by the
+*Free Software Foundation, either version 3 of the license,
+*or (at your option) any later version.
+*
+*There are special exceptions to the terms and conditions of the
+*licenses as they are applied to this software. View the full text of
+*the exception in file LICENSE-PROJECT.txt in the directory of this software
+*distribution.
+*
+*Pentila Nero is distributed in the hope that it will be useful,
+*but WITHOUT ANY WARRANTY; without even the implied warranty of
+*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+*Licenses for more details.
+*
+*You should have received a copy of the GNU Affero General Public License
+*and the CeCILL-C and the GNU Lesser General Public License along with
+*Pentila Nero. If not, see :
+*<http://www.gnu.org/licenses/> and
+*<http://www.cecill.info/licences.fr.html>.
+*/ %>
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<%@page import="java.util.Locale"%>
+<%@page import="java.text.Collator"%>
+<%@ include file="./initAjax.jsp" %>
+<%
+
+ renderResponse.setContentType("text/xml");
+ response.setContentType("text/xml");
+ response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache");
+
+ ResourceBundle messagesBundle = portletConfig.getResourceBundle(locale);
+
+ String query = ParamUtil.getString(request, "query", "");
+
+ /*Instantiation de l'operateur de comparaison avec Collator*/
+ Collator compareOperator = Collator.getInstance(Locale.FRENCH);
+ compareOperator.setStrength (Collator.PRIMARY);
+
+ int sizeQuery = query.length();
+
+ // Clé du cache
+ String cacheKeyPF="UserMailCompletionPF_"+user.getUserId();
+ String cacheKeyList="UserMailCompletionList_"+user.getUserId();
+
+ // Get value from cache instance
+ List<ProxyFiche> cachePF = (List<ProxyFiche>) ENTCacheUtils.getObjectFromCache(cacheKeyPF);
+ List<ProxyListCompletion> cacheList = (List<ProxyListCompletion>) ENTCacheUtils.getObjectFromCache(cacheKeyList);
+
+ if(cachePF==null){
+ // calcul du cache PF
+ cachePF = ListFicheFactory.createPersoContacts(user);
+ // on cache pour 10mn
+ ENTCacheUtils.storeObjectIntoCache(cacheKeyPF,cachePF, 600000);
+
+ }
+
+ Set<ProxyFiche> pfSet = new TreeSet<ProxyFiche>();
+ for (ProxyFiche f : cachePF) {
+ if (f.getType().equals("fiche") && f.getRelUserId().equals("")) {
+ continue;
+ }
+ if ((f.getNom().length()>=sizeQuery && (compareOperator.compare(f.getNom().substring(0,sizeQuery),query)==0)) ||
+ (f.getPrenom().length()>=sizeQuery && (compareOperator.compare(f.getPrenom().substring(0,sizeQuery),query)==0)) ||
+ ((f.getNom() + " " + f.getPrenom()).length()>=sizeQuery && (compareOperator.compare((f.getNom() + " " + f.getPrenom()).substring(0,sizeQuery),query)==0)) ||
+ ((f.getPrenom() + " " + f.getNom()).length()>=sizeQuery && (compareOperator.compare((f.getPrenom() + " " + f.getNom()).substring(0,sizeQuery),query)==0))) {
+ pfSet.add(f);
+ }
+ }
+
+
+ if(cacheList==null){
+ cacheList = new ArrayList<ProxyListCompletion>();
+ cacheList.add(new ProxyListCompletion(messagesBundle.getString("tous-mes-contacts-liste"), messagesBundle.getString("tous-mes-contacts-liste"), "all", "", "", ""));
+ cacheList.add(new ProxyListCompletion(messagesBundle.getString("tous-mes-contacts-perso-liste"), messagesBundle.getString("tous-mes-contacts-perso-liste"), "perso", "", "", ""));
+ cacheList.add(new ProxyListCompletion(messagesBundle.getString("tous-mes-amis-liste"), messagesBundle.getString("tous-mes-amis-liste"), "allAmis", "", "", ""));
+ cacheList.add(new ProxyListCompletion(messagesBundle.getString("tous-mes-contacts-inst-liste"), messagesBundle.getString("tous-mes-contacts-inst-liste"), "inst", "", "", ""));
+
+ List<Liste> lesListes = ListeLocalServiceUtil.findByGroupId(user.getGroup().getGroupId());
+ for (Liste list : lesListes) {
+ Map<String, List<ListProperty>> propsMapRes = ListeLocalServiceUtil.getPropertiesMap(list.getListeId());
+ String lName = propsMapRes.get("name").get(0).getValue();
+ cacheList.add(new ProxyListCompletion(lName + " " + messagesBundle.getString("liste"), lName + " " + messagesBundle.getString("liste"), "local", "", "", String.valueOf(list.getListeId())));
+ }
+
+ List<FriendFolder> listesAmis= FriendFolderLocalServiceUtil.getFriendFolderByUserIDParentFolderId(user.getUserId(),0);
+ for (FriendFolder ff : listesAmis) {
+ cacheList.add(new ProxyListCompletion(ff.getName() + " " + messagesBundle.getString("liste"), ff.getName() + " " + messagesBundle.getString("liste"), "amis", "", "", String.valueOf(ff.getFriendFolderId())));
+ }
+
+ InstitutionalListsFactory ilf = new InstitutionalListsFactory(user);
+ List<ProxyList> pls = ilf.getInstitutionnalProxyLists();
+ for (ProxyList pl : pls) {
+ cacheList.add(new ProxyListCompletion(pl.getName() + " " + messagesBundle.getString("liste"), pl.getName() + " " + messagesBundle.getString("liste"), pl.getType(), pl.getOrgId(), pl.getRoleId(), pl.getListeId()));
+ }
+
+
+
+ //CAS DES COMMUNAUTES
+ // presente l ensemble des groupes de l'utilisateur
+ LinkedHashMap<String, Object> groupParams = new LinkedHashMap<String, Object>();
+ groupParams.put("usersGroups", new Long(user.getUserId()));
+ groupParams.put("active", Boolean.TRUE);
+ GroupNameComparator gnc = new GroupNameComparator();
+
+ List<Group> resultsTmp = GroupLocalServiceUtil.search(user.getCompanyId(), null, null, groupParams, QueryUtil.ALL_POS, QueryUtil.ALL_POS, gnc);
+
+
+
+ for (Group gr : resultsTmp) {
+ try {
+ CommunityInfos ci = CommunityInfosLocalServiceUtil.getCommunityInfosByGroupId(gr.getGroupId());
+ if (ci.getStatus()==0) {
+ cacheList.add(new ProxyListCompletion(gr.getName() + " " + messagesBundle.getString("liste"), gr.getName() + " " + messagesBundle.getString("liste"), "search", "", "", String.valueOf(gr.getGroupId())));
+ }
+ }
+ catch(Exception e) {}
+
+ }
+ // on cache pour 10mn
+ ENTCacheUtils.storeObjectIntoCache(cacheKeyList, cacheList, 600000);
+
+ }
+
+ List<ProxyListCompletion> plCompResult = new ArrayList<ProxyListCompletion>();
+ for (ProxyListCompletion plc: cacheList) {
+ if (plc.getDisplay().length()>=sizeQuery && (compareOperator.compare(plc.getDisplay().substring(0,sizeQuery),query)==0)) {
+ plCompResult.add(plc);
+ }
+ }
+
+
+%>
+
+<%@page import="com.liferay.contacts.util.ListFicheFactory"%>
+<%@page import="com.liferay.contacts.util.ProxyFiche"%>
+<%@page import="java.util.ArrayList"%>
+<%@page import="java.util.Collections"%>
+<%@page import="com.liferay.portal.kernel.util.OrderByComparator"%>
+<%@page import="com.pentila.entSavoie.carnetDAdresses.CAEmailComparator"%>
+
+
+<%@page import="java.util.SortedSet"%>
+<%@page import="java.util.TreeSet"%>
+<%@page import="java.util.Set"%>
+<%@page import="javax.mail.internet.InternetAddress"%>
+<%@page import="javax.mail.internet.AddressException"%>
+<%@page import="java.util.Date"%>
+<%@page import="com.pentila.entSavoie.utils.ENTCacheUtils"%>
+<%@page import="java.util.Arrays"%>
+<%@page import="com.pentila.entSavoie.carnetDAdresses.model.Liste"%>
+<%@page import="com.pentila.entSavoie.carnetDAdresses.service.ListeLocalServiceUtil"%>
+<%@page import="com.pentila.entSavoie.carnetDAdresses.model.ListProperty"%>
+<%@page import="java.util.Map"%>
+<%@page import="com.pentila.entSavoie.amis.model.FriendFolder"%>
+<%@page import="com.pentila.entSavoie.amis.service.FriendFolderLocalServiceUtil"%>
+<%@page import="com.liferay.contacts.util.InstitutionalListsFactory"%>
+<%@page import="com.liferay.contacts.util.ProxyList"%>
+<%@page import="com.liferay.portal.util.comparator.GroupNameComparator"%>
+<%@page import="com.liferay.portal.service.GroupLocalServiceUtil"%>
+<%@page import="com.liferay.portal.model.Group"%>
+<%@page import="com.pentila.entSavoie.communityInfos.model.CommunityInfos"%>
+<%@page import="com.pentila.entSavoie.communityInfos.service.CommunityInfosLocalServiceUtil"%>
+<%@page import="com.liferay.contacts.util.ProxyListCompletion"%>
+<%@page import="java.util.ResourceBundle"%><completions>
+ <% for (ProxyFiche pf : pfSet) {
+ String userId = (pf.getType().equals("fiche"))?pf.getRelUserId():pf.getId();
+ if(!userId.equals("0")){
+ %>
+
+ <completion>
+ <value><![CDATA[2<%= userId %>]]></value>
+ <display><![CDATA[<%= pf.getPrenom() + " " +pf.getNom() %>]]></display>
+ <type></type>
+ </completion>
+
+ <%
+ }
+ }
+ %>
+
+ <% for (ProxyListCompletion plc: plCompResult) {
+ %>
+ <%= plc.getXML() %>
+ <%
+ }
+ %>
+</completions>
+