--- /dev/null
+/**
+ * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This library 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 GNU Lesser General Public License for more
+ * details.
+ */
+
+package com.pentila.entSavoie.blogEntryInfos.service.impl;
+
+import java.util.Date;
+import java.util.List;
+
+import com.liferay.portal.kernel.exception.PortalException;
+import com.liferay.portal.kernel.exception.SystemException;
+import com.liferay.portal.kernel.json.JSONFactoryUtil;
+import com.liferay.portal.kernel.json.JSONObject;
+import com.liferay.portal.kernel.log.Log;
+import com.liferay.portal.kernel.log.LogFactoryUtil;
+import com.liferay.portal.model.Company;
+import com.liferay.portal.model.User;
+import com.liferay.portal.security.ldap.LDAPLocalServiceUtil;
+import com.liferay.portal.service.CompanyLocalServiceUtil;
+import com.pentila.entSavoie.blogEntryInfos.service.base.ActualitesAwarnessServiceBaseImpl;
+import com.pentila.entSavoie.portlets.actualites.ActuUtils;
+import com.pentila.entSavoie.userManagement.service.LDAPMappingLocalServiceUtil;
+
+/**
+ * The implementation of the actualites awarness remote service.
+ *
+ * <p>
+ * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link com.pentila.entSavoie.blogEntryInfos.service.ActualitesAwarnessService} interface.
+ *
+ * <p>
+ * This is a remote service. Methods of this service are expected to have security checks based on the propagated JAAS credentials because this service can be accessed remotely.
+ * </p>
+ *
+ * @author Tardy Camille
+ * @see com.pentila.entSavoie.blogEntryInfos.service.base.ActualitesAwarnessServiceBaseImpl
+ * @see com.pentila.entSavoie.blogEntryInfos.service.ActualitesAwarnessServiceUtil
+ */
+public class ActualitesAwarnessServiceImpl
+ extends ActualitesAwarnessServiceBaseImpl {
+ /*
+ * NOTE FOR DEVELOPERS:
+ *
+ * Never reference this interface directly. Always use {@link com.pentila.entSavoie.blogEntryInfos.service.ActualitesAwarnessServiceUtil} to access the actualites awarness remote service.
+ */
+
+ /**
+ * Returns the actuality entries for the user given
+ *
+ * @param entPersonJointure Unique user identifier
+ * @param nbActus Number of actu wanted
+ * @param typeActu Type of actu 0: all - 1: etab - 2: group
+ * @return JSONObject
+ * @throws SystemException
+ * @throws PortalException
+ */
+
+ private static Log logger = LogFactoryUtil.getLog(ActualitesAwarnessServiceImpl.class);
+
+ /**
+ * This method return the actu depending of the paramter as JSONObject. It's a liferay webservice
+ * @param entPersonJointure the unique id of the user (ENTPersonJointure + academic code)
+ * @param nbActus int, it's the maximum number of actu to return
+ * @param typeActu int, this define the type of actu with type actu = 1 is classic actu, typeActu = 2 is headMaster actu && typeActu = 0 is both
+ * @return JSONObject which contains nbActus news description for the user with UID entPersonJointure
+ */
+ public JSONObject retrieveUserActu(
+ String entPersonJointure,
+ int nbActus,
+ int typeActu) throws SystemException, PortalException {
+
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ User user = null;
+
+ result.put("success", true);
+
+
+ // check the nbActus and typeActu values
+ if (nbActus<0 || typeActu<0 || typeActu>2 || nbActus>Integer.MAX_VALUE) {
+ result.put("success", false);
+ result.put("error_msg", "Error nbActus or typeActu arguments invalid");
+ return result;
+ }
+
+ boolean headMaster = true;
+ boolean classic = true;
+ if (typeActu==1) {
+ classic = false;
+ }
+ if (typeActu==2) {
+ headMaster = false;
+ }
+
+
+ // Handle the user from its UID attributes . ENTPersonJointrue Name is the name for UID
+ user = LDAPMappingLocalServiceUtil.getUserFromUID(entPersonJointure);
+
+
+ if(user == null){
+ result.put("success", false);
+ result.put("error_msg", "Unable to find a valid user with ENTPersonJointure: " + entPersonJointure);
+ return result;
+ }
+
+ try{
+ result = ActuUtils.getAllActu(user, null, user.getGroupId(), "", 0,
+ -1,
+ false,
+ 0,
+ nbActus,
+ false,
+ 0,
+ classic,
+ false,
+ headMaster,
+ true);
+
+ }
+ catch(Exception e){
+ logger.error(e);
+ result.put("success", false);
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns the actuality entries number for the user given
+ * between 2 dates
+ *
+ * @param entPersonJointure Unique user identifier (ENTPersonJointure + academic code) it's UID
+ * @param date_begin begin date represents by a timestamp
+ * @param date_end end date represents by a timestamp
+ * @return JSONObject
+ * @throws SystemException
+ */
+ public JSONObject retrieveNbActuRange(
+ String entPersonJointure,
+ long begin_date,
+ long end_date) throws SystemException {
+
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ User user = null;
+
+ result.put("success", true);
+
+ if (begin_date<0) {
+ begin_date = new Long(0);
+ }
+
+ if (end_date<0) {
+ end_date = (new Date()).getTime();
+ }
+
+ // check the nbActus and typeActu values
+ if (begin_date<0 || end_date<0 || begin_date>end_date) {
+ result.put("success", false);
+ result.put("error_msg", "Error date timestamp arguments invalid");
+ return result;
+ }
+
+
+ // Handle the user from its UID attributes.
+ user = LDAPMappingLocalServiceUtil.getUserFromUID(entPersonJointure);
+
+ if(user == null){
+ result.put("success", false);
+ result.put("error_msg", "Unable to find a valid user with ENTPersonJointure: " + entPersonJointure);
+ return result;
+ }
+
+// try {
+// result = ActuUtils.getCountUserActus(user, begin_date, end_date);
+// } catch (PortalException e) {
+// logger.error(e);
+// result.put("success", false);
+// return result;
+// }
+
+
+ return result;
+ }
+
+}
\ No newline at end of file