--- /dev/null
+/**\r
+ * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.\r
+ *\r
+ * This library is free software; you can redistribute it and/or modify it under\r
+ * the terms of the GNU Lesser General Public License as published by the Free\r
+ * Software Foundation; either version 2.1 of the License, or (at your option)\r
+ * any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more\r
+ * details.\r
+ */\r
+\r
+package com.liferay.portlet.documentlibrary.service.impl;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.Date;\r
+import java.util.List;\r
+\r
+import com.liferay.portal.kernel.exception.PortalException;\r
+import com.liferay.portal.kernel.exception.SystemException;\r
+import com.liferay.portal.kernel.log.Log;\r
+import com.liferay.portal.kernel.log.LogFactoryUtil;\r
+import com.liferay.portal.kernel.search.BooleanClauseOccur;\r
+import com.liferay.portal.kernel.search.BooleanQuery;\r
+import com.liferay.portal.kernel.search.BooleanQueryFactoryUtil;\r
+import com.liferay.portal.kernel.search.Field;\r
+import com.liferay.portal.kernel.search.Hits;\r
+import com.liferay.portal.kernel.search.Indexer;\r
+import com.liferay.portal.kernel.search.IndexerRegistryUtil;\r
+import com.liferay.portal.kernel.search.SearchContext;\r
+import com.liferay.portal.kernel.search.SearchEngineUtil;\r
+import com.liferay.portal.kernel.search.SolrQueryUtil;\r
+import com.liferay.portal.kernel.util.ObjectValuePair;\r
+import com.liferay.portal.kernel.util.OrderByComparator;\r
+import com.liferay.portal.kernel.util.ParamUtil;\r
+import com.liferay.portal.kernel.util.StringPool;\r
+import com.liferay.portal.kernel.util.Validator;\r
+import com.liferay.portal.kernel.workflow.WorkflowConstants;\r
+import com.liferay.portal.model.Group;\r
+import com.liferay.portal.model.ResourceConstants;\r
+import com.liferay.portal.model.User;\r
+import com.liferay.portal.repository.liferayrepository.model.LiferayFolder;\r
+import com.liferay.portal.service.ServiceContext;\r
+import com.liferay.portal.service.UserLocalServiceUtil;\r
+import com.liferay.portal.util.PortletKeys;\r
+import com.liferay.portal.util.PropsValues;\r
+import com.liferay.portlet.asset.util.AssetUtil;\r
+import com.liferay.portlet.documentlibrary.DuplicateFileException;\r
+import com.liferay.portlet.documentlibrary.DuplicateFolderNameException;\r
+import com.liferay.portlet.documentlibrary.FolderNameException;\r
+import com.liferay.portlet.documentlibrary.NoSuchDirectoryException;\r
+import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;\r
+import com.liferay.portlet.documentlibrary.folder.service.DLFolderLocalService;\r
+import com.liferay.portlet.documentlibrary.model.DLFileEntryTypeConstants;\r
+import com.liferay.portlet.documentlibrary.model.DLFolder;\r
+import com.liferay.portlet.documentlibrary.model.DLFolderConstants;\r
+import com.liferay.portlet.documentlibrary.service.base.DLFolderLocalServiceBaseImpl;\r
+import com.liferay.portlet.documentlibrary.store.CustomDLStoreUtil;\r
+import com.liferay.portlet.documentlibrary.store.DLStoreUtil;\r
+import com.pentila.entSavoie.ENTRolesConstants;\r
+import com.pentila.entSavoie.cartable.service.CasierEntryLocalServiceUtil;\r
+import com.pentila.entSavoie.search.util.IndexerUtil;\r
+\r
+/**\r
+ * @author Brian Wing Shun Chan\r
+ * @author Alexander Chow\r
+ */\r
+public class DLFolderLocalServiceImpl extends DLFolderLocalServiceBaseImpl implements DLFolderLocalService {\r
+\r
+ public static final String PORTLET_ID = "foldersearchengine";\r
+ \r
+ public DLFolder addFolder(\r
+ long userId, long groupId, long repositoryId, boolean mountPoint,\r
+ long parentFolderId, String name, String description,\r
+ ServiceContext serviceContext)\r
+ throws PortalException, SystemException {\r
+\r
+ // Folder\r
+\r
+ User user = userPersistence.findByPrimaryKey(userId);\r
+ parentFolderId = getParentFolderId(groupId, parentFolderId);\r
+ Date now = new Date();\r
+\r
+ validateFolder(groupId, parentFolderId, name);\r
+\r
+ long folderId = counterLocalService.increment();\r
+\r
+ DLFolder dlFolder = dlFolderPersistence.create(folderId);\r
+\r
+ dlFolder.setUuid(serviceContext.getUuid());\r
+ dlFolder.setGroupId(groupId);\r
+ dlFolder.setCompanyId(user.getCompanyId());\r
+ dlFolder.setUserId(user.getUserId());\r
+ dlFolder.setCreateDate(serviceContext.getCreateDate(now));\r
+ dlFolder.setModifiedDate(serviceContext.getModifiedDate(now));\r
+ dlFolder.setRepositoryId(repositoryId);\r
+ dlFolder.setMountPoint(mountPoint);\r
+ dlFolder.setParentFolderId(parentFolderId);\r
+ dlFolder.setName(name);\r
+ dlFolder.setDescription(description);\r
+ dlFolder.setOverrideFileEntryTypes(false);\r
+ dlFolder.setExpandoBridgeAttributes(serviceContext);\r
+\r
+ dlFolderPersistence.update(dlFolder, false);\r
+\r
+ // Resources\r
+\r
+ if (serviceContext.isAddGroupPermissions() ||\r
+ serviceContext.isAddGuestPermissions()) {\r
+\r
+ addFolderResources(\r
+ dlFolder, serviceContext.isAddGroupPermissions(),\r
+ serviceContext.isAddGuestPermissions());\r
+ }\r
+ else {\r
+ if (serviceContext.isDeriveDefaultPermissions()) {\r
+ serviceContext.deriveDefaultPermissions(\r
+ repositoryId, DLFolderConstants.getClassName());\r
+ }\r
+\r
+ addFolderResources(\r
+ dlFolder, serviceContext.getGroupPermissions(),\r
+ serviceContext.getGuestPermissions());\r
+ }\r
+\r
+ // Parent folder\r
+\r
+ if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {\r
+ DLFolder parentDLFolder = dlFolderPersistence.findByPrimaryKey(\r
+ parentFolderId);\r
+\r
+ parentDLFolder.setLastPostDate(now);\r
+\r
+ dlFolderPersistence.update(parentDLFolder, false);\r
+ }\r
+\r
+ // App helper\r
+\r
+ dlAppHelperLocalService.addFolder(\r
+ new LiferayFolder(dlFolder), serviceContext);\r
+\r
+\r
+ // Indexer\r
+ \r
+ Indexer indexer = IndexerRegistryUtil.getIndexer(DLFolder.class);\r
+ if(Validator.isNotNull(indexer)){\r
+ indexer.reindex(dlFolder);\r
+ }\r
+ \r
+ return dlFolder;\r
+ }\r
+ \r
+ public DLFolder update(DLFolder folder) throws PortalException, SystemException{\r
+ dlFolderPersistence.update(folder, true);\r
+ \r
+ // Indexer\r
+ \r
+ Indexer indexer = IndexerRegistryUtil.getIndexer(DLFolder.class);\r
+ indexer.reindex(folder);\r
+ \r
+ return folder;\r
+ }\r
+\r
+ public void deleteAll(long groupId)\r
+ throws PortalException, SystemException {\r
+\r
+ Group group = groupLocalService.getGroup(groupId);\r
+\r
+ List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(\r
+ groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);\r
+\r
+ for (DLFolder dlFolder : dlFolders) {\r
+ deleteFolder(dlFolder);\r
+ }\r
+\r
+ dlFileEntryLocalService.deleteFileEntries(\r
+ groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);\r
+\r
+ try {\r
+ DLStoreUtil.deleteDirectory(\r
+ group.getCompanyId(), groupId, StringPool.BLANK);\r
+ }\r
+ catch (NoSuchDirectoryException nsde) {\r
+ if (_log.isDebugEnabled()) {\r
+ _log.debug(nsde.getMessage());\r
+ }\r
+ }\r
+ }\r
+\r
+ public void deleteFolder(long folderId)\r
+ throws PortalException, SystemException {\r
+\r
+ DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);\r
+\r
+ deleteFolder(dlFolder);\r
+ }\r
+\r
+ public List<DLFolder> getCompanyFolders(long companyId, int start, int end)\r
+ throws SystemException {\r
+\r
+ return dlFolderPersistence.findByCompanyId(companyId, start, end);\r
+ }\r
+\r
+ public int getCompanyFoldersCount(long companyId) throws SystemException {\r
+ return dlFolderPersistence.countByCompanyId(companyId);\r
+ }\r
+\r
+ public List<Object> getFileEntriesAndFileShortcuts(\r
+ long groupId, long folderId, int status, int start, int end)\r
+ throws SystemException {\r
+\r
+ return dlFolderFinder.findFE_FS_ByG_F_S(\r
+ groupId, folderId, status, start, end);\r
+ }\r
+\r
+ public int getFileEntriesAndFileShortcutsCount(\r
+ long groupId, long folderId, int status)\r
+ throws SystemException {\r
+\r
+ int fileEntriesCount = 0;\r
+\r
+ if (status == WorkflowConstants.STATUS_ANY) {\r
+ fileEntriesCount = dlFileEntryPersistence.countByG_F(\r
+ groupId, folderId);\r
+ }\r
+ else {\r
+ fileEntriesCount = dlFolderFinder.countFE_ByG_F_S(\r
+ groupId, folderId, status);\r
+ }\r
+\r
+ int fileShortcutsCount = dlFileShortcutPersistence.countByG_F_S(\r
+ groupId, folderId, 0);\r
+\r
+ return fileEntriesCount + fileShortcutsCount;\r
+ }\r
+\r
+ public DLFolder getFolder(long folderId)\r
+ throws PortalException, SystemException {\r
+\r
+ return dlFolderPersistence.findByPrimaryKey(folderId);\r
+ }\r
+\r
+ public DLFolder getFolder(long groupId, long parentFolderId, String name)\r
+ throws PortalException, SystemException {\r
+\r
+ return dlFolderPersistence.findByG_P_N(groupId, parentFolderId, name);\r
+ }\r
+\r
+ public long getFolderId(long companyId, long folderId)\r
+ throws SystemException {\r
+\r
+ if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {\r
+\r
+ // Ensure folder exists and belongs to the proper company\r
+\r
+ DLFolder dlFolder = dlFolderPersistence.fetchByPrimaryKey(folderId);\r
+\r
+ if ((dlFolder == null) || (companyId != dlFolder.getCompanyId())) {\r
+ folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;\r
+ }\r
+ }\r
+\r
+ return folderId;\r
+ }\r
+\r
+ public List<DLFolder> getFolders(long groupId, long parentFolderId)\r
+ throws SystemException {\r
+\r
+ return getFolders(groupId, parentFolderId, true);\r
+ }\r
+\r
+ public List<DLFolder> getFolders(\r
+ long groupId, long parentFolderId, boolean includeMountfolders)\r
+ throws SystemException {\r
+\r
+ if (includeMountfolders) {\r
+ return dlFolderPersistence.findByG_P(groupId, parentFolderId);\r
+ }\r
+ else {\r
+ return dlFolderPersistence.findByG_P_M(\r
+ groupId, parentFolderId, false);\r
+ }\r
+ }\r
+\r
+ public List<DLFolder> getFolders(\r
+ long groupId, long parentFolderId, boolean includeMountfolders,\r
+ int start, int end, OrderByComparator obc)\r
+ throws SystemException {\r
+\r
+ if (includeMountfolders) {\r
+ return dlFolderPersistence.findByG_P(\r
+ groupId, parentFolderId, start, end, obc);\r
+ }\r
+ else {\r
+ return dlFolderPersistence.findByG_P_M(\r
+ groupId, parentFolderId, false, start, end, obc);\r
+ }\r
+ }\r
+\r
+ public List<DLFolder> getFolders(\r
+ long groupId, long parentFolderId, int start, int end,\r
+ OrderByComparator obc)\r
+ throws SystemException {\r
+\r
+ return getFolders(groupId, parentFolderId, true, start, end, obc);\r
+ }\r
+\r
+ public List<Object> getFoldersAndFileEntriesAndFileShortcuts(\r
+ long groupId, long folderId, int status,\r
+ boolean includeMountFolders, int start, int end,\r
+ OrderByComparator obc)\r
+ throws SystemException {\r
+\r
+ return dlFolderFinder.findF_FE_FS_ByG_F_S_M_M(\r
+ groupId, folderId, status, null, includeMountFolders, start, end,\r
+ obc);\r
+ }\r
+\r
+ public List<Object> getFoldersAndFileEntriesAndFileShortcuts(\r
+ long groupId, long folderId, int status, String[] mimeTypes,\r
+ boolean includeMountFolders, int start, int end,\r
+ OrderByComparator obc)\r
+ throws SystemException {\r
+\r
+ return dlFolderFinder.findF_FE_FS_ByG_F_S_M_M(\r
+ groupId, folderId, status, mimeTypes, includeMountFolders, start,\r
+ end, obc);\r
+ }\r
+\r
+ public int getFoldersAndFileEntriesAndFileShortcutsCount(\r
+ long groupId, long folderId, int status,\r
+ boolean includeMountFolders)\r
+ throws SystemException {\r
+\r
+ return dlFolderFinder.countF_FE_FS_ByG_F_S_M_M(\r
+ groupId, folderId, status, null, includeMountFolders);\r
+ }\r
+\r
+ public int getFoldersAndFileEntriesAndFileShortcutsCount(\r
+ long groupId, long folderId, int status, String[] mimeTypes,\r
+ boolean includeMountFolders)\r
+ throws SystemException {\r
+\r
+ return dlFolderFinder.countF_FE_FS_ByG_F_S_M_M(\r
+ groupId, folderId, status, mimeTypes, includeMountFolders);\r
+ }\r
+\r
+ public int getFoldersCount(long groupId, long parentFolderId)\r
+ throws SystemException {\r
+\r
+ return getFoldersCount(groupId, parentFolderId, true);\r
+ }\r
+\r
+ public int getFoldersCount(\r
+ long groupId, long parentFolderId, boolean includeMountfolders)\r
+ throws SystemException {\r
+\r
+ if (includeMountfolders) {\r
+ return dlFolderPersistence.countByG_P(groupId, parentFolderId);\r
+ }\r
+ else {\r
+ return dlFolderPersistence.countByG_P_M(\r
+ groupId, parentFolderId, false);\r
+ }\r
+ }\r
+\r
+ public int getFoldersFileEntriesCount(\r
+ long groupId, List<Long> folderIds, int status)\r
+ throws SystemException {\r
+\r
+ if (folderIds.size() <= PropsValues.SQL_DATA_MAX_PARAMETERS) {\r
+ return dlFileEntryFinder.countByG_F_S(groupId, folderIds, status);\r
+ }\r
+ else {\r
+ int start = 0;\r
+ int end = PropsValues.SQL_DATA_MAX_PARAMETERS;\r
+\r
+ int filesCount = dlFileEntryFinder.countByG_F_S(\r
+ groupId, folderIds.subList(start, end), status);\r
+\r
+ folderIds.subList(start, end).clear();\r
+\r
+ filesCount += getFoldersFileEntriesCount(\r
+ groupId, folderIds, status);\r
+\r
+ return filesCount;\r
+ }\r
+ }\r
+\r
+ public DLFolder getMountFolder(long repositoryId)\r
+ throws PortalException, SystemException {\r
+\r
+ return dlFolderPersistence.findByRepositoryId(repositoryId);\r
+ }\r
+\r
+ public List<DLFolder> getMountFolders(\r
+ long groupId, long parentFolderId, int start, int end,\r
+ OrderByComparator obc)\r
+ throws SystemException {\r
+\r
+ return dlFolderPersistence.findByG_P_M(\r
+ groupId, parentFolderId, true, start, end, obc);\r
+ }\r
+\r
+ public int getMountFoldersCount(long groupId, long parentFolderId)\r
+ throws SystemException {\r
+\r
+ return dlFolderPersistence.countByG_P_M(groupId, parentFolderId, true);\r
+ }\r
+\r
+ public void getSubfolderIds(\r
+ List<Long> folderIds, long groupId, long folderId)\r
+ throws SystemException {\r
+\r
+ List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(\r
+ groupId, folderId);\r
+\r
+ for (DLFolder dlFolder : dlFolders) {\r
+ folderIds.add(dlFolder.getFolderId());\r
+\r
+ getSubfolderIds(\r
+ folderIds, dlFolder.getGroupId(), dlFolder.getFolderId());\r
+ }\r
+ }\r
+\r
+ public DLFolder moveFolder(\r
+ long folderId, long parentFolderId, ServiceContext serviceContext)\r
+ throws PortalException, SystemException {\r
+\r
+ DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);\r
+\r
+ parentFolderId = getParentFolderId(dlFolder, parentFolderId);\r
+\r
+ validateFolder(\r
+ dlFolder.getFolderId(), dlFolder.getGroupId(), parentFolderId,\r
+ dlFolder.getName());\r
+\r
+ dlFolder.setModifiedDate(serviceContext.getModifiedDate(null));\r
+ dlFolder.setParentFolderId(parentFolderId);\r
+ dlFolder.setExpandoBridgeAttributes(serviceContext);\r
+\r
+ dlFolderPersistence.update(dlFolder, false);\r
+\r
+ dlAppHelperLocalService.moveFolder(new LiferayFolder(dlFolder));\r
+\r
+ return dlFolder;\r
+ }\r
+\r
+ public DLFolder updateFolder(\r
+ long folderId, long parentFolderId, String name, String description,\r
+ long defaultFileEntryTypeId, List<Long> fileEntryTypeIds,\r
+ boolean overrideFileEntryTypes, ServiceContext serviceContext)\r
+ throws PortalException, SystemException {\r
+\r
+ // File entry types\r
+\r
+ DLFolder dlFolder = null;\r
+\r
+ if (folderId > DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {\r
+ dlFolder = dlFolderLocalService.updateFolderAndFileEntryTypes(\r
+ folderId, parentFolderId, name, description,\r
+ defaultFileEntryTypeId, fileEntryTypeIds,\r
+ overrideFileEntryTypes, serviceContext);\r
+\r
+ dlFileEntryTypeLocalService.cascadeFileEntryTypes(\r
+ serviceContext.getUserId(), dlFolder);\r
+ }\r
+\r
+ // Workflow definitions\r
+\r
+ List<ObjectValuePair<Long, String>> workflowDefinitions =\r
+ new ArrayList<ObjectValuePair<Long, String>>();\r
+\r
+ if (fileEntryTypeIds.isEmpty()) {\r
+ fileEntryTypeIds.add(\r
+ DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL);\r
+ }\r
+ else {\r
+ workflowDefinitions.add(\r
+ new ObjectValuePair<Long, String>(\r
+ DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL,\r
+ StringPool.BLANK));\r
+ }\r
+\r
+ for (long fileEntryTypeId : fileEntryTypeIds) {\r
+ String workflowDefinition = ParamUtil.getString(\r
+ serviceContext, "workflowDefinition" + fileEntryTypeId);\r
+\r
+ workflowDefinitions.add(\r
+ new ObjectValuePair<Long, String>(\r
+ fileEntryTypeId, workflowDefinition));\r
+ }\r
+\r
+ workflowDefinitionLinkLocalService.updateWorkflowDefinitionLinks(\r
+ serviceContext.getUserId(), serviceContext.getCompanyId(),\r
+ serviceContext.getScopeGroupId(), DLFolder.class.getName(),\r
+ folderId, workflowDefinitions);\r
+\r
+ return dlFolder;\r
+ }\r
+\r
+ public DLFolder updateFolder(\r
+ long folderId, String name, String description,\r
+ long defaultFileEntryTypeId, List<Long> fileEntryTypeIds,\r
+ boolean overrideFileEntryTypes, ServiceContext serviceContext)\r
+ throws PortalException, SystemException {\r
+\r
+ return updateFolder(\r
+ folderId, folderId, name, description, defaultFileEntryTypeId,\r
+ fileEntryTypeIds, overrideFileEntryTypes, serviceContext);\r
+ }\r
+\r
+ public DLFolder updateFolderAndFileEntryTypes(\r
+ long folderId, long parentFolderId, String name, String description,\r
+ long defaultFileEntryTypeId, List<Long> fileEntryTypeIds,\r
+ boolean overrideFileEntryTypes, ServiceContext serviceContext)\r
+ throws PortalException, SystemException {\r
+\r
+ // Folder\r
+\r
+ if (!overrideFileEntryTypes) {\r
+ fileEntryTypeIds = Collections.emptyList();\r
+ }\r
+\r
+ DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);\r
+\r
+ parentFolderId = getParentFolderId(dlFolder, parentFolderId);\r
+\r
+ validateFolder(folderId, dlFolder.getGroupId(), parentFolderId, name);\r
+\r
+ dlFolder.setModifiedDate(serviceContext.getModifiedDate(null));\r
+ dlFolder.setParentFolderId(parentFolderId);\r
+ dlFolder.setName(name);\r
+ dlFolder.setDescription(description);\r
+ dlFolder.setExpandoBridgeAttributes(serviceContext);\r
+ dlFolder.setOverrideFileEntryTypes(overrideFileEntryTypes);\r
+ dlFolder.setDefaultFileEntryTypeId(defaultFileEntryTypeId);\r
+\r
+ dlFolderPersistence.update(dlFolder, false);\r
+\r
+ // File entry types\r
+\r
+ if (fileEntryTypeIds != null) {\r
+ dlFileEntryTypeLocalService.updateFolderFileEntryTypes(\r
+ dlFolder, fileEntryTypeIds, defaultFileEntryTypeId,\r
+ serviceContext);\r
+ }\r
+\r
+ // App helper\r
+\r
+ dlAppHelperLocalService.updateFolder(\r
+ new LiferayFolder(dlFolder), serviceContext);\r
+\r
+ return dlFolder;\r
+ }\r
+\r
+ public void updateLastPostDate(long folderId, Date lastPostDate)\r
+ throws PortalException, SystemException {\r
+\r
+ DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);\r
+\r
+ dlFolder.setLastPostDate(lastPostDate);\r
+\r
+ dlFolderPersistence.update(dlFolder, false);\r
+ }\r
+ \r
+ \r
+ public Hits search(\r
+ long companyId, long groupId, long userId, long[] folderIds,\r
+ String keywords, int start, int end)\r
+ throws SystemException {\r
+ \r
+ return CustomDLStoreUtil.search(\r
+ companyId, userId, PortletKeys.DOCUMENT_LIBRARY, groupId, folderIds,\r
+ keywords, start, end);\r
+ }\r
+ \r
+ public Hits search(\r
+ long companyId, long groupId, long userId, long ownerUserId,\r
+ String keywords, int start, int end)\r
+ throws SystemException {\r
+\r
+ _log.info("Searching '"+keywords+"' in documents (folders) ...");\r
+ \r
+ try {\r
+ Indexer indexer = IndexerRegistryUtil.getIndexer(DLFolder.class);\r
+ String searchEngineId = indexer.getSearchEngineId();\r
+ \r
+ SearchContext searchContext = new SearchContext();\r
+ searchContext.setSearchEngineId(searchEngineId);\r
+ \r
+ BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext);\r
+\r
+ contextQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);\r
+ \r
+ List<String> solrFilters = new ArrayList<String>();\r
+ \r
+ User user = UserLocalServiceUtil.getUser(userId);\r
+ \r
+ if (groupId > 0) {\r
+ solrFilters.add(Field.GROUP_ID + ":" + groupId);\r
+ } else if (ENTRolesConstants.hasGlobalVisibilityOnGroupOnItsSchool(user)) {\r
+ solrFilters.add("(" + Field.GROUP_ID + ":" + IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.INCLUDE_USER_GROUP) + ") "\r
+ + "OR (" + Field.ETAB_ID + ":" + IndexerUtil.getEtabVisibility(user) + ")");\r
+ } else {\r
+ String listGroupId = IndexerUtil.getSearchGroupsQuery(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, \r
+ IndexerUtil.INCLUDE_GLOBAL_ORG, IndexerUtil.INCLUDE_USER_GROUP);\r
+ solrFilters.add(Field.GROUP_ID + ":" + listGroupId);\r
+ }\r
+ \r
+ String query = SolrQueryUtil.getQueryFromKeywords(keywords, true);\r
+ String queryWithoutFuzzySearch = SolrQueryUtil.getQueryFromKeywords(keywords, false);\r
+ \r
+ solrFilters.add("(" + Field.USER_NAME + ":" + query + ") "\r
+ + "OR (" + Field.TITLE + ":" + query + ") "\r
+ + "OR (" + Field.DESCRIPTION + ":" + queryWithoutFuzzySearch + ") "\r
+ + "OR (" + Field.ASSET_TAG_NAMES + ":" + query + ")");\r
+\r
+ BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);\r
+\r
+ fullQuery.add(contextQuery, BooleanClauseOccur.MUST);\r
+\r
+ //userId a 0 car on gere nous meme les permissions\r
+ return SearchEngineUtil.search(\r
+ searchEngineId, companyId, fullQuery, solrFilters, start, end);\r
+ }\r
+ catch (Exception e) {\r
+ throw new SystemException(e);\r
+ }\r
+ }\r
+ \r
+ public Hits searchByDate(\r
+ long companyId, long groupId, long userId, long ownerUserId,\r
+ String keywords, int start, int end)\r
+ throws SystemException {\r
+ \r
+ try {\r
+ Indexer indexer = IndexerRegistryUtil.getIndexer(DLFolder.class);\r
+ String searchEngineId = indexer.getSearchEngineId();\r
+ \r
+ SearchContext searchContext = new SearchContext();\r
+ searchContext.setSearchEngineId(searchEngineId);\r
+ \r
+ BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext);\r
+\r
+ contextQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);\r
+ \r
+ List<String> solrFilters = new ArrayList<String>();\r
+ \r
+ User user = UserLocalServiceUtil.getUser(userId);\r
+ \r
+ if (groupId > 0) {\r
+ solrFilters.add(Field.GROUP_ID + ":" + groupId);\r
+ } else if (ENTRolesConstants.hasGlobalVisibilityOnGroupOnItsSchool(user)) {\r
+ solrFilters.add("(" + Field.GROUP_ID + ":" + IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.INCLUDE_USER_GROUP) + ") "\r
+ + "OR (" + Field.ETAB_ID + ":" + IndexerUtil.getEtabVisibility(user) + ")");\r
+ } else {\r
+ String listGroupId = IndexerUtil.getSearchGroupsQuery(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, \r
+ IndexerUtil.INCLUDE_GLOBAL_ORG, IndexerUtil.INCLUDE_USER_GROUP);\r
+ solrFilters.add(Field.GROUP_ID + ":" + listGroupId);\r
+ }\r
+\r
+ if (!keywords.isEmpty()) {\r
+ //Field.MODIFIED_DATE = "modified" only \r
+ solrFilters.add("modifiedDate" + ":" + keywords);\r
+ } \r
+\r
+ BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);\r
+\r
+ fullQuery.add(contextQuery, BooleanClauseOccur.MUST);\r
+\r
+ //userId a 0 car on gere nous meme les permissions\r
+ return SearchEngineUtil.search(\r
+ searchEngineId, companyId, fullQuery, solrFilters, start, end);\r
+ }\r
+ catch (Exception e) {\r
+ throw new SystemException(e);\r
+ }\r
+ }\r
+\r
+\r
+ protected void addFolderResources(\r
+ DLFolder dlFolder, boolean addGroupPermissions,\r
+ boolean addGuestPermissions)\r
+ throws PortalException, SystemException {\r
+\r
+ resourceLocalService.addResources(\r
+ dlFolder.getCompanyId(), dlFolder.getGroupId(),\r
+ dlFolder.getUserId(), DLFolder.class.getName(),\r
+ dlFolder.getFolderId(), false, addGroupPermissions,\r
+ addGuestPermissions);\r
+ }\r
+\r
+ protected void addFolderResources(\r
+ DLFolder dlFolder, String[] groupPermissions,\r
+ String[] guestPermissions)\r
+ throws PortalException, SystemException {\r
+\r
+ resourceLocalService.addModelResources(\r
+ dlFolder.getCompanyId(), dlFolder.getGroupId(),\r
+ dlFolder.getUserId(), DLFolder.class.getName(),\r
+ dlFolder.getFolderId(), groupPermissions, guestPermissions);\r
+ }\r
+\r
+ protected void addFolderResources(\r
+ long folderId, boolean addGroupPermissions,\r
+ boolean addGuestPermissions)\r
+ throws PortalException, SystemException {\r
+\r
+ DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);\r
+\r
+ addFolderResources(dlFolder, addGroupPermissions, addGuestPermissions);\r
+ }\r
+\r
+ protected void addFolderResources(\r
+ long folderId, String[] groupPermissions, String[] guestPermissions)\r
+ throws PortalException, SystemException {\r
+\r
+ DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);\r
+\r
+ addFolderResources(dlFolder, groupPermissions, guestPermissions);\r
+ }\r
+\r
+ protected void deleteFolder(DLFolder dlFolder)\r
+ throws PortalException, SystemException {\r
+\r
+ // Indexer\r
+ \r
+ Indexer indexer = IndexerRegistryUtil.getIndexer(DLFolder.class);\r
+ indexer.delete(dlFolder);\r
+ \r
+ // Folders\r
+\r
+ List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(\r
+ dlFolder.getGroupId(), dlFolder.getFolderId());\r
+\r
+ for (DLFolder curDLFolder : dlFolders) {\r
+ deleteFolder(curDLFolder);\r
+ }\r
+\r
+ // Dropbox (casier) entry\r
+ \r
+ try {\r
+ CasierEntryLocalServiceUtil.deleteBuC_G_Id(dlFolder.getCompanyId(), dlFolder.getGroupId(), dlFolder.getFolderId());\r
+ } catch (PortalException e){}\r
+\r
+ // Resources\r
+\r
+ resourceLocalService.deleteResource(\r
+ dlFolder.getCompanyId(), DLFolder.class.getName(),\r
+ ResourceConstants.SCOPE_INDIVIDUAL, dlFolder.getFolderId());\r
+\r
+ // WebDAVProps\r
+\r
+ webDAVPropsLocalService.deleteWebDAVProps(\r
+ DLFolder.class.getName(), dlFolder.getFolderId());\r
+\r
+ // File entries\r
+\r
+ dlFileEntryLocalService.deleteFileEntries(\r
+ dlFolder.getGroupId(), dlFolder.getFolderId());\r
+\r
+ // File entry types\r
+\r
+ dlFileEntryTypeLocalService.unsetFolderFileEntryTypes(\r
+ dlFolder.getFolderId());\r
+\r
+ // Expando\r
+\r
+ expandoValueLocalService.deleteValues(\r
+ DLFolder.class.getName(), dlFolder.getFolderId());\r
+\r
+ // App helper\r
+\r
+ dlAppHelperLocalService.deleteFolder(new LiferayFolder(dlFolder));\r
+\r
+ // Folder\r
+\r
+ dlFolderPersistence.remove(dlFolder);\r
+\r
+ // Directory\r
+\r
+ try {\r
+ DLStoreUtil.deleteDirectory(\r
+ dlFolder.getCompanyId(), dlFolder.getFolderId(),\r
+ StringPool.BLANK);\r
+ }\r
+ catch (NoSuchDirectoryException nsde) {\r
+ if (_log.isDebugEnabled()) {\r
+ _log.debug(nsde.getMessage());\r
+ }\r
+ }\r
+ }\r
+\r
+ protected long getParentFolderId(DLFolder dlFolder, long parentFolderId)\r
+ throws SystemException {\r
+\r
+ if (parentFolderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {\r
+ return parentFolderId;\r
+ }\r
+\r
+ if (dlFolder.getFolderId() == parentFolderId) {\r
+ return dlFolder.getParentFolderId();\r
+ }\r
+ else {\r
+ DLFolder parentDLFolder = dlFolderPersistence.fetchByPrimaryKey(\r
+ parentFolderId);\r
+\r
+ if ((parentDLFolder == null) ||\r
+ (dlFolder.getGroupId() != parentDLFolder.getGroupId())) {\r
+\r
+ return dlFolder.getParentFolderId();\r
+ }\r
+\r
+ List<Long> subfolderIds = new ArrayList<Long>();\r
+\r
+ getSubfolderIds(\r
+ subfolderIds, dlFolder.getGroupId(), dlFolder.getFolderId());\r
+\r
+ if (subfolderIds.contains(parentFolderId)) {\r
+ return dlFolder.getParentFolderId();\r
+ }\r
+\r
+ return parentFolderId;\r
+ }\r
+ }\r
+\r
+ protected long getParentFolderId(long groupId, long parentFolderId)\r
+ throws SystemException {\r
+\r
+ if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {\r
+ DLFolder parentDLFolder = dlFolderPersistence.fetchByPrimaryKey(\r
+ parentFolderId);\r
+\r
+ if ((parentDLFolder == null) ||\r
+ (groupId != parentDLFolder.getGroupId())) {\r
+\r
+ parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;\r
+ }\r
+ }\r
+\r
+ return parentFolderId;\r
+ }\r
+\r
+ protected void validateFolder(\r
+ long folderId, long groupId, long parentFolderId, String name)\r
+ throws PortalException, SystemException {\r
+\r
+ validateFolderName(name);\r
+\r
+ try {\r
+ dlFileEntryLocalService.getFileEntry(groupId, parentFolderId, name);\r
+\r
+ throw new DuplicateFileException(name);\r
+ }\r
+ catch (NoSuchFileEntryException nsfee) {\r
+ }\r
+\r
+ DLFolder dlFolder = dlFolderPersistence.fetchByG_P_N(\r
+ groupId, parentFolderId, name);\r
+\r
+ if ((dlFolder != null) && (dlFolder.getFolderId() != folderId)) {\r
+ throw new DuplicateFolderNameException(name);\r
+ }\r
+ }\r
+\r
+ protected void validateFolder(\r
+ long groupId, long parentFolderId, String name)\r
+ throws PortalException, SystemException {\r
+\r
+ long folderId = 0;\r
+\r
+ validateFolder(folderId, groupId, parentFolderId, name);\r
+ }\r
+\r
+ protected void validateFolderName(String name) throws PortalException {\r
+ if (!AssetUtil.isValidWord(name)) {\r
+ throw new FolderNameException();\r
+ }\r
+ }\r
+\r
+ private static Log _log = LogFactoryUtil.getLog(\r
+ DLFolderLocalServiceImpl.class);\r
+\r
+}
\ No newline at end of file