--- /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.proxy;
+
+import java.text.SimpleDateFormat;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+import com.liferay.portal.kernel.dao.orm.QueryUtil;
+import com.liferay.portal.kernel.language.LanguageUtil;
+import com.liferay.portal.kernel.workflow.WorkflowConstants;
+import com.liferay.portal.model.Group;
+import com.liferay.portal.model.Organization;
+import com.liferay.portal.model.Role;
+import com.liferay.portal.model.RoleConstants;
+import com.liferay.portal.model.User;
+import com.liferay.portal.service.RoleLocalServiceUtil;
+import com.liferay.portal.service.UserGroupRoleLocalServiceUtil;
+import com.liferay.portal.service.UserLocalServiceUtil;
+import com.liferay.portal.util.comparator.UserLastNameComparator;
+import com.pentila.entSavoie.ENTDisplayUtil;
+import com.pentila.entSavoie.communityInfos.model.CommunityInfos;
+import com.pentila.entSavoie.communityInfos.model.GroupInfos;
+import com.pentila.entSavoie.communityInfos.service.CommunityInfosLocalServiceUtil;
+import com.pentila.entSavoie.communityInfos.service.GroupInfosLocalServiceUtil;
+import com.pentila.entSavoie.utils.ENTMainUtilsLocalServiceUtil;
+
+public class ProxyGroup {
+
+ SimpleDateFormat classicDateFormat = new SimpleDateFormat("dd-MM-yyyy");
+ //String[] politiqueArray ={"-", "Public","Restreint","Privé"};
+ String[] politiqueArray ={"-", "public","restricted","private"};
+
+ String name = "";
+ String id = "";
+ String url = "";
+ String type = "";
+ String description = "";
+ String creationDate = "";
+ String expirationDate = "";
+ int nbMembres = 0;
+ String politique = "";
+ int status = 0;
+ Boolean isInclude = false;
+ long etabId = 0;
+ Boolean isAdmin = false;
+ Boolean isDescEmpty = false;
+ String creatorName = "";
+ int scopeGrp = 1;
+ String defaultPortletView ="";
+
+ // should not be used anymore
+ public ProxyGroup(Group grp) {
+ setType("group");
+ setName(grp.getName());
+ setId(String.valueOf(grp.getGroupId()));
+ setUrl(grp.getFriendlyURL());
+ setDescription(grp.getDescription());
+
+ try {
+ GroupInfos grpInfos = GroupInfosLocalServiceUtil.getGroupInfos(grp.getGroupId());
+ setDefaultPortletView(grpInfos.getDefaultGroupView());
+ }
+ catch(Exception exc) {
+ // pas de grp infos
+ setDefaultPortletView(ENTMainUtilsLocalServiceUtil.getEntGroupDefaultView(grp.getCompanyId()));
+ }
+
+ }
+
+ public ProxyGroup(Group grp, String defaultView) {
+ setType("group");
+ setName(grp.getName());
+ setId(String.valueOf(grp.getGroupId()));
+ setUrl(grp.getFriendlyURL());
+ setDescription(grp.getDescription());
+
+ setDefaultPortletView(defaultView);
+
+ }
+
+ public ProxyGroup(Group grp, User user, String defaultView) {
+ this(grp, user);
+ setDefaultPortletView(defaultView);
+ }
+
+ public ProxyGroup(Group grp, User user) {
+ setType("group");
+ setName(grp.getName());
+ setId(String.valueOf(grp.getGroupId()));
+ setUrl(grp.getFriendlyURL());
+ setDescription(grp.getDescription());
+
+
+ try {
+ Role managerRole = RoleLocalServiceUtil.getRole(user.getCompanyId(), RoleConstants.SITE_ADMINISTRATOR);
+ Role ownerRole = RoleLocalServiceUtil.getRole(user.getCompanyId(), RoleConstants.SITE_OWNER);
+ boolean isManager = UserGroupRoleLocalServiceUtil.hasUserGroupRole(user.getUserId(), grp.getGroupId(), managerRole.getRoleId());
+ boolean isOwner = UserGroupRoleLocalServiceUtil.hasUserGroupRole(user.getUserId(), grp.getGroupId(), ownerRole.getRoleId());
+ setIsAdmin(isManager || isOwner);
+
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+
+ try {
+ // on met a jour les infos via les community infos si cela est possible
+ CommunityInfos ci = CommunityInfosLocalServiceUtil.getCommunityInfosByGroupId(grp.getGroupId());
+ setCreationDate(classicDateFormat.format(ci.getCreationDate()));
+ setExpirationDate(classicDateFormat.format(ci.getExpirationDate()));
+ setPolitique(LanguageUtil.get(user.getLocale(), politiqueArray[grp.getType()]));
+ setStatus(ci.getStatus());
+ setEtabId(ci.getEtabId());
+ setScopeGrp(ci.getScope());
+
+ final LinkedHashMap<String, Object> searchParams = new LinkedHashMap<String, Object>();
+ searchParams.put("usersGroups", grp.getGroupId());
+
+ List<User> users = UserLocalServiceUtil.search(
+ user.getCompanyId(),
+ "",
+ WorkflowConstants.STATUS_APPROVED,
+ searchParams,
+ QueryUtil.ALL_POS,
+ QueryUtil.ALL_POS,
+ new UserLastNameComparator());
+ setNbMembres(users.size());
+
+ setIsInclude(users.contains(user));
+
+ User creator = UserLocalServiceUtil.getUser(ci.getCreatorId());
+ setCreatorName(creator.getLastName() + " " + creator.getFirstName());
+
+
+ } catch (Exception e) {
+ // cela a pour effet d'etre filtre par la suite
+ setStatus(-1);
+ }
+ }
+
+ public ProxyGroup(Organization org, User user, String defaultView) {
+ this(org, user);
+ setDefaultPortletView(defaultView);
+ }
+
+ public ProxyGroup(Organization org, User user) {
+
+ Group grp = org.getGroup();
+ setType("org");
+ setName(ENTDisplayUtil.formatSCONETName(user, org.getName()));
+ setId(String.valueOf(org.getOrganizationId()));
+ setUrl(grp.getFriendlyURL());
+ setDescription(org.getComments());
+
+ }
+
+ public ProxyGroup(Organization org, User user, boolean createAsGroup, String defaultView) {
+ this(org, user, createAsGroup);
+
+ setDefaultPortletView(defaultView);
+ }
+
+ public ProxyGroup(Organization org, User user, boolean createAsGroup) {
+ setType("org");
+ if(createAsGroup){
+ setId(String.valueOf(org.getGroup().getGroupId()));
+ } else {
+ setId(String.valueOf(org.getOrganizationId()));
+ }
+ setName(ENTDisplayUtil.formatSCONETName(user, org.getName()));
+ setUrl(org.getGroup().getFriendlyURL());
+ setDescription(org.getComments());
+
+ }
+
+
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getId() {
+ return id;
+ }
+ public void setId(String id) {
+ this.id = id;
+ }
+ public String getUrl() {
+ return url;
+ }
+ public void setUrl(String url) {
+ this.url = url;
+ }
+ public String getType() {
+ return type;
+ }
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ if (description.isEmpty()){
+ setIsDescEmpty(true);
+ }
+ }
+
+ public String getCreationDate() {
+ return creationDate;
+ }
+
+ public void setCreationDate(String creationDate) {
+ this.creationDate = creationDate;
+ }
+
+ public String getExpirationDate() {
+ return expirationDate;
+ }
+
+ public void setExpirationDate(String expirationDate) {
+ this.expirationDate = expirationDate;
+ }
+
+
+ public String getPolitique() {
+ return politique;
+ }
+
+ public void setPolitique(String politique) {
+ this.politique = politique;
+ }
+
+ public Boolean getIsInclude() {
+ return isInclude;
+ }
+
+ public void setIsInclude(Boolean isInclude) {
+ this.isInclude = isInclude;
+ }
+
+ public int getStatus() {
+ return status;
+ }
+
+ public void setStatus(int status) {
+ this.status = status;
+ }
+
+ public int getNbMembres() {
+ return nbMembres;
+ }
+
+ public void setNbMembres(int nbMembres) {
+ this.nbMembres = nbMembres;
+ }
+
+ public long getEtabId() {
+ return etabId;
+ }
+
+ public void setEtabId(long etabId) {
+ this.etabId = etabId;
+ }
+
+ public Boolean getIsAdmin() {
+ return isAdmin;
+ }
+
+ public void setIsAdmin(Boolean isAdmin) {
+ this.isAdmin = isAdmin;
+ }
+
+ public Boolean getIsDescEmpty() {
+ return isDescEmpty;
+ }
+
+ public void setIsDescEmpty(Boolean isDescEmpty) {
+ this.isDescEmpty = isDescEmpty;
+ }
+
+ public String getCreatorName() {
+ return creatorName;
+ }
+
+ public void setCreatorName(String creatorName) {
+ this.creatorName = creatorName;
+ }
+
+ public int getScopeGrp() {
+ return scopeGrp;
+ }
+
+ public void setScopeGrp(int scopeGrp) {
+ this.scopeGrp = scopeGrp;
+ }
+
+ /**
+ * @return the defaultPortletView
+ */
+ public String getDefaultPortletView() {
+ return defaultPortletView;
+ }
+
+ /**
+ * @param defaultPortletView the defaultPortletView to set
+ */
+ public void setDefaultPortletView(String defaultPortletView) {
+ this.defaultPortletView = defaultPortletView;
+ }
+
+}