List of usage examples for com.liferay.portal.kernel.trash TrashHandler checkRestorableEntry
public void checkRestorableEntry(TrashEntry trashEntry, long containerModelId, String newName) throws PortalException;
From source file:com.liferay.journal.service.test.JournalFolderServiceTest.java
License:Open Source License
@Test public void testMoveArticleFromTrashToFolder() throws Exception { JournalFolder folder1 = JournalTestUtil.addFolder(_group.getGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Test 1"); String xml = DDMStructureTestUtil.getSampleStructuredContent("Test Article"); DDMStructure ddmStructure1 = DDMStructureTestUtil.addStructure(_group.getGroupId(), JournalArticle.class.getName()); DDMTemplate ddmTemplate1 = DDMTemplateTestUtil.addTemplate(_group.getGroupId(), ddmStructure1.getStructureId(), PortalUtil.getClassNameId(JournalArticle.class), LocaleUtil.getDefault());/*from www . j a v a2 s. co m*/ JournalArticle article = JournalTestUtil.addArticleWithXMLContent(_group.getGroupId(), folder1.getFolderId(), JournalArticleConstants.CLASSNAME_ID_DEFAULT, xml, ddmStructure1.getStructureKey(), ddmTemplate1.getTemplateKey()); JournalFolderLocalServiceUtil.moveFolderToTrash(TestPropsValues.getUserId(), folder1.getFolderId()); JournalFolder folder2 = JournalTestUtil.addFolder(_group.getGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Test 2"); DDMStructure ddmStructure2 = DDMStructureTestUtil.addStructure(_group.getGroupId(), JournalArticle.class.getName()); long[] ddmStructureIds = new long[] { ddmStructure2.getStructureId() }; ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); JournalFolderLocalServiceUtil.updateFolder(TestPropsValues.getUserId(), serviceContext.getScopeGroupId(), folder2.getFolderId(), folder2.getParentFolderId(), folder2.getName(), folder2.getDescription(), ddmStructureIds, JournalFolderConstants.RESTRICTION_TYPE_DDM_STRUCTURES_AND_WORKFLOW, false, serviceContext); TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(JournalArticle.class.getName()); try { trashHandler.checkRestorableEntry(article.getResourcePrimKey(), folder2.getFolderId(), null); Assert.fail(); } catch (RestoreEntryException ree) { } JournalFolder subfolder = JournalTestUtil.addFolder(_group.getGroupId(), folder2.getFolderId(), "Test 2.1"); try { trashHandler.checkRestorableEntry(article.getResourcePrimKey(), subfolder.getFolderId(), null); Assert.fail(); } catch (RestoreEntryException ree) { } }
From source file:com.liferay.journal.service.test.JournalFolderServiceTest.java
License:Open Source License
@Test public void testMoveFolderWithAnArticleInTrashToFolder() throws Exception { JournalFolder folder1 = JournalTestUtil.addFolder(_group.getGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Test 1"); JournalFolder folder2 = JournalTestUtil.addFolder(_group.getGroupId(), folder1.getFolderId(), "Test 2"); String xml = DDMStructureTestUtil.getSampleStructuredContent("Test Article"); DDMStructure ddmStructure1 = DDMStructureTestUtil.addStructure(_group.getGroupId(), JournalArticle.class.getName()); DDMTemplate ddmTemplate1 = DDMTemplateTestUtil.addTemplate(_group.getGroupId(), ddmStructure1.getStructureId(), PortalUtil.getClassNameId(JournalArticle.class), LocaleUtil.getDefault());/*from www . jav a2s.co m*/ JournalTestUtil.addArticleWithXMLContent(_group.getGroupId(), folder2.getFolderId(), JournalArticleConstants.CLASSNAME_ID_DEFAULT, xml, ddmStructure1.getStructureKey(), ddmTemplate1.getTemplateKey()); JournalFolderLocalServiceUtil.moveFolderToTrash(TestPropsValues.getUserId(), folder1.getFolderId()); JournalFolder folder3 = JournalTestUtil.addFolder(_group.getGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Test 3"); DDMStructure ddmStructure2 = DDMStructureTestUtil.addStructure(_group.getGroupId(), JournalArticle.class.getName()); long[] ddmStructureIds = new long[] { ddmStructure2.getStructureId() }; ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); JournalFolderLocalServiceUtil.updateFolder(TestPropsValues.getUserId(), serviceContext.getScopeGroupId(), folder3.getFolderId(), folder3.getParentFolderId(), folder3.getName(), folder3.getDescription(), ddmStructureIds, JournalFolderConstants.RESTRICTION_TYPE_DDM_STRUCTURES_AND_WORKFLOW, false, serviceContext); TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(JournalFolder.class.getName()); try { trashHandler.checkRestorableEntry(folder2.getFolderId(), folder3.getFolderId(), null); Assert.fail(); } catch (RestoreEntryException ree) { } JournalFolder subfolder = JournalTestUtil.addFolder(_group.getGroupId(), folder3.getFolderId(), "Test 3.1"); try { trashHandler.checkRestorableEntry(folder2.getFolderId(), subfolder.getFolderId(), null); Assert.fail(); } catch (RestoreEntryException ree) { } }
From source file:com.liferay.trash.service.impl.TrashEntryServiceImpl.java
License:Open Source License
/** * Moves the trash entry with the entity class name and primary key, * restoring it to a new location identified by the destination container * model ID./*www . j a v a2s . c om*/ * * <p> * This method throws a {@link TrashPermissionException} if the user did not * have the permission to perform one of the necessary operations. The * exception is created with a type specific to the operation: * </p> * * <ul> * <li> * {@link TrashPermissionException#MOVE} - if the user did not have * permission to move the trash entry to the new * destination * </li> * <li> * {@link TrashPermissionException#RESTORE} - if the user did not have * permission to restore the trash entry * </li> * </ul> * * @param className the class name of the entity * @param classPK the primary key of the entity * @param destinationContainerModelId the primary key of the new location * @param serviceContext the service context to be applied (optionally * <code>null</code>) */ @Override public void moveEntry(String className, long classPK, long destinationContainerModelId, ServiceContext serviceContext) throws PortalException { PermissionChecker permissionChecker = getPermissionChecker(); long scopeGroupId = 0; if (serviceContext != null) { scopeGroupId = serviceContext.getScopeGroupId(); } TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className); destinationContainerModelId = trashHandler.getDestinationContainerModelId(classPK, destinationContainerModelId); if (!trashHandler.hasTrashPermission(permissionChecker, scopeGroupId, destinationContainerModelId, TrashActionKeys.MOVE)) { throw new TrashPermissionException(TrashPermissionException.MOVE); } if (trashHandler.isInTrash(classPK) && !trashHandler.hasTrashPermission(permissionChecker, 0, classPK, TrashActionKeys.RESTORE)) { throw new TrashPermissionException(TrashPermissionException.RESTORE); } TrashEntry trashEntry = ModelAdapterUtil.adapt(TrashEntry.class, trashHandler.getTrashEntry(classPK)); if (trashEntry.isTrashEntry(className, classPK)) { trashHandler.checkRestorableEntry( ModelAdapterUtil.adapt(com.liferay.trash.kernel.model.TrashEntry.class, trashEntry), destinationContainerModelId, StringPool.BLANK); } else { trashHandler.checkRestorableEntry(classPK, destinationContainerModelId, StringPool.BLANK); } trashHandler.moveTrashEntry(getUserId(), classPK, destinationContainerModelId, serviceContext); }
From source file:com.liferay.trash.service.impl.TrashEntryServiceImpl.java
License:Open Source License
/** * Restores the trash entry to its original location. In order to handle a * duplicate trash entry already existing at the original location, either * pass in the primary key of the existing trash entry's entity to overwrite * or pass in a new name to give to the trash entry being restored. * * <p>/*from w ww .j a v a2 s. com*/ * This method throws a {@link TrashPermissionException} if the user did not * have the permission to perform one of the necessary operations. The * exception is created with a type specific to the operation: * </p> * * <ul> * <li> * {@link TrashPermissionException#RESTORE} - if the user did not have * permission to restore the trash entry * </li> * <li> * {@link TrashPermissionException#RESTORE_OVERWRITE} - if the user did not * have permission to delete the existing trash entry * </li> * <li> * {@link TrashPermissionException#RESTORE_RENAME} - if the user did not * have permission to rename the trash entry * </li> * </ul> * * @param entryId the primary key of the trash entry to restore * @param overrideClassPK the primary key of the entity to overwrite * (optionally <code>0</code>) * @param name a new name to give to the trash entry being restored * (optionally <code>null</code>) * @return the restored trash entry */ @Override public TrashEntry restoreEntry(long entryId, long overrideClassPK, String name) throws PortalException { PermissionChecker permissionChecker = getPermissionChecker(); TrashEntry entry = trashEntryPersistence.findByPrimaryKey(entryId); TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(entry.getClassName()); if (!trashHandler.hasTrashPermission(permissionChecker, 0, entry.getClassPK(), TrashActionKeys.RESTORE)) { throw new TrashPermissionException(TrashPermissionException.RESTORE); } if (overrideClassPK > 0) { if (!trashHandler.hasTrashPermission(permissionChecker, 0, overrideClassPK, TrashActionKeys.OVERWRITE)) { throw new TrashPermissionException(TrashPermissionException.RESTORE_OVERWRITE); } trashHandler.deleteTrashEntry(overrideClassPK); trashHandler.checkRestorableEntry( ModelAdapterUtil.adapt(com.liferay.trash.kernel.model.TrashEntry.class, entry), TrashEntryConstants.DEFAULT_CONTAINER_ID, null); } else if (name != null) { if (!trashHandler.hasTrashPermission(permissionChecker, 0, entry.getClassPK(), TrashActionKeys.RENAME)) { throw new TrashPermissionException(TrashPermissionException.RESTORE_RENAME); } trashHandler.checkRestorableEntry( ModelAdapterUtil.adapt(com.liferay.trash.kernel.model.TrashEntry.class, entry), TrashEntryConstants.DEFAULT_CONTAINER_ID, name); trashHandler.updateTitle(entry.getClassPK(), name); } trashHandler.restoreTrashEntry(getUserId(), entry.getClassPK()); return entry; }
From source file:com.liferay.trash.web.internal.portlet.TrashPortlet.java
License:Open Source License
protected void checkEntry(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { long trashEntryId = ParamUtil.getLong(actionRequest, "trashEntryId"); String newName = ParamUtil.getString(actionRequest, "newName"); TrashEntry entry = _trashEntryLocalService.fetchTrashEntry(trashEntryId); TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(entry.getClassName()); try {/*w w w .java 2s . co m*/ trashHandler.checkRestorableEntry( ModelAdapterUtil.adapt(com.liferay.trash.kernel.model.TrashEntry.class, entry), TrashEntryConstants.DEFAULT_CONTAINER_ID, newName); } catch (RestoreEntryException ree) { String redirect = ParamUtil.getString(actionRequest, "redirect"); LiferayPortletResponse liferayPortletResponse = _portal.getLiferayPortletResponse(actionResponse); PortletURL renderURL = liferayPortletResponse.createRenderURL(); renderURL.setParameter("mvcPath", "/restore_entry.jsp"); renderURL.setParameter("redirect", redirect); renderURL.setParameter("trashEntryId", String.valueOf(ree.getTrashEntryId())); renderURL.setParameter("duplicateEntryId", String.valueOf(ree.getDuplicateEntryId())); renderURL.setParameter("oldName", ree.getOldName()); renderURL.setParameter("overridable", String.valueOf(ree.isOverridable())); actionRequest.setAttribute(WebKeys.REDIRECT, renderURL.toString()); hideDefaultErrorMessage(actionRequest); sendRedirect(actionRequest, actionResponse); throw new com.liferay.trash.exception.RestoreEntryException(ree.getType(), ree.getCause()); } }