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-94f89814c4dfpull/2/head
parent
91c33e8e69
commit
2e9cbb1f49
|
|
@ -89,15 +89,15 @@ public class ContentItemManager {
|
|||
@Inject
|
||||
private ContentTypeRepository typeRepo;
|
||||
|
||||
@Inject
|
||||
private ContentSectionManager sectionManager;
|
||||
|
||||
@Inject
|
||||
private LifecycleManager lifecycleManager;
|
||||
|
||||
@Inject
|
||||
private WorkflowManager workflowManager;
|
||||
|
||||
@Inject
|
||||
private FolderRepository folderRepo;
|
||||
|
||||
/**
|
||||
* Creates a new content item in the provided content section and folder
|
||||
* with the workflow.
|
||||
|
|
@ -378,9 +378,9 @@ public class ContentItemManager {
|
|||
try {
|
||||
source = (LocalizedString) readMethod.invoke(draftItem);
|
||||
target = (LocalizedString) readMethod.invoke(copy);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
|
|
@ -393,9 +393,9 @@ public class ContentItemManager {
|
|||
final ContentItem linkedItem;
|
||||
try {
|
||||
linkedItem = (ContentItem) readMethod.invoke(draftItem);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
|
|
@ -404,9 +404,9 @@ public class ContentItemManager {
|
|||
|
||||
try {
|
||||
writeMethod.invoke(copy, linkedDraftItem);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
} else if (propType != null
|
||||
|
|
@ -416,9 +416,9 @@ public class ContentItemManager {
|
|||
try {
|
||||
source = (List<Object>) readMethod.invoke(draftItem);
|
||||
target = (List<Object>) readMethod.invoke(copy);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
|
|
@ -431,9 +431,9 @@ public class ContentItemManager {
|
|||
try {
|
||||
source = (Map<Object, Object>) readMethod.invoke(draftItem);
|
||||
target = (Map<Object, Object>) readMethod.invoke(copy);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
|
|
@ -446,9 +446,9 @@ public class ContentItemManager {
|
|||
try {
|
||||
source = (Set<Object>) readMethod.invoke(draftItem);
|
||||
target = (Set<Object>) readMethod.invoke(copy);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
|
|
@ -458,9 +458,9 @@ public class ContentItemManager {
|
|||
try {
|
||||
value = readMethod.invoke(item);
|
||||
writeMethod.invoke(copy, value);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -623,9 +623,9 @@ public class ContentItemManager {
|
|||
try {
|
||||
source = (LocalizedString) readMethod.invoke(draftItem);
|
||||
target = (LocalizedString) readMethod.invoke(liveItem);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
|
|
@ -637,9 +637,9 @@ public class ContentItemManager {
|
|||
final ContentItem linkedItem;
|
||||
try {
|
||||
linkedItem = (ContentItem) readMethod.invoke(draftItem);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
|
|
@ -652,9 +652,9 @@ public class ContentItemManager {
|
|||
= getLiveVersion(
|
||||
linkedDraftItem, ContentItem.class);
|
||||
writeMethod.invoke(liveItem, linkedLiveItem);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -665,9 +665,9 @@ public class ContentItemManager {
|
|||
try {
|
||||
source = (List<Object>) readMethod.invoke(draftItem);
|
||||
target = (List<Object>) readMethod.invoke(liveItem);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
|
|
@ -680,9 +680,9 @@ public class ContentItemManager {
|
|||
try {
|
||||
source = (Map<Object, Object>) readMethod.invoke(draftItem);
|
||||
target = (Map<Object, Object>) readMethod.invoke(liveItem);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
|
|
@ -695,9 +695,9 @@ public class ContentItemManager {
|
|||
try {
|
||||
source = (Set<Object>) readMethod.invoke(draftItem);
|
||||
target = (Set<Object>) readMethod.invoke(liveItem);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
|
|
@ -707,9 +707,9 @@ public class ContentItemManager {
|
|||
try {
|
||||
value = readMethod.invoke(item);
|
||||
writeMethod.invoke(liveItem, value);
|
||||
} catch (IllegalAccessException |
|
||||
IllegalArgumentException |
|
||||
InvocationTargetException ex) {
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -721,6 +721,31 @@ public class ContentItemManager {
|
|||
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
|
||||
* 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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue