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 f90e5e4f6..3efd70867 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/AssetManager.java +++ b/ccm-cms/src/main/java/org/librecms/assets/AssetManager.java @@ -57,7 +57,7 @@ import static org.librecms.CmsConstants.*; public class AssetManager { private static final Logger LOGGER = LogManager. - getLogger(AssetManager.class); + getLogger(AssetManager.class); @Inject private EntityManager entityManager; @@ -78,21 +78,22 @@ public class AssetManager { * Creates a new, non shared {@link Asset} and adds it to the provided * {@link AttachmentList}. * - * @param Type variable for the type of the new {@link Asset}. - * @param name The name of the new {@link Asset}. + * @param Type variable for the type of the new {@link Asset}. + * @param name The name of the new {@link Asset}. * @param attachments The {@link AttachmentList} to which the new - * {@link Asset} is added. - * @param type The type of the new {@link Asset}. Must be a subclass of the - * {@link Asset} class. + * {@link Asset} is added. + * @param type The type of the new {@link Asset}. Must be a subclass + * of the {@link Asset} class. + * * @return The new {@link Asset}. */ @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) public T createAsset( - final String name, - @RequiresPrivilege(ItemPrivileges.EDIT) - final AttachmentList attachments, - final Class type) { + final String name, + @RequiresPrivilege(ItemPrivileges.EDIT) + final AttachmentList attachments, + final Class type) { throw new UnsupportedOperationException("Not implemented yet."); } @@ -103,20 +104,21 @@ public class AssetManager { * a content section. Otherwise an {@link IllegalArgumentException} is * thrown. * - * @param Type variable for the type of the {@link Asset} to create. - * @param name The name of the new {@link Asset}. + * @param Type variable for the type of the {@link Asset} to create. + * @param name The name of the new {@link Asset}. * @param folder The {@link Folder} in which the {@link Asset} is created. - * @param type The type of the new {@link Asset}. Must be a subclass of the - * {@link Asset} class. + * @param type The type of the new {@link Asset}. Must be a subclass of + * the {@link Asset} class. + * * @return The new {@link Asset}. */ @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) public T createAsset( - final String name, - @RequiresPrivilege(AssetPrivileges.CREATE_NEW) - final Folder folder, - final Class type) { + final String name, + @RequiresPrivilege(AssetPrivileges.CREATE_NEW) + final Folder folder, + final Class type) { throw new UnsupportedOperationException("Not implemented yet."); } @@ -134,15 +136,16 @@ public class AssetManager { * folder is provided and the caller does not add the created asset to an * {@link AttachmentList} the asset will become orphaned can't be accessed. * - * @param Type variable for the type of the {@link Asset}. - * @param name The name of the new {@link Asset}. + * @param Type variable for the type of the {@link Asset}. + * @param name The name of the new {@link Asset}. * @param folder Optional folder in which the new {@link Asset} is placed. - * @param type The type of the new {@link Asset}. Must be a subclass of the - * {@link Asset} class. + * @param type The type of the new {@link Asset}. Must be a subclass of + * the {@link Asset} class. + * * @return The new {@link Asset}. Note: If no {@link Folder} is provided and - * the and the returned {@link Asset} is not added to an - * {@link AttachmentList} the new {@code Asset} will become orphaned and - * can't be accessed by any method. + * the and the returned {@link Asset} is not added to an + * {@link AttachmentList} the new {@code Asset} will become orphaned + * and can't be accessed by any method. */ @Transactional(Transactional.TxType.REQUIRED) public T createAsset(final String name, @@ -158,30 +161,37 @@ public class AssetManager { @Transactional(Transactional.TxType.REQUIRED) @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) public void cleanOrphanedAssets() { - throw new UnsupportedOperationException("Not implemented yet."); + final List assets = assetRepo.findAll(); + + final List orphaned = assets.stream() + .filter(asset -> asset.getCategories().isEmpty() + && asset.getItemAttachments().isEmpty()) + .collect(Collectors.toList()); + + orphaned.forEach(orphan -> assetRepo.delete(orphan)); } /** * Moves an {@link Asset} to an folder. * - * @param asset The {@link Asset} to move. + * @param asset The {@link Asset} to move. * @param targetFolder The folder to which the {@link Asset} is moved. Must - * be an asset folder. + * be an asset folder. */ @AuthorizationRequired @Transactional(Transactional.TxType.REQUIRED) public void move( - @RequiresPrivilege(AssetPrivileges.EDIT) - final Asset asset, - @RequiresPrivilege(AssetPrivileges.CREATE_NEW) - final Folder targetFolder) { + @RequiresPrivilege(AssetPrivileges.EDIT) + final Asset asset, + @RequiresPrivilege(AssetPrivileges.CREATE_NEW) + final Folder targetFolder) { throw new UnsupportedOperationException("Not implemented yet."); } /** * Copies an {@link Asset}. * - * @param asset The {@link Asset} to copy. + * @param asset The {@link Asset} to copy. * @param targetFolder The folder to which the {@link Asset} is copied. */ @Transactional(Transactional.TxType.REQUIRED) @@ -197,8 +207,9 @@ public class AssetManager { * member of at least one {@link AttachmentList}. * * @param asset The {@link Asset} to check for usage. + * * @return {@code true} if the {@link Asset} is in use, {@link false} if - * not. + * not. */ @Transactional(Transactional.TxType.REQUIRED) public boolean isAssetInUse(final Asset asset) { @@ -211,8 +222,9 @@ public class AssetManager { * with the name of the asset. The path is relative to the content section. * * @param asset The {@link Assset} for which the path is generated. + * * @return The path of the {@link Asset}. If the {@link Asset} is a non - * shared asset the path is empty. + * shared asset the path is empty. * * @see #getAssetPath(org.librecms.assets.Asset, boolean) */ @@ -223,22 +235,24 @@ public class AssetManager { /** * Returns the path of an item as String. * - * @param asset The {@link Asset} for which the path is generated. + * @param asset The {@link Asset} for which the path is + * generated. * @param withContentSection Whether to include the content section into the - * path or not. + * path or not. + * * @return The path of the asset. For non shared assets this is an empty - * string. + * string. * * @see #getAssetPath(org.librecms.assets.Asset) */ public String getAssetPath(final Asset asset, final boolean withContentSection) { final List result = asset.getCategories().stream() - .filter(categorization -> { - return CATEGORIZATION_TYPE_FOLDER.equals( - categorization.getType()); - }) - .collect(Collectors.toList()); + .filter(categorization -> { + return CATEGORIZATION_TYPE_FOLDER.equals( + categorization.getType()); + }) + .collect(Collectors.toList()); if (result.isEmpty()) { return ""; @@ -247,17 +261,17 @@ public class AssetManager { 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()); + current = current.getParentCategory(); } Collections.reverse(tokens); final String path = String.join("/", tokens); if (withContentSection) { - final String sectionName = ((Folder) result.get(0).getCategory()). + final String sectionName + = ((Folder) result.get(0).getCategory()). getSection().getDisplayName(); return String.format("%s:/%s", sectionName, path); } else { @@ -270,29 +284,71 @@ public class AssetManager { * Creates a list of the folder in which an asset is placed. * * @param asset + * * @return A list of the folders which form the path of the asset. For non - * shared assets an empty list is returned. + * shared assets an empty list is returned. */ public List getAssetFolders(final Asset asset) { - throw new UnsupportedOperationException("Not implemented yet."); + final List result = asset.getCategories().stream() + .filter(categorization -> { + return CATEGORIZATION_TYPE_FOLDER.equals(categorization + .getType()); + }) + .collect(Collectors.toList()); + + final List folders = new ArrayList<>(); + if (!result.isEmpty()) { + Category current = result.get(0).getCategory(); + if (current instanceof Folder) { + folders.add((Folder) current); + } else { + throw new IllegalArgumentException(String.format( + "The asset %s is assigned to the category %s with the" + + "categorization type \"%s\", but the Category is not" + + "a folder. This is no supported.", + asset.getUuid(), + current.getUuid(), + CATEGORIZATION_TYPE_FOLDER)); + } + + while (current.getParentCategory() != null) { + current = current.getParentCategory(); + if (current instanceof Folder) { + folders.add((Folder) current); + } else { + throw new IllegalArgumentException(String.format( + "The asset %s is assigned to the category %s with the" + + "categorization type \"%s\", but the Category is not" + + "a folder. This is no supported.", + asset.getUuid(), + current.getUuid(), + CATEGORIZATION_TYPE_FOLDER)); + } + } + } + + Collections.reverse(folders); + return folders; } /** * Gets the folder in which an asset is placed. * * @param asset The asset. + * * @return The folder in which the asset is placed. If the asset is a non - * shared asset an empty {@link Optional} is returned. + * shared asset an empty {@link Optional} is returned. */ public Optional getAssetFolder(final Asset asset) { return asset.getCategories().stream() - .filter(categorization -> { - return CATEGORIZATION_TYPE_FOLDER.equals( - categorization.getType()); - }) - .map(categorization -> { - return (Folder) categorization.getCategory(); - }) - .findFirst(); + .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/assets/AssetRepository.java b/ccm-cms/src/main/java/org/librecms/assets/AssetRepository.java index 01f1c9aa0..e5294c654 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/AssetRepository.java +++ b/ccm-cms/src/main/java/org/librecms/assets/AssetRepository.java @@ -61,6 +61,9 @@ public class AssetRepository @Inject private CategoryManager categoryManager; + @Inject + private AssetManager assetManager; + @Override public Long getEntityId(final Asset asset) { return asset.getObjectId(); @@ -96,9 +99,9 @@ public class AssetRepository public void save( @RequiresPrivilege(AssetPrivileges.EDIT) final Asset asset) { - + } - + /** * Deletes an unused Asset. If the {@link Asset} is in use * (linked to at least one ContentItem) an {@link AssetInUseException} is @@ -116,7 +119,10 @@ public class AssetRepository @RequiresPrivilege(AssetPrivileges.DELETE) final Asset asset) { - if (asset.getItemAttachments().isEmpty()) { + if (assetManager.isAssetInUse(asset)) { + throw new AssetInUseException(String.format("Asset %s is in use.", + asset.getUuid())); + } else { final List categories = asset.getCategories() .stream() .map(categorization -> categorization.getCategory()) @@ -131,9 +137,6 @@ public class AssetRepository } ccmObjectRepo.delete(asset); - } else { - throw new AssetInUseException(String.format("Asset %s is in use.", - asset.getUuid())); } } 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 23b53ab24..9f6faa606 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java @@ -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,39 +159,40 @@ 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; @@ -199,14 +200,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(), @@ -217,16 +218,16 @@ public class ContentItemManager { if (workflowTemplate != null) { final Workflow workflow = workflowManager.createWorkflow( - workflowTemplate); + workflowTemplate); item.setWorkflow(workflow); } contentItemRepo.save(item); categoryManager.addObjectToCategory( - item, - folder, - CATEGORIZATION_TYPE_FOLDER); + item, + folder, + CATEGORIZATION_TYPE_FOLDER); contentItemRepo.save(item); @@ -244,23 +245,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()); @@ -269,18 +270,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()) { @@ -293,9 +294,9 @@ public class ContentItemManager { } categoryManager.addObjectToCategory( - draftItem, - targetFolder, - CATEGORIZATION_TYPE_FOLDER); + draftItem, + targetFolder, + CATEGORIZATION_TYPE_FOLDER); } @@ -309,10 +310,11 @@ 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 */ @@ -320,46 +322,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; @@ -373,31 +375,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, - CATEGORIZATION_TYPE_FOLDER); + copy, + targetFolder, + CATEGORIZATION_TYPE_FOLDER); // !!!!!!!!!!!!!!!!!!!!! // ToDo copy Attachments @@ -412,7 +414,7 @@ public class ContentItemManager { } for (final PropertyDescriptor propertyDescriptor : beanInfo - .getPropertyDescriptors()) { + .getPropertyDescriptors()) { if (propertyIsExcluded(propertyDescriptor.getName())) { continue; } @@ -432,52 +434,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; @@ -485,14 +487,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; @@ -500,8 +502,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); } @@ -512,8 +514,8 @@ public class ContentItemManager { value = readMethod.invoke(item); writeMethod.invoke(copy, value); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } } @@ -521,8 +523,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(), @@ -562,16 +564,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); } @@ -580,9 +582,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. */ @@ -590,18 +592,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); @@ -622,16 +624,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); @@ -641,9 +643,9 @@ public class ContentItemManager { }); draftItem.getCategories().forEach(categorization -> categoryManager - .addObjectToCategory(liveItem, - categorization.getCategory(), - categorization.getType())); + .addObjectToCategory(liveItem, + categorization.getCategory(), + categorization.getType())); // !!!!!!!!!!!!!!!!!!!!! // ToDo copy Attachments @@ -658,7 +660,7 @@ public class ContentItemManager { } for (final PropertyDescriptor propertyDescriptor : beanInfo - .getPropertyDescriptors()) { + .getPropertyDescriptors()) { if (propertyIsExcluded(propertyDescriptor.getName())) { continue; @@ -679,56 +681,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; @@ -736,14 +738,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; @@ -751,8 +753,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); } @@ -763,8 +765,8 @@ public class ContentItemManager { value = readMethod.invoke(item); writeMethod.invoke(liveItem, value); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } } @@ -786,8 +788,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 @@ -795,10 +797,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)); } /** @@ -810,17 +812,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.", @@ -829,11 +831,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 { @@ -859,8 +861,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 @@ -868,12 +870,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)); } /** @@ -882,12 +884,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(); @@ -896,35 +898,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(); @@ -941,50 +943,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(); @@ -1023,9 +1025,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 * @@ -1034,11 +1036,11 @@ public class ContentItemManager { public String getItemPath(final ContentItem item, final boolean withContentSection) { final List result = item.getCategories().stream() - .filter(categorization -> { - return CATEGORIZATION_TYPE_FOLDER.equals( - categorization.getType()); - }) - .collect(Collectors.toList()); + .filter(categorization -> { + return CATEGORIZATION_TYPE_FOLDER.equals( + categorization.getType()); + }) + .collect(Collectors.toList()); if (result.isEmpty()) { return item.getDisplayName(); @@ -1047,10 +1049,9 @@ public class ContentItemManager { tokens.add(item.getDisplayName()); Category current = result.get(0).getCategory(); - tokens.add(current.getName()); while (current.getParentCategory() != null) { - current = current.getParentCategory(); tokens.add(current.getName()); + current = current.getParentCategory(); } Collections.reverse(tokens); @@ -1058,9 +1059,9 @@ public class ContentItemManager { 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); } @@ -1075,12 +1076,12 @@ public class ContentItemManager { * @return */ public List getItemFolders(final ContentItem item) { - final List result = item.getCategories().stream(). - filter(categorization -> { - return 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()); final List folders = new ArrayList<>(); if (!result.isEmpty()) { @@ -1089,12 +1090,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(), - CATEGORIZATION_TYPE_FOLDER)); + item.getUuid(), + current.getUuid(), + CATEGORIZATION_TYPE_FOLDER)); } while (current.getParentCategory() != null) { @@ -1103,12 +1104,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(), - CATEGORIZATION_TYPE_FOLDER)); + + "a folder. This is no supported.", + item.getUuid(), + current.getUuid(), + CATEGORIZATION_TYPE_FOLDER)); } } @@ -1126,15 +1127,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 -> { - return CATEGORIZATION_TYPE_FOLDER. - equals(categorization.getType()); - }) - .collect(Collectors.toList()); + .filter(categorization -> { + return CATEGORIZATION_TYPE_FOLDER. + equals(categorization.getType()); + }) + .collect(Collectors.toList()); if (result.size() > 0) { final Category category = result.get(0).getCategory(); @@ -1142,12 +1143,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(), - 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 ed64fc383..5af4ad082 100644 --- a/ccm-cms/src/test/java/org/librecms/assets/AssetManagerTest.java +++ b/ccm-cms/src/test/java/org/librecms/assets/AssetManagerTest.java @@ -99,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"); } /** @@ -188,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(); } @@ -264,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(); } @@ -340,12 +340,12 @@ 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 = {"timestamp"}, + orderBy = {"asset_titles_aud.asset_id"}) public void cleanOrphanedAssets() { - fail(); + assetManager.cleanOrphanedAssets(); } /** @@ -356,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(); } @@ -372,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(); } @@ -433,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(); } @@ -449,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(); } @@ -466,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(); } @@ -571,15 +571,15 @@ public class AssetManagerTest { assertThat(catalog, is(not(nullValue()))); assertThat(assetManager.getAssetPath(header), - is(equalTo("/media/header.png"))); + is(equalTo("/media/images/header.png"))); assertThat(assetManager.getAssetPath(phb), - is(equalTo("/media/the-phb.png"))); + is(equalTo("/media/images/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"))); + is(equalTo("/media/downloads/catalog.pdf"))); } /** @@ -605,15 +605,15 @@ public class AssetManagerTest { assertThat(catalog, is(not(nullValue()))); assertThat(assetManager.getAssetPath(header, true), - is(equalTo("info:/media/header.png"))); + is(equalTo("info:/media/images/header.png"))); assertThat(assetManager.getAssetPath(phb, true), - is(equalTo("info:/media/the-phb.png"))); + is(equalTo("info:/media/images/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"))); + is(equalTo("info:/media/downloads/catalog.pdf"))); } /** @@ -639,18 +639,23 @@ public class AssetManagerTest { assertThat(catalog, is(not(nullValue()))); final Folder media = folderRepo.findById(-400L); + final Folder images = folderRepo.findById(-410L); + final Folder downloads = folderRepo.findById(-420L); + assertThat(media, is(not(nullValue()))); + assertThat(images, is(not(nullValue()))); + assertThat(downloads, is(not(nullValue()))); final Optional headerFolder = assetManager - .getAssetFolder(header); + .getAssetFolder(header); final Optional phbFolder = assetManager - .getAssetFolder(phb); + .getAssetFolder(phb); final Optional servicesHeaderFolder = assetManager - .getAssetFolder(servicesHeader); + .getAssetFolder(servicesHeader); final Optional product1DatasheetFolder = assetManager - .getAssetFolder(product1Datasheet); + .getAssetFolder(product1Datasheet); final Optional catalogFolder = assetManager - .getAssetFolder(catalog); + .getAssetFolder(catalog); assertThat(headerFolder.isPresent(), is(true)); assertThat(phbFolder.isPresent(), is(true)); @@ -658,10 +663,10 @@ public class AssetManagerTest { assertThat(product1DatasheetFolder.isPresent(), is(false)); assertThat(catalogFolder.isPresent(), is(true)); - assertThat(headerFolder.get(), is(equalTo(media))); - assertThat(phbFolder.get(), is(equalTo(media))); + assertThat(headerFolder.get(), is(equalTo(images))); + assertThat(phbFolder.get(), is(equalTo(images))); assertThat(servicesHeaderFolder.get(), is(equalTo(media))); - assertThat(catalogFolder.get(), is(equalTo(media))); + assertThat(catalogFolder.get(), is(equalTo(downloads))); } /** @@ -688,18 +693,22 @@ public class AssetManagerTest { final Folder infoAssets = folderRepo.findById(-300L); final Folder media = folderRepo.findById(-400L); + final Folder images = folderRepo.findById(-410L); + final Folder downloads = folderRepo.findById(-420L); assertThat(infoAssets, is(not(nullValue()))); assertThat(media, is(not(nullValue()))); + assertThat(images, is(not(nullValue()))); + assertThat(downloads, is(not(nullValue()))); final List headerFolders = assetManager.getAssetFolders(header); final List phbFolders = assetManager.getAssetFolders(phb); final List servicesHeaderFolders = assetManager.getAssetFolders( - phb); + servicesHeader); final List product1DatasheetFolders = assetManager. - getAssetFolders(product1Datasheet); + getAssetFolders(product1Datasheet); final List catalogFolders = assetManager. - getAssetFolders(catalog); + getAssetFolders(catalog); assertThat(headerFolders, is(not(nullValue()))); assertThat(phbFolders, is(not(nullValue()))); @@ -713,23 +722,26 @@ public class AssetManagerTest { assertThat(product1DatasheetFolders.isEmpty(), is(true)); assertThat(catalogFolders.isEmpty(), is(false)); - assertThat(headerFolders.size(), is(2)); - assertThat(phbFolders.size(), is(2)); + assertThat(headerFolders.size(), is(3)); + assertThat(phbFolders.size(), is(3)); assertThat(servicesHeaderFolders.size(), is(2)); assertThat(product1DatasheetFolders.size(), is(0)); - assertThat(catalogFolders.size(), is(2)); + assertThat(catalogFolders.size(), is(3)); assertThat(headerFolders.get(0), is(equalTo(infoAssets))); assertThat(headerFolders.get(1), is(equalTo(media))); + assertThat(headerFolders.get(2), is(equalTo(images))); assertThat(phbFolders.get(0), is(equalTo(infoAssets))); assertThat(phbFolders.get(1), is(equalTo(media))); + assertThat(phbFolders.get(2), is(equalTo(images))); 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))); + assertThat(catalogFolders.get(2), is(equalTo(downloads))); } 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 index ffc0a3b5a..269f3babd 100644 --- 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 @@ -10,6 +10,8 @@ + + + @@ -44,9 +52,6 @@ - @@ -94,6 +99,9 @@ rev="0" revtype="0" display_name="orphan.png" /> + + + + + @@ -196,6 +230,10 @@ type="ASSETS_FOLDER" /> + + + + - @@ -261,6 +302,9 @@ rev="0" /> + + - - + + - + + @@ -375,32 +415,40 @@ - - + + - - - + + @@ -111,13 +117,31 @@ category_order="1"/> + + + + @@ -196,6 +228,10 @@ type="ASSETS_FOLDER" /> + + + + + -