CCM NG/ccm-cms FolderBrowser: Link for deleting empty folders now shows up.

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

Former-commit-id: 9af0a34a98
pull/2/head
jensp 2017-02-22 09:45:48 +00:00
parent b2966f9392
commit 4b5ce9db84
3 changed files with 198 additions and 143 deletions

View File

@ -21,6 +21,7 @@ package com.arsdigita.cms.ui.folder;
import com.arsdigita.kernel.KernelConfig;
import org.libreccm.categorization.Categorization;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.core.CcmObject;
import org.libreccm.core.CcmObjectRepository;
@ -71,6 +72,9 @@ public class FolderBrowserController {
@Inject
private EntityManager entityManager;
@Inject
private CategoryManager categoryManager;
@Inject
private CcmObjectRepository objectRepo;
@ -326,6 +330,8 @@ public class FolderBrowserController {
row.setTitle(folder.getTitle().getValue(defaultLocale));
}
row.setFolder(true);
row.setDeletable(!categoryManager.hasSubCategories(folder)
&& !categoryManager.hasObjects(folder));
return row;
}

View File

@ -78,14 +78,25 @@ import javax.xml.bind.annotation.XmlRootElement;
@NamedQuery(
name = "Category.findByName",
query = "SELECT c FROM Category c WHERE c.name = :name")
,
@NamedQuery(
name = "Category.hasObjects",
query = "SELECT (CASE WHEN COUNT(c) > 0 THEN true ELSE false END) "
+ "FROM Categorization c "
+ "WHERE c.category = :category")
,
@NamedQuery(
name = "Category.hasSubCategories",
query = "SELECT (CASE WHEN COUNT(c) > 0 THEN true ELSE false END) "
+ "FROM Category c "
+ "WHERE c.parentCategory = :category")
})
@NamedEntityGraphs({
@NamedEntityGraph(
name = "Category.withSubCategoriesAndObjects",
attributeNodes = {
@NamedAttributeNode(value = "subCategories"
),
}
),}
)
})
@XmlRootElement(name = "category", namespace = CAT_XML_NS)

View File

@ -158,11 +158,37 @@ public class CategoryManager {
});
}
public boolean hasSubCategories(final Category category) {
Objects.requireNonNull(
category,
"Can't determine if Category null has sub categories.");
final TypedQuery<Boolean> query = entityManager.createNamedQuery(
"Category.hasSubCategories", Boolean.class);
query.setParameter("category", category);
return query.getSingleResult();
}
public boolean hasObjects(final Category category) {
Objects.requireNonNull(category,
"Can't determine if category null has objects.");
final TypedQuery<Boolean> query = entityManager.createNamedQuery(
"Category.hasObjects", Boolean.class);
query.setParameter("category", category);
return query.getSingleResult();
}
/**
* Check if an object is assigned to a category.
*
* @param category The category
* @param object The object
*
* @return {@code true} if the provided {@code object} is assigned to the
* provided {@code category}, {@code false} otherwise.
*/
@ -189,6 +215,7 @@ public class CategoryManager {
* @param object The object
* @param type The type with which the object has been assigned to the
* category. the type may be {@code null}.
*
* @return {@code true} if the provided {@code object} is assigned to the
* provided {@code category} using the provided {@code type}.
*/
@ -289,13 +316,14 @@ public class CategoryManager {
* The value of the {@code order} property of the object after the provided
* is decreased by one. Effectively the two objects are swapped.
*
* @param object The object which {@code order} property is decreased. Can't
* be {@code null}.
* @param object The object which {@code order} property is decreased.
* Can't be {@code null}.
* @param category The category to which the object is assigned. Can't be
* {@code null}.
*
* @throws ObjectNotAssignedToCategoryException Throws if the provided
* object is not assigned to the provided category.
* object is not assigned to
* the provided category.
*/
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
@ -362,13 +390,14 @@ public class CategoryManager {
* The value of the {@code order} property of the object before the provided
* is increased by one. Effectively the two objects are swapped.
*
* @param object The object which {@code order} property is decreased. Can't
* be {@code null}.
* @param object The object which {@code order} property is decreased.
* Can't be {@code null}.
* @param category The category to which the object is assigned. Can't be
* {@code null}.
*
* @throws ObjectNotAssignedToCategoryException Throws if the provided
* object is not assigned to the provided category.
* object is not assigned to
* the provided category.
*/
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
@ -441,7 +470,9 @@ public class CategoryManager {
* are assigned. Can't be {@code null}.
*
* @throws ObjectNotAssignedToCategoryException Thrown if one or both of the
* provided objects are not assigned to the provided category.
* provided objects are not
* assigned to the provided
* category.
*/
// public void swapObjects(final CcmObject objectA,
// final CcmObject objectB,
@ -517,7 +548,8 @@ public class CategoryManager {
* @param parentCategory The parent category. Can't be {@code null}.
*
* @throws IllegalArgumentException If the provided subcategory is not
* assigned to the provided parent category.
* assigned to the provided parent
* category.
*/
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
@ -555,13 +587,14 @@ public class CategoryManager {
* objects is decreased by one. If the object is the last one this method
* has not effect.
*
* @param subCategory The category which order property is increased. Can't
* be {@code null}.
* @param subCategory The category which order property is increased.
* Can't be {@code null}.
* @param parentCategory The parent category of the category. Can't be
* {@code null}.
*
* @throws IllegalArgumentException If the provided subcategory is not a
* subcategory of the provided parent category.
* subcategory of the provided parent
* category.
*/
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
@ -629,13 +662,14 @@ public class CategoryManager {
* preceeding objects is increased by one. If the object is the last one
* this method has not effect.
*
* @param subCategory The category which order property is increased. Can't
* be {@code null}.
* @param subCategory The category which order property is increased.
* Can't be {@code null}.
* @param parentCategory The parent category of the category. Can't be
* {@code null}.
*
* @throws IllegalArgumentException If the provided subcategory is not a
* subcategory of the provided parent category.
* subcategory of the provided parent
* category.
*/
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
@ -764,8 +798,11 @@ public class CategoryManager {
* @param category The category whose index object is set or changed.
* @param object The new index object for the category. The object must be
* assigned to the category.
*
* @throws ObjectNotAssignedToCategoryException If the provided
* {@code object} is not assigned to the provided {@code category}.
* {@code object} is not
* assigned to the provided
* {@code category}.
*/
@Transactional(Transactional.TxType.REQUIRED)
public void setIndexObject(final Category category,
@ -836,4 +873,5 @@ public class CategoryManager {
result.forEach(categorization -> categorization.setIndex(false));
result.forEach(categorization -> entityManager.merge(categorization));
}
}