CCM NG/ccm-cms: Moving folders

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4620 8810af33-2d31-482b-a856-94f89814c4df

Former-commit-id: 1f8e40d392
pull/2/head
jensp 2017-03-03 18:05:09 +00:00
parent 39d695730c
commit 7742b16afc
8 changed files with 239 additions and 198 deletions

View File

@ -670,13 +670,15 @@ public class FolderBrowserController {
"No folder with ID %d found in database. " "No folder with ID %d found in database. "
+ "Where did that ID come form?", + "Where did that ID come form?",
objectId))); objectId)));
if (folder.getParentFolder() == null) { final Optional<Folder> parentFolder = folderManager.getParentFolder(
folder);
if (parentFolder.isPresent()) {
return Optional.empty(); return Optional.empty();
} else { } else {
return Optional.ofNullable(String.format( return Optional.ofNullable(String.format(
"%s%d", "%s%d",
FOLDER_BROWSER_KEY_PREFIX_FOLDER, FOLDER_BROWSER_KEY_PREFIX_FOLDER,
folder.getParentFolder().getObjectId())); parentFolder.get().getObjectId()));
} }
} }

View File

@ -73,6 +73,7 @@ import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager; import org.libreccm.categorization.CategoryManager;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject; import org.libreccm.core.CcmObject;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionChecker;
import org.libreccm.security.Shiro; import org.libreccm.security.Shiro;
import org.librecms.CmsConstants; import org.librecms.CmsConstants;
@ -549,6 +550,8 @@ public class FolderManipulator extends SimpleContainer implements
ContentItemManager.class); ContentItemManager.class);
final FolderBrowserController controller = cdiUtil.findBean( final FolderBrowserController controller = cdiUtil.findBean(
FolderBrowserController.class); FolderBrowserController.class);
final FolderManager folderManager = cdiUtil.findBean(
FolderManager.class);
final PermissionChecker permissionChecker = cdiUtil.findBean( final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class); PermissionChecker.class);
@ -564,8 +567,44 @@ public class FolderManipulator extends SimpleContainer implements
name = folder.getName(); name = folder.getName();
//Check if folder or subfolder contains live items //Check if folder or subfolder contains live items
if (isMove(state) && controller.hasLiveItems(folder)) { if (isMove(state)) {
addErrorMessage(data, "cms.ui.folder.item_is_live", name); final FolderManager.FolderIsMovable movable = folderManager
.folderIsMovable(folder, target);
switch (movable) {
case DIFFERENT_SECTIONS:
addErrorMessage(data,
"cms.ui.folder.different_sections",
name);
break;
case HAS_LIVE_ITEMS:
addErrorMessage(data,
"cms.ui.folder.item_is_live",
name);
break;
case DIFFERENT_TYPES:
addErrorMessage(data,
"cms.ui.folder.different_folder_types",
name);
break;
case IS_ROOT_FOLDER:
addErrorMessage(data,
"cms.ui.folder.is_root_folder",
name);
break;
case SAME_FOLDER:
addErrorMessage(data,
"cms.ui.folder.same_folder",
name);
break;
case YES:
//Nothing
break;
default:
throw new UnexpectedErrorException(String.format(
"Unknown state '%s' for '%s'.",
movable,
FolderManager.FolderIsMovable.class.getName()));
}
} }
object = folder; object = folder;

View File

@ -97,6 +97,14 @@ import static org.librecms.CmsConstants.*;
// + "AND (LOWER(c.categorizedObject.displayName) LIKE :term " // + "AND (LOWER(c.categorizedObject.displayName) LIKE :term "
// + "OR LOWER(c.categorizedObject.name.value) LIKE :term)") // + "OR LOWER(c.categorizedObject.name.value) LIKE :term)")
// , // ,
@NamedQuery(
name = "Folder.hasLiveItems",
query = "SELECT (CASE WHEN COUNT(i) > 0 THEN true ELSE false END) "
+ "FROM ContentItem i JOIN i.categories c "
+ "WHERE c.category = :folder "
+ "AND i.version = org.librecms.contentsection.ContentItemVersion.LIVE"
)
,
@NamedQuery( @NamedQuery(
name = "Folder.findObjects", name = "Folder.findObjects",
query = "SELECT o FROM CcmObject o " query = "SELECT o FROM CcmObject o "
@ -109,8 +117,8 @@ import static org.librecms.CmsConstants.*;
+ "AND i.version = " + "AND i.version = "
+ "org.librecms.contentsection.ContentItemVersion.DRAFT " + "org.librecms.contentsection.ContentItemVersion.DRAFT "
+ "AND (LOWER(i.displayName) LIKE LOWER(:term) " + "AND (LOWER(i.displayName) LIKE LOWER(:term) "
// + "OR LOWER(i.name.values) LIKE LOWER(:term)" // + "OR LOWER(i.name.values) LIKE LOWER(:term)"
+ ")) " + ")) "
+ "ORDER BY o.displayName" + "ORDER BY o.displayName"
// query = "SELECT o FROM CcmObject o " // query = "SELECT o FROM CcmObject o "
// + "WHERE o IN (SELECT f FROM Folder f " // + "WHERE o IN (SELECT f FROM Folder f "
@ -140,8 +148,8 @@ import static org.librecms.CmsConstants.*;
+ "AND i.version = " + "AND i.version = "
+ "org.librecms.contentsection.ContentItemVersion.DRAFT " + "org.librecms.contentsection.ContentItemVersion.DRAFT "
+ "AND (LOWER(i.displayName) LIKE LOWER(:term) " + "AND (LOWER(i.displayName) LIKE LOWER(:term) "
// + "OR LOWER(i.name.values) LIKE LOWER(:term)" // + "OR LOWER(i.name.values) LIKE LOWER(:term)"
+ "))" + "))"
// query = "SELECT COUNT(o) FROM CcmObject o " // query = "SELECT COUNT(o) FROM CcmObject o "
// + "WHERE o IN (SELECT f FROM Folder f " // + "WHERE o IN (SELECT f FROM Folder f "
// + "WHERE f.parentCategory = :parent " // + "WHERE f.parentCategory = :parent "
@ -193,7 +201,7 @@ public class Folder extends Category implements Serializable {
public Folder getParentFolder() { public Folder getParentFolder() {
return (Folder) getParentCategory(); return (Folder) getParentCategory();
} }
/** /**
* A convenient method for getting all sub folders of folder. * A convenient method for getting all sub folders of folder.
* *

View File

@ -34,6 +34,9 @@ import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional; import javax.transaction.Transactional;
/** /**
@ -43,16 +46,19 @@ import javax.transaction.Transactional;
*/ */
@RequestScoped @RequestScoped
public class FolderManager { public class FolderManager {
@Inject
private EntityManager entityManager;
@Inject @Inject
private ConfigurationManager confManager; private ConfigurationManager confManager;
@Inject @Inject
private FolderRepository folderRepo; private FolderRepository folderRepo;
@Inject @Inject
private CategoryManager categoryManager; private CategoryManager categoryManager;
@Inject @Inject
private ContentItemManager itemManager; private ContentItemManager itemManager;
@ -110,22 +116,33 @@ public class FolderManager {
*/ */
HAS_LIVE_ITEMS HAS_LIVE_ITEMS
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public Optional<Folder> getParentFolder(final Folder folder) { public Optional<Folder> getParentFolder(final Folder folder) {
Objects.requireNonNull(folder); // Objects.requireNonNull(folder);
final Optional<Folder> theFolder = folderRepo.findById(folder. // final Optional<Folder> theFolder = folderRepo.findById(folder.
getObjectId()); // getObjectId());
if (!theFolder.isPresent()) { // if (!theFolder.isPresent()) {
throw new UnexpectedErrorException(String.format( // throw new UnexpectedErrorException(String.format(
"The folder %s should be in the database but is not.", // "The folder %s should be in the database but is not.",
Objects.toString(folder))); // Objects.toString(folder)));
} // }
final Category parentCategory = theFolder.get().getParentCategory(); // final Category parentCategory = theFolder.get().getParentCategory();
if (parentCategory == null) { // if (parentCategory == null) {
return Optional.empty(); // return Optional.empty();
} else { // } else {
// return folderRepo.findById(parentCategory.getObjectId());
// }
final TypedQuery<Category> query = entityManager.createNamedQuery(
"Category.findParentCategory", Category.class);
query.setParameter("category", folder);
try {
final Category parentCategory = query.getSingleResult();
return folderRepo.findById(parentCategory.getObjectId()); return folderRepo.findById(parentCategory.getObjectId());
} catch (NoResultException ex) {
return Optional.empty();
} }
} }
@ -134,7 +151,7 @@ public class FolderManager {
* 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
* the provided parent folder. * 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. * @param parent The folder in which the new folder is generated.
* *
* @return The new folder. * @return The new folder.
@ -143,17 +160,17 @@ public class FolderManager {
public Folder createFolder(final String name, final Folder parent) { public Folder createFolder(final String name, final Folder parent) {
if (parent == null) { if (parent == null) {
throw new IllegalArgumentException( 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()) { if (name == null || name.trim().isEmpty()) {
throw new IllegalArgumentException( 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( final KernelConfig kernelConfig = confManager.findConfiguration(
KernelConfig.class); KernelConfig.class);
final Folder folder = new Folder(); final Folder folder = new Folder();
folder.setName(name); folder.setName(name);
folder.setDisplayName(name); folder.setDisplayName(name);
@ -161,30 +178,30 @@ public class FolderManager {
folder.setSection(parent.getSection()); folder.setSection(parent.getSection());
folder.setType(parent.getType()); folder.setType(parent.getType());
folderRepo.save(folder); folderRepo.save(folder);
categoryManager.addSubCategoryToCategory(folder, parent); categoryManager.addSubCategoryToCategory(folder, parent);
return folder; return folder;
} }
public FolderIsDeletable folderIsDeletable(final Folder folder) { public FolderIsDeletable folderIsDeletable(final Folder folder) {
if (folder == null) { if (folder == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Can't check if null is deletable."); "Can't check if null is deletable.");
} }
if (!folder.getSubCategories().isEmpty()) { if (!folder.getSubCategories().isEmpty()) {
return FolderIsDeletable.HAS_SUBCATEGORIES; return FolderIsDeletable.HAS_SUBCATEGORIES;
} }
if (!folder.getObjects().isEmpty()) { if (!folder.getObjects().isEmpty()) {
return FolderIsDeletable.IS_NOT_EMPTY; return FolderIsDeletable.IS_NOT_EMPTY;
} }
if (!getParentFolder(folder).isPresent()) { if (!getParentFolder(folder).isPresent()) {
return FolderIsDeletable.IS_ROOT_FOLDER; return FolderIsDeletable.IS_ROOT_FOLDER;
} }
return FolderIsDeletable.YES; return FolderIsDeletable.YES;
} }
@ -198,7 +215,7 @@ public class FolderManager {
if (folder == null) { if (folder == null) {
throw new IllegalArgumentException("Can't delete folder null"); throw new IllegalArgumentException("Can't delete folder null");
} }
final FolderIsDeletable status = folderIsDeletable(folder); final FolderIsDeletable status = folderIsDeletable(folder);
switch (status) { switch (status) {
case YES: case YES:
@ -206,20 +223,20 @@ public class FolderManager {
break; break;
case HAS_SUBCATEGORIES: 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: case IS_NOT_EMPTY:
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: case IS_ROOT_FOLDER:
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: default:
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"Unexpected return value from #folderIsDeletable: " "Unexpected return value from #folderIsDeletable: "
+ "\"%s\".", + "\"%s\".",
status.toString())); status.toString()));
} }
} }
@ -234,176 +251,140 @@ 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) {
Objects.requireNonNull(folder, "Can't move folder null"); Objects.requireNonNull(folder, "Can't move folder null");
Objects.requireNonNull(target, "Can't move a folder to folder null"); Objects.requireNonNull(target, "Can't move a folder to folder null");
final FolderIsMovable status = folderIsMovable(folder, target); final Folder movingFolder = folderRepo.findById(folder.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String.format(
"No folder with ID %d in the database. Where did that ID come from?",
folder.getObjectId())));
final Folder targetFolder = folderRepo.findById(target.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String.format(
"No folder with ID %d in the database. Where did that ID come from?",
target.getObjectId())));
final FolderIsMovable status = folderIsMovable(movingFolder,
targetFolder);
switch (status) { switch (status) {
case YES: { case YES: {
final Folder source = getParentFolder(folder).get(); final Folder source = getParentFolder(movingFolder).get();
categoryManager.removeSubCategoryFromCategory(folder, source); categoryManager.removeSubCategoryFromCategory(movingFolder,
final boolean sameName = target.getSubCategories() source);
.stream() final boolean sameName = targetFolder.getSubCategories()
.anyMatch(subCategory -> folder.getName().equals( .stream()
subCategory.getName())); .anyMatch(subCategory -> movingFolder.getName().equals(
subCategory.getName()));
if (sameName) { if (sameName) {
final String name = String.format("%s_1", folder.getName()); final String name = String.format("%s_1", movingFolder
folder.setName(name); .getName());
folder.setDisplayName(name); movingFolder.setName(name);
movingFolder.setDisplayName(name);
final KernelConfig kernelConfig = confManager. final KernelConfig kernelConfig = confManager.
findConfiguration( findConfiguration(
KernelConfig.class); KernelConfig.class);
folder.getTitle().addValue(kernelConfig.getDefaultLocale(), movingFolder.getTitle().addValue(
name); kernelConfig.getDefaultLocale(), name);
} }
categoryManager.addSubCategoryToCategory(folder, target); categoryManager.addSubCategoryToCategory(movingFolder,
targetFolder);
break; break;
} }
case IS_ROOT_FOLDER: case IS_ROOT_FOLDER:
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"The folder \"%s\" to move is a root folder can can't " "The movingFolder \"%s\" to move is a root movingFolder can can't "
+ "be moved.", + "be moved.",
getFolderPath(folder))); getFolderPath(movingFolder)));
case SAME_FOLDER: case SAME_FOLDER:
throw new IllegalArgumentException( throw new IllegalArgumentException(
"The folder to move and the target folder are the same " "The movingFolder to move and the targetFolder movingFolder are the same "
+ "folder."); + "movingFolder.");
case DIFFERENT_SECTIONS: case DIFFERENT_SECTIONS:
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"Folders can't be moved between content section. The " "Folders can't be moved between content section. The "
+ "folder \"%s\" to move belongs to section " + "movingFolder \"%s\" to move belongs to section "
+ "\"%s\", the target folder \"%s\" belongs to " + "\"%s\", the targetFolder movingFolder \"%s\" belongs to "
+ "section \"%s\".", + "section \"%s\".",
getFolderPath(folder), getFolderPath(movingFolder),
folder.getSection().getDisplayName(), movingFolder.getSection().getDisplayName(),
getFolderPath(target), getFolderPath(targetFolder),
target.getSection().getDisplayName())); targetFolder.getSection().getDisplayName()));
case DIFFERENT_TYPES: case DIFFERENT_TYPES:
throw new IllegalArgumentException( throw new IllegalArgumentException(
"The folder to move is a \"%s\"," "The movingFolder to move is a \"%s\","
+ "but the target folder is a \"%s\" folder."); + "but the targetFolder movingFolder is a \"%s\" movingFolder.");
case HAS_LIVE_ITEMS: case HAS_LIVE_ITEMS:
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"Can't move folder \"%s\" because some items in the " "Can't move movingFolder \"%s\" because some items in the "
+ "folder or its sub folder are live.", + "movingFolder or its sub movingFolder are live.",
getFolderPath(folder, true))); getFolderPath(movingFolder, true)));
default: default:
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"Unexpected return value from #folderIsMovable: %s", "Unexpected return value from #movingFolderIsMovable: %s",
status.toString())); 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);
} }
@Transactional(Transactional.TxType.REQUIRED)
public FolderIsMovable folderIsMovable(final Folder folder, public FolderIsMovable folderIsMovable(final Folder folder,
final Folder target) { final Folder target) {
if (folder == null) {
throw new IllegalArgumentException("Can't check if null is movable."); Objects.requireNonNull(folder,
} "Can't check if null is movable.");
Objects.requireNonNull(target,
if (target == null) { "Can't check if a server can be moved to null.");
throw new IllegalArgumentException(
"Can't check if a server can be moved to null."); final Folder movingFolder = folderRepo.findById(folder.getObjectId())
} .orElseThrow(() -> new IllegalArgumentException(String.format(
"No folder with ID %d in the datbase. Where did that ID come from?",
if (!getParentFolder(folder).isPresent()) { folder.getObjectId())));
final Folder targetFolder = folderRepo.findById(target.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String.format(
"No folder with ID %d in the datbase. Where did that ID come from?",
target.getObjectId())));
if (!getParentFolder(movingFolder).isPresent()) {
return FolderIsMovable.IS_ROOT_FOLDER; return FolderIsMovable.IS_ROOT_FOLDER;
} }
if (folder.equals(target)) { if (movingFolder.equals(targetFolder)) {
return FolderIsMovable.SAME_FOLDER; return FolderIsMovable.SAME_FOLDER;
} }
if (!folder.getSection().equals(target.getSection())) { if (!movingFolder.getSection().equals(targetFolder.getSection())) {
return FolderIsMovable.DIFFERENT_SECTIONS; return FolderIsMovable.DIFFERENT_SECTIONS;
} }
if (folder.getType() != target.getType()) { if (movingFolder.getType() != targetFolder.getType()) {
return FolderIsMovable.DIFFERENT_TYPES; return FolderIsMovable.DIFFERENT_TYPES;
} }
if (liveItemsInFolder(folder)) { if (liveItemsInFolder(movingFolder)) {
return FolderIsMovable.HAS_LIVE_ITEMS; return FolderIsMovable.HAS_LIVE_ITEMS;
} }
return FolderIsMovable.YES; return FolderIsMovable.YES;
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public void copyFolder(final Folder folder, final Folder target) { public void copyFolder(final Folder folder, final Folder target) {
Objects.requireNonNull(folder, "Can't move null to a folder."); Objects.requireNonNull(folder, "Can't move null to a folder.");
Objects.requireNonNull(target, "Can't move a folder to null."); Objects.requireNonNull(target, "Can't move a folder to null.");
final Folder copy = createFolder(folder.getName(), target); final Folder copy = createFolder(folder.getName(), target);
final List<ContentItem> items = folder.getObjects() final List<ContentItem> items = folder.getObjects()
.stream() .stream()
.map(categorization -> categorization.getCategorizedObject()) .map(categorization -> categorization.getCategorizedObject())
.filter(object -> object instanceof ContentItem) .filter(object -> object instanceof ContentItem)
.map(object -> (ContentItem) object) .map(object -> (ContentItem) object)
.collect(Collectors.toList()); .collect(Collectors.toList());
for (final ContentItem item : items) { for (final ContentItem item : items) {
itemManager.copy(item, target); itemManager.copy(item, target);
} }
for(final Folder subFolder : folder.getSubFolders()) { for (final Folder subFolder : folder.getSubFolders()) {
copyFolder(subFolder, copy); copyFolder(subFolder, copy);
} }
} }
@ -415,20 +396,24 @@ public class FolderManager {
* @param folder The folder to check for live items. * @param folder The folder to check for live items.
* *
* @return {@code true} if there any live items in the folder or its sub * @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) { private boolean liveItemsInFolder(final Folder folder) {
final boolean liveItemsInFolder = folder.getObjects() // final boolean liveItemsInFolder = folder.getObjects()
.stream() // .stream()
.map(categorization -> categorization.getCategorizedObject()) // .map(categorization -> categorization.getCategorizedObject())
.filter(object -> object instanceof ContentItem) // .filter(object -> object instanceof ContentItem)
.map(object -> (ContentItem) object) // .map(object -> (ContentItem) object)
.anyMatch(item -> itemManager.isLive(item)); // .anyMatch(item -> itemManager.isLive(item));
final TypedQuery<Boolean> query = entityManager.createNamedQuery(
"Folder.hasLiveItems", Boolean.class);
query.setParameter("folder", folder);
final boolean liveItemsInFolder = query.getSingleResult();
final boolean liveItemsInSubFolders = folder.getSubFolders() final boolean liveItemsInSubFolders = folder.getSubFolders()
.stream() .stream()
.anyMatch(subFolder -> liveItemsInFolder(subFolder)); .anyMatch(subFolder -> liveItemsInFolder(subFolder));
return liveItemsInFolder || liveItemsInSubFolders; return liveItemsInFolder || liveItemsInSubFolders;
} }
@ -438,7 +423,7 @@ public class FolderManager {
* @param folder The folder. * @param folder The folder.
* *
* @return The path of the folder as a UNIX-like path, but without the * @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) { public String getFolderPath(final Folder folder) {
return getFolderPath(folder, false); return getFolderPath(folder, false);
@ -447,31 +432,31 @@ public class FolderManager {
/** /**
* Returns the path of folder. * Returns the path of folder.
* *
* @param folder The folder. * @param folder The folder.
* @param withContentSection Whether to include the content section in the * @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 * @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, public String getFolderPath(final Folder folder,
final boolean withContentSection) { final boolean withContentSection) {
if (folder == null) { if (folder == null) {
throw new IllegalArgumentException("Can't generate a path for null."); throw new IllegalArgumentException("Can't generate a path for null.");
} }
final List<String> tokens = new ArrayList<>(); final List<String> tokens = new ArrayList<>();
tokens.add(folder.getName()); tokens.add(folder.getName());
Folder current = folder; Folder current = folder;
while (getParentFolder(current).isPresent()) { while (getParentFolder(current).isPresent()) {
current = getParentFolder(current).get(); current = getParentFolder(current).get();
tokens.add(current.getName()); tokens.add(current.getName());
} }
Collections.reverse(tokens); Collections.reverse(tokens);
final String path = String.join("/", tokens); final String path = String.join("/", tokens);
if (withContentSection) { if (withContentSection) {
final String sectionName = folder.getSection().getDisplayName(); final String sectionName = folder.getSection().getDisplayName();
return String.format("%s:/%s/", sectionName, path); return String.format("%s:/%s/", sectionName, path);
@ -489,12 +474,12 @@ public class FolderManager {
*/ */
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
public List<Folder> getParentFolders(final Folder folder) { public List<Folder> getParentFolders(final Folder folder) {
if (folder == null) { if (folder == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Can't create a list of parent folder for folder null."); "Can't create a list of parent folder for folder null.");
} }
final List<Folder> folders = new ArrayList<>(); final List<Folder> folders = new ArrayList<>();
if (getParentFolder(folder).isPresent()) { if (getParentFolder(folder).isPresent()) {
Optional<Folder> currentFolder = getParentFolder(folder); Optional<Folder> currentFolder = getParentFolder(folder);
@ -503,9 +488,9 @@ public class FolderManager {
currentFolder = getParentFolder(currentFolder.get()); currentFolder = getParentFolder(currentFolder.get());
} }
} }
Collections.reverse(folders); Collections.reverse(folders);
return folders; return folders;
} }
} }

View File

@ -77,3 +77,4 @@ cms.ui.folder.move.action=Move
cms.ui.folder.copy.action=Copy cms.ui.folder.copy.action=Copy
cms.ui.folder.publish.action=(Re-)publish cms.ui.folder.publish.action=(Re-)publish
cms.ui.folder.unpublish.action=Unpublish cms.ui.folder.unpublish.action=Unpublish
cms.ui.folder.same_folder=Folders are equal

View File

@ -77,3 +77,4 @@ cms.ui.folder.move.action=Verschieben
cms.ui.folder.copy.action=Kopieren cms.ui.folder.copy.action=Kopieren
cms.ui.folder.publish.action=(Re-)Publizieren cms.ui.folder.publish.action=(Re-)Publizieren
cms.ui.folder.unpublish.action=Depublizieren cms.ui.folder.unpublish.action=Depublizieren
cms.ui.folder.same_folder=Folders are equal

View File

@ -72,3 +72,4 @@ cms.ui.folder.move.action=
cms.ui.folder.copy.action= cms.ui.folder.copy.action=
cms.ui.folder.publish.action= cms.ui.folder.publish.action=
cms.ui.folder.unpublish.action= cms.ui.folder.unpublish.action=
cms.ui.folder.same_folder=Der als Ziel gew\u00e4hlte Ordner ist der gleiche Ordner wie der zu verschiebene Ordner.

View File

@ -79,6 +79,10 @@ import javax.xml.bind.annotation.XmlRootElement;
name = "Category.findByName", name = "Category.findByName",
query = "SELECT c FROM Category c WHERE c.name = :name") query = "SELECT c FROM Category c WHERE c.name = :name")
, ,
@NamedQuery(
name = "Category.findParentCategory",
query = "SELECT c.parentCategory FROM Category c WHERE c = :category")
,
@NamedQuery( @NamedQuery(
name = "Category.countAssignedCategories", name = "Category.countAssignedCategories",
query = "SELECT COUNT(c) FROM Categorization c " query = "SELECT COUNT(c) FROM Categorization c "