diff --git a/ccm-bundle-devel-wildfly-web/pom.xml b/ccm-bundle-devel-wildfly-web/pom.xml index a2c15ff47..d61bfb295 100644 --- a/ccm-bundle-devel-wildfly-web/pom.xml +++ b/ccm-bundle-devel-wildfly-web/pom.xml @@ -93,13 +93,18 @@ org.apache.maven.plugins maven-war-plugin - + + + ../ccm-theme-foundry/src/main/resources/themes + + + diff --git a/ccm-cms/pom.xml b/ccm-cms/pom.xml index 57a77f9bd..3d1a811dd 100644 --- a/ccm-cms/pom.xml +++ b/ccm-cms/pom.xml @@ -170,7 +170,6 @@ org.jacoco jacoco-maven-plugin - 0.7.5.201505241946 default-prepare-agent diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/FolderManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/FolderManager.java index 64773ded7..2ab4d480b 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/FolderManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/FolderManager.java @@ -51,12 +51,67 @@ public class FolderManager { @Inject private ContentItemManager itemManager; + /** + * An enum describing if a folder can be deleted or not and why. + * + * @see #folderIsDeletable(org.librecms.contentsection.Folder) + */ + public enum FolderIsDeletable { + /** + * Folder can be deleted. + */ + YES, + /** + * Folder can't be deleted because is has sub categories. + */ + HAS_SUBCATEGORIES, + /** + * Folder can't be deleted because the folder is not empty. + */ + IS_NOT_EMPTY, + /** + * Folder can't be deleted because the folder is a root folder. + */ + IS_ROOT_FOLDER + } + + /** + * Describes if a folder is movable to another folder or not and why. + */ + public enum FolderIsMovable { + /** + * The folder can be moved to the specified target folder. + */ + YES, + /** + * The folder is a root folder. Root folders can't be moved. + */ + IS_ROOT_FOLDER, + /** + * The folder to move and the target folder are the same folder. + */ + SAME_FOLDER, + /** + * The folder to move and the target folder belong the different content + * sections. + */ + DIFFERENT_SECTIONS, + /** + * The folder to move and the target folder have different types. + */ + DIFFERENT_TYPES, + /** + * The folder to move contains live items. + */ + HAS_LIVE_ITEMS + } + /** * Creates new folder as sub folder of the provided parent folder. The type * and the content section to which the folder belongs are the same as for * the provided parent folder. * - * @param name The name of the new folder. + * @param name The name of the new folder. * @param parent The folder in which the new folder is generated. * * @return The new folder. @@ -65,16 +120,16 @@ public class FolderManager { public Folder createFolder(final String name, final Folder parent) { if (parent == null) { throw new IllegalArgumentException( - "Can't create a folder without a parent folder."); + "Can't create a folder without a parent folder."); } if (name == null || name.trim().isEmpty()) { throw new IllegalArgumentException( - "Can't create a folder with an empty name"); + "Can't create a folder with an empty name"); } final KernelConfig kernelConfig = confManager.findConfiguration( - KernelConfig.class); + KernelConfig.class); final Folder folder = new Folder(); folder.setName(name); @@ -89,6 +144,27 @@ public class FolderManager { return folder; } + public FolderIsDeletable folderIsDeletable(final Folder folder) { + if (folder == null) { + throw new IllegalArgumentException( + "Can't check if null is deletable."); + } + + if (!folder.getSubCategories().isEmpty()) { + return FolderIsDeletable.HAS_SUBCATEGORIES; + } + + if (!folder.getObjects().isEmpty()) { + return FolderIsDeletable.IS_NOT_EMPTY; + } + + if (folder.getParentFolder() == null) { + return FolderIsDeletable.IS_ROOT_FOLDER; + } + + return FolderIsDeletable.YES; + } + /** * Deletes a empty, none-root folder. * @@ -100,24 +176,28 @@ public class FolderManager { throw new IllegalArgumentException("Can't delete folder null"); } - if (!folder.getSubCategories().isEmpty()) { - throw new IllegalArgumentException(String.format( - "Can't delete folder \"%s\" because the folder is not empty", - getFolderPath(folder, true))); + final FolderIsDeletable status = folderIsDeletable(folder); + switch (status) { + case YES: + folderRepo.delete(folder); + break; + case HAS_SUBCATEGORIES: + throw new IllegalArgumentException(String.format( + "Can't delete folder \"%s\" because the folder is not empty", + getFolderPath(folder, true))); + case IS_NOT_EMPTY: + throw new IllegalArgumentException(String.format( + "Can't delete folder \"%s\" because the folder is not empty.", + getFolderPath(folder))); + case IS_ROOT_FOLDER: + throw new IllegalArgumentException( + "The folder to delete is a root folder can can't be deleted."); + default: + throw new IllegalArgumentException(String.format( + "Unexpected return value from #folderIsDeletable: " + + "\"%s\".", + status.toString())); } - - if (!folder.getObjects().isEmpty()) { - throw new IllegalArgumentException(String.format( - "Can't delete folder \"%s\" because the folder is not empty.", - getFolderPath(folder))); - } - - if (folder.getParentFolder() == null) { - throw new IllegalArgumentException( - "The folder to delete is a root folder can can't be deleted."); - } - - folderRepo.delete(folder); } /** @@ -131,65 +211,164 @@ public class FolderManager { */ @Transactional(Transactional.TxType.REQUIRED) public void moveFolder(final Folder folder, final Folder target) { - if (folder == null) { + + if (folder + == null) { throw new IllegalArgumentException("Can't move folder null"); } if (target == null) { throw new IllegalArgumentException( - "Can't move a folder to folder null"); + "Can't move a folder to folder null"); + } + + final FolderIsMovable status = folderIsMovable(folder, target); + switch (status) { + case YES: { + final Folder source = folder.getParentFolder(); + categoryManager.removeSubCategoryFromCategory(folder, source); + final boolean sameName = target.getSubCategories() + .stream() + .anyMatch(subCategory -> folder.getName().equals( + subCategory + .getName())); + if (sameName) { + final String name = String.format("%s_1", folder.getName()); + folder.setName(name); + folder.setDisplayName(name); + + final KernelConfig kernelConfig = confManager. + findConfiguration( + KernelConfig.class); + folder.getTitle().addValue(kernelConfig.getDefaultLocale(), + name); + } + categoryManager.addSubCategoryToCategory(folder, target); + break; + } + case IS_ROOT_FOLDER: + throw new IllegalArgumentException(String.format( + "The folder \"%s\" to move is a root folder can can't " + + "be moved.", + getFolderPath(folder))); + case SAME_FOLDER: + throw new IllegalArgumentException( + "The folder to move and the target folder are the same " + + "folder."); + case DIFFERENT_SECTIONS: + throw new IllegalArgumentException(String.format( + "Folders can't be moved between content section. The " + + "folder \"%s\" to move belongs to section " + + "\"%s\", the target folder \"%s\" belongs to " + + "section \"%s\".", + getFolderPath(folder), + folder.getSection().getDisplayName(), + getFolderPath(target), + target.getSection().getDisplayName())); + case DIFFERENT_TYPES: + throw new IllegalArgumentException( + "The folder to move is a \"%s\"," + + "but the target folder is a \"%s\" folder."); + case HAS_LIVE_ITEMS: + throw new IllegalArgumentException(String.format( + "Can't move folder \"%s\" because some items in the " + + "folder or its sub folder are live.", + getFolderPath(folder, true))); + default: + throw new IllegalArgumentException(String.format( + "Unexpected return value from #folderIsMovable: %s", + status.toString())); + } + +// if (folder.getParentFolder() +// == null) { +// throw new IllegalArgumentException(String.format( +// "The folder \"%s\" to move is a root folder can can't be moved.", +// getFolderPath(folder))); +// } +// +// if (folder.equals(target)) { +// throw new IllegalArgumentException( +// "The folder to move and the target folder are the same folder."); +// } +// +// if (!folder.getSection() +// .equals(target.getSection())) { +// throw new IllegalArgumentException(String.format( +// "Folders can't be moved between content section. The " +// + "folder \"%s\" to move belongs to section \"%s\", " +// + "the target folder \"%s\" belongs to section \"%s\".", +// getFolderPath(folder), +// folder.getSection().getDisplayName(), +// getFolderPath(target), +// target.getSection().getDisplayName())); +// } +// +// if (folder.getType() +// != target.getType()) { +// throw new IllegalArgumentException("The folder to move is a \"%s\"," +// + "but the target folder is a \"%s\" folder."); +// } +// +// if (liveItemsInFolder(folder)) { +// throw new IllegalArgumentException(String.format( +// "Can't move folder \"%s\" because some items in the folder or" +// + "its sub folder are live.", +// getFolderPath(folder, true))); +// } +// +// final Folder source = folder.getParentFolder(); +// +// categoryManager.removeSubCategoryFromCategory(folder, source); +// final boolean sameName = target.getSubCategories() +// .stream() +// .anyMatch(subCategory -> folder.getName().equals(subCategory +// .getName())); +// if (sameName) { +// final String name = String.format("%s_1", folder.getName()); +// folder.setName(name); +// folder.setDisplayName(name); +// +// final KernelConfig kernelConfig = confManager.findConfiguration( +// KernelConfig.class); +// folder.getTitle().addValue(kernelConfig.getDefaultLocale(), name); +// } +// +// categoryManager.addSubCategoryToCategory(folder, target); + } + + public FolderIsMovable folderIsMovable(final Folder folder, + final Folder target) { + if (folder == null) { + throw new IllegalArgumentException("Can't check if null is movable."); + } + + if (target == null) { + throw new IllegalArgumentException( + "Can't check if a server can be moved to null."); } if (folder.getParentFolder() == null) { - throw new IllegalArgumentException(String.format( - "The folder \"%s\" to move is a root folder can can't be moved.", - getFolderPath(folder))); + return FolderIsMovable.IS_ROOT_FOLDER; } if (folder.equals(target)) { - throw new IllegalArgumentException( - "The folder to move and the target folder are the same folder."); + return FolderIsMovable.SAME_FOLDER; } if (!folder.getSection().equals(target.getSection())) { - throw new IllegalArgumentException(String.format( - "Folders can't be moved between content section. The " - + "folder \"%s\" to move belongs to section \"%s\", " - + "the target folder \"%s\" belongs to section \"%s\".", - getFolderPath(folder), - folder.getSection().getDisplayName(), - getFolderPath(target), - target.getSection().getDisplayName())); + return FolderIsMovable.DIFFERENT_SECTIONS; } if (folder.getType() != target.getType()) { - throw new IllegalArgumentException("The folder to move is a \"%s\"," - + "but the target folder is a \"%s\" folder."); + return FolderIsMovable.DIFFERENT_TYPES; } if (liveItemsInFolder(folder)) { - throw new IllegalArgumentException(String.format( - "Can't move folder \"%s\" because some items in the folder or" - + "its sub folder are live.", - getFolderPath(folder, true))); + return FolderIsMovable.HAS_LIVE_ITEMS; } - final Folder source = folder.getParentFolder(); - categoryManager.removeSubCategoryFromCategory(folder, source); - final boolean sameName = target.getSubCategories() - .stream() - .anyMatch(subCategory -> folder.getName().equals(subCategory - .getName())); - if (sameName) { - final String name = String.format("%s_1", folder.getName()); - folder.setName(name); - folder.setDisplayName(name); - - final KernelConfig kernelConfig = confManager.findConfiguration( - KernelConfig.class); - folder.getTitle().addValue(kernelConfig.getDefaultLocale(), name); - } - categoryManager.addSubCategoryToCategory(folder, target); + return FolderIsMovable.YES; } /** @@ -199,19 +378,19 @@ public class FolderManager { * @param folder The folder to check for live items. * * @return {@code true} if there any live items in the folder or its sub - * folders, {@code false} if not. + * folders, {@code false} if not. */ private boolean liveItemsInFolder(final Folder folder) { final boolean liveItemsInFolder = folder.getObjects() - .stream() - .map(categorization -> categorization.getCategorizedObject()) - .filter(object -> object instanceof ContentItem) - .map(object -> (ContentItem) object) - .anyMatch(item -> itemManager.isLive(item)); + .stream() + .map(categorization -> categorization.getCategorizedObject()) + .filter(object -> object instanceof ContentItem) + .map(object -> (ContentItem) object) + .anyMatch(item -> itemManager.isLive(item)); final boolean liveItemsInSubFolders = folder.getSubFolders() - .stream() - .anyMatch(subFolder -> liveItemsInFolder(subFolder)); + .stream() + .anyMatch(subFolder -> liveItemsInFolder(subFolder)); return liveItemsInFolder || liveItemsInSubFolders; } @@ -222,7 +401,7 @@ public class FolderManager { * @param folder The folder. * * @return The path of the folder as a UNIX-like path, but without the - * content section as prefix. + * content section as prefix. */ public String getFolderPath(final Folder folder) { return getFolderPath(folder, false); @@ -231,19 +410,19 @@ public class FolderManager { /** * Returns the path of folder. * - * @param folder The folder. + * @param folder The folder. * @param withContentSection Whether to include the content section in the - * path. + * path. * * @return The path of the folder as a UNIX-like path, optionally with the - * content section the folder belongs to as prefix.. + * content section the folder belongs to as prefix.. */ public String getFolderPath(final Folder folder, final boolean withContentSection) { if (folder == null) { throw new IllegalArgumentException("Can't generate a path for null."); } - + final List tokens = new ArrayList<>(); tokens.add(folder.getName()); diff --git a/ccm-core/pom.xml b/ccm-core/pom.xml index 20b1cbd27..c6d49183b 100644 --- a/ccm-core/pom.xml +++ b/ccm-core/pom.xml @@ -239,7 +239,7 @@ --> - + src/main/resources true @@ -555,7 +555,7 @@ org.apache.maven.plugins maven-project-info-reports-plugin - 2.8.1 + 2.9 diff --git a/pom.xml b/pom.xml index d644eaa12..8edbfccf4 100644 --- a/pom.xml +++ b/pom.xml @@ -201,11 +201,11 @@ wildfly-maven-plugin 1.1.0.Alpha8 - + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.9 +