public void processAction(ActionEvent actionEvent) throws AbortProcessingException { try { FolderUserObject folderUserObject = docLibModelBean.getSelectedFolderUserObject(); DLFolder dlFolder = folderUserObject.getDlFolder(); long groupId = dlFolder.getGroupId(); long repositoryId = dlFolder.getRepositoryId(); boolean mountPoint = dlFolder.getMountPoint(); long parentFolderId = dlFolder.getFolderId(); ServiceContext serviceContext = new ServiceContext(); // Temporary: Make the default setting be that community members can view the file. Need to // develop a // "Viewable By" permissions Facelet composite component UI similar to // portal-web/docroot/html/taglib/ui/input_permissions/page.jsp serviceContext.setAddGroupPermissions(true); DLFolderServiceUtil.addFolder( groupId, repositoryId, mountPoint, parentFolderId, folderName, folderDescription, serviceContext); docLibModelBean.forceTreeRequery(); logger.debug("Added folderName=[{0}] description=[{1}]", folderName, folderDescription); } catch (Exception e) { logger.error(e.getMessage(), e); liferayFacesContext.addGlobalUnexpectedErrorMessage(); } docLibViewBean.setPopupRendered(false); }
public static boolean isSupportedFolder(DLFolder dlFolder) { if (dlFolder.isHidden() || dlFolder.isMountPoint()) { return false; } return true; }
public DLFileShortcut updateFileShortcut( long userId, long fileShortcutId, long folderId, long toFolderId, String toName) throws PortalException, SystemException { // File shortcut User user = userPersistence.findByPrimaryKey(userId); DLFolder folder = dlFolderPersistence.findByPrimaryKey(folderId); validate(user, toFolderId, toName); DLFileShortcut fileShortcut = dlFileShortcutPersistence.findByPrimaryKey(fileShortcutId); fileShortcut.setModifiedDate(new Date()); fileShortcut.setFolderId(folderId); fileShortcut.setToFolderId(toFolderId); fileShortcut.setToName(toName); dlFileShortcutPersistence.update(fileShortcut); // Folder folder.setLastPostDate(fileShortcut.getModifiedDate()); dlFolderPersistence.update(folder); return fileShortcut; }
public static void getFolder(HttpServletRequest request) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long folderId = ParamUtil.getLong(request, "folderId"); Folder folder = null; if ((folderId > 0) && (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) { folder = DLAppServiceUtil.getFolder(folderId); if (folder.getModel() instanceof DLFolder) { DLFolder dlFolder = (DLFolder) folder.getModel(); if (dlFolder.isInTrash() || dlFolder.isInTrashContainer()) { throw new NoSuchFolderException(); } } } else { DLPermission.check( themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), ActionKeys.VIEW); } request.setAttribute(WebKeys.DOCUMENT_LIBRARY_FOLDER, folder); }
public void restoreFolderFromTrash(long userId, Folder folder) throws PortalException, SystemException { // Folder TrashEntry trashEntry = trashEntryLocalService.getEntry(DLFolderConstants.getClassName(), folder.getFolderId()); DLFolder dlFolder = dlFolderLocalService.updateStatus( userId, folder.getFolderId(), WorkflowConstants.STATUS_APPROVED, new HashMap<String, Serializable>(), new ServiceContext()); dlFolder.setName(DLAppUtil.stripTrashNamespace(dlFolder.getName())); dlFolderPersistence.update(dlFolder, false); // File rank dlFileRankLocalService.enableFileRanksByFolderId(folder.getFolderId()); // Trash trashEntryLocalService.deleteEntry(trashEntry.getEntryId()); }
@Test public void testResetOriginalValues() throws Exception { if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) { return; } DLFolder newDLFolder = addDLFolder(); _persistence.clearCache(); DLFolderModelImpl existingDLFolderModelImpl = (DLFolderModelImpl) _persistence.findByPrimaryKey(newDLFolder.getPrimaryKey()); Assert.assertTrue( Validator.equals( existingDLFolderModelImpl.getUuid(), existingDLFolderModelImpl.getOriginalUuid())); Assert.assertEquals( existingDLFolderModelImpl.getGroupId(), existingDLFolderModelImpl.getOriginalGroupId()); Assert.assertEquals( existingDLFolderModelImpl.getRepositoryId(), existingDLFolderModelImpl.getOriginalRepositoryId()); Assert.assertEquals( existingDLFolderModelImpl.getGroupId(), existingDLFolderModelImpl.getOriginalGroupId()); Assert.assertEquals( existingDLFolderModelImpl.getParentFolderId(), existingDLFolderModelImpl.getOriginalParentFolderId()); Assert.assertTrue( Validator.equals( existingDLFolderModelImpl.getName(), existingDLFolderModelImpl.getOriginalName())); }
public void unlockFolder(long groupId, long parentFolderId, String name, String lockUuid) throws PortalException, SystemException { DLFolder dlFolder = getFolder(groupId, parentFolderId, name); unlockFolder(dlFolder.getFolderId(), lockUuid); }
@Override protected void doExportStagedModel(PortletDataContext portletDataContext, Repository repository) throws Exception { Element repositoryElement = portletDataContext.getExportDataElement(repository); Folder folder = DLAppLocalServiceUtil.getFolder(repository.getDlFolderId()); if (folder.getModel() instanceof DLFolder) { DLFolder dlFolder = (DLFolder) folder.getModel(); repositoryElement.addAttribute("hidden", String.valueOf(dlFolder.isHidden())); } portletDataContext.addClassedModel( repositoryElement, ExportImportPathUtil.getModelPath(repository), repository); List<RepositoryEntry> repositoryEntries = RepositoryEntryLocalServiceUtil.getRepositoryEntries(repository.getRepositoryId()); for (RepositoryEntry repositoryEntry : repositoryEntries) { StagedModelDataHandlerUtil.exportReferenceStagedModel( portletDataContext, repository, repositoryEntry, PortletDataContext.REFERENCE_TYPE_CHILD); } }
@Test public void testCreateLocalRepositoryFromExistingRepositoryId() throws Exception { DLFolder dlFolder = DLTestUtil.addDLFolder(_group.getGroupId()); RepositoryLocalServiceUtil.getLocalRepositoryImpl(dlFolder.getRepositoryId()); }
private Folder _getFolder(long groupId, String folderName) throws Exception { DLFolder dlFolder = new DLFolderImpl(); dlFolder.setFolderId(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID); dlFolder.setGroupId(groupId); Folder folder = new LiferayFolder(dlFolder); if (folderName.equals(StringPool.SLASH)) { return folder; } StringTokenizer st = new StringTokenizer(folderName, StringPool.SLASH); while (st.hasMoreTokens()) { String curFolderName = st.nextToken(); List<Folder> folders = DLAppServiceUtil.getFolders(groupId, folder.getFolderId()); for (Folder curFolder : folders) { if (curFolder.getName().equals(curFolderName)) { folder = curFolder; break; } } } return folder; }
@Override protected BaseModel<?> addBaseModel( BaseModel<?> parentBaseModel, boolean approved, ServiceContext serviceContext) throws Exception { DLFolder dlFolder = (DLFolder) parentBaseModel; String content = "Content: Enterprise. Open Source. For Life."; serviceContext = (ServiceContext) serviceContext.clone(); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); FileEntry fileEntry = DLAppServiceUtil.addFileEntry( dlFolder.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Text.txt", ContentTypes.TEXT_PLAIN, getSearchKeywords(), StringPool.BLANK, StringPool.BLANK, content.getBytes(), serviceContext); return DLAppServiceUtil.addFileShortcut( dlFolder.getGroupId(), dlFolder.getFolderId(), fileEntry.getFileEntryId(), serviceContext); }
@Override public boolean hasWorkflowDefinitionLink( long companyId, long groupId, long folderId, long fileEntryTypeId) throws Exception { while (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { DLFolder dlFolder = DLFolderLocalServiceUtil.fetchDLFolder(folderId); if (dlFolder == null) { return false; } if (dlFolder.isOverrideFileEntryTypes()) { break; } folderId = dlFolder.getParentFolderId(); } if (WorkflowDefinitionLinkLocalServiceUtil.hasWorkflowDefinitionLink( companyId, groupId, DLFolderConstants.getClassName(), folderId, fileEntryTypeId) || WorkflowDefinitionLinkLocalServiceUtil.hasWorkflowDefinitionLink( companyId, groupId, DLFolderConstants.getClassName(), folderId, DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL)) { return true; } return false; }
@Test public void testCreateRepositoryFromExistingRepositoryId() throws Exception { DLFolder dlFolder = DLTestUtil.addDLFolder(_group.getGroupId()); RepositoryFactoryUtil.create(dlFolder.getRepositoryId()); }
public Folder moveFolderToTrash(long userId, Folder folder) throws PortalException, SystemException { // Folder DLFolder dlFolder = dlFolderLocalService.updateStatus( userId, folder.getFolderId(), WorkflowConstants.STATUS_IN_TRASH, new HashMap<String, Serializable>(), new ServiceContext()); dlFolder.setName(DLAppUtil.appendTrashNamespace(dlFolder.getName())); dlFolderPersistence.update(dlFolder, false); // File rank dlFileRankLocalService.disableFileRanksByFolderId(folder.getFolderId()); // Trash trashEntryLocalService.addTrashEntry( userId, folder.getGroupId(), DLFolderConstants.getClassName(), folder.getFolderId(), WorkflowConstants.STATUS_APPROVED, null, null); return new LiferayFolder(dlFolder); }
@Test public void testFetchByPrimaryKeyExisting() throws Exception { DLFolder newDLFolder = addDLFolder(); DLFolder existingDLFolder = _persistence.fetchByPrimaryKey(newDLFolder.getPrimaryKey()); Assert.assertEquals(existingDLFolder, newDLFolder); }
@Test public void testCreateRepositoryFromExistingFileEntryId() throws Exception { DLFolder dlFolder = DLTestUtil.addDLFolder(_group.getGroupId()); DLFileEntry dlFileEntry = DLTestUtil.addDLFileEntry(dlFolder.getFolderId()); RepositoryFactoryUtil.create(0, dlFileEntry.getFileEntryId(), 0); }
@Override protected int getBaseModelsNotInTrashCount(BaseModel<?> parentBaseModel) throws Exception { DLFolder dlFolder = (DLFolder) parentBaseModel; return DLFileShortcutLocalServiceUtil.getFileShortcutsCount( dlFolder.getGroupId(), dlFolder.getFolderId(), true, WorkflowConstants.STATUS_APPROVED); }
public DLFileShortcut addFileShortcut( String uuid, long userId, long folderId, long toFolderId, String toName, Boolean addCommunityPermissions, Boolean addGuestPermissions, String[] communityPermissions, String[] guestPermissions) throws PortalException, SystemException { // File shortcut User user = userPersistence.findByPrimaryKey(userId); folderId = getFolderId(user.getCompanyId(), folderId); DLFolder folder = dlFolderPersistence.findByPrimaryKey(folderId); Date now = new Date(); validate(user, toFolderId, toName); long fileShortcutId = counterLocalService.increment(); DLFileShortcut fileShortcut = dlFileShortcutPersistence.create(fileShortcutId); fileShortcut.setUuid(uuid); fileShortcut.setCompanyId(user.getCompanyId()); fileShortcut.setUserId(user.getUserId()); fileShortcut.setUserName(user.getFullName()); fileShortcut.setCreateDate(now); fileShortcut.setModifiedDate(now); fileShortcut.setFolderId(folderId); fileShortcut.setToFolderId(toFolderId); fileShortcut.setToName(toName); dlFileShortcutPersistence.update(fileShortcut); // Resources if ((addCommunityPermissions != null) && (addGuestPermissions != null)) { addFileShortcutResources( folder, fileShortcut, addCommunityPermissions.booleanValue(), addGuestPermissions.booleanValue()); } else { addFileShortcutResources(folder, fileShortcut, communityPermissions, guestPermissions); } // Folder folder.setLastPostDate(fileShortcut.getModifiedDate()); dlFolderPersistence.update(folder); return fileShortcut; }
@Test public void testCreateLocalRepositoryFromExistingFileEntryId() throws Exception { DLFolder dlFolder = DLTestUtil.addDLFolder(_group.getGroupId()); DLFileEntry dlFileEntry = DLTestUtil.addDLFileEntry(dlFolder.getFolderId()); RepositoryLocalServiceUtil.getLocalRepositoryImpl(0, dlFileEntry.getFileEntryId(), 0); }
/** @deprecated As of 6.2.0 */ public void updateLastPostDate(long folderId, Date lastPostDate) throws PortalException, SystemException { DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId); dlFolder.setLastPostDate(lastPostDate); dlFolderPersistence.update(dlFolder); }
protected void cascadeFileEntryTypes( long groupId, long folderId, long defaultFileEntryTypeId, List<Long> fileEntryTypeIds, ServiceContext serviceContext) throws PortalException, SystemException { List<DLFileEntry> dlFileEntries = dlFileEntryPersistence.findByG_F(groupId, folderId); for (DLFileEntry dlFileEntry : dlFileEntries) { Long fileEntryTypeId = dlFileEntry.getFileEntryTypeId(); if (fileEntryTypeIds.contains(fileEntryTypeId)) { continue; } DLFileVersion dlFileVersion = dlFileVersionLocalService.getLatestFileVersion(dlFileEntry.getFileEntryId(), true); if (dlFileVersion.isPending()) { workflowInstanceLinkLocalService.deleteWorkflowInstanceLink( dlFileVersion.getCompanyId(), groupId, DLFileEntry.class.getName(), dlFileVersion.getFileVersionId()); } dlFileEntryService.updateFileEntry( dlFileEntry.getFileEntryId(), null, null, null, null, null, false, defaultFileEntryTypeId, null, null, null, 0, serviceContext); } List<DLFolder> subFolders = dlFolderPersistence.findByG_M_P_H(groupId, false, folderId, false); for (DLFolder subFolder : subFolders) { long subFolderId = subFolder.getFolderId(); if (subFolder.isOverrideFileEntryTypes()) { continue; } cascadeFileEntryTypes( groupId, subFolderId, defaultFileEntryTypeId, fileEntryTypeIds, serviceContext); } }
@Override public String buildTreePath() throws PortalException { if (getFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { return StringPool.SLASH; } DLFolder dlFolder = getFolder(); return dlFolder.buildTreePath(); }
@Test public void testCreate() throws Exception { long pk = ServiceTestUtil.nextLong(); DLFolder dlFolder = _persistence.create(pk); Assert.assertNotNull(dlFolder); Assert.assertEquals(dlFolder.getPrimaryKey(), pk); }
@Test public void testRemove() throws Exception { DLFolder newDLFolder = addDLFolder(); _persistence.remove(newDLFolder); DLFolder existingDLFolder = _persistence.fetchByPrimaryKey(newDLFolder.getPrimaryKey()); Assert.assertNull(existingDLFolder); }
public static SyncDLObject toSyncDLObject(DLFolder dlFolder, String event) { SyncDLObject syncDLObject = new SyncDLObjectImpl(); syncDLObject.setCompanyId(dlFolder.getCompanyId()); syncDLObject.setCreateDate(dlFolder.getCreateDate()); syncDLObject.setModifiedDate(dlFolder.getModifiedDate()); syncDLObject.setRepositoryId(dlFolder.getRepositoryId()); syncDLObject.setParentFolderId(dlFolder.getParentFolderId()); syncDLObject.setName(dlFolder.getName()); syncDLObject.setExtension(StringPool.BLANK); syncDLObject.setMimeType(StringPool.BLANK); syncDLObject.setDescription(dlFolder.getDescription()); syncDLObject.setChangeLog(StringPool.BLANK); syncDLObject.setExtraSettings(StringPool.BLANK); syncDLObject.setVersion(StringPool.BLANK); syncDLObject.setSize(0); syncDLObject.setChecksum(StringPool.BLANK); syncDLObject.setEvent(event); syncDLObject.setLockExpirationDate(null); syncDLObject.setLockUserId(0); syncDLObject.setLockUserName(StringPool.BLANK); syncDLObject.setType(SyncConstants.TYPE_FOLDER); syncDLObject.setTypePK(dlFolder.getFolderId()); syncDLObject.setTypeUuid(dlFolder.getUuid()); return syncDLObject; }
protected long getParentFolderId(DLFolder dlFolder, long parentFolderId) throws SystemException { if (parentFolderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { return parentFolderId; } if (dlFolder.getFolderId() == parentFolderId) { return dlFolder.getParentFolderId(); } else { DLFolder parentDLFolder = dlFolderPersistence.fetchByPrimaryKey(parentFolderId); if ((parentDLFolder == null) || (dlFolder.getGroupId() != parentDLFolder.getGroupId())) { return dlFolder.getParentFolderId(); } List<Long> subfolderIds = new ArrayList<Long>(); getSubfolderIds(subfolderIds, dlFolder.getGroupId(), dlFolder.getFolderId()); if (subfolderIds.contains(parentFolderId)) { return dlFolder.getParentFolderId(); } return parentFolderId; } }
protected void cascadeFileEntryTypes( long userId, long groupId, long folderId, long defaultFileEntryTypeId, List<Long> fileEntryTypeIds, ServiceContext serviceContext) throws PortalException { List<DLFileEntry> dlFileEntries = dlFileEntryPersistence.findByG_F(groupId, folderId); for (DLFileEntry dlFileEntry : dlFileEntries) { Long fileEntryTypeId = dlFileEntry.getFileEntryTypeId(); if (fileEntryTypeIds.contains(fileEntryTypeId)) { continue; } DLFileVersion dlFileVersion = dlFileVersionLocalService.getLatestFileVersion(dlFileEntry.getFileEntryId(), true); if (dlFileVersion.isPending()) { workflowInstanceLinkLocalService.deleteWorkflowInstanceLink( dlFileVersion.getCompanyId(), groupId, DLFileEntry.class.getName(), dlFileVersion.getFileVersionId()); } dlFileEntryLocalService.updateFileEntryType( userId, dlFileEntry.getFileEntryId(), defaultFileEntryTypeId, serviceContext); dlAppHelperLocalService.updateAsset( userId, new LiferayFileEntry(dlFileEntry), new LiferayFileVersion(dlFileVersion), serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds()); } List<DLFolder> subFolders = dlFolderPersistence.findByG_M_P_H(groupId, false, folderId, false); for (DLFolder subFolder : subFolders) { long subFolderId = subFolder.getFolderId(); if (subFolder.getRestrictionType() == DLFolderConstants.RESTRICTION_TYPE_INHERIT) { continue; } cascadeFileEntryTypes( userId, groupId, subFolderId, defaultFileEntryTypeId, fileEntryTypeIds, serviceContext); } }
@Override protected void doDelete(Object obj) throws Exception { DLFolder dlFolder = (DLFolder) obj; Document document = new DocumentImpl(); document.addUID(PORTLET_ID, dlFolder.getFolderId()); SearchEngineUtil.deleteDocument( getSearchEngineId(), dlFolder.getCompanyId(), document.get(Field.UID)); }
public void getSubfolderIds(List<Long> folderIds, long groupId, long folderId) throws SystemException { List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(groupId, folderId); for (DLFolder dlFolder : dlFolders) { folderIds.add(dlFolder.getFolderId()); getSubfolderIds(folderIds, dlFolder.getGroupId(), dlFolder.getFolderId()); } }
@Test public void testCreateRepositoryFromExistingFileVersionId() throws Exception { DLFolder dlFolder = DLTestUtil.addDLFolder(_group.getGroupId()); DLFileEntry dlFileEntry = DLTestUtil.addDLFileEntry(dlFolder.getFolderId()); DLFileVersion dlFileVersion = dlFileEntry.getLatestFileVersion(true); RepositoryLocalServiceUtil.getRepositoryImpl(0, 0, dlFileVersion.getFileVersionId()); }