public void restoreFileShortcutFromTrash(long userId, DLFileShortcut dlFileShortcut) throws PortalException, SystemException { // File shortcut TrashEntry trashEntry = trashEntryLocalService.getEntry( DLFileShortcut.class.getName(), dlFileShortcut.getFileShortcutId()); dlFileShortcutLocalService.updateStatus( userId, dlFileShortcut.getFileShortcutId(), trashEntry.getStatus(), new ServiceContext()); // Social socialActivityCounterLocalService.enableActivityCounters( DLFileShortcut.class.getName(), dlFileShortcut.getFileShortcutId()); socialActivityLocalService.addActivity( userId, dlFileShortcut.getGroupId(), DLFileShortcut.class.getName(), dlFileShortcut.getFileShortcutId(), SocialActivityConstants.TYPE_RESTORE_FROM_TRASH, StringPool.BLANK, 0); // Trash trashEntryLocalService.deleteEntry(trashEntry.getEntryId()); }
@Override public boolean isInTrashContainer(long classPK) throws PortalException, SystemException { DLFileShortcut fileShortcut = DLFileShortcutLocalServiceUtil.getDLFileShortcut(classPK); return fileShortcut.isInTrashContainer(); }
protected FileEntry getFileEntry(String[] pathArray) throws Exception { if (pathArray.length == 1) { long dlFileShortcutId = GetterUtil.getLong(pathArray[0]); DLFileShortcut dlFileShortcut = DLAppServiceUtil.getFileShortcut(dlFileShortcutId); return DLAppServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId()); } else if (pathArray.length == 2) { long groupId = GetterUtil.getLong(pathArray[0]); return DLAppServiceUtil.getFileEntryByUuidAndGroupId(pathArray[1], groupId); } else if (pathArray.length == 3) { long groupId = GetterUtil.getLong(pathArray[0]); long folderId = GetterUtil.getLong(pathArray[1]); String fileName = pathArray[2]; if (fileName.contains(StringPool.QUESTION)) { fileName = fileName.substring(0, fileName.indexOf(StringPool.QUESTION)); } return DLAppServiceUtil.getFileEntry(groupId, folderId, fileName); } else { long groupId = GetterUtil.getLong(pathArray[0]); String uuid = pathArray[3]; return DLAppServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId); } }
private static void _checkFileEntry(String[] pathArray) throws Exception { if (pathArray.length == 1) { long dlFileShortcutId = GetterUtil.getLong(pathArray[0]); DLFileShortcut dlFileShortcut = DLAppLocalServiceUtil.getFileShortcut(dlFileShortcutId); DLAppLocalServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId()); } else if (pathArray.length == 2) { // Unable to check with UUID because of multiple repositories } else if (pathArray.length == 3) { long groupId = GetterUtil.getLong(pathArray[0]); long folderId = GetterUtil.getLong(pathArray[1]); String fileName = pathArray[2]; try { DLAppLocalServiceUtil.getFileEntry(groupId, folderId, fileName); } catch (RepositoryException re) { } } else { long groupId = GetterUtil.getLong(pathArray[0]); String uuid = pathArray[3]; try { DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId); } catch (RepositoryException re) { } } }
protected void updateFileShortcut(ActionRequest actionRequest) throws Exception { long fileShortcutId = ParamUtil.getLong(actionRequest, "fileShortcutId"); long repositoryId = ParamUtil.getLong(actionRequest, "repositoryId"); long folderId = ParamUtil.getLong(actionRequest, "folderId"); long toFileEntryId = ParamUtil.getLong(actionRequest, "toFileEntryId"); ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileShortcut.class.getName(), actionRequest); if (fileShortcutId <= 0) { // Add file shortcut DLFileShortcut fileShortcut = DLAppServiceUtil.addFileShortcut(repositoryId, folderId, toFileEntryId, serviceContext); AssetPublisherUtil.addAndStoreSelection( actionRequest, DLFileShortcut.class.getName(), fileShortcut.getFileShortcutId(), -1); } else { // Update file shortcut DLAppServiceUtil.updateFileShortcut(fileShortcutId, folderId, toFileEntryId, serviceContext); AssetPublisherUtil.addRecentFolderId(actionRequest, DLFileShortcut.class.getName(), folderId); } }
@Override protected boolean isInTrashFolder(ClassedModel classedModel) throws Exception { DLFileShortcut dLFileShortcut = (DLFileShortcut) classedModel; return dLFileShortcut.isInTrashFolder(); }
protected void trashFileEntry() throws Exception { Group group = ServiceTestUtil.addGroup(); ServiceContext serviceContext = ServiceTestUtil.getServiceContext(); serviceContext.setScopeGroupId(group.getGroupId()); BaseModel<?> parentBaseModel = getParentBaseModel(group, serviceContext); int initialBaseModelsCount = getBaseModelsNotInTrashCount(parentBaseModel); int initialTrashEntriesCount = getTrashEntriesCount(group.getGroupId()); BaseModel<?> baseModel = addBaseModel(parentBaseModel, true, serviceContext); DLFileShortcut dlFileShortcut = (DLFileShortcut) baseModel; FileEntry fileEntry = DLAppServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId()); Assert.assertEquals(initialBaseModelsCount + 1, getBaseModelsNotInTrashCount(parentBaseModel)); Assert.assertEquals(initialTrashEntriesCount, getTrashEntriesCount(group.getGroupId())); DLAppServiceUtil.moveFileEntryToTrash(fileEntry.getFileEntryId()); Assert.assertEquals(initialBaseModelsCount, getBaseModelsNotInTrashCount(parentBaseModel)); Assert.assertEquals(initialTrashEntriesCount + 1, getTrashEntriesCount(group.getGroupId())); DLAppServiceUtil.restoreFileEntryFromTrash(fileEntry.getFileEntryId()); Assert.assertEquals(initialBaseModelsCount + 1, getBaseModelsNotInTrashCount(parentBaseModel)); }
public void getFileAsStream(long userId, FileEntry fileEntry, boolean incrementCounter) throws SystemException { if (!incrementCounter) { return; } // File rank if (userId > 0) { dlFileRankLocalService.updateFileRank( fileEntry.getGroupId(), fileEntry.getCompanyId(), userId, fileEntry.getFileEntryId(), new ServiceContext()); } // File read count assetEntryLocalService.incrementViewCounter( userId, DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId(), 1); List<DLFileShortcut> fileShortcuts = dlFileShortcutPersistence.findByToFileEntryId(fileEntry.getFileEntryId()); for (DLFileShortcut fileShortcut : fileShortcuts) { assetEntryLocalService.incrementViewCounter( userId, DLFileShortcut.class.getName(), fileShortcut.getFileShortcutId(), 1); } }
@Override public boolean isRestorable(long classPK) throws PortalException, SystemException { DLFileShortcut dlFileShortcut = getDLFileShortcut(classPK); return !dlFileShortcut.isInTrashContainer(); }
@Override public String getRestoreMessage(PortletRequest portletRequest, long classPK) throws PortalException, SystemException { DLFileShortcut fileShortcut = DLFileShortcutLocalServiceUtil.getDLFileShortcut(classPK); return DLUtil.getAbsolutePath(portletRequest, fileShortcut.getFolderId()); }
@Override public String getRestoreLink(PortletRequest portletRequest, long classPK) throws PortalException, SystemException { DLFileShortcut fileShortcut = DLFileShortcutLocalServiceUtil.getDLFileShortcut(classPK); return DLUtil.getDLControlPanelLink(portletRequest, fileShortcut.getFolderId()); }
public void addFileShortcutResources( long fileShortcutId, String[] communityPermissions, String[] guestPermissions) throws PortalException, SystemException { DLFileShortcut fileShortcut = dlFileShortcutPersistence.findByPrimaryKey(fileShortcutId); DLFolder folder = fileShortcut.getFolder(); addFileShortcutResources(folder, fileShortcut, communityPermissions, guestPermissions); }
@Test public void testFetchByPrimaryKeyExisting() throws Exception { DLFileShortcut newDLFileShortcut = addDLFileShortcut(); DLFileShortcut existingDLFileShortcut = _persistence.fetchByPrimaryKey(newDLFileShortcut.getPrimaryKey()); Assert.assertEquals(existingDLFileShortcut, newDLFileShortcut); }
@Override public void moveEntry(long classPK, long containerModelId, ServiceContext serviceContext) throws PortalException, SystemException { DLFileShortcut dlFileShortcut = getDLFileShortcut(classPK); DLAppServiceUtil.updateFileShortcut( classPK, containerModelId, dlFileShortcut.getToFileEntryId(), serviceContext); }
@Test public void testCreate() throws Exception { long pk = RandomTestUtil.nextLong(); DLFileShortcut dlFileShortcut = _persistence.create(pk); Assert.assertNotNull(dlFileShortcut); Assert.assertEquals(dlFileShortcut.getPrimaryKey(), pk); }
@Test public void testRemove() throws Exception { DLFileShortcut newDLFileShortcut = addDLFileShortcut(); _persistence.remove(newDLFileShortcut); DLFileShortcut existingDLFileShortcut = _persistence.fetchByPrimaryKey(newDLFileShortcut.getPrimaryKey()); Assert.assertNull(existingDLFileShortcut); }
@Override public ContainerModel getParentContainerModel(long classPK) throws PortalException, SystemException { DLFileShortcut dlFileShortcut = getDLFileShortcut(classPK); long parentFolderId = dlFileShortcut.getFolderId(); if (parentFolderId <= 0) { return null; } return getContainerModel(parentFolderId); }
@Test public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception { DLFileShortcut newDLFileShortcut = addDLFileShortcut(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newDLFileShortcut.getPrimaryKey()); Map<Serializable, DLFileShortcut> dlFileShortcuts = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(1, dlFileShortcuts.size()); Assert.assertEquals(newDLFileShortcut, dlFileShortcuts.get(newDLFileShortcut.getPrimaryKey())); }
public void updateFileShortcuts( long oldToFolderId, String oldToName, long newToFolderId, String newToName) throws PortalException, SystemException { Iterator itr = dlFileShortcutPersistence.findByTF_TN(oldToFolderId, oldToName).iterator(); while (itr.hasNext()) { DLFileShortcut fileShortcut = (DLFileShortcut) itr.next(); fileShortcut.setToFolderId(newToFolderId); fileShortcut.setToName(newToName); dlFileShortcutPersistence.update(fileShortcut); } }
public void deleteFileShortcut(DLFileShortcut fileShortcut) throws PortalException, SystemException { // Resources resourceLocalService.deleteResource( fileShortcut.getCompanyId(), DLFileShortcut.class.getName(), ResourceImpl.SCOPE_INDIVIDUAL, fileShortcut.getFileShortcutId()); // File shortcut dlFileShortcutPersistence.remove(fileShortcut.getFileShortcutId()); }
@Override protected Repository getRepository(long classPK) throws PortalException, SystemException { DLFileShortcut dlFileShortcut = getDLFileShortcut(classPK); Repository repository = RepositoryServiceUtil.getRepositoryImpl(0, dlFileShortcut.getToFileEntryId(), 0); if (!(repository instanceof LiferayRepository)) { throw new InvalidRepositoryException( "Repository " + repository.getRepositoryId() + " does not support trash operations"); } return repository; }
public void addFileShortcutResources( DLFolder folder, DLFileShortcut fileShortcut, String[] communityPermissions, String[] guestPermissions) throws PortalException, SystemException { resourceLocalService.addModelResources( fileShortcut.getCompanyId(), folder.getGroupId(), fileShortcut.getUserId(), DLFileShortcut.class.getName(), fileShortcut.getFileShortcutId(), communityPermissions, guestPermissions); }
public void addFileShortcutResources( DLFolder folder, DLFileShortcut fileShortcut, boolean addCommunityPermissions, boolean addGuestPermissions) throws PortalException, SystemException { resourceLocalService.addResources( fileShortcut.getCompanyId(), folder.getGroupId(), fileShortcut.getUserId(), DLFileShortcut.class.getName(), fileShortcut.getFileShortcutId(), false, addCommunityPermissions, addGuestPermissions); }
@Test public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist() throws Exception { DLFileShortcut newDLFileShortcut = addDLFileShortcut(); long pk = RandomTestUtil.nextLong(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newDLFileShortcut.getPrimaryKey()); primaryKeys.add(pk); Map<Serializable, DLFileShortcut> dlFileShortcuts = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(1, dlFileShortcuts.size()); Assert.assertEquals(newDLFileShortcut, dlFileShortcuts.get(newDLFileShortcut.getPrimaryKey())); }
public static void addPortletBreadcrumbEntries( DLFileShortcut dlFileShortcut, HttpServletRequest request, RenderResponse renderResponse) throws Exception { Folder folder = dlFileShortcut.getFolder(); if (folder.getFolderId() != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { addPortletBreadcrumbEntries(folder, request, renderResponse); } PortletURL portletURL = renderResponse.createRenderURL(); portletURL.setParameter("struts_action", "/document_library/view_file_entry"); portletURL.setParameter("fileEntryId", String.valueOf(dlFileShortcut.getToFileEntryId())); PortalUtil.addPortletBreadcrumbEntry( request, dlFileShortcut.getToTitle(), portletURL.toString()); }
protected void moveFileShortcut(ActionRequest actionRequest, boolean moveFromTrash) throws Exception { long fileShortcutId = ParamUtil.getLong(actionRequest, "fileShortcutId"); long newFolderId = ParamUtil.getLong(actionRequest, "newFolderId"); DLFileShortcut fileShortcut = DLAppServiceUtil.getFileShortcut(fileShortcutId); ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileShortcut.class.getName(), actionRequest); if (moveFromTrash) { DLAppServiceUtil.moveFileShortcutFromTrash(fileShortcutId, newFolderId, serviceContext); } else { DLAppServiceUtil.updateFileShortcut( fileShortcutId, newFolderId, fileShortcut.getToFileEntryId(), serviceContext); } }
@Test public void testDynamicQueryByPrimaryKeyExisting() throws Exception { DLFileShortcut newDLFileShortcut = addDLFileShortcut(); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass( DLFileShortcut.class, DLFileShortcut.class.getClassLoader()); dynamicQuery.add( RestrictionsFactoryUtil.eq("fileShortcutId", newDLFileShortcut.getFileShortcutId())); List<DLFileShortcut> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(1, result.size()); DLFileShortcut existingDLFileShortcut = result.get(0); Assert.assertEquals(existingDLFileShortcut, newDLFileShortcut); }
@Test public void testResetOriginalValues() throws Exception { if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) { return; } DLFileShortcut newDLFileShortcut = addDLFileShortcut(); _persistence.clearCache(); DLFileShortcutModelImpl existingDLFileShortcutModelImpl = (DLFileShortcutModelImpl) _persistence.findByPrimaryKey(newDLFileShortcut.getPrimaryKey()); Assert.assertTrue( Validator.equals( existingDLFileShortcutModelImpl.getUuid(), existingDLFileShortcutModelImpl.getOriginalUuid())); Assert.assertEquals( existingDLFileShortcutModelImpl.getGroupId(), existingDLFileShortcutModelImpl.getOriginalGroupId()); }
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; }
protected Date getCreateDate(Object obj) { if (obj instanceof DLFileEntry) { DLFileEntry dlFileEntry = (DLFileEntry) obj; return dlFileEntry.getCreateDate(); } else if (obj instanceof DLFileShortcut) { DLFileShortcut dlFileShortcut = (DLFileShortcut) obj; return dlFileShortcut.getCreateDate(); } else if (obj instanceof DLFolder) { DLFolder dlFolder = (DLFolder) obj; return dlFolder.getCreateDate(); } else if (obj instanceof FileEntry) { FileEntry fileEntry = (FileEntry) obj; return fileEntry.getCreateDate(); } else { Folder folder = (Folder) obj; return folder.getCreateDate(); } }