1 /*******************************************************************************
2 * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
3 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
4 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
6 * This file is part of the work and learning management system Pentila Nero.
8 * Pentila Nero is free software. You can redistribute it and/or modify since
9 * you respect the terms of either (at least one of the both license) :
10 * - under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 * - the CeCILL-C as published by CeCILL-C; either version 1 of the
14 * License, or any later version
15 * - the GNU Lesser General Public License as published by the
16 * Free Software Foundation, either version 3 of the license,
17 * or (at your option) any later version.
19 * There are special exceptions to the terms and conditions of the
20 * licenses as they are applied to this software. View the full text of
21 * the exception in file LICENSE-PROJECT.txt in the directory of this software
24 * Pentila Nero is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * Licenses for more details.
29 * You should have received a copy of the GNU Affero General Public License
30 * and the CeCILL-C and the GNU Lesser General Public License along with
31 * Pentila Nero. If not, see :
32 * <http://www.gnu.org/licenses/> and
33 * <http://www.cecill.info/licences.fr.html>.
34 ******************************************************************************/
35 package com.pentila.entSavoie.proxy;
37 import java.text.SimpleDateFormat;
38 import java.util.LinkedHashMap;
39 import java.util.List;
41 import com.liferay.portal.kernel.dao.orm.QueryUtil;
42 import com.liferay.portal.kernel.language.LanguageUtil;
43 import com.liferay.portal.kernel.workflow.WorkflowConstants;
44 import com.liferay.portal.model.Group;
45 import com.liferay.portal.model.Organization;
46 import com.liferay.portal.model.Role;
47 import com.liferay.portal.model.RoleConstants;
48 import com.liferay.portal.model.User;
49 import com.liferay.portal.service.RoleLocalServiceUtil;
50 import com.liferay.portal.service.UserGroupRoleLocalServiceUtil;
51 import com.liferay.portal.service.UserLocalServiceUtil;
52 import com.liferay.portal.util.comparator.UserLastNameComparator;
53 import com.pentila.entSavoie.ENTDisplayUtil;
54 import com.pentila.entSavoie.communityInfos.model.CommunityInfos;
55 import com.pentila.entSavoie.communityInfos.model.GroupInfos;
56 import com.pentila.entSavoie.communityInfos.service.CommunityInfosLocalServiceUtil;
57 import com.pentila.entSavoie.communityInfos.service.GroupInfosLocalServiceUtil;
58 import com.pentila.entSavoie.utils.ENTMainUtilsLocalServiceUtil;
60 public class ProxyGroup {
62 SimpleDateFormat classicDateFormat = new SimpleDateFormat("dd-MM-yyyy");
63 //String[] politiqueArray ={"-", "Public","Restreint","Privé"};
64 String[] politiqueArray ={"-", "public","restricted","private"};
70 String description = "";
71 String creationDate = "";
72 String expirationDate = "";
74 String politique = "";
76 Boolean isInclude = false;
78 Boolean isAdmin = false;
79 Boolean isDescEmpty = false;
80 String creatorName = "";
82 String defaultPortletView ="";
84 // should not be used anymore
85 public ProxyGroup(Group grp) {
87 setName(grp.getName());
88 setId(String.valueOf(grp.getGroupId()));
89 setUrl(grp.getFriendlyURL());
90 setDescription(grp.getDescription());
93 GroupInfos grpInfos = GroupInfosLocalServiceUtil.getGroupInfos(grp.getGroupId());
94 setDefaultPortletView(grpInfos.getDefaultGroupView());
96 catch(Exception exc) {
98 setDefaultPortletView(ENTMainUtilsLocalServiceUtil.getEntGroupDefaultView(grp.getCompanyId()));
103 public ProxyGroup(Group grp, String defaultView) {
105 setName(grp.getName());
106 setId(String.valueOf(grp.getGroupId()));
107 setUrl(grp.getFriendlyURL());
108 setDescription(grp.getDescription());
110 setDefaultPortletView(defaultView);
114 public ProxyGroup(Group grp, User user, String defaultView) {
116 setDefaultPortletView(defaultView);
119 public ProxyGroup(Group grp, User user) {
121 setName(grp.getName());
122 setId(String.valueOf(grp.getGroupId()));
123 setUrl(grp.getFriendlyURL());
124 setDescription(grp.getDescription());
128 Role managerRole = RoleLocalServiceUtil.getRole(user.getCompanyId(), RoleConstants.SITE_ADMINISTRATOR);
129 Role ownerRole = RoleLocalServiceUtil.getRole(user.getCompanyId(), RoleConstants.SITE_OWNER);
130 boolean isManager = UserGroupRoleLocalServiceUtil.hasUserGroupRole(user.getUserId(), grp.getGroupId(), managerRole.getRoleId());
131 boolean isOwner = UserGroupRoleLocalServiceUtil.hasUserGroupRole(user.getUserId(), grp.getGroupId(), ownerRole.getRoleId());
132 setIsAdmin(isManager || isOwner);
134 } catch (Exception e1) {
135 e1.printStackTrace();
139 // on met a jour les infos via les community infos si cela est possible
140 CommunityInfos ci = CommunityInfosLocalServiceUtil.getCommunityInfosByGroupId(grp.getGroupId());
141 setCreationDate(classicDateFormat.format(ci.getCreationDate()));
142 setExpirationDate(classicDateFormat.format(ci.getExpirationDate()));
143 setPolitique(LanguageUtil.get(user.getLocale(), politiqueArray[grp.getType()]));
144 setStatus(ci.getStatus());
145 setEtabId(ci.getEtabId());
146 setScopeGrp(ci.getScope());
148 final LinkedHashMap<String, Object> searchParams = new LinkedHashMap<String, Object>();
149 searchParams.put("usersGroups", grp.getGroupId());
151 List<User> users = UserLocalServiceUtil.search(
154 WorkflowConstants.STATUS_APPROVED,
158 new UserLastNameComparator());
159 setNbMembres(users.size());
161 setIsInclude(users.contains(user));
163 User creator = UserLocalServiceUtil.getUser(ci.getCreatorId());
164 setCreatorName(creator.getLastName() + " " + creator.getFirstName());
167 } catch (Exception e) {
168 // cela a pour effet d'etre filtre par la suite
173 public ProxyGroup(Organization org, User user, String defaultView) {
175 setDefaultPortletView(defaultView);
178 public ProxyGroup(Organization org, User user) {
180 Group grp = org.getGroup();
182 setName(ENTDisplayUtil.formatSCONETName(user, org.getName()));
183 setId(String.valueOf(org.getOrganizationId()));
184 setUrl(grp.getFriendlyURL());
185 setDescription(org.getComments());
189 public ProxyGroup(Organization org, User user, boolean createAsGroup, String defaultView) {
190 this(org, user, createAsGroup);
192 setDefaultPortletView(defaultView);
195 public ProxyGroup(Organization org, User user, boolean createAsGroup) {
198 setId(String.valueOf(org.getGroup().getGroupId()));
200 setId(String.valueOf(org.getOrganizationId()));
202 setName(ENTDisplayUtil.formatSCONETName(user, org.getName()));
203 setUrl(org.getGroup().getFriendlyURL());
204 setDescription(org.getComments());
209 public String getName() {
212 public void setName(String name) {
215 public String getId() {
218 public void setId(String id) {
221 public String getUrl() {
224 public void setUrl(String url) {
227 public String getType() {
230 public void setType(String type) {
234 public String getDescription() {
238 public void setDescription(String description) {
239 this.description = description;
240 if (description.isEmpty()){
241 setIsDescEmpty(true);
245 public String getCreationDate() {
249 public void setCreationDate(String creationDate) {
250 this.creationDate = creationDate;
253 public String getExpirationDate() {
254 return expirationDate;
257 public void setExpirationDate(String expirationDate) {
258 this.expirationDate = expirationDate;
262 public String getPolitique() {
266 public void setPolitique(String politique) {
267 this.politique = politique;
270 public Boolean getIsInclude() {
274 public void setIsInclude(Boolean isInclude) {
275 this.isInclude = isInclude;
278 public int getStatus() {
282 public void setStatus(int status) {
283 this.status = status;
286 public int getNbMembres() {
290 public void setNbMembres(int nbMembres) {
291 this.nbMembres = nbMembres;
294 public long getEtabId() {
298 public void setEtabId(long etabId) {
299 this.etabId = etabId;
302 public Boolean getIsAdmin() {
306 public void setIsAdmin(Boolean isAdmin) {
307 this.isAdmin = isAdmin;
310 public Boolean getIsDescEmpty() {
314 public void setIsDescEmpty(Boolean isDescEmpty) {
315 this.isDescEmpty = isDescEmpty;
318 public String getCreatorName() {
322 public void setCreatorName(String creatorName) {
323 this.creatorName = creatorName;
326 public int getScopeGrp() {
330 public void setScopeGrp(int scopeGrp) {
331 this.scopeGrp = scopeGrp;
335 * @return the defaultPortletView
337 public String getDefaultPortletView() {
338 return defaultPortletView;
342 * @param defaultPortletView the defaultPortletView to set
344 public void setDefaultPortletView(String defaultPortletView) {
345 this.defaultPortletView = defaultPortletView;