--- /dev/null
+/*******************************************************************************
+ * Copyright © Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+ *
+ * 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>.
+ ******************************************************************************/
+/**
+ * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.pentila.entSavoie.portlets.gestionMenus;
+
+import com.liferay.portal.PortalException;
+import com.liferay.portal.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.kernel.log.Log;
+import com.liferay.portal.kernel.log.LogFactoryUtil;
+import com.liferay.portal.kernel.servlet.ImageServletTokenUtil;
+import com.liferay.portal.kernel.upload.UploadPortletRequest;
+import com.liferay.portal.kernel.util.MimeTypesUtil;
+import com.liferay.portal.kernel.util.ParamUtil;
+import com.liferay.portal.kernel.util.Validator;
+import com.liferay.portal.kernel.util.WebKeys;
+import com.liferay.portal.model.Image;
+import com.liferay.portal.model.Organization;
+import com.liferay.portal.model.User;
+import com.liferay.portal.service.ImageLocalServiceUtil;
+import com.liferay.portal.service.RoleLocalServiceUtil;
+import com.liferay.portal.service.ServiceContext;
+import com.liferay.portal.theme.ThemeDisplay;
+import com.liferay.portal.util.PortalUtil;
+import com.liferay.portlet.documentlibrary.model.DLFileEntry;
+import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
+import com.liferay.portlet.imagegallery.model.IGFolder;
+import com.liferay.portlet.imagegallery.model.IGImage;
+import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
+
+import com.pentila.entSavoie.directory.OrganizationFinderServiceUtil;
+import com.pentila.entSavoie.gestionMenus.NoSuchLinkEtabException;
+import com.pentila.entSavoie.gestionMenus.model.EntityMenu;
+import com.pentila.entSavoie.gestionMenus.model.InternationalMenu;
+import com.pentila.entSavoie.gestionMenus.model.LinkEtab;
+import com.pentila.entSavoie.gestionMenus.service.EntityMenuLocalServiceUtil;
+import com.pentila.entSavoie.gestionMenus.service.InternationalMenuLocalServiceUtil;
+import com.pentila.entSavoie.gestionMenus.service.LinkEtabLocalServiceUtil;
+import com.pentila.entSavoie.utils.DLEntryUtil;
+import com.pentila.entSavoie.utils.IGFoldersUtil;
+import com.pentila.entSavoie.utils.IGUtils;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.naming.NamingException;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+/**
+ * <a href="JSPPortlet.java.html"><b><i>View Source</i></b></a>
+ *
+ * @author Brian Wing Shun Chan
+ *
+ */
+public class JSPPortlet extends GenericPortlet {
+
+ public void init() throws PortletException {
+ editJSP = getInitParameter("edit-jsp");
+ helpJSP = getInitParameter("help-jsp");
+ viewJSP = getInitParameter("view-jsp");
+ }
+
+ public void doDispatch(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ String jspPage = renderRequest.getParameter("jspPage");
+
+ if (jspPage != null) {
+ include(jspPage, renderRequest, renderResponse);
+ }
+ else {
+ super.doDispatch(renderRequest, renderResponse);
+ }
+ }
+
+ public void doEdit(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ if (renderRequest.getPreferences() == null) {
+ super.doEdit(renderRequest, renderResponse);
+ }
+ else {
+ include(editJSP, renderRequest, renderResponse);
+ }
+ }
+
+ public void doHelp(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ include(helpJSP, renderRequest, renderResponse);
+ }
+
+ public void doView(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ include(viewJSP, renderRequest, renderResponse);
+ }
+
+ public void processAction(
+ ActionRequest actionRequest, ActionResponse actionResponse)
+ throws IOException, PortletException {
+
+ final String cmd = ParamUtil.getString(actionRequest, "cmd","");
+
+ // Ajout d'une catégorie
+ if (cmd.equals("addCategory")) {
+ try {
+ this.createCategory(actionRequest, actionResponse);
+ } catch (NamingException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ // Suppression d'une catégorie
+ if (cmd.equals("delCategory")) {
+ try {
+ this.deleteCategory(actionRequest, actionResponse);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ // Modification d'un intitulé
+ if (cmd.equals("modifyEntity")) {
+ try {
+ this.modifyEntity(actionRequest, actionResponse);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ // Application du menu actuel à tous les établissements
+ if (cmd.equals("applyAll")) {
+ try {
+ this.applyAll(actionRequest, actionResponse);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ // Application du menu actuel à tous les établissements
+ if (cmd.equals("forceAll")) {
+ try {
+ this.forceAll(actionRequest, actionResponse);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ // Déplacement d'une application
+ if (cmd.equals("moveNode")) {
+ try {
+ this.moveNode(actionRequest, actionResponse);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ // Choix d'une image
+ if (cmd.equals("pictureChoosed") || cmd.equals("uploadPicture")) {
+ try {
+ this.pictureChoosedProcess(actionRequest, actionResponse);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ // Obtention de l'image d'un menu
+ if (cmd.equals("getMenuImageAndInternationalMenus")) {
+ try {
+ this.getImageAndAllMenus(actionRequest, actionResponse);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ // Obtention du titre d'un menu
+ if (cmd.equals("getMenuTitle")) {
+ try {
+ this.getMenuTitle(actionRequest, actionResponse);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ if (cmd.equals("addLink")) {
+ try {
+ this.addLink(actionRequest, actionResponse);
+ } catch (SystemException e) {
+ e.printStackTrace();
+ }
+ }
+ if (cmd.equals("editLink")) {
+ try {
+ this.editLink(actionRequest, actionResponse);
+ } catch (SystemException e) {
+ e.printStackTrace();
+ } catch (PortalException e) {
+ e.printStackTrace();
+ }
+ }
+ if (cmd.equals("deleteLink")) {
+ try {
+ this.deleteLink(actionRequest, actionResponse);
+ } catch (SystemException e) {
+ e.printStackTrace();
+ } catch (PortalException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ // Ajout d'une catégorie
+ private void createCategory(ActionRequest actionRequest,
+ ActionResponse actionResponse) throws NamingException, Exception {
+
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+ result.put("success", true);
+
+ final long etabId = ParamUtil.getLong(actionRequest, "etabId", 0);
+ final String categoryName = ParamUtil.getString(actionRequest, "categoryName");
+
+ if (Validator.isNull(categoryName) || categoryName.equals(""))
+ return;
+ try {
+
+ int i = EntityMenuLocalServiceUtil.countEntityMenu(etabId, "menu");
+
+ EntityMenu e = EntityMenuLocalServiceUtil.addEntityMenu();
+
+
+ e.setEntityName(categoryName);
+ e.setEtabId(etabId);
+ e.setNodePath("menu");
+ e.setIsLeaf(false);
+ e.setOrderEntity(i);
+ e.setStyleEntity("");
+
+ EntityMenuLocalServiceUtil.updateEntityMenu(e, true);
+
+ result.put("id", e.getEntityId());
+ result.put("text", e.getEntityName());
+ result.put("leaf", e.getIsLeaf());
+ result.put("order", e.getOrderEntity());
+
+ } catch (Exception e) {
+ if (_log.isErrorEnabled()) {
+ _log.error(e);
+ }
+ result.put("success", false);
+ }
+
+
+ actionResponse.setRenderParameter("jspPage", "/ajax/defaultJSONResponse.jsp");
+ actionResponse.setRenderParameter("result", result.toString());
+ }
+
+ // Suppression d'une catégorie
+ private void deleteCategory(ActionRequest actionRequest,
+ ActionResponse actionResponse) throws PortalException, SystemException {
+
+ final long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
+
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+ result.put("success", true);
+ result.put("removeNodeId", nodeId);
+
+ try {
+
+ EntityMenu e = EntityMenuLocalServiceUtil.getEntityMenu(nodeId);
+ String oldNodePath = e.getNodePath();
+ long etabId = e.getEtabId();
+ int oldOrder = e.getOrderEntity();
+
+ // suppression effective
+ int order = EntityMenuLocalServiceUtil.countEntityMenu(etabId, "menu");
+ if(oldNodePath.equals("menu")){
+ order-=1;
+ }
+ recursiveDelete(e, order);
+
+ for (EntityMenu em: EntityMenuLocalServiceUtil.getEntityMenus(etabId, oldNodePath)) {
+ // on met a jour l'ancien dossier
+ if (em.getOrderEntity()>oldOrder) {
+ em.setOrderEntity(em.getOrderEntity()-1);
+ EntityMenuLocalServiceUtil.updateEntityMenu(em);
+ }
+ }
+
+
+ } catch (Exception e) {
+ if (_log.isErrorEnabled()) {
+ _log.error(e);
+ }
+ result.put("success", false);
+ }
+
+ actionResponse.setRenderParameter("jspPage", "/ajax/defaultJSONResponse.jsp");
+ actionResponse.setRenderParameter("result", result.toString());
+
+ }
+
+ private void recursiveDelete(EntityMenu entity, int order) throws SystemException, PortalException {
+ for (EntityMenu em: EntityMenuLocalServiceUtil.getEntityMenus(entity.getEtabId(), String.valueOf(entity.getEntityId()))) {
+ if (em.getIsLeaf()) {
+
+ em.setNodePath("menu");
+ em.setOrderEntity(order);
+ order+=1;
+ EntityMenuLocalServiceUtil.updateEntityMenu(em);
+ }
+ else {
+ recursiveDelete(em, order);
+ }
+ }
+
+ long oldImageId = entity.getImageId();
+ EntityMenuLocalServiceUtil.deleteEntityMenu(entity);
+
+ //pour utiliser la méthode canDeleteImage il faut avoir supprimer/modifier avant le menu
+ //on supprime l'ancienne image si aucun autre menu ne l'utilise
+ if(oldImageId!=0){
+ if (EntityMenuLocalServiceUtil.canDeleteImage(oldImageId)){
+ IGImageLocalServiceUtil.deleteIGImage(oldImageId);
+ }
+ }
+ }
+
+ // Modification d'un intitulé
+ private void modifyEntity(ActionRequest actionRequest,
+ ActionResponse actionResponse) throws NamingException, Exception {
+
+ final User user = PortalUtil.getUser(actionRequest);
+ final long entityId = ParamUtil.getLong(actionRequest, "entityId");
+ final String entityName = ParamUtil.getString(actionRequest, "entityName");
+ final String entityStyle = ParamUtil.getString(actionRequest, "entityStyle");
+ final long imageId = ParamUtil.getLong(actionRequest, "imageId", new Long(0));
+
+ JSONArray localeArray = JSONFactoryUtil.createJSONArray(ParamUtil.getString(actionRequest, "localeArray"));
+ JSONArray menuNameArray = JSONFactoryUtil.createJSONArray(ParamUtil.getString(actionRequest, "menuNameArray"));
+
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+ result.put("success", true);
+
+ try {
+
+ EntityMenu e = EntityMenuLocalServiceUtil.getEntityMenu(entityId);
+
+ InternationalMenuLocalServiceUtil.deleteByEntityMenuId(entityId);
+ //On recrée les menus traduits
+ for(int i=0; i<localeArray.length(); i++){
+ String menuName = menuNameArray.getString(i);
+ if(menuName.equals("")){
+ menuName = "Menu Non Défini";
+ }
+ InternationalMenuLocalServiceUtil.addInternationalMenu(entityId, localeArray.getString(i), menuName);
+ }
+
+ e.setEntityName(entityName);
+ e.setStyleEntity(entityStyle);
+
+ long oldImageId = e.getImageId();
+ long newImageId = oldImageId;
+
+ //l'image a changé
+ if (oldImageId!=imageId){
+ newImageId = 0;
+ //on supprime l'image courante du menu si elle existe
+ if(imageId!=0){
+ //on recupere l'image temp
+ IGImage igiTmp = IGImageLocalServiceUtil.getImage(imageId);
+
+ //on recupere le folder
+ Organization cds = OrganizationFinderServiceUtil.getPrincipalOrganization(user);
+ Long cdsGpId = cds.getGroup().getGroupId();
+ IGFolder igfMenu = IGFoldersUtil.getMenuImgFolder(user.getUserId(),cdsGpId);
+
+ //on lui copie l'image
+ IGImage finalIgi = null;
+ // Title
+ String originalTitle = igiTmp.getName();
+
+ String[] splitFN = DLEntryUtil.splitFileName(igiTmp.getNameWithExtension());
+ //String originalTitle = splitFN[0];
+ String extension = "." + splitFN[1];
+
+
+ String name ="";
+
+ boolean finished = false;
+ int count = 1;
+ String suffixe = "";
+ while (!finished && count<50) {
+ try {
+ Image original = ImageLocalServiceUtil.getImage(igiTmp.getLargeImageId());
+
+ name = originalTitle+suffixe+extension;
+ finalIgi = IGImageLocalServiceUtil.addImage(
+ user.getUserId(),
+ igfMenu.getFolderId(),
+ name,
+ igiTmp.getDescription(),
+ name,
+ original.getTextObj(),
+ igiTmp.getImageType(),
+ new ServiceContext());
+
+ finished = true;
+ }
+ catch (Exception exc) {
+ count ++;
+ suffixe = "_" + count;
+ }
+ }
+ //on recupere l'id de cette nouvelle image
+ newImageId = finalIgi.getImageId();
+ //on supprime l'image temp
+ IGImageLocalServiceUtil.deleteIGImage(igiTmp);
+ }
+ }
+ e.setImageId(newImageId);
+ result.put("imageId", newImageId);
+
+ InternationalMenu im = InternationalMenuLocalServiceUtil.getByEntityMenuId_Locale(entityId, user.getLocale().getLanguage());
+
+ if(im == null){
+ result.put("text", entityName);
+ } else {
+ result.put("text", im.getMenuName());
+ }
+ result.put("style", entityStyle);
+
+ EntityMenuLocalServiceUtil.updateEntityMenu(e, true);
+
+ //pour utiliser la méthode canDeleteImage il faut avoir supprimer/modifier avant le menu
+ //on supprime l'ancienne image si aucun autre menu ne l'utilise
+ if(oldImageId!=0){
+ if (EntityMenuLocalServiceUtil.canDeleteImage(oldImageId)){
+ IGImageLocalServiceUtil.deleteIGImage(oldImageId);
+ }
+ }
+
+ } catch (Exception e) {
+ if (_log.isErrorEnabled()) {
+ _log.error(e);
+ }
+ result.put("success", false);
+ }
+
+ actionResponse.setRenderParameter("jspPage", "/ajax/defaultJSONResponse.jsp");
+ actionResponse.setRenderParameter("result", result.toString());
+ }
+
+ // Application du menu actuel à tous les établissements
+ private void applyAll(ActionRequest actionRequest,
+ ActionResponse actionResponse) throws NamingException, Exception {
+
+ final User currUser = PortalUtil.getUser(actionRequest);
+ final long currEtabId = ParamUtil.getLong(actionRequest, "etabId");
+
+
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+ result.put("success", true);
+
+ try {
+ final Organization principalOrg = OrganizationFinderServiceUtil.getPrincipalOrganization(currUser);
+
+ for (Organization o: principalOrg.getSuborganizations()) {
+
+ List<EntityMenu> lnew = EntityMenuLocalServiceUtil.getEntityMenus(o.getOrganizationId());
+
+ // On copie le menu pour tous les établissements sauf l'actuel et si l'établissement n'a pas de menu
+ if (o.getOrganizationId() != currEtabId && lnew.isEmpty()) {
+
+ for (EntityMenu em: EntityMenuLocalServiceUtil.getEntityMenus(currEtabId, "menu")) {
+ copyNodeForEtab(em, o.getOrganizationId(), "menu");
+ }
+
+ }
+
+ }
+
+ } catch (Exception e) {
+ if (_log.isErrorEnabled()) {
+ _log.error(e);
+ }
+ result.put("success", false);
+ }
+
+ actionResponse.setRenderParameter("jspPage", "/ajax/defaultJSONResponse.jsp");
+ actionResponse.setRenderParameter("result", result.toString());
+ }
+
+ // Application du menu actuel à tous les établissements --> remplacement des menus deja defini
+ private void forceAll(ActionRequest actionRequest,
+ ActionResponse actionResponse) throws NamingException, Exception {
+
+ final User currUser = PortalUtil.getUser(actionRequest);
+ final long currEtabId = ParamUtil.getLong(actionRequest, "etabId");
+
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+ result.put("success", true);
+
+ try {
+ final Organization principalOrg = OrganizationFinderServiceUtil.getPrincipalOrganization(currUser);
+
+ for (Organization o: principalOrg.getSuborganizations()) {
+
+ List<EntityMenu> lnew = EntityMenuLocalServiceUtil.getEntityMenus(o.getOrganizationId());
+
+ // On copie le menu pour tous les établissements sauf l'actuel et si l'établissement n'a pas de menu
+ if (o.getOrganizationId() != currEtabId) {
+ // on supprime l'actuel
+ for (EntityMenu em: lnew) {
+ long oldImageId = em.getImageId();
+ EntityMenuLocalServiceUtil.deleteEntityMenu(em);
+ InternationalMenuLocalServiceUtil.deleteByEntityMenuId(em.getEntityId());
+
+ //pour utiliser la méthode canDeleteImage il faut avoir supprimer/modifier avant le menu
+ //on supprime l'ancienne image si aucun autre menu ne l'utilise
+ if(oldImageId!=0){
+ if (EntityMenuLocalServiceUtil.canDeleteImage(oldImageId)){
+ IGImageLocalServiceUtil.deleteIGImage(oldImageId);
+ }
+ }
+ }
+
+ // on copîe maintenant le menu
+ for (EntityMenu em: EntityMenuLocalServiceUtil.getEntityMenus(currEtabId, "menu")) {
+ copyNodeForEtab(em, o.getOrganizationId(), "menu");
+ }
+
+ }
+
+ }
+
+ } catch (Exception e) {
+ if (_log.isErrorEnabled()) {
+ _log.error(e);
+ }
+ result.put("success", false);
+ }
+
+ actionResponse.setRenderParameter("jspPage", "/ajax/defaultJSONResponse.jsp");
+ actionResponse.setRenderParameter("result", result.toString());
+ }
+
+ private void copyNodeForEtab(EntityMenu em, long targetEtabId, String nodePath) throws SystemException {
+
+ EntityMenu newEm = EntityMenuLocalServiceUtil.addEntityMenu();
+ newEm.setEntityName(em.getEntityName());
+ newEm.setEtabId(targetEtabId);
+ newEm.setAppRoleId(em.getAppRoleId());
+ newEm.setIsLeaf(em.getIsLeaf());
+ newEm.setNodePath(nodePath);
+ newEm.setOrderEntity(em.getOrderEntity());
+ newEm.setStyleEntity(em.getStyleEntity());
+ newEm.setImageId(em.getImageId());
+ EntityMenuLocalServiceUtil.updateEntityMenu(newEm, false);
+
+ List<InternationalMenu> lim = InternationalMenuLocalServiceUtil.getByEntityMenuId(em.getEntityId());
+
+ for(InternationalMenu im: lim){
+ InternationalMenuLocalServiceUtil.addInternationalMenu(newEm.getEntityId(), im.getLocale(), im.getMenuName());
+ }
+
+ if (!em.getIsLeaf()) {
+ // il s agit d'une categorie donc on recurse
+ for (EntityMenu e: EntityMenuLocalServiceUtil.getEntityMenus(em.getEtabId(), String.valueOf(em.getEntityId()))) {
+ copyNodeForEtab(e, targetEtabId, String.valueOf(newEm.getEntityId()));
+ }
+ }
+ }
+
+ // Déplacement d'une application
+ private void moveNode(ActionRequest actionRequest,
+ ActionResponse actionResponse) throws NamingException, Exception {
+
+ final long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
+ final String nodePath = ParamUtil.getString(actionRequest, "nodePath");
+ final int index = ParamUtil.getInteger(actionRequest, "index");
+
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+ result.put("success", true);
+
+ try {
+
+ EntityMenu e = EntityMenuLocalServiceUtil.getEntityMenu(nodeId);
+
+ String oldNodePath = e.getNodePath();
+ int oldOrder = e.getOrderEntity();
+
+ // on met a jour le noeud
+ e.setNodePath(nodePath);
+ e.setOrderEntity(index);
+ EntityMenuLocalServiceUtil.updateEntityMenu(e, true);
+
+ if (oldNodePath.equals(nodePath)) {
+ // on a pas changer de dossier (parent)
+ // on met maintenant a jour les autres entity menu
+ if (oldOrder>index) {
+ // on a remonte dans l arbre
+ for (EntityMenu em: EntityMenuLocalServiceUtil.getEntityMenus(e.getEtabId(), nodePath)) {
+ if (em.getOrderEntity()>=index && em.getEntityId()!=nodeId && em.getOrderEntity()<oldOrder) {
+ em.setOrderEntity(em.getOrderEntity()+1);
+ EntityMenuLocalServiceUtil.updateEntityMenu(em);
+ }
+ }
+ }
+ else {
+ // on a descendu ds l arbre
+ for (EntityMenu em: EntityMenuLocalServiceUtil.getEntityMenus(e.getEtabId(), nodePath)) {
+ if (em.getOrderEntity()>oldOrder && em.getEntityId()!=nodeId && em.getOrderEntity()<=index) {
+ em.setOrderEntity(em.getOrderEntity()-1);
+ EntityMenuLocalServiceUtil.updateEntityMenu(em);
+ }
+ }
+ }
+ }
+ else {
+ // on a change de dossier
+ for (EntityMenu em: EntityMenuLocalServiceUtil.getEntityMenus(e.getEtabId(), oldNodePath)) {
+ // on met a jour l'ancien dossier
+ if (em.getOrderEntity()>oldOrder) {
+ em.setOrderEntity(em.getOrderEntity()-1);
+ EntityMenuLocalServiceUtil.updateEntityMenu(em);
+ }
+ }
+ for (EntityMenu em: EntityMenuLocalServiceUtil.getEntityMenus(e.getEtabId(), nodePath)) {
+ // on met a jour le nouveau dossier
+ if (em.getOrderEntity()>=index && em.getEntityId()!=nodeId) {
+ em.setOrderEntity(em.getOrderEntity()+1);
+ EntityMenuLocalServiceUtil.updateEntityMenu(em);
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ if (_log.isErrorEnabled()) {
+ _log.error(e);
+ }
+ result.put("success", false);
+ }
+
+ actionResponse.setRenderParameter("jspPage", "/ajax/defaultJSONResponse.jsp");
+ actionResponse.setRenderParameter("result", result.toString());
+ }
+
+ private void pictureChoosedProcess(ActionRequest actionRequest,
+ ActionResponse actionResponse) {
+
+
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+ result.put("success", true);
+
+ ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
+
+ try {
+ IGImage igi = null;
+ final Long idFile = ParamUtil.getLong(actionRequest, "idFile", 0);
+
+ if(idFile!=0) {
+ // on recupere l image depuis le cartable
+ igi = IGUtils.getImageFromFile(idFile, actionRequest);
+ actionResponse.setRenderParameter("jspPage", "/ajax/defaultJSONResponse.jsp");
+ }
+ else {
+ // on prend l image dans la request
+ UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
+ // attention dans la request le file doit se nommer uploadedFile
+ igi = IGUtils.getImageFromUpload(uploadRequest, actionRequest);
+ actionResponse.setRenderParameter("jspPage", "/ajax/specialJSONResponse.jsp");
+ }
+
+ // on retourne l'id du IGI et son url pour le thumbnail
+ Image smallImage = ImageLocalServiceUtil.getImage(igi.getCustom2ImageId());
+
+ if (smallImage != null) {
+ long smallImageId = smallImage.getImageId();
+ int smallImageHeight = smallImage.getHeight();
+ int smallImageWidth = smallImage.getWidth();
+
+ String urlThumb = themeDisplay.getPathImage() + "/image_gallery?img_id=" + smallImageId + "&t="+ ImageServletTokenUtil.getToken(smallImageId);
+ result.put("imageId", igi.getImageId());
+ result.put("urlThumb", urlThumb);
+ result.put("height", smallImageHeight);
+ result.put("width", smallImageWidth);
+ }
+
+ } catch (Exception e) {
+ if (_log.isErrorEnabled()) {
+ _log.error(e);
+ }
+ result.put("success", false);
+ }
+ actionResponse.setRenderParameter("result", result.toString());
+ }
+
+
+ private void getImageAndAllMenus(ActionRequest actionRequest,
+ ActionResponse actionResponse) throws PortalException, SystemException {
+
+ final long fileId = ParamUtil.getLong(actionRequest, "idFile");
+ ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
+ final long entityMenuId = ParamUtil.getLong(actionRequest, "entityMenuId");
+
+ actionResponse.setRenderParameter("jspPage", "/ajax/defaultJSONResponse.jsp");
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+ result.put("success", true);
+
+ if(fileId != 0){
+
+ IGImage igi = IGImageLocalServiceUtil.getIGImage(fileId);
+
+ // on retourne l'id du IGI et son url pour le thumbnail
+ Image smallImage = ImageLocalServiceUtil.getImage(igi.getCustom2ImageId());
+
+ if (smallImage != null) {
+ long smallImageId = smallImage.getImageId();
+ int smallImageHeight = smallImage.getHeight();
+ int smallImageWidth = smallImage.getWidth();
+
+ String urlThumb = themeDisplay.getPathImage() + "/image_gallery?img_id=" + smallImageId + "&t="+ ImageServletTokenUtil.getToken(smallImageId);
+
+ result.put("hasImage", true);
+ result.put("urlThumb", urlThumb);
+ result.put("height", smallImageHeight);
+ result.put("width", smallImageWidth);
+ }
+ }
+
+ JSONArray menus = JSONFactoryUtil.createJSONArray();
+ List<InternationalMenu> lim = InternationalMenuLocalServiceUtil.getByEntityMenuId(entityMenuId);
+ for(InternationalMenu im: lim){
+ JSONObject curr = JSONFactoryUtil.createJSONObject();
+ curr.put("locale", im.getLocale());
+ curr.put("menuName", im.getMenuName());
+ menus.put(curr);
+ }
+ result.put("menus", menus);
+
+ actionResponse.setRenderParameter("result", result.toString());
+
+ }
+
+ public static String getNewsImageTag(Long imageId, ThemeDisplay themeDisplay) {
+ String tag = "";
+ if (imageId!=0){
+ IGImage igi = null;
+ Image smallImage = null;
+ try {
+ igi = IGImageLocalServiceUtil.getIGImage(imageId);
+ // on retourne l'id du IGI et son url pour le thumbnail
+ smallImage = ImageLocalServiceUtil.getImage(igi.getCustom2ImageId());
+ } catch (Exception e) {
+ return tag;
+ }
+
+ if (smallImage != null) {
+ long smallImageId = smallImage.getImageId();
+ int smallImageHeight = smallImage.getHeight();
+ int smallImageWidth = smallImage.getWidth();
+
+ String centre_imgURL = themeDisplay.getPathImage() + "/image_gallery?img_id=" + smallImageId + "&t="+ ImageServletTokenUtil.getToken(smallImageId);
+ tag = "<img border='0' src='"+centre_imgURL+"' style='margin-top:3px; height: "+smallImageHeight+"; width: "+smallImageWidth+"' />";
+ }
+
+ }
+ return tag;
+ }
+
+ // Retourne si le user peut manager les menus --> appliquer un menu à tous les établissements
+ public static Boolean isManager(User u) {
+ try {
+ if (RoleLocalServiceUtil.hasUserRole(u.getUserId(), u.getCompanyId(), "Administrator", false)) {
+ return true;
+ }
+ } catch (PortalException e) {
+ e.printStackTrace();
+ } catch (SystemException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+
+ private void getMenuTitle(ActionRequest actionRequest,
+ ActionResponse actionResponse) throws SystemException {
+ final long entityMenuId = ParamUtil.getLong(actionRequest, "entityMenuId");
+ final String locale = ParamUtil.getString(actionRequest, "locale");
+
+ actionResponse.setRenderParameter("jspPage", "/ajax/defaultJSONResponse.jsp");
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+ result.put("success", true);
+
+ InternationalMenu im = InternationalMenuLocalServiceUtil.getByEntityMenuId_Locale(entityMenuId, locale);
+
+ if(im != null){
+ result.put("entityName", im.getMenuName());
+ } else {
+ result.put("noMenuFound", true);
+ }
+
+ actionResponse.setRenderParameter("result", result.toString());
+
+ }
+
+ private void addLink(ActionRequest actionRequest, ActionResponse actionResponse) throws SystemException{
+ final long etabId = ParamUtil.getLong(actionRequest, "etabId");
+ final String nom = ParamUtil.getString(actionRequest, "name");
+ final String url = ParamUtil.getString(actionRequest, "url");
+ final String style = ParamUtil.getString(actionRequest, "style");
+ final int ordre = ParamUtil.getInteger(actionRequest, "ordre");
+
+
+ actionResponse.setRenderParameter("jspPage", "/ajax/defaultJSONResponse.jsp");
+ LinkEtab link = LinkEtabLocalServiceUtil.addLinkEtab(nom, url, etabId, style, ordre);
+
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+ result.put("success", true);
+
+ actionResponse.setRenderParameter("result", result.toString());
+ }
+
+ private void editLink(ActionRequest actionRequest, ActionResponse actionResponse) throws SystemException, PortalException{
+ final long linkEtabId = ParamUtil.getLong(actionRequest, "linkEtabId");
+ final String nom = ParamUtil.getString(actionRequest, "name");
+ final String url = ParamUtil.getString(actionRequest, "url");
+ final String style = ParamUtil.getString(actionRequest, "style");
+ final int ordre = ParamUtil.getInteger(actionRequest, "ordre");
+
+
+ actionResponse.setRenderParameter("jspPage", "/ajax/defaultJSONResponse.jsp");
+ LinkEtab link = LinkEtabLocalServiceUtil.getLinkEtab(linkEtabId);
+ link.setName(nom);
+ link.setUrl(url);
+ link.setStyle(style);
+ link.setOrders(ordre);
+
+ LinkEtabLocalServiceUtil.updateLinkEtab(link);
+
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+ result.put("success", true);
+
+ actionResponse.setRenderParameter("result", result.toString());
+ }
+
+ private void deleteLink(ActionRequest actionRequest, ActionResponse actionResponse) throws NoSuchLinkEtabException, PortalException, SystemException{
+ final long linkEtabId = ParamUtil.getLong(actionRequest, "linkEtabId");
+ actionResponse.setRenderParameter("jspPage", "/ajax/defaultJSONResponse.jsp");
+ LinkEtabLocalServiceUtil.deleteLinkEtab(linkEtabId);
+
+ actionResponse.setRenderParameter("jspPage", "/ajax/defaultJSONResponse.jsp");
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+ result.put("success", true);
+
+ actionResponse.setRenderParameter("result", result.toString());
+ }
+
+
+ protected void include(
+ String path, RenderRequest renderRequest,
+ RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ PortletRequestDispatcher portletRequestDispatcher =
+ getPortletContext().getRequestDispatcher(path);
+
+ if (portletRequestDispatcher == null) {
+ _log.error(path + " is not a valid include");
+ }
+ else {
+ portletRequestDispatcher.include(renderRequest, renderResponse);
+ }
+ }
+
+ protected String editJSP;
+ protected String helpJSP;
+ protected String viewJSP;
+
+ private static Log _log = LogFactoryUtil.getLog(JSPPortlet.class);
+
+}