--- /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.utils;
+
+import java.awt.image.RenderedImage;
+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.Criterion;
+import com.liferay.portal.kernel.dao.orm.DynamicQuery;
+import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
+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.image.ImageToolUtil;
+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.repository.model.FileEntry;
+import com.liferay.portal.kernel.repository.model.Folder;
+import com.liferay.portal.kernel.util.FileUtil;
+import com.liferay.portal.kernel.util.MimeTypesOverrideUtil;
+import com.liferay.portal.model.Group;
+import com.liferay.portal.model.Organization;
+import com.liferay.portal.model.User;
+import com.liferay.portal.service.GroupLocalServiceUtil;
+import com.liferay.portal.service.OrganizationLocalServiceUtil;
+import com.liferay.portal.service.ServiceContext;
+import com.liferay.portal.service.UserLocalServiceUtil;
+import com.liferay.portal.theme.ThemeDisplay;
+import com.liferay.portlet.documentlibrary.FolderNameException;
+import com.liferay.portlet.documentlibrary.NoSuchFolderException;
+import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
+import com.liferay.portlet.documentlibrary.model.DLFileEntry;
+import com.liferay.portlet.documentlibrary.model.DLFolder;
+import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
+import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
+import com.liferay.portlet.documentlibrary.util.DLPreviewableProcessor;
+import com.pentila.entSavoie.amis.model.FriendFolder;
+import com.pentila.entSavoie.amis.service.FriendFolderLocalServiceUtil;
+import com.pentila.entSavoie.casier.Constants;
+import com.pentila.entSavoie.userManagement.service.ClpSerializer;
+
+public class FoldersUtil {
+
+ private static Log logger = LogFactoryUtil.getLog(FoldersUtil.class);
+
+ public static Folder getRootFolder(long userId, long groupId) throws PortalException, SystemException {
+ return getRootFolder(userId, groupId, true);
+ }
+
+ public static Folder getRootFolder(long userId, long groupId, boolean createIt) throws PortalException, SystemException {
+ final Group group = GroupLocalServiceUtil.getGroup(groupId);
+ Folder rootFolder = null;
+ //Selon s'il s'agit d'un group d'organizatoin ou d'utilisateur, le nom
+ //sera différent.
+
+ if (group.isUser()) {
+ try {
+ rootFolder = DLAppLocalServiceUtil.getFolder(groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, Constants.SCHOOL_BAG_FOLDER_NAME);
+ } catch (NoSuchFolderException e) {
+ if (createIt) {
+ // signifie une mauvaise initialisation du portail. Cree le dossier
+ rootFolder = DLAppLocalServiceUtil.addFolder(
+ userId,
+ groupId,
+ DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
+ Constants.SCHOOL_BAG_FOLDER_NAME,
+ "Cartable personnel.",
+ new ServiceContext());
+ }
+ }
+ } else {
+ try {
+ rootFolder = DLAppLocalServiceUtil.getFolder(groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, Constants.GROUP_FOLDER_NAME);
+ }
+ catch (Exception ex) {
+ if (createIt) {
+ // signifie une mauvaise initialisation du portail. Cree le dossier
+ rootFolder = DLAppLocalServiceUtil.addFolder(
+ group.getCreatorUserId(),
+ groupId,
+ DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
+ Constants.GROUP_FOLDER_NAME,
+ "Espace de groupe.",
+ new ServiceContext());
+ PermissionsUtils.addDefaultPermissionsFolder(rootFolder);
+ }
+ }
+ }
+ return rootFolder;
+ }
+
+ public static Folder getDropBox(long userid) throws PortalException, SystemException {
+ final User user = UserLocalServiceUtil.getUser(userid);
+ Folder fol = null;
+ try {
+ fol = DLAppLocalServiceUtil.getFolder(user.getGroup().getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, Constants.DROP_BOX_FOLDER_NAME);
+ } catch (NoSuchFolderException e) {
+ fol = DLAppLocalServiceUtil.addFolder(
+ user.getUserId(),
+ user.getGroup().getGroupId(),
+ DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
+ Constants.DROP_BOX_FOLDER_NAME,
+ "Casier",
+ new ServiceContext());
+ }
+ return fol;
+ }
+
+ public static Folder getSendingBox(long userid) throws PortalException, SystemException {
+ final User user = UserLocalServiceUtil.getUser(userid);
+ Folder fol = null;
+ try {
+ fol = DLAppLocalServiceUtil.getFolder(user.getGroup().getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, Constants.SENDING_BOX_FOLDER_NAME);
+ } catch (NoSuchFolderException e) {
+ fol = DLAppLocalServiceUtil.addFolder(
+ user.getUserId(),
+ user.getGroup().getGroupId(),
+ DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
+ Constants.SENDING_BOX_FOLDER_NAME,
+ "Boite d envoi tmp",
+ new ServiceContext());
+ }
+ PermissionsUtils.setViewPermissionForRessources(fol);
+ return fol;
+ }
+
+ public static Folder getIMBox(long userid) throws PortalException, SystemException {
+ final User user = UserLocalServiceUtil.getUser(userid);
+ Folder fol = null;
+ try {
+ fol = DLAppLocalServiceUtil.getFolder(user.getGroup().getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, Constants.IM_BOX_FOLDER_NAME);
+ } catch (NoSuchFolderException e) {
+ fol = DLAppLocalServiceUtil.addFolder(user.getUserId(), user.getGroup().getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, Constants.IM_BOX_FOLDER_NAME, "Boite Instant Message", new ServiceContext());
+ }
+ PermissionsUtils.setViewPermissionForRessources(fol);
+ return fol;
+ }
+
+ public static Folder getCDTEventsBox(long userId, long groupId) throws PortalException, SystemException {
+ // il s'agit d'un folder stockant les objs attaches aux evt dans le cdt d'un group ou user
+ // --> ceci est l'espace dans lequel est entreposé ces documents
+ Folder fol = null;
+ try {
+ fol = DLAppLocalServiceUtil.getFolder(groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, Constants.CDT_EVENT_FOLDER_NAME);
+ } catch (NoSuchFolderException e) {
+ fol = DLAppLocalServiceUtil.addFolder(
+ userId,
+ groupId,
+ DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
+ Constants.CDT_EVENT_FOLDER_NAME,
+ "Entrepot CDT",
+ new ServiceContext());
+ }
+
+ return fol;
+ }
+
+ public static Folder getTmpFileFolderBox(long userId, long groupId) throws PortalException, SystemException {
+ return getTmpFileFolderBox(userId, groupId, true);
+ }
+
+ public static Folder getTmpFileFolderBox(long userId, long groupId, boolean createIt) throws PortalException, SystemException {
+ // il s'agit d'un folder temporaire stockant des fichier proveneant du disk de l'utilisateur
+ // --> ceci est l'espace dans lequel est entreposé ces documents
+ Folder fol = null;
+ try {
+ fol = DLAppLocalServiceUtil.getFolder(groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, Constants.TMP_IMG_FOLDER_NAME);
+ } catch (NoSuchFolderException e) {
+ if (createIt) {
+ fol = DLAppLocalServiceUtil.addFolder(
+ userId,
+ groupId,
+ DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
+ Constants.TMP_IMG_FOLDER_NAME,
+ "Fichier provenant du disk",
+ new ServiceContext());
+ }
+ }
+
+ return fol;
+ }
+
+
+
+ public static JSONArray getTreeViewAsJSON(long folderId) {
+ JSONArray ret = JSONFactoryUtil.createJSONArray();
+ try {
+ final Folder currFolder = DLAppLocalServiceUtil.getFolder(folderId);
+ for (Folder f : DLAppLocalServiceUtil.getFolders(currFolder.
+ getGroupId(), currFolder.getFolderId())) {
+ if (!f.getName().startsWith(".")){
+
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+ ob.put("id", f.getFolderId());
+ ob.put("text", f.getName());
+ ob.put("leaf", false);
+ ret.put(ob);
+ }
+ }
+ } catch (Exception e) {}
+ return ret;
+ }
+
+ public static JSONArray getCartableTreeViewAsJSON(long folderId) {
+ JSONArray ret = JSONFactoryUtil.createJSONArray();
+ try {
+ final Folder currFolder = DLAppLocalServiceUtil.getFolder(folderId);
+ for (Folder f : DLAppLocalServiceUtil.getFolders(currFolder.
+ getGroupId(), currFolder.getFolderId())) {
+ if (!f.getName().startsWith(".")){
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+ ob.put("id", f.getFolderId());
+ ob.put("text", f.getName());
+ ob.put("draggable", true);
+ ob.put("leaf", false);
+ ret.put(ob);
+ }
+ }
+ for (FileEntry f : DLAppLocalServiceUtil.getFileEntries(currFolder.getGroupId(), folderId)) {
+ if (!f.getTitle().startsWith(".")){
+ boolean isSignet = false;
+ String extension = f.getExtension();
+ if(extension.contains("html")){
+ isSignet = DLEntryUtil.isSignetFile(f);
+ }
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+ ob.put("id", f.getFileEntryId());
+ ob.put("text", f.getTitle());
+ ob.put("leaf", true);
+ ob.put("draggable", true);
+ ob.put("iconCls", isSignet?"file-signet":"file-" + f.getExtension());
+ ob.put("isSignet", isSignet);
+ ret.put(ob);
+ }
+ }
+ } catch (Exception e) {}
+ return ret;
+ }
+
+ public static JSONArray getCartableTreeViewWithDragNDropAsJSON(long folderId) {
+ JSONArray ret = JSONFactoryUtil.createJSONArray();
+ try {
+ final Folder currFolder = DLAppLocalServiceUtil.getFolder(folderId);
+ for (Folder f : DLAppLocalServiceUtil.getFolders(currFolder.
+ getGroupId(), currFolder.getFolderId())) {
+ if (!f.getName().startsWith(".")){
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+ ob.put("id", f.getFolderId());
+ ob.put("text", f.getName());
+ ob.put("draggable", true);
+ ob.put("leaf", false);
+ ret.put(ob);
+ }
+ }
+ for (FileEntry f : DLAppLocalServiceUtil.getFileEntries(currFolder.getGroupId(), folderId)) {
+ if (!f.getTitle().startsWith(".")){
+ boolean isSignet = false;
+ String extension = f.getExtension();
+ if(extension.contains("html")){
+ isSignet = DLEntryUtil.isSignetFile(f);
+ }
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+ ob.put("id", f.getFileEntryId());
+ ob.put("text", f.getTitle());
+ ob.put("leaf", true);
+ ob.put("draggable", true);
+ ob.put("iconCls", isSignet?"file-signet":"file-" + f.getExtension());
+ ob.put("isSignet", isSignet);
+ ret.put(ob);
+ }
+ }
+ } catch (Exception e) {}
+ return ret;
+ }
+
+ public static JSONArray getCartableTreeViewWithDragNDropAndPermissionsAsJSON(long folderId, ThemeDisplay themeDisplay) {
+ JSONArray ret = JSONFactoryUtil.createJSONArray();
+ try {
+ final Folder currFolder = DLAppLocalServiceUtil.getFolder(folderId);
+ for (Folder f : DLAppLocalServiceUtil.getFolders(currFolder.
+ getGroupId(), currFolder.getFolderId())) {
+ //if has the view permission
+ if (PermissionsUtils.checkFolderPermission(themeDisplay.getPermissionChecker(), f, "VIEW")){
+ if (!f.getName().startsWith(".")){
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+ ob.put("id", f.getFolderId());
+ ob.put("text", f.getName());
+ ob.put("draggable", true);
+ ob.put("leaf", false);
+ if (PermissionsUtils.checkFolderPermission(themeDisplay.getPermissionChecker(), f, "PASTE")){
+ ob.put("hasPermission", true);
+ } else {
+ ob.put("hasPermission", false);
+ }
+
+ ret.put(ob);
+ }
+ }
+ }
+ for (FileEntry f : DLAppLocalServiceUtil.getFileEntries(currFolder.getGroupId(), folderId)) {
+ //if has the view permission
+ if (PermissionsUtils.checkFilePermission(themeDisplay.getPermissionChecker(), f, "VIEW")){
+ if (!f.getTitle().startsWith(".")){
+ boolean isSignet = false;
+ String extension = f.getExtension();
+ if(extension.contains("html")){
+ isSignet = DLEntryUtil.isSignetFile(f);
+ }
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+ ob.put("id", f.getFileEntryId());
+ ob.put("text", f.getTitle());
+ ob.put("leaf", true);
+ ob.put("draggable", true);
+ ob.put("iconCls", isSignet?"file-signet":"file-" + f.getExtension());
+ ob.put("isSignet", isSignet);
+ ret.put(ob);
+ }
+ }
+ }
+ } catch (Exception e) {}
+ return ret;
+ }
+
+ public static JSONArray getCartableTreeViewAsJSONWithoutFolderSelection(long folderId) {
+ JSONArray ret = JSONFactoryUtil.createJSONArray();
+ try {
+ final Folder currFolder = DLAppLocalServiceUtil.getFolder(folderId);
+ for (Folder f : DLAppLocalServiceUtil.getFolders(currFolder.
+ getGroupId(), currFolder.getFolderId())) {
+ if (!f.getName().startsWith(".")){
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+ ob.put("id", f.getFolderId());
+ ob.put("text", f.getName());
+ ob.put("draggable", false);
+ ob.put("leaf", false);
+ ret.put(ob);
+ }
+ }
+ for (FileEntry f : DLAppLocalServiceUtil.getFileEntries(currFolder.getGroupId(), folderId)) {
+ if (!f.getTitle().startsWith(".")){
+ boolean isSignet = false;
+ String extension = f.getExtension();
+ if(extension.contains("html")){
+ isSignet = DLEntryUtil.isSignetFile(f);
+ }
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+ ob.put("id", f.getFileEntryId());
+ ob.put("text", f.getTitle());
+ ob.put("leaf", true);
+ ob.put("draggable", true);
+ ob.put("iconCls", isSignet?"file-signet":"file-" + f.getExtension());
+ ob.put("isSignet", isSignet);
+ ret.put(ob);
+ }
+ }
+ } catch (Exception e) {}
+ return ret;
+ }
+
+ public static JSONArray getCartableTreeViewAsJSON(long folderId, String extensions) {
+ return getCartableTreeViewAsJSON(folderId, extensions, false);
+ }
+
+ public static JSONArray getCartableTreeViewAsJSON(long folderId, String extensions, boolean leafFilter) {
+ JSONArray ret = JSONFactoryUtil.createJSONArray();
+ try {
+
+ //enable select sur treeElt seulement sur ces extension
+ String[] extensionsArray = extensions.split(",");
+
+ final Folder currFolder = DLAppLocalServiceUtil.getFolder(folderId);
+ for (Folder f : DLAppLocalServiceUtil.getFolders(currFolder.
+ getGroupId(), currFolder.getFolderId())) {
+ if (!f.getName().startsWith(".")){
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+ ob.put("id", f.getFolderId());
+ ob.put("text", f.getName());
+ ob.put("draggable", !leafFilter);
+ ob.put("leaf", false);
+ ret.put(ob);
+ }
+ }
+ for (FileEntry f : DLAppLocalServiceUtil.getFileEntries(currFolder.getGroupId(), folderId)) {
+ for (int i=0; i < extensionsArray.length; i++) {
+ String ext = extensionsArray[i];
+ if(f.getTitle().toLowerCase().endsWith("."+ext)){
+ if (!f.getTitle().startsWith(".")){
+ boolean isSignet = false;
+ String extension = f.getExtension();
+ if(extension.contains("html")){
+ isSignet = DLEntryUtil.isSignetFile(f);
+ }
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+ ob.put("id", f.getFileEntryId());
+ ob.put("text", f.getTitle());
+ ob.put("leaf", true);
+ ob.put("draggable", true);
+ ob.put("iconCls", isSignet?"file-signet":"file-" + f.getExtension());
+ ob.put("isSignet", isSignet);
+ ret.put(ob);
+ }
+ }
+ }
+ }
+ } catch (Exception e) {}
+ return ret;
+ }
+
+ public static JSONArray getCartableTreeViewAsJSON(long folderId, String extensions, boolean leafFilter, ThemeDisplay themeDisplay) {
+ JSONArray ret = JSONFactoryUtil.createJSONArray();
+ try {
+
+ //enable select sur treeElt seulement sur ces extension
+ String[] extensionsArray = extensions.split(",");
+
+ final Folder currFolder = DLAppLocalServiceUtil.getFolder(folderId);
+ for (Folder f : DLAppLocalServiceUtil.getFolders(currFolder.
+ getGroupId(), currFolder.getFolderId())) {
+ if (!f.getName().startsWith(".")){
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+ ob.put("id", f.getFolderId());
+ ob.put("text", f.getName());
+ ob.put("draggable", !leafFilter);
+ ob.put("leaf", false);
+ ret.put(ob);
+ }
+ }
+ for (FileEntry f : DLAppLocalServiceUtil.getFileEntries(currFolder.getGroupId(), folderId)) {
+ for (int i=0; i < extensionsArray.length; i++) {
+ String ext = extensionsArray[i];
+ if(f.getTitle().toLowerCase().endsWith("."+ext)){
+ if (!f.getTitle().startsWith(".")){
+ boolean isSignet = false;
+ String extension = f.getExtension();
+ if(extension.contains("html")){
+ isSignet = DLEntryUtil.isSignetFile(f);
+ }
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+ ob.put("id", f.getFileEntryId());
+ ob.put("text", f.getTitle());
+ ob.put("leaf", true);
+ ob.put("draggable", true);
+ ob.put("iconCls", isSignet?"file-signet":"file-" + f.getExtension());
+ ob.put("isSignet", isSignet);
+ String contentType = MimeTypesOverrideUtil.getContentType(f.getTitle().toLowerCase());
+ if(contentType.contains("image")){
+ Date d = new Date();
+ ob.put("url", themeDisplay.getPathMain() + "/document_library/get_file?p_l_id=" + themeDisplay.getPlid() + "&fileEntryId=" + f.getFileEntryId() + "&token=" + d.getTime() + "&contentDispo=inline&imageThumbnail=true");
+ byte[] image = FileUtil.getBytes(f.getContentStream());
+ RenderedImage renderedImage = ImageToolUtil.read(image).getRenderedImage();
+ ob.put("imageWidth", renderedImage.getWidth());
+ ob.put("imageHeight", renderedImage.getHeight());
+ }
+ ret.put(ob);
+ }
+ }
+ }
+ }
+ } catch (Exception e) {}
+ return ret;
+ }
+
+
+ public static JSONArray getListesAmisViewAsJSON(long userId, long parentId) {
+ JSONArray ret = JSONFactoryUtil.createJSONArray();
+ try {
+
+ final List<FriendFolder> listFF = FriendFolderLocalServiceUtil.getFriendFolderByUserIDParentFolderId(userId, parentId);
+ for (FriendFolder f : listFF) {
+ JSONObject ob = JSONFactoryUtil.createJSONObject();
+
+ //amis-portlet
+ ob.put("id", f.getFriendFolderId());
+ ob.put("text", f.getName());
+
+ //contact-portlet
+ ob.put("folderId", f.getFriendFolderId());
+ ob.put("listName", f.getName());
+ ob.put("isDisplayed", true);
+ ob.put("leaf", false);
+ ret.put(ob);
+ }
+ } catch (Exception e) {}
+ return ret;
+ }
+
+ /**
+ * This method get the subfolder of the folder in parameter
+ * @param pParentFolder Folder the method get the subfolder
+ * @return Return LIst of DLFolder which are contains in pParentFolder
+ */
+ public static List<DLFolder> getSubFolders(Folder pParentFolder){
+ List<DLFolder> subFolder = new ArrayList<DLFolder>();
+
+ //We want to return all the organizations and the org roots. So we search for then as well without taking all their tree path.
+ ClassLoader classLoader = (ClassLoader)PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(),"portletClassLoader");
+ DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(DLFolder.class,classLoader);
+ Criterion criterionParentFolder = null;
+ Criterion criterionRepository = null;
+ Criterion criterionAnd = null;
+
+ criterionParentFolder = RestrictionsFactoryUtil.eq("parentFolderId",pParentFolder.getFolderId());
+ criterionRepository = RestrictionsFactoryUtil.eq("repositoryId",pParentFolder.getRepositoryId());
+ criterionAnd = RestrictionsFactoryUtil.and(criterionParentFolder, criterionRepository);
+
+ dynamicQuery.add(criterionAnd);
+ try {
+ subFolder = DLFolderLocalServiceUtil.dynamicQuery(dynamicQuery);
+ } catch (SystemException e1) {
+ logger.error(e1);
+ }
+
+ if(subFolder == null || subFolder.size() == 0){
+ return new ArrayList<DLFolder>();
+ }
+
+ // dynamic query returns unmodifiedList, need to cas it
+ return new ArrayList<DLFolder>(subFolder);
+ }
+
+ /**
+ * This method get file in folder in parameter
+ * @param pParentFolder Folder wherein the method search the file entry
+ * @return List<DLFileEntry> of file in pParentFOlder
+ */
+ public static List<DLFileEntry> getFilesEntriesInFolder(Folder pParentFolder){
+ List<DLFileEntry> filesEntries = new ArrayList<DLFileEntry>();
+ //We want to return all the organizations and the org roots. So we search for then as well without taking all their tree path.
+ ClassLoader classLoader = (ClassLoader)PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(),"portletClassLoader");
+ DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(DLFileEntry.class,classLoader);
+ Criterion criterionFolder = null;
+ Criterion criterionRepository = null;
+ Criterion criterionAnd = null;
+ // filter on folderId and repository id
+ criterionFolder = RestrictionsFactoryUtil.eq("folderId",pParentFolder.getFolderId());
+ criterionRepository = RestrictionsFactoryUtil.eq("repositoryId",pParentFolder.getRepositoryId());
+ criterionAnd = RestrictionsFactoryUtil.and(criterionFolder, criterionRepository);
+
+ dynamicQuery.add(criterionAnd);
+
+ try {
+ filesEntries = DLFolderLocalServiceUtil.dynamicQuery(dynamicQuery);
+ } catch (SystemException e1) {
+ logger.error(e1);
+ }
+
+ if(filesEntries == null || filesEntries.size() == 0){
+ return new ArrayList<DLFileEntry>();
+ }
+
+ // dynamic query returns unmodifiedList, need to cas it
+ return new ArrayList<DLFileEntry>(filesEntries);
+ }
+
+}