- Changed resource integration in the web module to avoid problems when building the Maven site
- added two methods to FolderManager which can be used to check if a folder is deletable/movable. 


git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4348 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-10-04 12:19:35 +00:00
parent a2866cef95
commit 689991f364
5 changed files with 264 additions and 81 deletions

View File

@ -93,13 +93,18 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId> <artifactId>maven-war-plugin</artifactId>
<configuration> <configuration>
<overlays> <webResources>
<resource>
<directory>../ccm-theme-foundry/src/main/resources/themes</directory>
</resource>
</webResources>
<!--<overlays>
<overlay> <overlay>
<groupId>org.libreccm</groupId> <groupId>org.libreccm</groupId>
<artifactId>ccm-theme-foundry</artifactId> <artifactId>ccm-theme-foundry</artifactId>
<type>jar</type> <type>jar</type>
</overlay> </overlay>
</overlays> </overlays>-->
</configuration> </configuration>
</plugin> </plugin>

View File

@ -170,7 +170,6 @@
<plugin> <plugin>
<groupId>org.jacoco</groupId> <groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId> <artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions> <executions>
<execution> <execution>
<id>default-prepare-agent</id> <id>default-prepare-agent</id>

View File

@ -51,6 +51,61 @@ public class FolderManager {
@Inject @Inject
private ContentItemManager itemManager; 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 * 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 * and the content section to which the folder belongs are the same as for
@ -89,6 +144,27 @@ public class FolderManager {
return folder; 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. * Deletes a empty, none-root folder.
* *
@ -100,24 +176,28 @@ public class FolderManager {
throw new IllegalArgumentException("Can't delete folder null"); throw new IllegalArgumentException("Can't delete folder null");
} }
if (!folder.getSubCategories().isEmpty()) { final FolderIsDeletable status = folderIsDeletable(folder);
switch (status) {
case YES:
folderRepo.delete(folder);
break;
case HAS_SUBCATEGORIES:
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"Can't delete folder \"%s\" because the folder is not empty", "Can't delete folder \"%s\" because the folder is not empty",
getFolderPath(folder, true))); getFolderPath(folder, true)));
} case IS_NOT_EMPTY:
if (!folder.getObjects().isEmpty()) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"Can't delete folder \"%s\" because the folder is not empty.", "Can't delete folder \"%s\" because the folder is not empty.",
getFolderPath(folder))); getFolderPath(folder)));
} case IS_ROOT_FOLDER:
if (folder.getParentFolder() == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"The folder to delete is a root folder can can't be deleted."); "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()));
} }
folderRepo.delete(folder);
} }
/** /**
@ -131,7 +211,9 @@ public class FolderManager {
*/ */
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public void moveFolder(final Folder folder, final Folder target) { public void moveFolder(final Folder folder, final Folder target) {
if (folder == null) {
if (folder
== null) {
throw new IllegalArgumentException("Can't move folder null"); throw new IllegalArgumentException("Can't move folder null");
} }
@ -140,56 +222,153 @@ public class FolderManager {
"Can't move a folder to folder null"); "Can't move a folder to folder null");
} }
if (folder.getParentFolder() == null) { final FolderIsMovable status = folderIsMovable(folder, target);
throw new IllegalArgumentException(String.format( switch (status) {
"The folder \"%s\" to move is a root folder can can't be moved.", case YES: {
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(); final Folder source = folder.getParentFolder();
categoryManager.removeSubCategoryFromCategory(folder, source); categoryManager.removeSubCategoryFromCategory(folder, source);
final boolean sameName = target.getSubCategories() final boolean sameName = target.getSubCategories()
.stream() .stream()
.anyMatch(subCategory -> folder.getName().equals(subCategory .anyMatch(subCategory -> folder.getName().equals(
subCategory
.getName())); .getName()));
if (sameName) { if (sameName) {
final String name = String.format("%s_1", folder.getName()); final String name = String.format("%s_1", folder.getName());
folder.setName(name); folder.setName(name);
folder.setDisplayName(name); folder.setDisplayName(name);
final KernelConfig kernelConfig = confManager.findConfiguration( final KernelConfig kernelConfig = confManager.
findConfiguration(
KernelConfig.class); KernelConfig.class);
folder.getTitle().addValue(kernelConfig.getDefaultLocale(), name); folder.getTitle().addValue(kernelConfig.getDefaultLocale(),
name);
} }
categoryManager.addSubCategoryToCategory(folder, target); 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) {
return FolderIsMovable.IS_ROOT_FOLDER;
}
if (folder.equals(target)) {
return FolderIsMovable.SAME_FOLDER;
}
if (!folder.getSection().equals(target.getSection())) {
return FolderIsMovable.DIFFERENT_SECTIONS;
}
if (folder.getType() != target.getType()) {
return FolderIsMovable.DIFFERENT_TYPES;
}
if (liveItemsInFolder(folder)) {
return FolderIsMovable.HAS_LIVE_ITEMS;
}
return FolderIsMovable.YES;
} }
/** /**

View File

@ -555,7 +555,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId> <artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.8.1</version> <version>2.9</version>
<reportSets> <reportSets>
<reportSet> <reportSet>
<reports> <reports>

10
pom.xml
View File

@ -201,11 +201,11 @@
<artifactId>wildfly-maven-plugin</artifactId> <artifactId>wildfly-maven-plugin</artifactId>
<version>1.1.0.Alpha8</version> <version>1.1.0.Alpha8</version>
</plugin> </plugin>
<!--<plugin> <plugin>
<groupId>org.jboss.tattletale</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>tattletale-maven</artifactId> <artifactId>maven-project-info-reports-plugin</artifactId>
<version>1.1.2.Final</version> <version>2.9</version>
</plugin>--> </plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>