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-94f89814c4dfccm-docs
parent
b2d1eb997f
commit
4e1c732e57
|
|
@ -21,6 +21,7 @@ package com.arsdigita.cms.ui.folder;
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
|
||||||
import org.libreccm.categorization.Categorization;
|
import org.libreccm.categorization.Categorization;
|
||||||
|
import org.libreccm.categorization.CategoryManager;
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
import org.libreccm.configuration.ConfigurationManager;
|
||||||
import org.libreccm.core.CcmObject;
|
import org.libreccm.core.CcmObject;
|
||||||
import org.libreccm.core.CcmObjectRepository;
|
import org.libreccm.core.CcmObjectRepository;
|
||||||
|
|
@ -71,6 +72,9 @@ public class FolderBrowserController {
|
||||||
@Inject
|
@Inject
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private CategoryManager categoryManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private CcmObjectRepository objectRepo;
|
private CcmObjectRepository objectRepo;
|
||||||
|
|
||||||
|
|
@ -326,6 +330,8 @@ public class FolderBrowserController {
|
||||||
row.setTitle(folder.getTitle().getValue(defaultLocale));
|
row.setTitle(folder.getTitle().getValue(defaultLocale));
|
||||||
}
|
}
|
||||||
row.setFolder(true);
|
row.setFolder(true);
|
||||||
|
row.setDeletable(!categoryManager.hasSubCategories(folder)
|
||||||
|
&& !categoryManager.hasObjects(folder));
|
||||||
|
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,14 +78,25 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
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.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({
|
@NamedEntityGraphs({
|
||||||
@NamedEntityGraph(
|
@NamedEntityGraph(
|
||||||
name = "Category.withSubCategoriesAndObjects",
|
name = "Category.withSubCategoriesAndObjects",
|
||||||
attributeNodes = {
|
attributeNodes = {
|
||||||
@NamedAttributeNode(value = "subCategories"
|
@NamedAttributeNode(value = "subCategories"
|
||||||
),
|
),}
|
||||||
}
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@XmlRootElement(name = "category", namespace = CAT_XML_NS)
|
@XmlRootElement(name = "category", namespace = CAT_XML_NS)
|
||||||
|
|
|
||||||
|
|
@ -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.
|
* Check if an object is assigned to a category.
|
||||||
*
|
*
|
||||||
* @param category The category
|
* @param category The category
|
||||||
* @param object The object
|
* @param object The object
|
||||||
|
*
|
||||||
* @return {@code true} if the provided {@code object} is assigned to the
|
* @return {@code true} if the provided {@code object} is assigned to the
|
||||||
* provided {@code category}, {@code false} otherwise.
|
* provided {@code category}, {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
|
|
@ -189,6 +215,7 @@ public class CategoryManager {
|
||||||
* @param object The object
|
* @param object The object
|
||||||
* @param type The type with which the object has been assigned to the
|
* @param type The type with which the object has been assigned to the
|
||||||
* category. the type may be {@code null}.
|
* category. the type may be {@code null}.
|
||||||
|
*
|
||||||
* @return {@code true} if the provided {@code object} is assigned to the
|
* @return {@code true} if the provided {@code object} is assigned to the
|
||||||
* provided {@code category} using the provided {@code type}.
|
* 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
|
* The value of the {@code order} property of the object after the provided
|
||||||
* is decreased by one. Effectively the two objects are swapped.
|
* is decreased by one. Effectively the two objects are swapped.
|
||||||
*
|
*
|
||||||
* @param object The object which {@code order} property is decreased. Can't
|
* @param object The object which {@code order} property is decreased.
|
||||||
* be {@code null}.
|
* Can't be {@code null}.
|
||||||
* @param category The category to which the object is assigned. Can't be
|
* @param category The category to which the object is assigned. Can't be
|
||||||
* {@code null}.
|
* {@code null}.
|
||||||
*
|
*
|
||||||
* @throws ObjectNotAssignedToCategoryException Throws if the provided
|
* @throws ObjectNotAssignedToCategoryException Throws if the provided
|
||||||
* object is not assigned to the provided category.
|
* object is not assigned to
|
||||||
|
* the provided category.
|
||||||
*/
|
*/
|
||||||
@AuthorizationRequired
|
@AuthorizationRequired
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
|
@ -362,13 +390,14 @@ public class CategoryManager {
|
||||||
* The value of the {@code order} property of the object before the provided
|
* The value of the {@code order} property of the object before the provided
|
||||||
* is increased by one. Effectively the two objects are swapped.
|
* is increased by one. Effectively the two objects are swapped.
|
||||||
*
|
*
|
||||||
* @param object The object which {@code order} property is decreased. Can't
|
* @param object The object which {@code order} property is decreased.
|
||||||
* be {@code null}.
|
* Can't be {@code null}.
|
||||||
* @param category The category to which the object is assigned. Can't be
|
* @param category The category to which the object is assigned. Can't be
|
||||||
* {@code null}.
|
* {@code null}.
|
||||||
*
|
*
|
||||||
* @throws ObjectNotAssignedToCategoryException Throws if the provided
|
* @throws ObjectNotAssignedToCategoryException Throws if the provided
|
||||||
* object is not assigned to the provided category.
|
* object is not assigned to
|
||||||
|
* the provided category.
|
||||||
*/
|
*/
|
||||||
@AuthorizationRequired
|
@AuthorizationRequired
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
|
@ -441,7 +470,9 @@ public class CategoryManager {
|
||||||
* are assigned. Can't be {@code null}.
|
* are assigned. Can't be {@code null}.
|
||||||
*
|
*
|
||||||
* @throws ObjectNotAssignedToCategoryException Thrown if one or both of the
|
* @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,
|
// public void swapObjects(final CcmObject objectA,
|
||||||
// final CcmObject objectB,
|
// final CcmObject objectB,
|
||||||
|
|
@ -517,7 +548,8 @@ public class CategoryManager {
|
||||||
* @param parentCategory The parent category. Can't be {@code null}.
|
* @param parentCategory The parent category. Can't be {@code null}.
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException If the provided subcategory is not
|
* @throws IllegalArgumentException If the provided subcategory is not
|
||||||
* assigned to the provided parent category.
|
* assigned to the provided parent
|
||||||
|
* category.
|
||||||
*/
|
*/
|
||||||
@AuthorizationRequired
|
@AuthorizationRequired
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@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
|
* objects is decreased by one. If the object is the last one this method
|
||||||
* has not effect.
|
* has not effect.
|
||||||
*
|
*
|
||||||
* @param subCategory The category which order property is increased. Can't
|
* @param subCategory The category which order property is increased.
|
||||||
* be {@code null}.
|
* Can't be {@code null}.
|
||||||
* @param parentCategory The parent category of the category. Can't be
|
* @param parentCategory The parent category of the category. Can't be
|
||||||
* {@code null}.
|
* {@code null}.
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException If the provided subcategory is not a
|
* @throws IllegalArgumentException If the provided subcategory is not a
|
||||||
* subcategory of the provided parent category.
|
* subcategory of the provided parent
|
||||||
|
* category.
|
||||||
*/
|
*/
|
||||||
@AuthorizationRequired
|
@AuthorizationRequired
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
|
@ -629,13 +662,14 @@ public class CategoryManager {
|
||||||
* preceeding objects is increased by one. If the object is the last one
|
* preceeding objects is increased by one. If the object is the last one
|
||||||
* this method has not effect.
|
* this method has not effect.
|
||||||
*
|
*
|
||||||
* @param subCategory The category which order property is increased. Can't
|
* @param subCategory The category which order property is increased.
|
||||||
* be {@code null}.
|
* Can't be {@code null}.
|
||||||
* @param parentCategory The parent category of the category. Can't be
|
* @param parentCategory The parent category of the category. Can't be
|
||||||
* {@code null}.
|
* {@code null}.
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException If the provided subcategory is not a
|
* @throws IllegalArgumentException If the provided subcategory is not a
|
||||||
* subcategory of the provided parent category.
|
* subcategory of the provided parent
|
||||||
|
* category.
|
||||||
*/
|
*/
|
||||||
@AuthorizationRequired
|
@AuthorizationRequired
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
|
@ -764,8 +798,11 @@ public class CategoryManager {
|
||||||
* @param category The category whose index object is set or changed.
|
* @param category The category whose index object is set or changed.
|
||||||
* @param object The new index object for the category. The object must be
|
* @param object The new index object for the category. The object must be
|
||||||
* assigned to the category.
|
* assigned to the category.
|
||||||
|
*
|
||||||
* @throws ObjectNotAssignedToCategoryException If the provided
|
* @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)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public void setIndexObject(final Category category,
|
public void setIndexObject(final Category category,
|
||||||
|
|
@ -836,4 +873,5 @@ public class CategoryManager {
|
||||||
result.forEach(categorization -> categorization.setIndex(false));
|
result.forEach(categorization -> categorization.setIndex(false));
|
||||||
result.forEach(categorization -> entityManager.merge(categorization));
|
result.forEach(categorization -> entityManager.merge(categorization));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue