CCM NG/ccm-cms: Bulk publish and unpublish for folders

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4370 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-10-10 15:31:25 +00:00
parent 91c33e8e69
commit 2e9cbb1f49
1 changed files with 100 additions and 49 deletions

View File

@ -89,15 +89,15 @@ public class ContentItemManager {
@Inject @Inject
private ContentTypeRepository typeRepo; private ContentTypeRepository typeRepo;
@Inject
private ContentSectionManager sectionManager;
@Inject @Inject
private LifecycleManager lifecycleManager; private LifecycleManager lifecycleManager;
@Inject @Inject
private WorkflowManager workflowManager; private WorkflowManager workflowManager;
@Inject
private FolderRepository folderRepo;
/** /**
* Creates a new content item in the provided content section and folder * Creates a new content item in the provided content section and folder
* with the workflow. * with the workflow.
@ -378,9 +378,9 @@ public class ContentItemManager {
try { try {
source = (LocalizedString) readMethod.invoke(draftItem); source = (LocalizedString) readMethod.invoke(draftItem);
target = (LocalizedString) readMethod.invoke(copy); target = (LocalizedString) readMethod.invoke(copy);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@ -393,9 +393,9 @@ public class ContentItemManager {
final ContentItem linkedItem; final ContentItem linkedItem;
try { try {
linkedItem = (ContentItem) readMethod.invoke(draftItem); linkedItem = (ContentItem) readMethod.invoke(draftItem);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@ -404,9 +404,9 @@ public class ContentItemManager {
try { try {
writeMethod.invoke(copy, linkedDraftItem); writeMethod.invoke(copy, linkedDraftItem);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} else if (propType != null } else if (propType != null
@ -416,9 +416,9 @@ public class ContentItemManager {
try { try {
source = (List<Object>) readMethod.invoke(draftItem); source = (List<Object>) readMethod.invoke(draftItem);
target = (List<Object>) readMethod.invoke(copy); target = (List<Object>) readMethod.invoke(copy);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@ -431,9 +431,9 @@ public class ContentItemManager {
try { try {
source = (Map<Object, Object>) readMethod.invoke(draftItem); source = (Map<Object, Object>) readMethod.invoke(draftItem);
target = (Map<Object, Object>) readMethod.invoke(copy); target = (Map<Object, Object>) readMethod.invoke(copy);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@ -446,9 +446,9 @@ public class ContentItemManager {
try { try {
source = (Set<Object>) readMethod.invoke(draftItem); source = (Set<Object>) readMethod.invoke(draftItem);
target = (Set<Object>) readMethod.invoke(copy); target = (Set<Object>) readMethod.invoke(copy);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@ -458,9 +458,9 @@ public class ContentItemManager {
try { try {
value = readMethod.invoke(item); value = readMethod.invoke(item);
writeMethod.invoke(copy, value); writeMethod.invoke(copy, value);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} }
@ -623,9 +623,9 @@ public class ContentItemManager {
try { try {
source = (LocalizedString) readMethod.invoke(draftItem); source = (LocalizedString) readMethod.invoke(draftItem);
target = (LocalizedString) readMethod.invoke(liveItem); target = (LocalizedString) readMethod.invoke(liveItem);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@ -637,9 +637,9 @@ public class ContentItemManager {
final ContentItem linkedItem; final ContentItem linkedItem;
try { try {
linkedItem = (ContentItem) readMethod.invoke(draftItem); linkedItem = (ContentItem) readMethod.invoke(draftItem);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@ -652,9 +652,9 @@ public class ContentItemManager {
= getLiveVersion( = getLiveVersion(
linkedDraftItem, ContentItem.class); linkedDraftItem, ContentItem.class);
writeMethod.invoke(liveItem, linkedLiveItem); writeMethod.invoke(liveItem, linkedLiveItem);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} }
@ -665,9 +665,9 @@ public class ContentItemManager {
try { try {
source = (List<Object>) readMethod.invoke(draftItem); source = (List<Object>) readMethod.invoke(draftItem);
target = (List<Object>) readMethod.invoke(liveItem); target = (List<Object>) readMethod.invoke(liveItem);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@ -680,9 +680,9 @@ public class ContentItemManager {
try { try {
source = (Map<Object, Object>) readMethod.invoke(draftItem); source = (Map<Object, Object>) readMethod.invoke(draftItem);
target = (Map<Object, Object>) readMethod.invoke(liveItem); target = (Map<Object, Object>) readMethod.invoke(liveItem);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@ -695,9 +695,9 @@ public class ContentItemManager {
try { try {
source = (Set<Object>) readMethod.invoke(draftItem); source = (Set<Object>) readMethod.invoke(draftItem);
target = (Set<Object>) readMethod.invoke(liveItem); target = (Set<Object>) readMethod.invoke(liveItem);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@ -707,9 +707,9 @@ public class ContentItemManager {
try { try {
value = readMethod.invoke(item); value = readMethod.invoke(item);
writeMethod.invoke(liveItem, value); writeMethod.invoke(liveItem, value);
} catch (IllegalAccessException | } catch (IllegalAccessException
IllegalArgumentException | | IllegalArgumentException
InvocationTargetException ex) { | InvocationTargetException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} }
@ -721,6 +721,31 @@ public class ContentItemManager {
return liveItem; return liveItem;
} }
/**
* Publishes all items in a folder. Items which are already live will be
* republished. Note: Items in sub folders will <strong>not</strong> be
* published!
*
* @param folder The folder which items should be published.
*/
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
public void publish(
@RequiresPrivilege(CmsConstants.PRIVILEGE_ITEMS_PUBLISH)
final Folder folder) {
// Ensure that we are using a fresh folder and that the folder was
// retrieved in this transaction to avoid problems with lazy fetched
// data.
final Folder theFolder = folderRepo.findById(folder.getObjectId());
theFolder.getObjects()
.stream()
.map(categorization -> categorization.getCategorizedObject())
.filter(object -> object instanceof ContentItem)
.forEach(item -> publish((ContentItem) item));
}
/** /**
* Unpublishes a content item by deleting its live version if there is a * Unpublishes a content item by deleting its live version if there is a
* live version. * live version.
@ -770,6 +795,32 @@ public class ContentItemManager {
} }
/**
* Unpublishes all live items in a folder. Items in sub folders will
* <strong>not</strong> be unpublished!.
*
* @param folder The folders which items are unpublished.
*/
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
public void unpublish(
@RequiresPrivilege(CmsConstants.PRIVILEGE_ITEMS_PUBLISH)
final Folder folder) {
// Ensure that we are using a fresh folder and that the folder was
// retrieved in this transaction to avoid problems with lazy fetched
// data.
final Folder theFolder = folderRepo.findById(folder.getObjectId());
theFolder.getObjects()
.stream()
.map(categorization -> categorization.getCategorizedObject())
.filter(object -> object instanceof ContentItem)
.map(object -> (ContentItem) object)
.filter(item -> isLive(item))
.forEach(item -> unpublish(item));
}
/** /**
* Determines if a content item has a live version. * Determines if a content item has a live version.
* *
@ -929,7 +980,7 @@ public class ContentItemManager {
final boolean withContentSection) { final boolean withContentSection) {
final List<Categorization> result = item.getCategories().stream(). final List<Categorization> result = item.getCategories().stream().
filter(categorization -> CmsConstants.CATEGORIZATION_TYPE_FOLDER. filter(categorization -> CmsConstants.CATEGORIZATION_TYPE_FOLDER.
equals(categorization.getType())) equals(categorization.getType()))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (result.isEmpty()) { if (result.isEmpty()) {
@ -969,7 +1020,7 @@ public class ContentItemManager {
public List<Folder> getItemFolders(final ContentItem item) { public List<Folder> getItemFolders(final ContentItem item) {
final List<Categorization> result = item.getCategories().stream(). final List<Categorization> result = item.getCategories().stream().
filter(categorization -> CmsConstants.CATEGORIZATION_TYPE_FOLDER. filter(categorization -> CmsConstants.CATEGORIZATION_TYPE_FOLDER.
equals(categorization.getType())) equals(categorization.getType()))
.collect(Collectors.toList()); .collect(Collectors.toList());
final List<Folder> folders = new ArrayList<>(); final List<Folder> folders = new ArrayList<>();
@ -1021,7 +1072,7 @@ public class ContentItemManager {
public Optional<Folder> getItemFolder(final ContentItem item) { public Optional<Folder> getItemFolder(final ContentItem item) {
final List<Categorization> result = item.getCategories().stream(). final List<Categorization> result = item.getCategories().stream().
filter(categorization -> CmsConstants.CATEGORIZATION_TYPE_FOLDER. filter(categorization -> CmsConstants.CATEGORIZATION_TYPE_FOLDER.
equals(categorization.getType())) equals(categorization.getType()))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (result.size() > 0) { if (result.size() > 0) {