--- /dev/null
+/*******************************************************************************
+ * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
+ *
+ * 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>.
+ ******************************************************************************/
+package com.pentila.entSavoie.utils;
+
+import info.ineighborhood.cardme.io.CompatibilityMode;
+import info.ineighborhood.cardme.io.VCardWriter;
+import info.ineighborhood.cardme.vcard.VCardImpl;
+import info.ineighborhood.cardme.vcard.VCardVersion;
+import info.ineighborhood.cardme.vcard.features.AddressFeature;
+import info.ineighborhood.cardme.vcard.features.DisplayableNameFeature;
+import info.ineighborhood.cardme.vcard.features.FormattedNameFeature;
+import info.ineighborhood.cardme.vcard.features.NameFeature;
+import info.ineighborhood.cardme.vcard.features.NoteFeature;
+import info.ineighborhood.cardme.vcard.features.OrganizationFeature;
+import info.ineighborhood.cardme.vcard.features.RoleFeature;
+import info.ineighborhood.cardme.vcard.features.TelephoneFeature;
+import info.ineighborhood.cardme.vcard.types.AddressType;
+import info.ineighborhood.cardme.vcard.types.BeginType;
+import info.ineighborhood.cardme.vcard.types.DisplayableNameType;
+import info.ineighborhood.cardme.vcard.types.EmailType;
+import info.ineighborhood.cardme.vcard.types.EndType;
+import info.ineighborhood.cardme.vcard.types.FormattedNameType;
+import info.ineighborhood.cardme.vcard.types.NameType;
+import info.ineighborhood.cardme.vcard.types.NoteType;
+import info.ineighborhood.cardme.vcard.types.OrganizationType;
+import info.ineighborhood.cardme.vcard.types.RoleType;
+import info.ineighborhood.cardme.vcard.types.TelephoneType;
+import info.ineighborhood.cardme.vcard.types.VersionType;
+import info.ineighborhood.cardme.vcard.types.parameters.AddressParameterType;
+import info.ineighborhood.cardme.vcard.types.parameters.ParameterTypeStyle;
+import info.ineighborhood.cardme.vcard.types.parameters.TelephoneParameterType;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+import java.util.ResourceBundle;
+
+import net.fortuna.ical4j.model.DateTime;
+import net.fortuna.ical4j.model.TimeZone;
+import net.fortuna.ical4j.model.TimeZoneRegistry;
+import net.fortuna.ical4j.model.TimeZoneRegistryFactory;
+import net.fortuna.ical4j.model.component.VEvent;
+import net.fortuna.ical4j.model.component.VTimeZone;
+import net.fortuna.ical4j.model.property.CalScale;
+import net.fortuna.ical4j.model.property.Description;
+import net.fortuna.ical4j.model.property.Location;
+import net.fortuna.ical4j.model.property.ProdId;
+import net.fortuna.ical4j.model.property.Uid;
+import net.fortuna.ical4j.model.property.Url;
+import net.fortuna.ical4j.model.property.Version;
+
+import com.liferay.contacts.util.ListFicheFactory;
+import com.liferay.contacts.util.ProxyFiche;
+import com.liferay.portal.kernel.dao.orm.QueryUtil;
+import com.liferay.portal.kernel.exception.PortalException;
+import com.liferay.portal.kernel.exception.SystemException;
+import com.liferay.portal.kernel.json.JSONArray;
+import com.liferay.portal.kernel.json.JSONFactoryUtil;
+import com.liferay.portal.kernel.json.JSONObject;
+import com.liferay.portal.model.Organization;
+import com.liferay.portal.model.User;
+import com.liferay.portal.service.UserLocalServiceUtil;
+import com.liferay.portal.theme.ThemeDisplay;
+import com.pentila.entSavoie.ENTDisplayUtil;
+import com.pentila.entSavoie.agenda.model.EventAgenda;
+import com.pentila.entSavoie.agenda.model.Ressource;
+import com.pentila.entSavoie.agenda.service.EventAgendaLocalServiceUtil;
+import com.pentila.entSavoie.agenda.service.RessourceLocalServiceUtil;
+import com.pentila.entSavoie.amis.model.Relationship;
+import com.pentila.entSavoie.amis.service.RelationshipLocalServiceUtil;
+import com.pentila.entSavoie.cahierDeTexte.model.EventCDT;
+import com.pentila.entSavoie.cahierDeTexte.util.CDTUtil;
+import com.pentila.entSavoie.carnetDAdresses.FicheConstant;
+import com.pentila.entSavoie.carnetDAdresses.model.Fiche;
+import com.pentila.entSavoie.carnetDAdresses.model.Liste;
+import com.pentila.entSavoie.carnetDAdresses.service.FicheLocalServiceUtil;
+import com.pentila.entSavoie.carnetDAdresses.service.ListeLocalServiceUtil;
+
+public class ENTExport {
+
+
+ private static JSONObject getEventCDT(JSONObject evt, User user, Ressource res){
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ SimpleDateFormat onlyDate = new SimpleDateFormat("yyyy-MM-dd");
+ JSONObject e = JSONFactoryUtil.createJSONObject();
+
+ e.put("id", ""+evt.getLong("id") +res.getIdRessource() );
+ e.put("cid", res.getIdRessource());
+
+ Calendar cal = new GregorianCalendar();
+ String[] startEvt = evt.getString("ymd").split("-");
+ int intYear = Integer.valueOf(startEvt[0]);
+ int intMonth = Integer.valueOf(startEvt[1]) - 1;
+ int intDay = Integer.valueOf(startEvt[2]);
+
+ String[] startHour = evt.getString("startTime").split(":");
+ int intHour = Integer.valueOf(startHour[0]);
+ int intMinute = Integer.valueOf(startHour[1]);
+ int intSecond = 0;
+
+ cal.set(intYear, intMonth, intDay, intHour, intMinute, intSecond);
+ e.put("start", df.format(cal.getTime()));
+
+
+ String[] endEvt = evt.getString("eymd").split("-");
+ intYear = Integer.valueOf(endEvt[0]);
+ intMonth = Integer.valueOf(endEvt[1]) - 1;
+ intDay = Integer.valueOf(endEvt[2]);
+
+ String[] endHour = evt.getString("endTime").split(":");
+ intHour = Integer.valueOf(endHour[0]);
+ intMinute = Integer.valueOf(endHour[1]);
+ intSecond = 0;
+
+ cal.set(intYear, intMonth, intDay, intHour, intMinute, intSecond);
+
+ e.put("end", df.format(cal.getTime()));
+
+ e.put("title", evt.getString("subject"));
+ e.put("notes", getDescription(evt));
+ e.put("url", "");
+ e.put("loc", "");
+ e.put("ad", false);
+ e.put("rem", "");
+ e.put("recur_rule", "");
+ e.put("recurrenceId", 0);
+ e.put("recurrenceScope", "one"); // par defaut on ne modifie que l'evt
+
+
+ e.put("isEditable", false);
+
+ // auteur de l'evt
+
+ long authorId = evt.getLong("creatorId");
+
+ String author = evt.getString("creatorName");
+
+
+ e.put("author", author);
+ e.put("authorId", authorId);
+ e.put("userId", user.getUserId());
+ e.put("token", new Date().getTime());
+
+ return e;
+ }
+
+ public static List<String> exportRessourceAgenda(User user, JSONArray ressourceIdArray, JSONArray ressourceNameArray, ThemeDisplay themeDisplay, ResourceBundle messages, Date startDate, Date endDate, long filteredEtabOrgId) throws URISyntaxException, PortalException, SystemException, ParseException{
+ long ressourceId;
+
+// List <FileOutputStream> listFile = new ArrayList<FileOutputStream>();
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ List <String> listCalendar = new ArrayList<String>();
+ for(int i=0; i < ressourceIdArray.length(); i++){
+ ressourceId = ressourceIdArray.getLong(i);
+
+ // on doit juste supprimer via le service car les dependances sont supprimées au niveau du service
+ Ressource res = RessourceLocalServiceUtil.getRessource(ressourceId);
+ if(res.getKind() != 2){
+ List <EventAgenda> listEvent = EventAgendaLocalServiceUtil.getEventAgendaByCallIdRangeDate(res.getIdRessource(), startDate, endDate);
+
+ net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
+ calendar.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN"));
+ calendar.getProperties().add(Version.VERSION_2_0);
+ calendar.getProperties().add(CalScale.GREGORIAN);
+
+
+ TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
+ TimeZone timezone = registry.getTimeZone("Europe/Paris");
+ VTimeZone tz = timezone.getVTimeZone();
+ calendar.getComponents().add(tz);
+
+ for(EventAgenda evt : listEvent){
+
+ net.fortuna.ical4j.model.Date startAllDay = new net.fortuna.ical4j.model.Date(evt.getStartEvt().getTime() + (3600*2000));
+ net.fortuna.ical4j.model.Date endAllDay = new net.fortuna.ical4j.model.Date(evt.getEndEvt().getTime() + (3600*2000));
+
+ java.util.Calendar c = java.util.Calendar.getInstance();
+ c.setTime(endAllDay);
+ c.add(java.util.Calendar.DATE, 1);
+ endAllDay = new net.fortuna.ical4j.model.Date(c.getTime());
+
+ DateTime start = new DateTime(evt.getStartEvt());
+ start.setTimeZone(timezone);
+ start.setUtc(false);
+ DateTime end = new DateTime(evt.getEndEvt());
+ end.setTimeZone(timezone);
+ end.setUtc(false);
+
+ VEvent e;
+ if(evt.getIsAllDay()){
+ e = new VEvent(startAllDay, endAllDay, evt.getTitle());
+ }else{
+ e = new VEvent(start, end, evt.getTitle());
+ }
+
+
+ Uid uid = new Uid(""+evt.getEvtId() + "@Nero");
+ Description desc = new Description(evt.getNotes());
+ Location loc = new Location(evt.getLocation());
+ Url url = new Url(new URI(evt.getUrl()));
+ e.getProperties().add(uid);
+ e.getProperties().add(loc);
+ e.getProperties().add(desc);
+ e.getProperties().add(url);
+
+
+
+ calendar.getComponents().add(e);
+ }
+ listCalendar.add(calendar.toString());
+ }else{
+ JSONArray listEvents = JSONFactoryUtil.createJSONArray();
+ JSONArray events = JSONFactoryUtil.createJSONArray();
+ try {
+
+ JSONObject result = CDTUtil.calendarEvent_listJSON(user.getUserId(), res.getCdtUserId(), res.getFiltreCours(), res.getClasse(), res.getMatiere(), res.getOnlyMyClass(), startDate, endDate, filteredEtabOrgId, themeDisplay, messages);
+ listEvents = result.getJSONArray("results");
+
+ } catch (PortalException e) {
+ e.printStackTrace();
+ } catch (SystemException e) {
+ e.printStackTrace();
+ }
+
+ for(int j=0; j<listEvents.length(); j++){
+ events.put(getEventCDT(listEvents.getJSONObject(j), user, res));
+ }
+
+ net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
+ calendar.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN"));
+ calendar.getProperties().add(Version.VERSION_2_0);
+ calendar.getProperties().add(CalScale.GREGORIAN);
+
+
+ TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
+ TimeZone timezone = registry.getTimeZone("Europe/Paris");
+ VTimeZone tz = timezone.getVTimeZone();
+ calendar.getComponents().add(tz);
+
+ for(int j=0; j<events.length(); j++){
+
+ JSONObject e = events.getJSONObject(j);
+
+ DateTime start = new DateTime(df.parse(e.getString("start")));
+ start.setTimeZone(timezone);
+ start.setUtc(false);
+ DateTime end = new DateTime(df.parse(e.getString("end")));
+ end.setTimeZone(timezone);
+ end.setUtc(false);
+
+ VEvent vEvent = new VEvent(start, end, e.getString("title"));
+
+ Uid uid = new Uid(e.getString("id") + "@Nero");
+ Description desc = new Description(e.getString("notes"));
+ Location loc = new Location(e.getString("location"));
+ Url url = new Url(new URI(e.getString("url")));
+ vEvent.getProperties().add(uid);
+ vEvent.getProperties().add(loc);
+ vEvent.getProperties().add(desc);
+ vEvent.getProperties().add(url);
+
+ calendar.getComponents().add(vEvent);
+ }
+ listCalendar.add(calendar.toString());
+ }
+ }
+
+ return listCalendar;
+ }
+
+ private static String getDescription(JSONObject evt){
+// + " - " + evt.getGroupId() +" <br/> " + evt.getDescription()
+
+ String result = "";
+
+ result += "<b>" + evt.getString("matiereLabel") + "</b> - ";
+
+ result += evt.getString("classeName") + "<br/>";
+
+ String description = evt.getString("description");
+
+ if(!description.equals("")){
+ result += description + "<br/>";
+ }
+
+ String annotation = evt.getString("annotation");
+
+ if(!annotation.equals("")){
+ result += "<b>Annotation :</b> " + annotation + "<br/><br/>";
+ }
+
+
+// String attachText = evt.getString("attachments");
+// if(attachText.length() > 2){
+// JSONArray attach = JSONFactoryUtil.createJSONArray();
+// try {
+// attach = JSONFactoryUtil.createJSONArray(attachText);
+// } catch (JSONException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+//
+// result += "<b>piece(s) jointe(s) :</b> <ul>";
+// for(int i=0; i<attach.length(); i++){
+// result += "<li>" + attach.getJSONObject(i).getString("fileHref") + "</li>";
+// }
+// result += "</ul>";
+// }
+
+ return result;
+
+ }
+
+ public static List<String> exportCDT(User user, Date startDate, Date endDate, long filteredEtabOrgId) throws PortalException, SystemException{
+ final Long userId = user.getUserId();
+ final Integer showFilter = 0;
+ final Long calendarIdShow = -1l;
+
+ //final String filterSubjectId = actionRequest.getParameter("filterSubjectId");
+ final String filterSubjectIds = "[-1]";
+ final Boolean onlyCreatorEvent = false;
+
+
+ List<EventCDT> listEvt = CDTUtil.calendarEvent_list(userId, showFilter, calendarIdShow, filterSubjectIds, onlyCreatorEvent, startDate, endDate, filteredEtabOrgId);
+ List <String> listCalendar = new ArrayList<String>();
+ net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
+ calendar.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN"));
+ calendar.getProperties().add(Version.VERSION_2_0);
+ calendar.getProperties().add(CalScale.GREGORIAN);
+
+
+ TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
+ TimeZone timezone = registry.getTimeZone("Europe/Paris");
+ VTimeZone tz = timezone.getVTimeZone();
+ calendar.getComponents().add(tz);
+ for(EventCDT evt : listEvt){
+
+ net.fortuna.ical4j.model.Date startAllDay = new net.fortuna.ical4j.model.Date(evt.getStartDay());
+ net.fortuna.ical4j.model.Date endAllDay = new net.fortuna.ical4j.model.Date(evt.getEndDay());
+
+ java.util.Calendar c = java.util.Calendar.getInstance();
+ c.setTime(endAllDay);
+ c.add(java.util.Calendar.DATE, 1);
+ endAllDay = new net.fortuna.ical4j.model.Date(c.getTime());
+
+ DateTime start = new DateTime(evt.getStartDay());
+ start.setTimeZone(timezone);
+ start.setUtc(false);
+ DateTime end = new DateTime(evt.getEndDay());
+ end.setTimeZone(timezone);
+ end.setUtc(false);
+
+ VEvent e = new VEvent(start, end, evt.getSubject());
+
+
+ Uid uid = new Uid(""+evt.getEvtId() + "@Nero");
+ Description desc = new Description(evt.getDescription());
+ Location loc = new Location("");
+ e.getProperties().add(uid);
+ e.getProperties().add(loc);
+ e.getProperties().add(desc);
+
+ calendar.getComponents().add(e);
+ }
+
+ listCalendar.add(calendar.toString());
+
+ return listCalendar;
+ }
+
+ public static String exportVcard(User user, JSONArray listArray, ThemeDisplay themeDisplay) throws SystemException, PortalException{
+
+ List<ProxyFiche> lesFiches = new ArrayList<ProxyFiche>();
+ String finalVcard = "";
+
+ for (int i=0; i<listArray.length(); i++) {
+
+ JSONObject jobj = listArray.getJSONObject(i);
+ String mbrtype = jobj.getString("type");
+
+ if (!mbrtype.equals("")) {
+ // cas d'une liste
+ if (mbrtype.equals("all")) {
+ // cas de tous mes contacts
+ lesFiches.addAll(ListFicheFactory.createAllContacts(user));
+ }
+ else if (mbrtype.equals("perso")) {
+ // cas de tous mes contacts personnels
+ lesFiches.addAll(ListFicheFactory.createPersoContacts(user));
+ }
+ else if (mbrtype.equals("allAmis")) {
+ List<Relationship> listAllRel = RelationshipLocalServiceUtil.getRelationshipByUserIdStateId(user.getUserId(), 2, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
+ List<Long> lesAmis = new ArrayList<Long>();
+ for(Relationship rel : listAllRel){
+ lesAmis.add(rel.getFriendId());
+ }
+ lesFiches.addAll(ListFicheFactory.createAmisContacts(user, lesAmis));
+ }
+ else if (mbrtype.equals("amis")) {
+ long listId = jobj.getLong("listId");
+ List<Relationship> listRel = RelationshipLocalServiceUtil.getRelationshipByUserIdFriendFolderIdStateId(user.getUserId(), listId, 2, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
+ List<Long> lesAmis = new ArrayList<Long>();
+ for(Relationship rel : listRel){
+ lesAmis.add(rel.getFriendId());
+ }
+ lesFiches.addAll(ListFicheFactory.createAmisContacts(user, lesAmis));
+ }
+ else if (mbrtype.equals("inst")) {
+ // cas de tous mes contact inst
+ lesFiches.addAll(ListFicheFactory.createInstContacts(user));
+ }
+ else if (mbrtype.equals("local")) {
+ // cas d'une liste perso
+ long listId = jobj.getLong("listId");
+ Liste userListe = ListeLocalServiceUtil.getListe(listId);
+ lesFiches.addAll(ListFicheFactory.createUserListContacts(user, userListe));
+ }
+ else if (mbrtype.equals("search")) {
+ // cas d'une organisation
+ String roleId = jobj.getString("roleId");
+ String orgId = jobj.getString("orgId");
+ long listId = jobj.getLong("listId");
+ Long roleIdL = new Long(0);
+ Long orgIdL = new Long(0);
+
+ if (!roleId.equals("")) {
+ roleIdL = Long.valueOf(roleId);
+ }
+ if (!orgId.equals("")) {
+ orgIdL = Long.valueOf(orgId);
+ }
+
+ lesFiches.addAll(ListFicheFactory.createSearchContacts(user, orgIdL, roleIdL, listId));
+ }
+ else if (mbrtype.equals("user")){
+ lesFiches.add(new ProxyFiche(
+ user,
+ UserLocalServiceUtil.getUser(Long.valueOf(jobj.getString("userId")))));
+ }
+ else if (mbrtype.equals("fiche")){
+ Fiche current = FicheLocalServiceUtil.getFiche(new Long(jobj.getString("userId")));
+
+ lesFiches.add(new ProxyFiche(user, current));
+
+ }
+ else {
+ // ce cas ne doit jamais arriver
+
+ }
+ }
+ else {
+ // cas d'un user, il demarrre avec un 2
+
+ }
+ }
+
+ VCardWriter writer = new VCardWriter();
+ writer.setCompatibilityMode(CompatibilityMode.RFC2426);
+
+ for (ProxyFiche f : lesFiches) {
+
+ VCardImpl tmpVcard = new VCardImpl();
+ tmpVcard.setVersion(new VersionType(VCardVersion.V3_0));
+
+ tmpVcard.setBegin(new BeginType());
+ tmpVcard.setEnd(new EndType());
+
+ DisplayableNameFeature displayableName = new DisplayableNameType(f.getPrenom() + " " + f.getNom());
+ tmpVcard.setDisplayableNameFeature(displayableName);
+
+ NameFeature name = new NameType(f.getNom(), f.getPrenom());
+ tmpVcard.setName(name);
+
+ FormattedNameFeature formattedName = new FormattedNameType();
+ formattedName.setFormattedName(f.getPrenom() + " " + f.getNom());
+ tmpVcard.setFormattedName(formattedName);
+
+ AddressFeature addressFeature = new AddressType();
+ addressFeature.addAddressParameterType(AddressParameterType.HOME);
+
+ tmpVcard.addEmail(new EmailType(f.getMail()));
+
+ RoleFeature role = new RoleType(f.getStatut());
+ tmpVcard.setRole(role);
+
+ JSONObject jsonProperties = null;
+ try {
+ jsonProperties = FicheLocalServiceUtil.getProperties(new Long(f.getId()));
+ } catch (Exception e){}
+
+ if (jsonProperties != null) {
+
+ // Organization
+ String[] orgs = jsonProperties.getString(FicheConstant.ORGANIZATION).split(",");
+ if (orgs.length > 0) {
+ OrganizationFeature organizations = new OrganizationType();
+ //On set seulement les 2 premières si elles existent (ENT et collège)
+ organizations.addOrganization(orgs[0]);
+
+ if (orgs.length > 1) {
+ organizations.addOrganization(orgs[1]);
+ }
+
+ tmpVcard.setOrganizations(organizations);
+ }
+
+ // Phone
+ String phone = jsonProperties.getString(FicheConstant.PHONE);
+ if(!phone.isEmpty()){
+ TelephoneFeature telephone2 = new TelephoneType();
+ telephone2.setTelephone(phone);
+ telephone2.addTelephoneParameterType(TelephoneParameterType.CELL);
+ telephone2.setParameterTypeStyle(ParameterTypeStyle.PARAMETER_LIST);
+ tmpVcard.addTelephoneNumber(telephone2);
+ }
+
+ // Mobile
+ String mobile = jsonProperties.getString(FicheConstant.MOBILE);
+ if(!mobile.isEmpty()){
+ TelephoneFeature telephone2 = new TelephoneType();
+ telephone2.setTelephone(mobile);
+ telephone2.addTelephoneParameterType(TelephoneParameterType.CELL);
+ telephone2.setParameterTypeStyle(ParameterTypeStyle.PARAMETER_LIST);
+ tmpVcard.addTelephoneNumber(telephone2);
+ }
+
+ // Fax
+ String fax = jsonProperties.getString(FicheConstant.FAX);
+ if(!fax.isEmpty()){
+ TelephoneFeature telephone3 = new TelephoneType();
+ telephone3.setTelephone(fax);
+ telephone3.addTelephoneParameterType(TelephoneParameterType.FAX);
+ telephone3.setParameterTypeStyle(ParameterTypeStyle.PARAMETER_LIST);
+ tmpVcard.addTelephoneNumber(telephone3);
+ }
+
+ // Address
+ String address = jsonProperties.getString(FicheConstant.ADDRESS);
+ if(!address.isEmpty()){
+ addressFeature.setStreetAddress(address);
+ }
+
+ // City
+ String city = jsonProperties.getString(FicheConstant.CITY);
+ if(!city.isEmpty()){
+ addressFeature.setLocality(city);
+ }
+
+ // Postal Code
+ String postalCode = jsonProperties.getString(FicheConstant.POSTAL_CODE);
+ if(!postalCode.isEmpty()){
+ addressFeature.setPostalCode(postalCode);
+ }
+
+ // Note
+ String note = jsonProperties.getString(FicheConstant.NOTE);
+ if(!note.isEmpty()){
+ NoteFeature noteFeature = new NoteType();
+ noteFeature.setNote(note);
+ tmpVcard.addNote(noteFeature);
+ }
+
+ tmpVcard.addAddress(addressFeature);
+
+ }
+ else {
+ // Cas d'un user
+ //On set juste l'organisation
+ long idUser = 0;
+
+ String typeUser = f.getType();
+ if (typeUser.equals("user")) {
+ idUser = Long.valueOf(f.getId());
+ } else {
+ idUser = Long.valueOf(f.getRelUserId());
+ }
+ if (idUser != 0) {
+ User u = UserLocalServiceUtil.getUser(idUser);
+ List<Organization> orgs = u.getOrganizations();
+ if (orgs.size() > 0) {
+ OrganizationFeature organizations = new OrganizationType();
+ //On set seulement les 2 premières si elles existent (ENT et collège)
+ organizations.addOrganization(ENTDisplayUtil.formatSCONETName(user, orgs.get(0).getName()));
+
+ if (orgs.size() > 1) {
+ organizations.addOrganization(ENTDisplayUtil.formatSCONETName(user, orgs.get(1).getName()));
+ }
+
+ tmpVcard.setOrganizations(organizations);
+ }
+ }
+
+ }
+
+ writer.setVCard(tmpVcard);
+ finalVcard += writer.buildVCardString();
+ }
+
+ return finalVcard;
+ }
+}