From 0e4b8ed5c26b786446e8021d7da58c172d8a0479 Mon Sep 17 00:00:00 2001 From: jensp Date: Tue, 25 Oct 2016 13:24:11 +0000 Subject: [PATCH] CCM NG/ccm-cms: Tests and implementations for some methods of the AssetManager git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4408 8810af33-2d31-482b-a856-94f89814c4df --- .../cms/ui/category/AddUseContextForm.java | 6 +- .../org/librecms/assets/AssetManager.java | 59 +- .../contentsection/ContentItemManager.java | 498 ++++++++-------- .../org/librecms/assets/AssetManagerTest.java | 342 ++++++++--- .../org/librecms/assets/DatasetsTest.java | 8 + .../AssetManagerTest/after-clean-orphaned.xml | 562 ++++++++++++++++++ .../after-copy-to-other-contentsection.xml | 562 ++++++++++++++++++ .../after-copy-to-other-folder.xml | 562 ++++++++++++++++++ .../after-copy-to-same-folder.xml | 562 ++++++++++++++++++ .../after-create-nonshared.xml | 562 ++++++++++++++++++ .../AssetManagerTest/after-create-shared.xml | 562 ++++++++++++++++++ .../after-move-to-other-contentsection.xml | 562 ++++++++++++++++++ .../after-move-to-other-folder.xml | 562 ++++++++++++++++++ .../librecms/assets/AssetManagerTest/data.xml | 49 +- 14 files changed, 5097 insertions(+), 361 deletions(-) create mode 100644 ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-clean-orphaned.xml create mode 100644 ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-other-contentsection.xml create mode 100644 ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-other-folder.xml create mode 100644 ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-same-folder.xml create mode 100644 ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-create-nonshared.xml create mode 100644 ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-create-shared.xml create mode 100644 ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-move-to-other-contentsection.xml create mode 100644 ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-move-to-other-folder.xml diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/AddUseContextForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/AddUseContextForm.java index 5ecd651c0..9e98967af 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/AddUseContextForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/AddUseContextForm.java @@ -131,9 +131,9 @@ class AddUseContextForm extends BaseForm { } }*/ - m_model.setSelectedKey(state, useContext == null ? - CategoryUseContextModelBuilder.DEFAULT_USE_CONTEXT : - useContext); +// m_model.setSelectedKey(state, useContext == null ? +// CategoryUseContextModelBuilder.DEFAULT_USE_CONTEXT : +// useContext); } } } diff --git a/ccm-cms/src/main/java/org/librecms/assets/AssetManager.java b/ccm-cms/src/main/java/org/librecms/assets/AssetManager.java index 76795e9e5..f90e5e4f6 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/AssetManager.java +++ b/ccm-cms/src/main/java/org/librecms/assets/AssetManager.java @@ -18,8 +18,11 @@ */ package org.librecms.assets; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; @@ -28,6 +31,8 @@ import javax.transaction.Transactional; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.libreccm.categorization.Categorization; +import org.libreccm.categorization.Category; import org.libreccm.categorization.CategoryManager; import org.libreccm.core.CoreConstants; import org.libreccm.security.AuthorizationRequired; @@ -40,6 +45,8 @@ import org.librecms.contentsection.FolderRepository; import org.librecms.contentsection.privileges.AssetPrivileges; import org.librecms.contentsection.privileges.ItemPrivileges; +import static org.librecms.CmsConstants.*; + /** * Provides methods for managing {@link Asset}s, especially sharable * {@link Asset}. @@ -195,7 +202,7 @@ public class AssetManager { */ @Transactional(Transactional.TxType.REQUIRED) public boolean isAssetInUse(final Asset asset) { - throw new UnsupportedOperationException("Not implemented yet."); + return !asset.getItemAttachments().isEmpty(); } /** @@ -210,7 +217,7 @@ public class AssetManager { * @see #getAssetPath(org.librecms.assets.Asset, boolean) */ public String getAssetPath(final Asset asset) { - throw new UnsupportedOperationException("Not implemented yet."); + return getAssetPath(asset, false); } /** @@ -219,20 +226,52 @@ public class AssetManager { * @param asset The {@link Asset} for which the path is generated. * @param withContentSection Whether to include the content section into the * path or not. - * @return The path of the asset. + * @return The path of the asset. For non shared assets this is an empty + * string. * * @see #getAssetPath(org.librecms.assets.Asset) */ public String getAssetPath(final Asset asset, final boolean withContentSection) { - throw new UnsupportedOperationException("Not implemented yet."); + final List result = asset.getCategories().stream() + .filter(categorization -> { + return CATEGORIZATION_TYPE_FOLDER.equals( + categorization.getType()); + }) + .collect(Collectors.toList()); + + if (result.isEmpty()) { + return ""; + } else { + final List tokens = new ArrayList<>(); + tokens.add(asset.getDisplayName()); + + Category current = result.get(0).getCategory(); + tokens.add(current.getName()); + while (current.getParentCategory() != null) { + current = current.getParentCategory(); + tokens.add(current.getName()); + } + + Collections.reverse(tokens); + final String path = String.join("/", tokens); + + if (withContentSection) { + final String sectionName = ((Folder) result.get(0).getCategory()). + getSection().getDisplayName(); + return String.format("%s:/%s", sectionName, path); + } else { + return String.format("/%s", path); + } + } } /** * Creates a list of the folder in which an asset is placed. * * @param asset - * @return + * @return A list of the folders which form the path of the asset. For non + * shared assets an empty list is returned. */ public List getAssetFolders(final Asset asset) { throw new UnsupportedOperationException("Not implemented yet."); @@ -246,6 +285,14 @@ public class AssetManager { * shared asset an empty {@link Optional} is returned. */ public Optional getAssetFolder(final Asset asset) { - throw new UnsupportedOperationException("Not implemented yet."); + return asset.getCategories().stream() + .filter(categorization -> { + return CATEGORIZATION_TYPE_FOLDER.equals( + categorization.getType()); + }) + .map(categorization -> { + return (Folder) categorization.getCategory(); + }) + .findFirst(); } } diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java index f4b2b28dc..23b53ab24 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java @@ -46,7 +46,7 @@ import org.libreccm.security.AuthorizationRequired; import org.libreccm.security.RequiresPrivilege; import org.libreccm.workflow.Workflow; import org.libreccm.workflow.WorkflowManager; -import org.librecms.CmsConstants; +import static org.librecms.CmsConstants.*; import org.librecms.contentsection.privileges.ItemPrivileges; import org.librecms.lifecycle.Lifecycle; import org.librecms.lifecycle.LifecycleManager; @@ -73,7 +73,7 @@ import javax.transaction.Transactional; public class ContentItemManager { private static final Logger LOGGER = LogManager.getLogger( - ContentItemManager.class); + ContentItemManager.class); @Inject private EntityManager entityManager; @@ -113,31 +113,31 @@ public class ContentItemManager { * {@link ContentSection#rootDocumentsFolder} of the provided content * section. Otherwise an {@link IllegalArgumentException} is thrown. * - * @param The type of the content item. - * @param name The name (URL stub) of the new content item. + * @param The type of the content item. + * @param name The name (URL stub) of the new content item. * @param section The content section in which the item is generated. - * @param folder The folder in which in the item is stored. - * @param type The type of the new content item. + * @param folder The folder in which in the item is stored. + * @param type The type of the new content item. * * @return The new content item. */ @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) public T createContentItem( - final String name, - final ContentSection section, - @RequiresPrivilege(ItemPrivileges.CREATE_NEW) - final Folder folder, - final Class type) { + final String name, + final ContentSection section, + @RequiresPrivilege(ItemPrivileges.CREATE_NEW) + final Folder folder, + final Class type) { final Optional contentType = typeRepo - .findByContentSectionAndClass(section, type); + .findByContentSectionAndClass(section, type); if (!contentType.isPresent()) { throw new IllegalArgumentException(String.format( - "ContentSection \"%s\" has no content type for \"%s\".", - section.getLabel(), - type.getName())); + "ContentSection \"%s\" has no content type for \"%s\".", + section.getLabel(), + type.getName())); } return createContentItem(name, @@ -159,40 +159,39 @@ public class ContentItemManager { * provided content section. Otherwise an {@link IllegalArgumentException} * is thrown. * - * @param The type of the content item. - * @param name The name (URL stub) of the new content item. - * @param section The content section in which the item is - * generated. - * @param folder The folder in which in the item is stored. + * @param The type of the content item. + * @param name The name (URL stub) of the new content item. + * @param section The content section in which the item is generated. + * @param folder The folder in which in the item is stored. * @param workflowTemplate The template for the workflow to apply to the new - * item. - * @param type The type of the new content item. + * item. + * @param type The type of the new content item. * * @return The new content item. */ @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) public T createContentItem( - final String name, - final ContentSection section, - @RequiresPrivilege(ItemPrivileges.CREATE_NEW) - final Folder folder, - final WorkflowTemplate workflowTemplate, - final Class type) { + final String name, + final ContentSection section, + @RequiresPrivilege(ItemPrivileges.CREATE_NEW) + final Folder folder, + final WorkflowTemplate workflowTemplate, + final Class type) { final Optional contentType = typeRepo - .findByContentSectionAndClass(section, type); + .findByContentSectionAndClass(section, type); if (!contentType.isPresent()) { throw new IllegalArgumentException(String.format( - "ContentSection \"%s\" has no content type for \"%s\".", - section.getLabel(), - type.getName())); + "ContentSection \"%s\" has no content type for \"%s\".", + section.getLabel(), + type.getName())); } if (name == null || name.trim().isEmpty()) { throw new IllegalArgumentException( - "The name of a content item can't be blank."); + "The name of a content item can't be blank."); } final T item; @@ -200,14 +199,14 @@ public class ContentItemManager { item = type.newInstance(); } catch (InstantiationException | IllegalAccessException ex) { LOGGER.error("Failed to create new content item of type \"{}\" " - + "in content section \"{}\".", + + "in content section \"{}\".", type.getName(), section.getLabel()); throw new RuntimeException(ex); } final KernelConfig kernelConfig = confManager.findConfiguration( - KernelConfig.class); + KernelConfig.class); item.setDisplayName(name); item.getName().addValue(kernelConfig.getDefaultLocale(), @@ -218,16 +217,16 @@ public class ContentItemManager { if (workflowTemplate != null) { final Workflow workflow = workflowManager.createWorkflow( - workflowTemplate); + workflowTemplate); item.setWorkflow(workflow); } contentItemRepo.save(item); categoryManager.addObjectToCategory( - item, - folder, - CmsConstants.CATEGORIZATION_TYPE_FOLDER); + item, + folder, + CATEGORIZATION_TYPE_FOLDER); contentItemRepo.save(item); @@ -245,23 +244,23 @@ public class ContentItemManager { * only moves the draft version of the item. The live version is moved after * a the item is republished. * - * @param item The item to move. + * @param item The item to move. * @param targetFolder The folder to which the item is moved. */ @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) public void move( - @RequiresPrivilege(ItemPrivileges.EDIT) - final ContentItem item, - @RequiresPrivilege(ItemPrivileges.CREATE_NEW) - final Folder targetFolder) { + @RequiresPrivilege(ItemPrivileges.EDIT) + final ContentItem item, + @RequiresPrivilege(ItemPrivileges.CREATE_NEW) + final Folder targetFolder) { if (item == null) { throw new IllegalArgumentException("The item to move can't be null."); } if (targetFolder == null) { throw new IllegalArgumentException( - "The target folder can't be null."); + "The target folder can't be null."); } final ContentItem draftItem = getDraftVersion(item, item.getClass()); @@ -270,18 +269,18 @@ public class ContentItemManager { if (!sectionManager.hasContentType(draftItem.getClass(), targetFolder.getSection())) { throw new IllegalArgumentException(String.format( - "Can't move item %d:\"%s\" to folder \"%s\"." - + "The target folder %d:\"%s\" belongs to content section " + "Can't move item %d:\"%s\" to folder \"%s\"." + + "The target folder %d:\"%s\" belongs to content section " + "%d:\"%s\". The content type \"%s\" has not registered" - + "for this section.", - draftItem.getObjectId(), - draftItem.getDisplayName(), - folderManager.getFolderPath(targetFolder, true), - targetFolder.getObjectId(), - targetFolder.getDisplayName(), - targetFolder.getSection().getObjectId(), - targetFolder.getSection().getDisplayName(), - draftItem.getClass().getName())); + + "for this section.", + draftItem.getObjectId(), + draftItem.getDisplayName(), + folderManager.getFolderPath(targetFolder, true), + targetFolder.getObjectId(), + targetFolder.getDisplayName(), + targetFolder.getSection().getObjectId(), + targetFolder.getSection().getDisplayName(), + draftItem.getClass().getName())); } if (currentFolder.isPresent()) { @@ -294,9 +293,9 @@ public class ContentItemManager { } categoryManager.addObjectToCategory( - draftItem, - targetFolder, - CmsConstants.CATEGORIZATION_TYPE_FOLDER); + draftItem, + targetFolder, + CATEGORIZATION_TYPE_FOLDER); } @@ -310,11 +309,10 @@ public class ContentItemManager { * section and the type of the item is not registered for the target section * an {@link IllegalArgumentException} is thrown. * - * @param item The item to copy. + * @param item The item to copy. * @param targetFolder The folder in which the copy is created. If the - * target folder is the same folder as the folder of the - * original item an index is appended to the name of the - * item. + * target folder is the same folder as the folder of the original item an + * index is appended to the name of the item. * * @return The copy of the item */ @@ -322,46 +320,46 @@ public class ContentItemManager { @AuthorizationRequired @SuppressWarnings("unchecked") public ContentItem copy( - final ContentItem item, - @RequiresPrivilege(ItemPrivileges.CREATE_NEW) - final Folder targetFolder) { + final ContentItem item, + @RequiresPrivilege(ItemPrivileges.CREATE_NEW) + final Folder targetFolder) { if (item == null) { throw new IllegalArgumentException("The item to copy can't be null."); } if (targetFolder == null) { throw new IllegalArgumentException( - "The target folder to which the item is copied can't be null"); + "The target folder to which the item is copied can't be null"); } final Optional contentType = typeRepo - .findByContentSectionAndClass( - item.getContentType().getContentSection(), item. - getClass()); + .findByContentSectionAndClass( + item.getContentType().getContentSection(), item. + getClass()); if (!contentType.isPresent()) { throw new IllegalArgumentException(String.format( - "ContentSection \"%s\" has no content type for \"%s\".", - item.getContentType().getContentSection(), - item.getClass().getName())); + "ContentSection \"%s\" has no content type for \"%s\".", + item.getContentType().getContentSection(), + item.getClass().getName())); } final ContentItem draftItem = getDraftVersion(item, item.getClass()); if (!sectionManager.hasContentType(draftItem.getClass(), targetFolder.getSection())) { throw new IllegalArgumentException(String.format( - "Can't copy item %d:\"%s\" to folder \"%s\"." - + "The target folder %d:\"%s\" belongs to content section " + "Can't copy item %d:\"%s\" to folder \"%s\"." + + "The target folder %d:\"%s\" belongs to content section " + "%d:\"%s\". The content type \"%s\" has not registered" - + "for this section.", - draftItem.getObjectId(), - draftItem.getDisplayName(), - folderManager.getFolderPath(targetFolder, true), - targetFolder.getObjectId(), - targetFolder.getDisplayName(), - targetFolder.getSection().getObjectId(), - targetFolder.getSection().getDisplayName(), - draftItem.getClass().getName())); + + "for this section.", + draftItem.getObjectId(), + draftItem.getDisplayName(), + folderManager.getFolderPath(targetFolder, true), + targetFolder.getObjectId(), + targetFolder.getDisplayName(), + targetFolder.getSection().getObjectId(), + targetFolder.getSection().getDisplayName(), + draftItem.getClass().getName())); } final ContentItem copy; @@ -375,31 +373,31 @@ public class ContentItemManager { if (draftItem.getWorkflow() != null) { final WorkflowTemplate template = draftItem.getWorkflow() - .getTemplate(); + .getTemplate(); final Workflow copyWorkflow = workflowManager.createWorkflow( - template); + template); copy.setWorkflow(copyWorkflow); } contentItemRepo.save(copy); draftItem.getCategories().forEach(categorization -> categoryManager - .addObjectToCategory(copy, categorization.getCategory())); + .addObjectToCategory(copy, categorization.getCategory())); final Optional itemFolder = getItemFolder(draftItem); if (itemFolder.isPresent()) { try { categoryManager.removeObjectFromCategory( - copy, getItemFolder(draftItem).get()); + copy, getItemFolder(draftItem).get()); } catch (ObjectNotAssignedToCategoryException ex) { throw new RuntimeException(ex); } } categoryManager.addObjectToCategory( - copy, - targetFolder, - CmsConstants.CATEGORIZATION_TYPE_FOLDER); + copy, + targetFolder, + CATEGORIZATION_TYPE_FOLDER); // !!!!!!!!!!!!!!!!!!!!! // ToDo copy Attachments @@ -414,7 +412,7 @@ public class ContentItemManager { } for (final PropertyDescriptor propertyDescriptor : beanInfo - .getPropertyDescriptors()) { + .getPropertyDescriptors()) { if (propertyIsExcluded(propertyDescriptor.getName())) { continue; } @@ -434,52 +432,52 @@ public class ContentItemManager { source = (LocalizedString) readMethod.invoke(draftItem); target = (LocalizedString) readMethod.invoke(copy); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } source.getAvailableLocales().forEach( - locale -> target.addValue(locale, - source.getValue(locale))); + locale -> target.addValue(locale, + source.getValue(locale))); } else if (propType != null - && propType.isAssignableFrom(ContentItem.class)) { + && propType.isAssignableFrom(ContentItem.class)) { final ContentItem linkedItem; try { linkedItem = (ContentItem) readMethod.invoke(draftItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } final ContentItem linkedDraftItem = getDraftVersion( - linkedItem, linkedItem.getClass()); + linkedItem, linkedItem.getClass()); try { writeMethod.invoke(copy, linkedDraftItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } } else if (propType != null - && propType.isAssignableFrom(List.class)) { + && propType.isAssignableFrom(List.class)) { final List source; final List target; try { source = (List) readMethod.invoke(draftItem); target = (List) readMethod.invoke(copy); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } target.addAll(source); } else if (propType != null - && propType.isAssignableFrom(Map.class)) { + && propType.isAssignableFrom(Map.class)) { final Map source; final Map target; @@ -487,14 +485,14 @@ public class ContentItemManager { source = (Map) readMethod.invoke(draftItem); target = (Map) readMethod.invoke(copy); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } source.forEach((key, value) -> target.put(key, value)); } else if (propType != null - && propType.isAssignableFrom(Set.class)) { + && propType.isAssignableFrom(Set.class)) { final Set source; final Set target; @@ -502,8 +500,8 @@ public class ContentItemManager { source = (Set) readMethod.invoke(draftItem); target = (Set) readMethod.invoke(copy); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } @@ -514,8 +512,8 @@ public class ContentItemManager { value = readMethod.invoke(item); writeMethod.invoke(copy, value); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } } @@ -523,8 +521,8 @@ public class ContentItemManager { if (targetFolder.equals(getItemFolder(item).orElse(null))) { final long number = contentItemRepo.countFilterByFolderAndName( - targetFolder, String.format("%s_copy", - item.getDisplayName())); + targetFolder, String.format("%s_copy", + item.getDisplayName())); final long index = number + 1; copy.setDisplayName(String.format("%s_copy%d", copy.getDisplayName(), @@ -564,16 +562,16 @@ public class ContentItemManager { @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) public ContentItem publish( - @RequiresPrivilege(ItemPrivileges.PUBLISH) - final ContentItem item) { + @RequiresPrivilege(ItemPrivileges.PUBLISH) + final ContentItem item) { if (item == null) { throw new IllegalArgumentException( - "The item to publish can't be null."); + "The item to publish can't be null."); } final LifecycleDefinition lifecycleDefinition = item.getContentType() - .getDefaultLifecycle(); + .getDefaultLifecycle(); return publish(item, lifecycleDefinition); } @@ -582,9 +580,9 @@ public class ContentItemManager { * Creates a live version of content item or updates the live version of a * content item if there already a live version. * - * @param item The content item to publish. + * @param item The content item to publish. * @param lifecycleDefinition The definition of the lifecycle to use for the - * new item. + * new item. * * @return The published content item. */ @@ -592,18 +590,18 @@ public class ContentItemManager { @Transactional(Transactional.TxType.REQUIRED) @SuppressWarnings("unchecked") public ContentItem publish( - @RequiresPrivilege(ItemPrivileges.PUBLISH) - final ContentItem item, - final LifecycleDefinition lifecycleDefinition) { + @RequiresPrivilege(ItemPrivileges.PUBLISH) + final ContentItem item, + final LifecycleDefinition lifecycleDefinition) { if (item == null) { throw new IllegalArgumentException( - "The item to publish can't be null."); + "The item to publish can't be null."); } if (lifecycleDefinition == null) { throw new IllegalArgumentException( - "The lifecycle definition for the " - + "lifecycle of the item to publish can't be null."); + "The lifecycle definition for the " + + "lifecycle of the item to publish can't be null."); } final ContentItem draftItem = getDraftVersion(item, ContentItem.class); @@ -624,16 +622,16 @@ public class ContentItemManager { liveItem.setContentType(draftItem.getContentType()); final Lifecycle lifecycle = lifecycleManager.createLifecycle( - lifecycleDefinition); + lifecycleDefinition); liveItem.setLifecycle(lifecycle); liveItem.setWorkflow(draftItem.getWorkflow()); final List oldCategories = liveItem - .getCategories() - .stream() - .map(categorization -> categorization.getCategory()) - .collect(Collectors.toList()); + .getCategories() + .stream() + .map(categorization -> categorization.getCategory()) + .collect(Collectors.toList()); oldCategories.forEach(category -> { try { categoryManager.removeObjectFromCategory(liveItem, category); @@ -643,9 +641,9 @@ public class ContentItemManager { }); draftItem.getCategories().forEach(categorization -> categoryManager - .addObjectToCategory(liveItem, - categorization.getCategory(), - categorization.getType())); + .addObjectToCategory(liveItem, + categorization.getCategory(), + categorization.getType())); // !!!!!!!!!!!!!!!!!!!!! // ToDo copy Attachments @@ -660,7 +658,7 @@ public class ContentItemManager { } for (final PropertyDescriptor propertyDescriptor : beanInfo - .getPropertyDescriptors()) { + .getPropertyDescriptors()) { if (propertyIsExcluded(propertyDescriptor.getName())) { continue; @@ -681,56 +679,56 @@ public class ContentItemManager { source = (LocalizedString) readMethod.invoke(draftItem); target = (LocalizedString) readMethod.invoke(liveItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } source.getAvailableLocales().forEach( - locale -> target.addValue(locale, source. - getValue(locale))); + locale -> target.addValue(locale, source. + getValue(locale))); } else if (propType != null - && propType.isAssignableFrom(ContentItem.class)) { + && propType.isAssignableFrom(ContentItem.class)) { final ContentItem linkedItem; try { linkedItem = (ContentItem) readMethod.invoke(draftItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } final ContentItem linkedDraftItem = getDraftVersion( - linkedItem, linkedItem.getClass()); + linkedItem, linkedItem.getClass()); if (isLive(linkedDraftItem)) { try { final Optional linkedLiveItem - = getLiveVersion( - linkedDraftItem, ContentItem.class); + = getLiveVersion( + linkedDraftItem, ContentItem.class); writeMethod.invoke(liveItem, linkedLiveItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } } } else if (propType != null - && propType.isAssignableFrom(List.class)) { + && propType.isAssignableFrom(List.class)) { final List source; final List target; try { source = (List) readMethod.invoke(draftItem); target = (List) readMethod.invoke(liveItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } target.addAll(source); } else if (propType != null - && propType.isAssignableFrom(Map.class)) { + && propType.isAssignableFrom(Map.class)) { final Map source; final Map target; @@ -738,14 +736,14 @@ public class ContentItemManager { source = (Map) readMethod.invoke(draftItem); target = (Map) readMethod.invoke(liveItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } source.forEach((key, value) -> target.put(key, value)); } else if (propType != null - && propType.isAssignableFrom(Set.class)) { + && propType.isAssignableFrom(Set.class)) { final Set source; final Set target; @@ -753,8 +751,8 @@ public class ContentItemManager { source = (Set) readMethod.invoke(draftItem); target = (Set) readMethod.invoke(liveItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } @@ -765,8 +763,8 @@ public class ContentItemManager { value = readMethod.invoke(item); writeMethod.invoke(liveItem, value); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } } @@ -788,8 +786,8 @@ public class ContentItemManager { @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) public void publish( - @RequiresPrivilege(ItemPrivileges.PUBLISH) - final Folder folder) { + @RequiresPrivilege(ItemPrivileges.PUBLISH) + final Folder folder) { // Ensure that we are using a fresh folder and that the folder was // retrieved in this transaction to avoid problems with lazy fetched @@ -797,10 +795,10 @@ public class ContentItemManager { final Folder theFolder = folderRepo.findById(folder.getObjectId()); theFolder.getObjects() - .stream() - .map(categorization -> categorization.getCategorizedObject()) - .filter(object -> object instanceof ContentItem) - .forEach(item -> publish((ContentItem) item)); + .stream() + .map(categorization -> categorization.getCategorizedObject()) + .filter(object -> object instanceof ContentItem) + .forEach(item -> publish((ContentItem) item)); } /** @@ -812,17 +810,17 @@ public class ContentItemManager { @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) public void unpublish( - @RequiresPrivilege(ItemPrivileges.PUBLISH) - final ContentItem item) { + @RequiresPrivilege(ItemPrivileges.PUBLISH) + final ContentItem item) { if (item == null) { throw new IllegalArgumentException( - "The item to unpublish can't be null"); + "The item to unpublish can't be null"); } LOGGER.debug("Unpublishing item {}...", item.getItemUuid()); final Optional liveItem = getLiveVersion( - item, ContentItem.class); + item, ContentItem.class); if (!liveItem.isPresent()) { LOGGER.info("ContentItem {} has no live version.", @@ -831,11 +829,11 @@ public class ContentItemManager { } final List categories = liveItem - .get() - .getCategories() - .stream() - .map(categorization -> categorization.getCategory()) - .collect(Collectors.toList()); + .get() + .getCategories() + .stream() + .map(categorization -> categorization.getCategory()) + .collect(Collectors.toList()); categories.forEach(category -> { try { @@ -861,8 +859,8 @@ public class ContentItemManager { @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) public void unpublish( - @RequiresPrivilege(ItemPrivileges.PUBLISH) - final Folder folder) { + @RequiresPrivilege(ItemPrivileges.PUBLISH) + final Folder folder) { // Ensure that we are using a fresh folder and that the folder was // retrieved in this transaction to avoid problems with lazy fetched @@ -870,12 +868,12 @@ public class ContentItemManager { final Folder theFolder = folderRepo.findById(folder.getObjectId()); theFolder.getObjects() - .stream() - .map(categorization -> categorization.getCategorizedObject()) - .filter(object -> object instanceof ContentItem) - .map(object -> (ContentItem) object) - .filter(item -> isLive(item)) - .forEach(item -> unpublish(item)); + .stream() + .map(categorization -> categorization.getCategorizedObject()) + .filter(object -> object instanceof ContentItem) + .map(object -> (ContentItem) object) + .filter(item -> isLive(item)) + .forEach(item -> unpublish(item)); } /** @@ -884,12 +882,12 @@ public class ContentItemManager { * @param item The item * * @return {@code true} if the content item has a live version, - * {@code false} if not. + * {@code false} if not. */ @Transactional(Transactional.TxType.REQUIRED) public boolean isLive(final ContentItem item) { final TypedQuery query = entityManager.createNamedQuery( - "ContentItem.hasLiveVersion", Boolean.class); + "ContentItem.hasLiveVersion", Boolean.class); query.setParameter("uuid", item.getItemUuid()); return query.getSingleResult(); @@ -898,35 +896,35 @@ public class ContentItemManager { /** * Retrieves the live version of the provided content item if any. * - * @param Type of the content item. + * @param Type of the content item. * @param item The item of which the live version should be retrieved. * @param type Type of the content item. * * @return The live version of an item. If the item provided is already the - * live version the provided item is returned, otherwise the live - * version is returned. If there is no live version an empty - * {@link Optional} is returned. + * live version the provided item is returned, otherwise the live version is + * returned. If there is no live version an empty {@link Optional} is + * returned. */ @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) @SuppressWarnings({"unchecked"}) public Optional getLiveVersion( - @RequiresPrivilege(ItemPrivileges.VIEW_PUBLISHED) - final ContentItem item, - final Class type) { + @RequiresPrivilege(ItemPrivileges.VIEW_PUBLISHED) + final ContentItem item, + final Class type) { if (!ContentItem.class.isAssignableFrom(type)) { throw new IllegalArgumentException(String.format( - "The provided type \"%s\" does match the type of the provided " + "The provided type \"%s\" does match the type of the provided " + "item (\"%s\").", - type.getName(), - item.getClass().getName())); + type.getName(), + item.getClass().getName())); } if (isLive(item)) { final TypedQuery query = entityManager - .createNamedQuery( - "ContentItem.findLiveVersion", ContentItem.class); + .createNamedQuery( + "ContentItem.findLiveVersion", ContentItem.class); query.setParameter("uuid", item.getItemUuid()); final ContentItem result = query.getSingleResult(); @@ -943,50 +941,50 @@ public class ContentItemManager { /** * Retrieves the pending versions of an item if there are any. * - * @param Type of the content item to retrieve. + * @param Type of the content item to retrieve. * @param item The item of which the pending versions are retrieved. * @param type Type of the content item to retrieve. * * @return A list of the pending versions of the item. */ public List getPendingVersions( - final ContentItem item, - final Class type) { + final ContentItem item, + final Class type) { throw new UnsupportedOperationException(); } /** * Retrieves the draft version * - * @param Type of the item. + * @param Type of the item. * @param item The item of which the draft version is retrieved. * @param type Type of the item. * * @return The draft version of the provided content item. If the provided - * item is the draft version the provided item is simply returned. - * Otherwise the draft version is retrieved from the database and is - * returned. Each content item has a draft version (otherwise - * something is seriously wrong with the database) this method will + * item is the draft version the provided item is simply returned. Otherwise + * the draft version is retrieved from the database and is returned. Each + * content item has a draft version (otherwise something is seriously wrong + * with the database) this method will * never return {@code null}. */ @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) @SuppressWarnings("unchecked") public T getDraftVersion( - @RequiresPrivilege(ItemPrivileges.PREVIEW) - final ContentItem item, - final Class type) { + @RequiresPrivilege(ItemPrivileges.PREVIEW) + final ContentItem item, + final Class type) { if (!ContentItem.class.isAssignableFrom(type)) { throw new IllegalArgumentException(String.format( - "The provided type \"%s\" does match the type of the provided " + "The provided type \"%s\" does match the type of the provided " + "item (\"%s\").", - type.getName(), - item.getClass().getName())); + type.getName(), + item.getClass().getName())); } final TypedQuery query = entityManager.createNamedQuery( - "ContentItem.findDraftVersion", ContentItem.class); + "ContentItem.findDraftVersion", ContentItem.class); query.setParameter("uuid", item.getItemUuid()); return (T) query.getSingleResult(); @@ -1012,10 +1010,10 @@ public class ContentItemManager { } /** - * Returns the path of an item as String. The path of an item is the path of the - * folder category the item is a member of concatenated with the name of the - * item. The path is relative to the content section. For instance, the path - * of an item in the folder category + * Returns the path of an item as String. The path of an item is the path of + * the folder category the item is a member of concatenated with the name of + * the item. The path is relative to the content section. For instance, the + * path of an item in the folder category * {@code /research/computer-science/artifical-intelligence} and with the * name {@code neural-nets} has the path * {@code /research/computer-science/artificial-intelligence/neural-nets}. @@ -1025,9 +1023,9 @@ public class ContentItemManager { * {@code info}, the path including the content section would be * {@code info:/research/computer-science/artificial-intelligence/neural-nets}. * - * @param item The item whose path is generated. + * @param item The item whose path is generated. * @param withContentSection Whether to include the content section into the - * path. + * path. * * @return The path of the content item * @@ -1035,10 +1033,12 @@ public class ContentItemManager { */ public String getItemPath(final ContentItem item, final boolean withContentSection) { - final List result = item.getCategories().stream(). - filter(categorization -> CmsConstants.CATEGORIZATION_TYPE_FOLDER. - equals(categorization.getType())) - .collect(Collectors.toList()); + final List result = item.getCategories().stream() + .filter(categorization -> { + return CATEGORIZATION_TYPE_FOLDER.equals( + categorization.getType()); + }) + .collect(Collectors.toList()); if (result.isEmpty()) { return item.getDisplayName(); @@ -1053,14 +1053,14 @@ public class ContentItemManager { tokens.add(current.getName()); } - Collections.reverse(result); + Collections.reverse(tokens); final String path = String.join("/", tokens); if (withContentSection) { final String sectionName = item.getContentType(). - getContentSection().getDisplayName(); + getContentSection().getDisplayName(); return String.format( - "%s:/%s", sectionName, path); + "%s:/%s", sectionName, path); } else { return String.format("/%s", path); } @@ -1076,9 +1076,11 @@ public class ContentItemManager { */ public List getItemFolders(final ContentItem item) { final List result = item.getCategories().stream(). - filter(categorization -> CmsConstants.CATEGORIZATION_TYPE_FOLDER. - equals(categorization.getType())) - .collect(Collectors.toList()); + filter(categorization -> { + return CATEGORIZATION_TYPE_FOLDER.equals( + categorization.getType()); + }) + .collect(Collectors.toList()); final List folders = new ArrayList<>(); if (!result.isEmpty()) { @@ -1087,12 +1089,12 @@ public class ContentItemManager { folders.add((Folder) current); } else { throw new IllegalArgumentException(String.format( - "The item %s is assigned to the category %s with the" - + "categorization type \"%s\", but the Category is not" + "The item %s is assigned to the category %s with the" + + "categorization type \"%s\", but the Category is not" + "a folder. This is no supported.", - item.getUuid(), - current.getUuid(), - CmsConstants.CATEGORIZATION_TYPE_FOLDER)); + item.getUuid(), + current.getUuid(), + CATEGORIZATION_TYPE_FOLDER)); } while (current.getParentCategory() != null) { @@ -1101,12 +1103,12 @@ public class ContentItemManager { folders.add((Folder) current); } else { throw new IllegalArgumentException(String.format( - "The item %s is assigned to the category %s with the" + "The item %s is assigned to the category %s with the" + "categorization type \"%s\", but the Category is not" - + "a folder. This is no supported.", - item.getUuid(), - current.getUuid(), - CmsConstants.CATEGORIZATION_TYPE_FOLDER)); + + "a folder. This is no supported.", + item.getUuid(), + current.getUuid(), + CATEGORIZATION_TYPE_FOLDER)); } } @@ -1124,13 +1126,15 @@ public class ContentItemManager { * @param item The item * * @return An {@link Optional} containing the folder of the item if the item - * is part of a folder. + * is part of a folder. */ public Optional getItemFolder(final ContentItem item) { - final List result = item.getCategories().stream(). - filter(categorization -> CmsConstants.CATEGORIZATION_TYPE_FOLDER. - equals(categorization.getType())) - .collect(Collectors.toList()); + final List result = item.getCategories().stream() + .filter(categorization -> { + return CATEGORIZATION_TYPE_FOLDER. + equals(categorization.getType()); + }) + .collect(Collectors.toList()); if (result.size() > 0) { final Category category = result.get(0).getCategory(); @@ -1138,12 +1142,12 @@ public class ContentItemManager { return Optional.of((Folder) category); } else { throw new IllegalArgumentException(String.format( - "The item %s is assigned to the category %s with the" - + "categorization type \"%s\", but the Category is not" + "The item %s is assigned to the category %s with the" + + "categorization type \"%s\", but the Category is not" + "a folder. This is no supported.", - item.getUuid(), - category.getUuid(), - CmsConstants.CATEGORIZATION_TYPE_FOLDER)); + item.getUuid(), + category.getUuid(), + CATEGORIZATION_TYPE_FOLDER)); } } else { return Optional.empty(); diff --git a/ccm-cms/src/test/java/org/librecms/assets/AssetManagerTest.java b/ccm-cms/src/test/java/org/librecms/assets/AssetManagerTest.java index 3aa7cc6ca..ed64fc383 100644 --- a/ccm-cms/src/test/java/org/librecms/assets/AssetManagerTest.java +++ b/ccm-cms/src/test/java/org/librecms/assets/AssetManagerTest.java @@ -18,6 +18,9 @@ */ package org.librecms.assets; +import java.util.List; +import java.util.Optional; + import static org.libreccm.testutils.DependenciesHelpers.*; import org.jboss.arquillian.container.test.api.Deployment; @@ -45,6 +48,7 @@ import org.librecms.attachments.AttachmentList; import org.librecms.contentsection.FolderRepository; import javax.inject.Inject; +import org.librecms.contentsection.Folder; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; @@ -95,61 +99,61 @@ public class AssetManagerTest { @Deployment public static WebArchive createDeployment() { return ShrinkWrap - .create(WebArchive.class, - "LibreCCM-org.librecms.assets.AssetManagerTest.war") - .addPackage(org.libreccm.auditing.CcmRevision.class.getPackage()) - .addPackage(org.libreccm.categorization.Categorization.class - .getPackage()) - .addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage()) - .addPackage(org.libreccm.configuration.Configuration.class - .getPackage()) - .addPackage(org.libreccm.core.CcmCore.class.getPackage()) - .addPackage(org.libreccm.jpa.EntityManagerProducer.class - .getPackage()) - .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class - .getPackage()) - .addPackage(org.libreccm.l10n.LocalizedString.class - .getPackage()) - .addPackage(org.libreccm.security.Permission.class.getPackage()) - .addPackage(org.libreccm.web.CcmApplication.class.getPackage()) - .addPackage(org.libreccm.workflow.Workflow.class.getPackage()) - .addPackage(com.arsdigita.bebop.Component.class.getPackage()) - .addPackage(com.arsdigita.bebop.util.BebopConstants.class - .getPackage()) - .addClass(com.arsdigita.kernel.KernelConfig.class) - .addClass(com.arsdigita.runtime.CCMResourceManager.class) - .addClass( - com.arsdigita.ui.admin.applications.AbstractAppInstanceForm.class) - .addClass( - com.arsdigita.ui.admin.applications.AbstractAppSettingsPane.class) - .addClass( - com.arsdigita.ui.admin.applications.DefaultApplicationInstanceForm.class) - .addClass( - com.arsdigita.ui.admin.applications.DefaultApplicationSettingsPane.class) - .addClass(com.arsdigita.cms.dispatcher.ItemResolver.class) - .addPackage(com.arsdigita.util.Lockable.class.getPackage()) - .addPackage(com.arsdigita.web.BaseServlet.class.getPackage()) - .addPackage(org.librecms.Cms.class.getPackage()) - .addPackage(org.librecms.assets.Asset.class.getPackage()) - .addPackage(org.librecms.attachments.AttachmentList.class - .getPackage()) - .addPackage(org.librecms.lifecycle.Lifecycle.class.getPackage()) - .addPackage(org.librecms.contentsection.ContentSection.class - .getPackage()) - .addPackage(org.librecms.contenttypes.Article.class.getPackage()). - addClass(com.arsdigita.kernel.security.SecurityConfig.class) - .addPackage(org.libreccm.tests.categories.IntegrationTest.class - .getPackage()) - // .addAsLibraries(getModuleDependencies()) - .addAsLibraries(getCcmCoreDependencies()) - .addAsResource("configs/shiro.ini", "shiro.ini") - .addAsResource( - "configs/org/librecms/contentsection/ContentItemManagerTest/log4j2.xml", - "log4j2.xml") - .addAsResource("test-persistence.xml", - "META-INF/persistence.xml") - .addAsWebInfResource("test-web.xml", "web.xml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); + .create(WebArchive.class, + "LibreCCM-org.librecms.assets.AssetManagerTest.war") + .addPackage(org.libreccm.auditing.CcmRevision.class.getPackage()). + addPackage(org.libreccm.categorization.Categorization.class + .getPackage()) + .addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage()) + .addPackage(org.libreccm.configuration.Configuration.class + .getPackage()) + .addPackage(org.libreccm.core.CcmCore.class.getPackage()) + .addPackage(org.libreccm.jpa.EntityManagerProducer.class + .getPackage()) + .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class + .getPackage()) + .addPackage(org.libreccm.l10n.LocalizedString.class + .getPackage()) + .addPackage(org.libreccm.security.Permission.class.getPackage()) + .addPackage(org.libreccm.web.CcmApplication.class.getPackage()) + .addPackage(org.libreccm.workflow.Workflow.class.getPackage()) + .addPackage(com.arsdigita.bebop.Component.class.getPackage()) + .addPackage(com.arsdigita.bebop.util.BebopConstants.class + .getPackage()) + .addClass(com.arsdigita.kernel.KernelConfig.class) + .addClass(com.arsdigita.runtime.CCMResourceManager.class) + .addClass( + com.arsdigita.ui.admin.applications.AbstractAppInstanceForm.class). + addClass( + com.arsdigita.ui.admin.applications.AbstractAppSettingsPane.class). + addClass( + com.arsdigita.ui.admin.applications.DefaultApplicationInstanceForm.class). + addClass( + com.arsdigita.ui.admin.applications.DefaultApplicationSettingsPane.class). + addClass(com.arsdigita.cms.dispatcher.ItemResolver.class) + .addPackage(com.arsdigita.util.Lockable.class.getPackage()) + .addPackage(com.arsdigita.web.BaseServlet.class.getPackage()) + .addPackage(org.librecms.Cms.class.getPackage()) + .addPackage(org.librecms.assets.Asset.class.getPackage()) + .addPackage(org.librecms.attachments.AttachmentList.class + .getPackage()) + .addPackage(org.librecms.lifecycle.Lifecycle.class.getPackage()) + .addPackage(org.librecms.contentsection.ContentSection.class + .getPackage()) + .addPackage(org.librecms.contenttypes.Article.class.getPackage()). + addClass(com.arsdigita.kernel.security.SecurityConfig.class) + .addPackage(org.libreccm.tests.categories.IntegrationTest.class + .getPackage()) + // .addAsLibraries(getModuleDependencies()) + .addAsLibraries(getCcmCoreDependencies()) + .addAsResource("configs/shiro.ini", "shiro.ini") + .addAsResource( + "configs/org/librecms/contentsection/ContentItemManagerTest/log4j2.xml", + "log4j2.xml") + .addAsResource("test-persistence.xml", + "META-INF/persistence.xml") + .addAsWebInfResource("test-web.xml", "web.xml") + .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); } /** @@ -184,10 +188,10 @@ public class AssetManagerTest { @InSequence(100) @UsingDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/assets/AssetManagerTest/" - + "after-create-nonshared.xml", - excludeColumns = {"object_id", - "uuid"}) + value = "datasets/org/librecms/assets/AssetManagerTest/" + + "after-create-nonshared.xml", + excludeColumns = {"object_id", + "uuid"}) public void createNonSharedAssets() { fail(); } @@ -260,10 +264,10 @@ public class AssetManagerTest { @InSequence(200) @UsingDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/assets/AssetManagerTest/" - + "after-create-shared.xml", - excludeColumns = {"object_id", - "uuid"}) + value = "datasets/org/librecms/assets/AssetManagerTest/" + + "after-create-shared.xml", + excludeColumns = {"object_id", + "uuid"}) public void createSharedAssets() { fail(); } @@ -336,10 +340,10 @@ public class AssetManagerTest { @InSequence(300) @UsingDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/assets/AssetManagerTest/" - + "after-clean-orphaned.xml", - excludeColumns = {"object_id", - "uuid"}) + value = "datasets/org/librecms/assets/AssetManagerTest/" + + "after-clean-orphaned.xml", + excludeColumns = {"object_id", + "uuid"}) public void cleanOrphanedAssets() { fail(); } @@ -352,10 +356,10 @@ public class AssetManagerTest { @InSequence(400) @UsingDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/assets/AssetManagerTest/" - + "after-move-to-other-folder.xml", - excludeColumns = {"object_id", - "uuid"}) + value = "datasets/org/librecms/assets/AssetManagerTest/" + + "after-move-to-other-folder.xml", + excludeColumns = {"object_id", + "uuid"}) public void moveAssetToOtherFolder() { fail(); } @@ -368,10 +372,10 @@ public class AssetManagerTest { @InSequence(410) @UsingDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/assets/AssetManagerTest/" - + "after-move-to-other-contentsection.xml", - excludeColumns = {"object_id", - "uuid"}) + value = "datasets/org/librecms/assets/AssetManagerTest/" + + "after-move-to-other-contentsection.xml", + excludeColumns = {"object_id", + "uuid"}) public void moveAssetToFolderInOtherContentSection() { fail(); } @@ -429,10 +433,10 @@ public class AssetManagerTest { @InSequence(500) @UsingDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/assets/AssetManagerTest/" - + "after-copy-to-other-folder.xml", - excludeColumns = {"object_id", - "uuid"}) + value = "datasets/org/librecms/assets/AssetManagerTest/" + + "after-copy-to-other-folder.xml", + excludeColumns = {"object_id", + "uuid"}) public void copyAssetToOtherFolder() { fail(); } @@ -445,10 +449,10 @@ public class AssetManagerTest { @InSequence(510) @UsingDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/assets/AssetManagerTest/" - + "after-copy-to-same-folder.xml", - excludeColumns = {"object_id", - "uuid"}) + value = "datasets/org/librecms/assets/AssetManagerTest/" + + "after-copy-to-same-folder.xml", + excludeColumns = {"object_id", + "uuid"}) public void copyAssetToSameFolder() { fail(); } @@ -462,10 +466,10 @@ public class AssetManagerTest { @InSequence(520) @UsingDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/assets/AssetManagerTest/" - + "after-copy-to-other-contentsection.xml", - excludeColumns = {"object_id", - "uuid"}) + value = "datasets/org/librecms/assets/AssetManagerTest/" + + "after-copy-to-other-contentsection.xml", + excludeColumns = {"object_id", + "uuid"}) public void copyAssetToOtherContentSection() { fail(); } @@ -520,11 +524,28 @@ public class AssetManagerTest { * {@link AssetManager#isAssetInUse(org.librecms.assets.Asset)} for various * {@link Asset}s. */ + @Test @InSequence(600) @UsingDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") public void verifyIsAssetInUse() { - fail(); + final Asset header = assetRepo.findById(-700L); + final Asset phb = assetRepo.findById(-800L); + final Asset servicesHeader = assetRepo.findById(-900L); + final Asset product1Datasheet = assetRepo.findById(-1000L); + final Asset catalog = assetRepo.findById(-1100L); + + assertThat(header, is(not(nullValue()))); + assertThat(phb, is(not(nullValue()))); + assertThat(servicesHeader, is(not(nullValue()))); + assertThat(product1Datasheet, is(not(nullValue()))); + assertThat(catalog, is(not(nullValue()))); + + assertThat(assetManager.isAssetInUse(header), is(true)); + assertThat(assetManager.isAssetInUse(phb), is(false)); + assertThat(assetManager.isAssetInUse(servicesHeader), is(true)); + assertThat(assetManager.isAssetInUse(product1Datasheet), is(true)); + assertThat(assetManager.isAssetInUse(catalog), is(true)); } /** @@ -532,11 +553,33 @@ public class AssetManagerTest { * {@link AssetManager#getAssetPath(org.librecms.assets.Asset)} for various * {@link Asset}s. */ + @Test @InSequence(700) @UsingDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") public void verifyGetAssetPathWithoutContentSection() { - fail(); + final Asset header = assetRepo.findById(-700L); + final Asset phb = assetRepo.findById(-800L); + final Asset servicesHeader = assetRepo.findById(-900L); + final Asset product1Datasheet = assetRepo.findById(-1000L); + final Asset catalog = assetRepo.findById(-1100L); + + assertThat(header, is(not(nullValue()))); + assertThat(phb, is(not(nullValue()))); + assertThat(servicesHeader, is(not(nullValue()))); + assertThat(product1Datasheet, is(not(nullValue()))); + assertThat(catalog, is(not(nullValue()))); + + assertThat(assetManager.getAssetPath(header), + is(equalTo("/media/header.png"))); + assertThat(assetManager.getAssetPath(phb), + is(equalTo("/media/the-phb.png"))); + assertThat(assetManager.getAssetPath(servicesHeader), + is(equalTo("/media/services-header.png"))); + assertThat(assetManager.getAssetPath(product1Datasheet), + is(equalTo(""))); + assertThat(assetManager.getAssetPath(catalog), + is(equalTo("/media/catalog.pdf"))); } /** @@ -544,11 +587,33 @@ public class AssetManagerTest { * } * for various {@link Asset}s. */ + @Test @InSequence(800) @UsingDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") public void verifyGetAssetPathWithContentSection() { - fail(); + final Asset header = assetRepo.findById(-700L); + final Asset phb = assetRepo.findById(-800L); + final Asset servicesHeader = assetRepo.findById(-900L); + final Asset product1Datasheet = assetRepo.findById(-1000L); + final Asset catalog = assetRepo.findById(-1100L); + + assertThat(header, is(not(nullValue()))); + assertThat(phb, is(not(nullValue()))); + assertThat(servicesHeader, is(not(nullValue()))); + assertThat(product1Datasheet, is(not(nullValue()))); + assertThat(catalog, is(not(nullValue()))); + + assertThat(assetManager.getAssetPath(header, true), + is(equalTo("info:/media/header.png"))); + assertThat(assetManager.getAssetPath(phb, true), + is(equalTo("info:/media/the-phb.png"))); + assertThat(assetManager.getAssetPath(servicesHeader, true), + is(equalTo("info:/media/services-header.png"))); + assertThat(assetManager.getAssetPath(product1Datasheet, true), + is(equalTo(""))); + assertThat(assetManager.getAssetPath(catalog, true), + is(equalTo("info:/media/catalog.pdf"))); } /** @@ -556,11 +621,47 @@ public class AssetManagerTest { * {@link AssetManager#getAssetFolder(org.librecms.assets.Asset)} for * various {@link Asset}s. */ + @Test @InSequence(900) @UsingDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") public void verifyGetAssetFolder() { - fail(); + final Asset header = assetRepo.findById(-700L); + final Asset phb = assetRepo.findById(-800L); + final Asset servicesHeader = assetRepo.findById(-900L); + final Asset product1Datasheet = assetRepo.findById(-1000L); + final Asset catalog = assetRepo.findById(-1100L); + + assertThat(header, is(not(nullValue()))); + assertThat(phb, is(not(nullValue()))); + assertThat(servicesHeader, is(not(nullValue()))); + assertThat(product1Datasheet, is(not(nullValue()))); + assertThat(catalog, is(not(nullValue()))); + + final Folder media = folderRepo.findById(-400L); + assertThat(media, is(not(nullValue()))); + + final Optional headerFolder = assetManager + .getAssetFolder(header); + final Optional phbFolder = assetManager + .getAssetFolder(phb); + final Optional servicesHeaderFolder = assetManager + .getAssetFolder(servicesHeader); + final Optional product1DatasheetFolder = assetManager + .getAssetFolder(product1Datasheet); + final Optional catalogFolder = assetManager + .getAssetFolder(catalog); + + assertThat(headerFolder.isPresent(), is(true)); + assertThat(phbFolder.isPresent(), is(true)); + assertThat(servicesHeaderFolder.isPresent(), is(true)); + assertThat(product1DatasheetFolder.isPresent(), is(false)); + assertThat(catalogFolder.isPresent(), is(true)); + + assertThat(headerFolder.get(), is(equalTo(media))); + assertThat(phbFolder.get(), is(equalTo(media))); + assertThat(servicesHeaderFolder.get(), is(equalTo(media))); + assertThat(catalogFolder.get(), is(equalTo(media))); } /** @@ -568,11 +669,68 @@ public class AssetManagerTest { * } * for various {@link Asset}s. */ + @Test @InSequence(1000) @UsingDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/assets/AssetManagerTest/data.xml") public void verifyGetAssetFolders() { - fail(); + final Asset header = assetRepo.findById(-700L); + final Asset phb = assetRepo.findById(-800L); + final Asset servicesHeader = assetRepo.findById(-900L); + final Asset product1Datasheet = assetRepo.findById(-1000L); + final Asset catalog = assetRepo.findById(-1100L); + + assertThat(header, is(not(nullValue()))); + assertThat(phb, is(not(nullValue()))); + assertThat(servicesHeader, is(not(nullValue()))); + assertThat(product1Datasheet, is(not(nullValue()))); + assertThat(catalog, is(not(nullValue()))); + + final Folder infoAssets = folderRepo.findById(-300L); + final Folder media = folderRepo.findById(-400L); + + assertThat(infoAssets, is(not(nullValue()))); + assertThat(media, is(not(nullValue()))); + + final List headerFolders = assetManager.getAssetFolders(header); + final List phbFolders = assetManager.getAssetFolders(phb); + final List servicesHeaderFolders = assetManager.getAssetFolders( + phb); + final List product1DatasheetFolders = assetManager. + getAssetFolders(product1Datasheet); + final List catalogFolders = assetManager. + getAssetFolders(catalog); + + assertThat(headerFolders, is(not(nullValue()))); + assertThat(phbFolders, is(not(nullValue()))); + assertThat(servicesHeaderFolders, is(not(nullValue()))); + assertThat(product1DatasheetFolders, is(not(nullValue()))); + assertThat(catalogFolders, is(not(nullValue()))); + + assertThat(headerFolders.isEmpty(), is(false)); + assertThat(phbFolders.isEmpty(), is(false)); + assertThat(servicesHeaderFolders.isEmpty(), is(false)); + assertThat(product1DatasheetFolders.isEmpty(), is(true)); + assertThat(catalogFolders.isEmpty(), is(false)); + + assertThat(headerFolders.size(), is(2)); + assertThat(phbFolders.size(), is(2)); + assertThat(servicesHeaderFolders.size(), is(2)); + assertThat(product1DatasheetFolders.size(), is(0)); + assertThat(catalogFolders.size(), is(2)); + + assertThat(headerFolders.get(0), is(equalTo(infoAssets))); + assertThat(headerFolders.get(1), is(equalTo(media))); + + assertThat(phbFolders.get(0), is(equalTo(infoAssets))); + assertThat(phbFolders.get(1), is(equalTo(media))); + + assertThat(servicesHeaderFolders.get(0), is(equalTo(infoAssets))); + assertThat(servicesHeaderFolders.get(1), is(equalTo(media))); + + assertThat(catalogFolders.get(0), is(equalTo(infoAssets))); + assertThat(catalogFolders.get(1), is(equalTo(media))); + } } diff --git a/ccm-cms/src/test/java/org/librecms/assets/DatasetsTest.java b/ccm-cms/src/test/java/org/librecms/assets/DatasetsTest.java index 1c2391409..9e93c2a28 100644 --- a/ccm-cms/src/test/java/org/librecms/assets/DatasetsTest.java +++ b/ccm-cms/src/test/java/org/librecms/assets/DatasetsTest.java @@ -48,6 +48,14 @@ public class DatasetsTest extends DatasetsVerifier { "/datasets/org/librecms/assets/AssetRepositoryTest/after-delete.xml", "/datasets/org/librecms/assets/AssetManagerTest/data.xml", + "/datasets/org/librecms/assets/AssetManagerTest/after-clean-orphaned.xml", + "/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-other-contentsection.xml", + "/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-other-folder.xml", + "/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-same-folder.xml", + "/datasets/org/librecms/assets/AssetManagerTest/after-create-nonshared.xml", + "/datasets/org/librecms/assets/AssetManagerTest/after-create-shared.xml", + "/datasets/org/librecms/assets/AssetManagerTest/after-move-to-other-contentsection.xml", + "/datasets/org/librecms/assets/AssetManagerTest/after-move-to-other-folder.xml", }); } diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-clean-orphaned.xml b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-clean-orphaned.xml new file mode 100644 index 000000000..ffc0a3b5a --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-clean-orphaned.xml @@ -0,0 +1,562 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-other-contentsection.xml b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-other-contentsection.xml new file mode 100644 index 000000000..ffc0a3b5a --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-other-contentsection.xml @@ -0,0 +1,562 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-other-folder.xml b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-other-folder.xml new file mode 100644 index 000000000..ffc0a3b5a --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-other-folder.xml @@ -0,0 +1,562 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-same-folder.xml b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-same-folder.xml new file mode 100644 index 000000000..ffc0a3b5a --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-copy-to-same-folder.xml @@ -0,0 +1,562 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-create-nonshared.xml b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-create-nonshared.xml new file mode 100644 index 000000000..ffc0a3b5a --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-create-nonshared.xml @@ -0,0 +1,562 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-create-shared.xml b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-create-shared.xml new file mode 100644 index 000000000..ffc0a3b5a --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-create-shared.xml @@ -0,0 +1,562 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-move-to-other-contentsection.xml b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-move-to-other-contentsection.xml new file mode 100644 index 000000000..ffc0a3b5a --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-move-to-other-contentsection.xml @@ -0,0 +1,562 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-move-to-other-folder.xml b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-move-to-other-folder.xml new file mode 100644 index 000000000..ffc0a3b5a --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/after-move-to-other-folder.xml @@ -0,0 +1,562 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/data.xml b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/data.xml index 24882f76b..ffc0a3b5a 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/data.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/assets/AssetManagerTest/data.xml @@ -44,6 +44,9 @@ + @@ -87,6 +90,10 @@ rev="0" revtype="0" display_name="catalog.pdf" /> + + content_section_id="-1300" /> + @@ -251,6 +259,8 @@ rev="0" /> + + + + mime_type="image/png" + data_size="0" /> + data_size="0" /> + + + @@ -444,13 +474,6 @@ object_order="4" category_index="false" type="folder" /> -