CCM NG:
- 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-94f89814c4dfpull/2/head
parent
a2866cef95
commit
689991f364
|
|
@ -93,13 +93,18 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration>
|
||||
<overlays>
|
||||
<webResources>
|
||||
<resource>
|
||||
<directory>../ccm-theme-foundry/src/main/resources/themes</directory>
|
||||
</resource>
|
||||
</webResources>
|
||||
<!--<overlays>
|
||||
<overlay>
|
||||
<groupId>org.libreccm</groupId>
|
||||
<artifactId>ccm-theme-foundry</artifactId>
|
||||
<type>jar</type>
|
||||
</overlay>
|
||||
</overlays>
|
||||
</overlays>-->
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
|
|
|||
|
|
@ -170,7 +170,6 @@
|
|||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.7.5.201505241946</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-prepare-agent</id>
|
||||
|
|
|
|||
|
|
@ -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<String> tokens = new ArrayList<>();
|
||||
|
||||
tokens.add(folder.getName());
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@
|
|||
</resource>
|
||||
</resources>-->
|
||||
|
||||
<resources>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
|
|
@ -555,7 +555,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>2.8.1</version>
|
||||
<version>2.9</version>
|
||||
<reportSets>
|
||||
<reportSet>
|
||||
<reports>
|
||||
|
|
|
|||
10
pom.xml
10
pom.xml
|
|
@ -201,11 +201,11 @@
|
|||
<artifactId>wildfly-maven-plugin</artifactId>
|
||||
<version>1.1.0.Alpha8</version>
|
||||
</plugin>
|
||||
<!--<plugin>
|
||||
<groupId>org.jboss.tattletale</groupId>
|
||||
<artifactId>tattletale-maven</artifactId>
|
||||
<version>1.1.2.Final</version>
|
||||
</plugin>-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>2.9</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue