2 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
\r
4 * This library is free software; you can redistribute it and/or modify it under
\r
5 * the terms of the GNU Lesser General Public License as published by the Free
\r
6 * Software Foundation; either version 2.1 of the License, or (at your option)
\r
9 * This library is distributed in the hope that it will be useful, but WITHOUT
\r
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
\r
15 package com.liferay.portlet.documentlibrary.service.impl;
\r
17 import java.util.ArrayList;
\r
18 import java.util.Collections;
\r
19 import java.util.Date;
\r
20 import java.util.List;
\r
22 import com.liferay.portal.kernel.exception.PortalException;
\r
23 import com.liferay.portal.kernel.exception.SystemException;
\r
24 import com.liferay.portal.kernel.log.Log;
\r
25 import com.liferay.portal.kernel.log.LogFactoryUtil;
\r
26 import com.liferay.portal.kernel.search.BooleanClauseOccur;
\r
27 import com.liferay.portal.kernel.search.BooleanQuery;
\r
28 import com.liferay.portal.kernel.search.BooleanQueryFactoryUtil;
\r
29 import com.liferay.portal.kernel.search.Field;
\r
30 import com.liferay.portal.kernel.search.Hits;
\r
31 import com.liferay.portal.kernel.search.Indexer;
\r
32 import com.liferay.portal.kernel.search.IndexerRegistryUtil;
\r
33 import com.liferay.portal.kernel.search.SearchContext;
\r
34 import com.liferay.portal.kernel.search.SearchEngineUtil;
\r
35 import com.liferay.portal.kernel.search.SolrQueryUtil;
\r
36 import com.liferay.portal.kernel.util.ObjectValuePair;
\r
37 import com.liferay.portal.kernel.util.OrderByComparator;
\r
38 import com.liferay.portal.kernel.util.ParamUtil;
\r
39 import com.liferay.portal.kernel.util.StringPool;
\r
40 import com.liferay.portal.kernel.util.Validator;
\r
41 import com.liferay.portal.kernel.workflow.WorkflowConstants;
\r
42 import com.liferay.portal.model.Group;
\r
43 import com.liferay.portal.model.ResourceConstants;
\r
44 import com.liferay.portal.model.User;
\r
45 import com.liferay.portal.repository.liferayrepository.model.LiferayFolder;
\r
46 import com.liferay.portal.service.ServiceContext;
\r
47 import com.liferay.portal.service.UserLocalServiceUtil;
\r
48 import com.liferay.portal.util.PortletKeys;
\r
49 import com.liferay.portal.util.PropsValues;
\r
50 import com.liferay.portlet.asset.util.AssetUtil;
\r
51 import com.liferay.portlet.documentlibrary.DuplicateFileException;
\r
52 import com.liferay.portlet.documentlibrary.DuplicateFolderNameException;
\r
53 import com.liferay.portlet.documentlibrary.FolderNameException;
\r
54 import com.liferay.portlet.documentlibrary.NoSuchDirectoryException;
\r
55 import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
\r
56 import com.liferay.portlet.documentlibrary.folder.service.DLFolderLocalService;
\r
57 import com.liferay.portlet.documentlibrary.model.DLFileEntryTypeConstants;
\r
58 import com.liferay.portlet.documentlibrary.model.DLFolder;
\r
59 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
\r
60 import com.liferay.portlet.documentlibrary.service.base.DLFolderLocalServiceBaseImpl;
\r
61 import com.liferay.portlet.documentlibrary.store.CustomDLStoreUtil;
\r
62 import com.liferay.portlet.documentlibrary.store.DLStoreUtil;
\r
63 import com.pentila.entSavoie.ENTRolesConstants;
\r
64 import com.pentila.entSavoie.cartable.service.CasierEntryLocalServiceUtil;
\r
65 import com.pentila.entSavoie.search.util.IndexerUtil;
\r
68 * @author Brian Wing Shun Chan
\r
69 * @author Alexander Chow
\r
71 public class DLFolderLocalServiceImpl extends DLFolderLocalServiceBaseImpl implements DLFolderLocalService {
\r
73 public static final String PORTLET_ID = "foldersearchengine";
\r
75 public DLFolder addFolder(
\r
76 long userId, long groupId, long repositoryId, boolean mountPoint,
\r
77 long parentFolderId, String name, String description,
\r
78 ServiceContext serviceContext)
\r
79 throws PortalException, SystemException {
\r
83 User user = userPersistence.findByPrimaryKey(userId);
\r
84 parentFolderId = getParentFolderId(groupId, parentFolderId);
\r
85 Date now = new Date();
\r
87 validateFolder(groupId, parentFolderId, name);
\r
89 long folderId = counterLocalService.increment();
\r
91 DLFolder dlFolder = dlFolderPersistence.create(folderId);
\r
93 dlFolder.setUuid(serviceContext.getUuid());
\r
94 dlFolder.setGroupId(groupId);
\r
95 dlFolder.setCompanyId(user.getCompanyId());
\r
96 dlFolder.setUserId(user.getUserId());
\r
97 dlFolder.setCreateDate(serviceContext.getCreateDate(now));
\r
98 dlFolder.setModifiedDate(serviceContext.getModifiedDate(now));
\r
99 dlFolder.setRepositoryId(repositoryId);
\r
100 dlFolder.setMountPoint(mountPoint);
\r
101 dlFolder.setParentFolderId(parentFolderId);
\r
102 dlFolder.setName(name);
\r
103 dlFolder.setDescription(description);
\r
104 dlFolder.setOverrideFileEntryTypes(false);
\r
105 dlFolder.setExpandoBridgeAttributes(serviceContext);
\r
107 dlFolderPersistence.update(dlFolder, false);
\r
111 if (serviceContext.isAddGroupPermissions() ||
\r
112 serviceContext.isAddGuestPermissions()) {
\r
114 addFolderResources(
\r
115 dlFolder, serviceContext.isAddGroupPermissions(),
\r
116 serviceContext.isAddGuestPermissions());
\r
119 if (serviceContext.isDeriveDefaultPermissions()) {
\r
120 serviceContext.deriveDefaultPermissions(
\r
121 repositoryId, DLFolderConstants.getClassName());
\r
124 addFolderResources(
\r
125 dlFolder, serviceContext.getGroupPermissions(),
\r
126 serviceContext.getGuestPermissions());
\r
131 if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
\r
132 DLFolder parentDLFolder = dlFolderPersistence.findByPrimaryKey(
\r
135 parentDLFolder.setLastPostDate(now);
\r
137 dlFolderPersistence.update(parentDLFolder, false);
\r
142 dlAppHelperLocalService.addFolder(
\r
143 new LiferayFolder(dlFolder), serviceContext);
\r
148 Indexer indexer = IndexerRegistryUtil.getIndexer(DLFolder.class);
\r
149 if(Validator.isNotNull(indexer)){
\r
150 indexer.reindex(dlFolder);
\r
156 public DLFolder update(DLFolder folder) throws PortalException, SystemException{
\r
157 dlFolderPersistence.update(folder, true);
\r
161 Indexer indexer = IndexerRegistryUtil.getIndexer(DLFolder.class);
\r
162 indexer.reindex(folder);
\r
167 public void deleteAll(long groupId)
\r
168 throws PortalException, SystemException {
\r
170 Group group = groupLocalService.getGroup(groupId);
\r
172 List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(
\r
173 groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
\r
175 for (DLFolder dlFolder : dlFolders) {
\r
176 deleteFolder(dlFolder);
\r
179 dlFileEntryLocalService.deleteFileEntries(
\r
180 groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
\r
183 DLStoreUtil.deleteDirectory(
\r
184 group.getCompanyId(), groupId, StringPool.BLANK);
\r
186 catch (NoSuchDirectoryException nsde) {
\r
187 if (_log.isDebugEnabled()) {
\r
188 _log.debug(nsde.getMessage());
\r
193 public void deleteFolder(long folderId)
\r
194 throws PortalException, SystemException {
\r
196 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
\r
198 deleteFolder(dlFolder);
\r
201 public List<DLFolder> getCompanyFolders(long companyId, int start, int end)
\r
202 throws SystemException {
\r
204 return dlFolderPersistence.findByCompanyId(companyId, start, end);
\r
207 public int getCompanyFoldersCount(long companyId) throws SystemException {
\r
208 return dlFolderPersistence.countByCompanyId(companyId);
\r
211 public List<Object> getFileEntriesAndFileShortcuts(
\r
212 long groupId, long folderId, int status, int start, int end)
\r
213 throws SystemException {
\r
215 return dlFolderFinder.findFE_FS_ByG_F_S(
\r
216 groupId, folderId, status, start, end);
\r
219 public int getFileEntriesAndFileShortcutsCount(
\r
220 long groupId, long folderId, int status)
\r
221 throws SystemException {
\r
223 int fileEntriesCount = 0;
\r
225 if (status == WorkflowConstants.STATUS_ANY) {
\r
226 fileEntriesCount = dlFileEntryPersistence.countByG_F(
\r
227 groupId, folderId);
\r
230 fileEntriesCount = dlFolderFinder.countFE_ByG_F_S(
\r
231 groupId, folderId, status);
\r
234 int fileShortcutsCount = dlFileShortcutPersistence.countByG_F_S(
\r
235 groupId, folderId, 0);
\r
237 return fileEntriesCount + fileShortcutsCount;
\r
240 public DLFolder getFolder(long folderId)
\r
241 throws PortalException, SystemException {
\r
243 return dlFolderPersistence.findByPrimaryKey(folderId);
\r
246 public DLFolder getFolder(long groupId, long parentFolderId, String name)
\r
247 throws PortalException, SystemException {
\r
249 return dlFolderPersistence.findByG_P_N(groupId, parentFolderId, name);
\r
252 public long getFolderId(long companyId, long folderId)
\r
253 throws SystemException {
\r
255 if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
\r
257 // Ensure folder exists and belongs to the proper company
\r
259 DLFolder dlFolder = dlFolderPersistence.fetchByPrimaryKey(folderId);
\r
261 if ((dlFolder == null) || (companyId != dlFolder.getCompanyId())) {
\r
262 folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
\r
269 public List<DLFolder> getFolders(long groupId, long parentFolderId)
\r
270 throws SystemException {
\r
272 return getFolders(groupId, parentFolderId, true);
\r
275 public List<DLFolder> getFolders(
\r
276 long groupId, long parentFolderId, boolean includeMountfolders)
\r
277 throws SystemException {
\r
279 if (includeMountfolders) {
\r
280 return dlFolderPersistence.findByG_P(groupId, parentFolderId);
\r
283 return dlFolderPersistence.findByG_P_M(
\r
284 groupId, parentFolderId, false);
\r
288 public List<DLFolder> getFolders(
\r
289 long groupId, long parentFolderId, boolean includeMountfolders,
\r
290 int start, int end, OrderByComparator obc)
\r
291 throws SystemException {
\r
293 if (includeMountfolders) {
\r
294 return dlFolderPersistence.findByG_P(
\r
295 groupId, parentFolderId, start, end, obc);
\r
298 return dlFolderPersistence.findByG_P_M(
\r
299 groupId, parentFolderId, false, start, end, obc);
\r
303 public List<DLFolder> getFolders(
\r
304 long groupId, long parentFolderId, int start, int end,
\r
305 OrderByComparator obc)
\r
306 throws SystemException {
\r
308 return getFolders(groupId, parentFolderId, true, start, end, obc);
\r
311 public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
\r
312 long groupId, long folderId, int status,
\r
313 boolean includeMountFolders, int start, int end,
\r
314 OrderByComparator obc)
\r
315 throws SystemException {
\r
317 return dlFolderFinder.findF_FE_FS_ByG_F_S_M_M(
\r
318 groupId, folderId, status, null, includeMountFolders, start, end,
\r
322 public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
\r
323 long groupId, long folderId, int status, String[] mimeTypes,
\r
324 boolean includeMountFolders, int start, int end,
\r
325 OrderByComparator obc)
\r
326 throws SystemException {
\r
328 return dlFolderFinder.findF_FE_FS_ByG_F_S_M_M(
\r
329 groupId, folderId, status, mimeTypes, includeMountFolders, start,
\r
333 public int getFoldersAndFileEntriesAndFileShortcutsCount(
\r
334 long groupId, long folderId, int status,
\r
335 boolean includeMountFolders)
\r
336 throws SystemException {
\r
338 return dlFolderFinder.countF_FE_FS_ByG_F_S_M_M(
\r
339 groupId, folderId, status, null, includeMountFolders);
\r
342 public int getFoldersAndFileEntriesAndFileShortcutsCount(
\r
343 long groupId, long folderId, int status, String[] mimeTypes,
\r
344 boolean includeMountFolders)
\r
345 throws SystemException {
\r
347 return dlFolderFinder.countF_FE_FS_ByG_F_S_M_M(
\r
348 groupId, folderId, status, mimeTypes, includeMountFolders);
\r
351 public int getFoldersCount(long groupId, long parentFolderId)
\r
352 throws SystemException {
\r
354 return getFoldersCount(groupId, parentFolderId, true);
\r
357 public int getFoldersCount(
\r
358 long groupId, long parentFolderId, boolean includeMountfolders)
\r
359 throws SystemException {
\r
361 if (includeMountfolders) {
\r
362 return dlFolderPersistence.countByG_P(groupId, parentFolderId);
\r
365 return dlFolderPersistence.countByG_P_M(
\r
366 groupId, parentFolderId, false);
\r
370 public int getFoldersFileEntriesCount(
\r
371 long groupId, List<Long> folderIds, int status)
\r
372 throws SystemException {
\r
374 if (folderIds.size() <= PropsValues.SQL_DATA_MAX_PARAMETERS) {
\r
375 return dlFileEntryFinder.countByG_F_S(groupId, folderIds, status);
\r
379 int end = PropsValues.SQL_DATA_MAX_PARAMETERS;
\r
381 int filesCount = dlFileEntryFinder.countByG_F_S(
\r
382 groupId, folderIds.subList(start, end), status);
\r
384 folderIds.subList(start, end).clear();
\r
386 filesCount += getFoldersFileEntriesCount(
\r
387 groupId, folderIds, status);
\r
393 public DLFolder getMountFolder(long repositoryId)
\r
394 throws PortalException, SystemException {
\r
396 return dlFolderPersistence.findByRepositoryId(repositoryId);
\r
399 public List<DLFolder> getMountFolders(
\r
400 long groupId, long parentFolderId, int start, int end,
\r
401 OrderByComparator obc)
\r
402 throws SystemException {
\r
404 return dlFolderPersistence.findByG_P_M(
\r
405 groupId, parentFolderId, true, start, end, obc);
\r
408 public int getMountFoldersCount(long groupId, long parentFolderId)
\r
409 throws SystemException {
\r
411 return dlFolderPersistence.countByG_P_M(groupId, parentFolderId, true);
\r
414 public void getSubfolderIds(
\r
415 List<Long> folderIds, long groupId, long folderId)
\r
416 throws SystemException {
\r
418 List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(
\r
419 groupId, folderId);
\r
421 for (DLFolder dlFolder : dlFolders) {
\r
422 folderIds.add(dlFolder.getFolderId());
\r
425 folderIds, dlFolder.getGroupId(), dlFolder.getFolderId());
\r
429 public DLFolder moveFolder(
\r
430 long folderId, long parentFolderId, ServiceContext serviceContext)
\r
431 throws PortalException, SystemException {
\r
433 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
\r
435 parentFolderId = getParentFolderId(dlFolder, parentFolderId);
\r
438 dlFolder.getFolderId(), dlFolder.getGroupId(), parentFolderId,
\r
439 dlFolder.getName());
\r
441 dlFolder.setModifiedDate(serviceContext.getModifiedDate(null));
\r
442 dlFolder.setParentFolderId(parentFolderId);
\r
443 dlFolder.setExpandoBridgeAttributes(serviceContext);
\r
445 dlFolderPersistence.update(dlFolder, false);
\r
447 dlAppHelperLocalService.moveFolder(new LiferayFolder(dlFolder));
\r
452 public DLFolder updateFolder(
\r
453 long folderId, long parentFolderId, String name, String description,
\r
454 long defaultFileEntryTypeId, List<Long> fileEntryTypeIds,
\r
455 boolean overrideFileEntryTypes, ServiceContext serviceContext)
\r
456 throws PortalException, SystemException {
\r
458 // File entry types
\r
460 DLFolder dlFolder = null;
\r
462 if (folderId > DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
\r
463 dlFolder = dlFolderLocalService.updateFolderAndFileEntryTypes(
\r
464 folderId, parentFolderId, name, description,
\r
465 defaultFileEntryTypeId, fileEntryTypeIds,
\r
466 overrideFileEntryTypes, serviceContext);
\r
468 dlFileEntryTypeLocalService.cascadeFileEntryTypes(
\r
469 serviceContext.getUserId(), dlFolder);
\r
472 // Workflow definitions
\r
474 List<ObjectValuePair<Long, String>> workflowDefinitions =
\r
475 new ArrayList<ObjectValuePair<Long, String>>();
\r
477 if (fileEntryTypeIds.isEmpty()) {
\r
478 fileEntryTypeIds.add(
\r
479 DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL);
\r
482 workflowDefinitions.add(
\r
483 new ObjectValuePair<Long, String>(
\r
484 DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL,
\r
485 StringPool.BLANK));
\r
488 for (long fileEntryTypeId : fileEntryTypeIds) {
\r
489 String workflowDefinition = ParamUtil.getString(
\r
490 serviceContext, "workflowDefinition" + fileEntryTypeId);
\r
492 workflowDefinitions.add(
\r
493 new ObjectValuePair<Long, String>(
\r
494 fileEntryTypeId, workflowDefinition));
\r
497 workflowDefinitionLinkLocalService.updateWorkflowDefinitionLinks(
\r
498 serviceContext.getUserId(), serviceContext.getCompanyId(),
\r
499 serviceContext.getScopeGroupId(), DLFolder.class.getName(),
\r
500 folderId, workflowDefinitions);
\r
505 public DLFolder updateFolder(
\r
506 long folderId, String name, String description,
\r
507 long defaultFileEntryTypeId, List<Long> fileEntryTypeIds,
\r
508 boolean overrideFileEntryTypes, ServiceContext serviceContext)
\r
509 throws PortalException, SystemException {
\r
511 return updateFolder(
\r
512 folderId, folderId, name, description, defaultFileEntryTypeId,
\r
513 fileEntryTypeIds, overrideFileEntryTypes, serviceContext);
\r
516 public DLFolder updateFolderAndFileEntryTypes(
\r
517 long folderId, long parentFolderId, String name, String description,
\r
518 long defaultFileEntryTypeId, List<Long> fileEntryTypeIds,
\r
519 boolean overrideFileEntryTypes, ServiceContext serviceContext)
\r
520 throws PortalException, SystemException {
\r
524 if (!overrideFileEntryTypes) {
\r
525 fileEntryTypeIds = Collections.emptyList();
\r
528 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
\r
530 parentFolderId = getParentFolderId(dlFolder, parentFolderId);
\r
532 validateFolder(folderId, dlFolder.getGroupId(), parentFolderId, name);
\r
534 dlFolder.setModifiedDate(serviceContext.getModifiedDate(null));
\r
535 dlFolder.setParentFolderId(parentFolderId);
\r
536 dlFolder.setName(name);
\r
537 dlFolder.setDescription(description);
\r
538 dlFolder.setExpandoBridgeAttributes(serviceContext);
\r
539 dlFolder.setOverrideFileEntryTypes(overrideFileEntryTypes);
\r
540 dlFolder.setDefaultFileEntryTypeId(defaultFileEntryTypeId);
\r
542 dlFolderPersistence.update(dlFolder, false);
\r
544 // File entry types
\r
546 if (fileEntryTypeIds != null) {
\r
547 dlFileEntryTypeLocalService.updateFolderFileEntryTypes(
\r
548 dlFolder, fileEntryTypeIds, defaultFileEntryTypeId,
\r
554 dlAppHelperLocalService.updateFolder(
\r
555 new LiferayFolder(dlFolder), serviceContext);
\r
560 public void updateLastPostDate(long folderId, Date lastPostDate)
\r
561 throws PortalException, SystemException {
\r
563 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
\r
565 dlFolder.setLastPostDate(lastPostDate);
\r
567 dlFolderPersistence.update(dlFolder, false);
\r
571 public Hits search(
\r
572 long companyId, long groupId, long userId, long[] folderIds,
\r
573 String keywords, int start, int end)
\r
574 throws SystemException {
\r
576 return CustomDLStoreUtil.search(
\r
577 companyId, userId, PortletKeys.DOCUMENT_LIBRARY, groupId, folderIds,
\r
578 keywords, start, end);
\r
581 public Hits search(
\r
582 long companyId, long groupId, long userId, long ownerUserId,
\r
583 String keywords, int start, int end)
\r
584 throws SystemException {
\r
586 _log.info("Searching '"+keywords+"' in documents (folders) ...");
\r
589 Indexer indexer = IndexerRegistryUtil.getIndexer(DLFolder.class);
\r
590 String searchEngineId = indexer.getSearchEngineId();
\r
592 SearchContext searchContext = new SearchContext();
\r
593 searchContext.setSearchEngineId(searchEngineId);
\r
595 BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext);
\r
597 contextQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);
\r
599 List<String> solrFilters = new ArrayList<String>();
\r
601 User user = UserLocalServiceUtil.getUser(userId);
\r
604 solrFilters.add(Field.GROUP_ID + ":" + groupId);
\r
605 } else if (ENTRolesConstants.hasGlobalVisibilityOnGroupOnItsSchool(user)) {
\r
606 solrFilters.add("(" + Field.GROUP_ID + ":" + IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.INCLUDE_USER_GROUP) + ") "
\r
607 + "OR (" + Field.ETAB_ID + ":" + IndexerUtil.getEtabVisibility(user) + ")");
\r
609 String listGroupId = IndexerUtil.getSearchGroupsQuery(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY,
\r
610 IndexerUtil.INCLUDE_GLOBAL_ORG, IndexerUtil.INCLUDE_USER_GROUP);
\r
611 solrFilters.add(Field.GROUP_ID + ":" + listGroupId);
\r
614 String query = SolrQueryUtil.getQueryFromKeywords(keywords, true);
\r
615 String queryWithoutFuzzySearch = SolrQueryUtil.getQueryFromKeywords(keywords, false);
\r
617 solrFilters.add("(" + Field.USER_NAME + ":" + query + ") "
\r
618 + "OR (" + Field.TITLE + ":" + query + ") "
\r
619 + "OR (" + Field.DESCRIPTION + ":" + queryWithoutFuzzySearch + ") "
\r
620 + "OR (" + Field.ASSET_TAG_NAMES + ":" + query + ")");
\r
622 BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
\r
624 fullQuery.add(contextQuery, BooleanClauseOccur.MUST);
\r
626 //userId a 0 car on gere nous meme les permissions
\r
627 return SearchEngineUtil.search(
\r
628 searchEngineId, companyId, fullQuery, solrFilters, start, end);
\r
630 catch (Exception e) {
\r
631 throw new SystemException(e);
\r
635 public Hits searchByDate(
\r
636 long companyId, long groupId, long userId, long ownerUserId,
\r
637 String keywords, int start, int end)
\r
638 throws SystemException {
\r
641 Indexer indexer = IndexerRegistryUtil.getIndexer(DLFolder.class);
\r
642 String searchEngineId = indexer.getSearchEngineId();
\r
644 SearchContext searchContext = new SearchContext();
\r
645 searchContext.setSearchEngineId(searchEngineId);
\r
647 BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext);
\r
649 contextQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);
\r
651 List<String> solrFilters = new ArrayList<String>();
\r
653 User user = UserLocalServiceUtil.getUser(userId);
\r
656 solrFilters.add(Field.GROUP_ID + ":" + groupId);
\r
657 } else if (ENTRolesConstants.hasGlobalVisibilityOnGroupOnItsSchool(user)) {
\r
658 solrFilters.add("(" + Field.GROUP_ID + ":" + IndexerUtil.getExtendedVisibility(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY, IndexerUtil.INCLUDE_USER_GROUP) + ") "
\r
659 + "OR (" + Field.ETAB_ID + ":" + IndexerUtil.getEtabVisibility(user) + ")");
\r
661 String listGroupId = IndexerUtil.getSearchGroupsQuery(user, IndexerUtil.INCLUDE_USER_AND_COMMUNITY,
\r
662 IndexerUtil.INCLUDE_GLOBAL_ORG, IndexerUtil.INCLUDE_USER_GROUP);
\r
663 solrFilters.add(Field.GROUP_ID + ":" + listGroupId);
\r
666 if (!keywords.isEmpty()) {
\r
667 //Field.MODIFIED_DATE = "modified" only
\r
668 solrFilters.add("modifiedDate" + ":" + keywords);
\r
671 BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
\r
673 fullQuery.add(contextQuery, BooleanClauseOccur.MUST);
\r
675 //userId a 0 car on gere nous meme les permissions
\r
676 return SearchEngineUtil.search(
\r
677 searchEngineId, companyId, fullQuery, solrFilters, start, end);
\r
679 catch (Exception e) {
\r
680 throw new SystemException(e);
\r
685 protected void addFolderResources(
\r
686 DLFolder dlFolder, boolean addGroupPermissions,
\r
687 boolean addGuestPermissions)
\r
688 throws PortalException, SystemException {
\r
690 resourceLocalService.addResources(
\r
691 dlFolder.getCompanyId(), dlFolder.getGroupId(),
\r
692 dlFolder.getUserId(), DLFolder.class.getName(),
\r
693 dlFolder.getFolderId(), false, addGroupPermissions,
\r
694 addGuestPermissions);
\r
697 protected void addFolderResources(
\r
698 DLFolder dlFolder, String[] groupPermissions,
\r
699 String[] guestPermissions)
\r
700 throws PortalException, SystemException {
\r
702 resourceLocalService.addModelResources(
\r
703 dlFolder.getCompanyId(), dlFolder.getGroupId(),
\r
704 dlFolder.getUserId(), DLFolder.class.getName(),
\r
705 dlFolder.getFolderId(), groupPermissions, guestPermissions);
\r
708 protected void addFolderResources(
\r
709 long folderId, boolean addGroupPermissions,
\r
710 boolean addGuestPermissions)
\r
711 throws PortalException, SystemException {
\r
713 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
\r
715 addFolderResources(dlFolder, addGroupPermissions, addGuestPermissions);
\r
718 protected void addFolderResources(
\r
719 long folderId, String[] groupPermissions, String[] guestPermissions)
\r
720 throws PortalException, SystemException {
\r
722 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
\r
724 addFolderResources(dlFolder, groupPermissions, guestPermissions);
\r
727 protected void deleteFolder(DLFolder dlFolder)
\r
728 throws PortalException, SystemException {
\r
732 Indexer indexer = IndexerRegistryUtil.getIndexer(DLFolder.class);
\r
733 indexer.delete(dlFolder);
\r
737 List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(
\r
738 dlFolder.getGroupId(), dlFolder.getFolderId());
\r
740 for (DLFolder curDLFolder : dlFolders) {
\r
741 deleteFolder(curDLFolder);
\r
744 // Dropbox (casier) entry
\r
747 CasierEntryLocalServiceUtil.deleteBuC_G_Id(dlFolder.getCompanyId(), dlFolder.getGroupId(), dlFolder.getFolderId());
\r
748 } catch (PortalException e){}
\r
752 resourceLocalService.deleteResource(
\r
753 dlFolder.getCompanyId(), DLFolder.class.getName(),
\r
754 ResourceConstants.SCOPE_INDIVIDUAL, dlFolder.getFolderId());
\r
758 webDAVPropsLocalService.deleteWebDAVProps(
\r
759 DLFolder.class.getName(), dlFolder.getFolderId());
\r
763 dlFileEntryLocalService.deleteFileEntries(
\r
764 dlFolder.getGroupId(), dlFolder.getFolderId());
\r
766 // File entry types
\r
768 dlFileEntryTypeLocalService.unsetFolderFileEntryTypes(
\r
769 dlFolder.getFolderId());
\r
773 expandoValueLocalService.deleteValues(
\r
774 DLFolder.class.getName(), dlFolder.getFolderId());
\r
778 dlAppHelperLocalService.deleteFolder(new LiferayFolder(dlFolder));
\r
782 dlFolderPersistence.remove(dlFolder);
\r
787 DLStoreUtil.deleteDirectory(
\r
788 dlFolder.getCompanyId(), dlFolder.getFolderId(),
\r
791 catch (NoSuchDirectoryException nsde) {
\r
792 if (_log.isDebugEnabled()) {
\r
793 _log.debug(nsde.getMessage());
\r
798 protected long getParentFolderId(DLFolder dlFolder, long parentFolderId)
\r
799 throws SystemException {
\r
801 if (parentFolderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
\r
802 return parentFolderId;
\r
805 if (dlFolder.getFolderId() == parentFolderId) {
\r
806 return dlFolder.getParentFolderId();
\r
809 DLFolder parentDLFolder = dlFolderPersistence.fetchByPrimaryKey(
\r
812 if ((parentDLFolder == null) ||
\r
813 (dlFolder.getGroupId() != parentDLFolder.getGroupId())) {
\r
815 return dlFolder.getParentFolderId();
\r
818 List<Long> subfolderIds = new ArrayList<Long>();
\r
821 subfolderIds, dlFolder.getGroupId(), dlFolder.getFolderId());
\r
823 if (subfolderIds.contains(parentFolderId)) {
\r
824 return dlFolder.getParentFolderId();
\r
827 return parentFolderId;
\r
831 protected long getParentFolderId(long groupId, long parentFolderId)
\r
832 throws SystemException {
\r
834 if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
\r
835 DLFolder parentDLFolder = dlFolderPersistence.fetchByPrimaryKey(
\r
838 if ((parentDLFolder == null) ||
\r
839 (groupId != parentDLFolder.getGroupId())) {
\r
841 parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
\r
845 return parentFolderId;
\r
848 protected void validateFolder(
\r
849 long folderId, long groupId, long parentFolderId, String name)
\r
850 throws PortalException, SystemException {
\r
852 validateFolderName(name);
\r
855 dlFileEntryLocalService.getFileEntry(groupId, parentFolderId, name);
\r
857 throw new DuplicateFileException(name);
\r
859 catch (NoSuchFileEntryException nsfee) {
\r
862 DLFolder dlFolder = dlFolderPersistence.fetchByG_P_N(
\r
863 groupId, parentFolderId, name);
\r
865 if ((dlFolder != null) && (dlFolder.getFolderId() != folderId)) {
\r
866 throw new DuplicateFolderNameException(name);
\r
870 protected void validateFolder(
\r
871 long groupId, long parentFolderId, String name)
\r
872 throws PortalException, SystemException {
\r
876 validateFolder(folderId, groupId, parentFolderId, name);
\r
879 protected void validateFolderName(String name) throws PortalException {
\r
880 if (!AssetUtil.isValidWord(name)) {
\r
881 throw new FolderNameException();
\r
885 private static Log _log = LogFactoryUtil.getLog(
\r
886 DLFolderLocalServiceImpl.class);
\r