--- /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.userProperties.service.impl;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import com.liferay.portal.kernel.bean.PortletBeanLocatorUtil;
+import com.liferay.portal.kernel.dao.orm.Disjunction;
+import com.liferay.portal.kernel.dao.orm.DynamicQuery;
+import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
+import com.liferay.portal.kernel.dao.orm.Property;
+import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
+import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil;
+import com.liferay.portal.kernel.exception.PortalException;
+import com.liferay.portal.kernel.exception.SystemException;
+import com.liferay.portal.kernel.util.OrderByComparator;
+import com.liferay.portal.model.User;
+import com.liferay.portal.service.UserLocalServiceUtil;
+import com.pentila.entSavoie.userProperties.NoSuchUserPropertiesException;
+import com.pentila.entSavoie.userProperties.model.UserProperties;
+import com.pentila.entSavoie.userProperties.service.ClpSerializer;
+import com.pentila.entSavoie.userProperties.service.UserPropertiesLocalServiceUtil;
+import com.pentila.entSavoie.userProperties.service.base.UserPropertiesLocalServiceBaseImpl;
+import com.pentila.entSavoie.userProperties.service.persistence.UserPropertiesFinderUtil;
+import com.pentila.entSavoie.utils.ENTMainUtilsLocalServiceUtil;
+import com.pentila.entSavoie.utils.UserInformationsUtil;
+
+
+public class UserPropertiesLocalServiceImpl
+ extends UserPropertiesLocalServiceBaseImpl {
+
+ public UserProperties addUserProperties() throws PortalException, SystemException {
+ final long userPropertiesId = counterLocalService.increment();
+ final UserProperties userProperties = userPropertiesPersistence.create(userPropertiesId);
+ return userProperties;
+ }
+
+ public UserProperties addUserProperties(long userId, boolean portraitVisible) throws SystemException, PortalException {
+ User user = UserLocalServiceUtil.fetchUserById(userId);
+ UserProperties userProperties = this.addUserProperties(user, portraitVisible);
+
+ return userProperties;
+ }
+
+ public UserProperties addUserProperties(User user, boolean portraitVisible) throws SystemException, PortalException {
+ UserProperties userProperties = this.addUserProperties(user, portraitVisible, "list");
+
+ return userProperties;
+ }
+
+ public UserProperties addUserProperties(User user, boolean portraitVisible, String cartableView) throws SystemException, PortalException {
+ boolean forwardByMail = false;
+ if (ENTMainUtilsLocalServiceUtil.isEnableMailForward(user.getCompanyId())) {
+ forwardByMail = true;
+ }
+ UserProperties userProperties = this.addUserProperties(user, portraitVisible, cartableView, forwardByMail);
+
+ return userProperties;
+ }
+
+ public UserProperties addUserProperties(User user, boolean portraitVisible, String cartableView, boolean forwardByMail) throws SystemException, PortalException {
+ UserProperties userProperties = this.addUserProperties();
+
+ userProperties.setUserId(user.getUserId());
+ userProperties.setPortraitVisible(portraitVisible);
+ userProperties.setCartableView(cartableView);
+ userProperties.setCdtView("planning");
+ userProperties.setImSignature("");
+ userProperties.setEntPersonJointure("");
+ userProperties.setImUseSignature(false);
+ userProperties.setUnfoldMenu(false);
+ userProperties.setAjaxablePortlets(false);
+ userProperties.setMailPasswordRecovery("");
+ userProperties.setDateMailPasswordRecovery(new Date());
+ userProperties.setKeyPasswordRecovery("");
+
+ String suffixe = ENTMainUtilsLocalServiceUtil.getENTOrgRootSuffixeMail(user.getCompanyId());
+ boolean isMailValid = !user.getEmailAddress().equals(user.getScreenName()+suffixe);
+
+ if (forwardByMail && isMailValid) {
+ userProperties.setForwardByMail(forwardByMail);
+ userProperties.setForwardMail(user.getEmailAddress());
+ }
+ else {
+ userProperties.setForwardByMail(false);
+ userProperties.setForwardMail("");
+ }
+
+ userPropertiesPersistence.update(userProperties, false);
+
+ return userProperties;
+ }
+
+ public UserProperties getUserPropertiesByUserId(long userId) throws SystemException, PortalException {
+ try {
+ return userPropertiesPersistence.findByuserId(userId);
+ }
+ catch (NoSuchUserPropertiesException e) {
+ return addUserProperties(userId, true);
+ }
+ }
+
+ public UserProperties getUserPropertiesByENTPersonJointure(String entPersonJointure) throws SystemException, PortalException {
+ try {
+ return userPropertiesPersistence.findByentPersonJointure(entPersonJointure);
+ }
+ catch (NoSuchUserPropertiesException e) {
+ return null;
+ }
+ }
+
+ public void deleteUserPropertiesByUserId(long userId) throws SystemException, PortalException {
+ try {
+ userPropertiesPersistence.removeByuserId(userId);
+ }
+ catch (NoSuchUserPropertiesException e) {
+
+ }
+ }
+
+ public UserProperties getUserPropertiesByMailPasswordRecovery(String mailPasswordRecovery) throws SystemException, PortalException {
+ try {
+ return userPropertiesPersistence.findBymailPasswordRecovery(mailPasswordRecovery);
+ }
+ catch (NoSuchUserPropertiesException e) {
+ return null;
+ }
+ }
+
+ public UserProperties getUserPropertiesByKeyPasswordRecovery(String keyPasswordRecovery) throws SystemException, PortalException {
+ try {
+ return userPropertiesPersistence.findBykeyPasswordRecovery(keyPasswordRecovery);
+ }
+ catch (NoSuchUserPropertiesException e) {
+ return null;
+ }
+ }
+
+ public final List<Long> getRoleEtab(final Long etabId) throws SystemException, PortalException {
+ return userPropertiesFinder.getRoleEtab(etabId);
+ }
+
+ public final Long getCountUsersRoleEtab(final Long etabId, final Long roleId) throws SystemException, PortalException {
+ return userPropertiesFinder.countUsersRoleEtab(etabId, roleId);
+ }
+
+ public final List<User> getUserFromContactSearch(String query, List<Long> organizationIds, List<Long> roleIds, List<String> scolarshipsLabel,
+ int grant, int transport, int start, int stop, OrderByComparator obc) throws SystemException, PortalException {
+ return UserPropertiesFinderUtil.getUserFromContactSearch(query, organizationIds, roleIds, scolarshipsLabel, grant, transport, start, stop, obc);
+ }
+
+ public final Long getUserCountFromContactSearch(String query, List<Long> organizationIds, List<Long> roleIds, List<String> scolarshipsLabel,
+ int grant, int transport) throws SystemException, PortalException {
+ return UserPropertiesFinderUtil.getUserCountFromContactSearch(query, organizationIds, roleIds, scolarshipsLabel, grant, transport);
+ }
+
+ public List<UserProperties> filterScholarshipAndGrant(List<User> userList, String scholarship, int grant, int transport) {
+
+ System.out.println("Start filterScholarshipAndGrant");
+ List<UserProperties> filteredUserProperties = new ArrayList<UserProperties>();
+
+ ClassLoader classLoader = (ClassLoader)PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(),"portletClassLoader");
+ DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(UserProperties.class,classLoader);
+ Disjunction disjunctionUserIds = RestrictionsFactoryUtil.disjunction();
+ Property userIdProperty = PropertyFactoryUtil.forName("userId");
+
+ if (userList != null && userList.size() > 0) {
+
+ long time0 = System.currentTimeMillis();
+ for (User user : userList){
+ disjunctionUserIds.add(userIdProperty.eq(user.getUserId()));
+ }
+ dynamicQuery.add(disjunctionUserIds);
+
+ List<UserProperties> userPropertiesList = new ArrayList<UserProperties>();
+ try {
+ userPropertiesList = (List<UserProperties>) UserPropertiesLocalServiceUtil.dynamicQuery(dynamicQuery);
+ } catch (Exception e) {
+
+ }
+
+ long time1 = System.currentTimeMillis();
+ System.out.println("filterScholarshipAndGrant fetch took "+(time1 - time0)+" ms");
+
+ boolean isUserScolarshipMatching = false;
+ if (scholarship.equals("internal")) {
+ UserInformationsUtil.isInternalScholarship(scholarship);
+ } else if (scholarship.equals("external")) {
+ UserInformationsUtil.isExternalScholarship(scholarship);
+ } else if (scholarship.equals("semi")) {
+ UserInformationsUtil.isSemiPensionScholarship(scholarship);
+ }
+
+ // Loop over the results to filter matching scholarship and grant
+ for (UserProperties userProperties : userPropertiesList) {
+ if ((scholarship.equals("") || isUserScolarshipMatching)
+ &&
+ (grant == -1 || ( (grant == 1) == userProperties.getGrantHolder()))
+ &&
+ (transport == -1 || ( (transport == 1) == userProperties.getTransported())) ) {
+ filteredUserProperties.add(userProperties);
+ }
+ }
+ long time2 = System.currentTimeMillis();
+ System.out.println("filterScholarshipAndGrant filter took "+(time2 - time1)+" ms");
+ }
+ return filteredUserProperties;
+ }
+
+}