CCM NG/ccm-cms: Copying and moving items to another contentsection is now supported by the ContentItemManager.

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4374 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-10-13 17:05:58 +00:00
parent 325c6fbc80
commit 938f44f106
6 changed files with 416 additions and 298 deletions

View File

@ -83,6 +83,12 @@ public class ContentItemManager {
@Inject
private CategoryManager categoryManager;
@Inject
private FolderManager folderManager;
@Inject
private ContentSectionManager sectionManager;
@Inject
private ContentItemRepository contentItemRepo;
@ -94,7 +100,7 @@ public class ContentItemManager {
@Inject
private WorkflowManager workflowManager;
@Inject
private FolderRepository folderRepo;
@ -183,7 +189,7 @@ public class ContentItemManager {
type.getName()));
}
if (name == null || name.isEmpty()) {
if (name == null || name.trim().isEmpty()) {
throw new IllegalArgumentException(
"The name of a content item can't be blank.");
}
@ -233,7 +239,7 @@ public class ContentItemManager {
* a the item is republished.
*
* @param item The item to move.
* @param target The folder to which the item is moved.
* @param targetFolder The folder to which the item is moved.
*/
@AuthorizationRequired
@Transactional(Transactional.TxType.REQUIRED)
@ -241,12 +247,12 @@ public class ContentItemManager {
@RequiresPrivilege(CmsConstants.PRIVILEGE_ITEMS_EDIT)
final ContentItem item,
@RequiresPrivilege(CmsConstants.PRIVILEGE_ITEMS_EDIT)
final Folder target) {
final Folder targetFolder) {
if (item == null) {
throw new IllegalArgumentException("The item to move can't be null.");
}
if (target == null) {
if (targetFolder == null) {
throw new IllegalArgumentException(
"The target folder can't be null.");
}
@ -254,6 +260,23 @@ public class ContentItemManager {
final ContentItem draftItem = getDraftVersion(item, item.getClass());
final Optional<Folder> currentFolder = getItemFolder(item);
if (!sectionManager.hasContentType(draftItem.getClass(),
targetFolder.getSection())) {
throw new IllegalArgumentException(String.format(
"Can't move item %d:\"%s\" to folder \"%s\"."
+ "The target folder %d:\"%s\" belongs to content section "
+ "%d:\"%s\". The content type \"%s\" has not registered"
+ "for this section.",
draftItem.getObjectId(),
draftItem.getDisplayName(),
folderManager.getFolderPath(targetFolder, true),
targetFolder.getObjectId(),
targetFolder.getDisplayName(),
targetFolder.getSection().getObjectId(),
targetFolder.getSection().getDisplayName(),
draftItem.getClass().getName()));
}
if (currentFolder.isPresent()) {
try {
categoryManager.removeObjectFromCategory(draftItem,
@ -265,7 +288,7 @@ public class ContentItemManager {
categoryManager.addObjectToCategory(
draftItem,
target,
targetFolder,
CmsConstants.CATEGORIZATION_TYPE_FOLDER);
}
@ -279,10 +302,12 @@ public class ContentItemManager {
* target folder is the same folder as the folder of the
* original item an index is appended to the name of the
* item.
*
* @return The copy of the item
*/
@Transactional(Transactional.TxType.REQUIRED)
@SuppressWarnings("unchecked")
public void copy(
public ContentItem copy(
final ContentItem item,
@RequiresPrivilege(CmsConstants.PRIVILEGE_ITEMS_CREATE_NEW)
final Folder targetFolder) {
@ -308,6 +333,22 @@ public class ContentItemManager {
}
final ContentItem draftItem = getDraftVersion(item, item.getClass());
if (!sectionManager.hasContentType(draftItem.getClass(),
targetFolder.getSection())) {
throw new IllegalArgumentException(String.format(
"Can't copy item %d:\"%s\" to folder \"%s\"."
+ "The target folder %d:\"%s\" belongs to content section "
+ "%d:\"%s\". The content type \"%s\" has not registered"
+ "for this section.",
draftItem.getObjectId(),
draftItem.getDisplayName(),
folderManager.getFolderPath(targetFolder, true),
targetFolder.getObjectId(),
targetFolder.getDisplayName(),
targetFolder.getSection().getObjectId(),
targetFolder.getSection().getDisplayName(),
draftItem.getClass().getName()));
}
final ContentItem copy;
try {
@ -477,6 +518,8 @@ public class ContentItemManager {
}
contentItemRepo.save(copy);
return copy;
}
private boolean propertyIsExcluded(final String name) {
@ -738,7 +781,7 @@ public class ContentItemManager {
// 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())
@ -798,7 +841,7 @@ 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
@ -806,12 +849,12 @@ public class ContentItemManager {
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())
@ -820,7 +863,7 @@ public class ContentItemManager {
.filter(item -> isLive(item))
.forEach(item -> unpublish(item));
}
/**
* Determines if a content item has a live version.
*

View File

@ -76,7 +76,6 @@ public class News extends ContentItem implements Serializable {
* the function recentItems.
*/
@Column(name = "HOMEPAGE")
@NotEmpty
private boolean homepage;
public LocalizedString getText() {
@ -88,11 +87,11 @@ public class News extends ContentItem implements Serializable {
}
public Date getReleaseDate() {
return releaseDate;
return new Date(releaseDate.getTime());
}
public void setReleaseDate(final Date releaseDate) {
this.releaseDate = releaseDate;
this.releaseDate = new Date(releaseDate.getTime());
}
public boolean isHomepage() {

View File

@ -37,7 +37,6 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.security.Shiro;
import org.libreccm.tests.categories.IntegrationTest;
import org.libreccm.workflow.WorkflowTemplate;
@ -116,61 +115,61 @@ public class ContentItemManagerTest {
@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap
.create(WebArchive.class,
"LibreCCM-org.librecms.contentsection.ContentItemManagerTest.war").
addPackage(org.libreccm.auditing.CcmRevision.class.getPackage())
.addPackage(org.libreccm.categorization.Categorization.class
.getPackage())
.addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage())
.addPackage(org.libreccm.configuration.Configuration.class
.getPackage())
.addPackage(org.libreccm.core.CcmCore.class.getPackage())
.addPackage(org.libreccm.jpa.EntityManagerProducer.class
.getPackage())
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
.getPackage())
.addPackage(org.libreccm.l10n.LocalizedString.class
.getPackage())
.addPackage(org.libreccm.security.Permission.class.getPackage())
.addPackage(org.libreccm.web.CcmApplication.class.getPackage())
.addPackage(org.libreccm.workflow.Workflow.class.getPackage())
.addPackage(com.arsdigita.bebop.Component.class.getPackage())
.addPackage(com.arsdigita.bebop.util.BebopConstants.class
.getPackage())
.addClass(com.arsdigita.kernel.KernelConfig.class)
.addClass(com.arsdigita.runtime.CCMResourceManager.class)
.addClass(
com.arsdigita.ui.admin.applications.AbstractAppInstanceForm.class).
addClass(
com.arsdigita.ui.admin.applications.AbstractAppSettingsPane.class).
addClass(
com.arsdigita.ui.admin.applications.DefaultApplicationInstanceForm.class).
addClass(
com.arsdigita.ui.admin.applications.DefaultApplicationSettingsPane.class).
addClass(com.arsdigita.cms.dispatcher.ItemResolver.class)
.addPackage(com.arsdigita.util.Lockable.class.getPackage())
.addPackage(com.arsdigita.web.BaseServlet.class.getPackage())
.addPackage(org.librecms.Cms.class.getPackage())
.addPackage(org.librecms.assets.Asset.class.getPackage())
.addPackage(org.librecms.attachments.AttachmentList.class
.getPackage())
.addPackage(org.librecms.lifecycle.Lifecycle.class.getPackage())
.addPackage(org.librecms.contentsection.ContentSection.class
.getPackage())
.addPackage(org.librecms.contenttypes.Article.class.getPackage()).
addClass(com.arsdigita.kernel.security.SecurityConfig.class)
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
.getPackage())
// .addAsLibraries(getModuleDependencies())
.addAsLibraries(getCcmCoreDependencies())
.addAsResource("configs/shiro.ini", "shiro.ini")
.addAsResource(
"configs/org/librecms/contentsection/ContentItemManagerTest/log4j2.xml",
"log4j2.xml")
.addAsResource("test-persistence.xml",
"META-INF/persistence.xml")
.addAsWebInfResource("test-web.xml", "web.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
.create(WebArchive.class,
"LibreCCM-org.librecms.contentsection.ContentItemManagerTest.war")
.addPackage(org.libreccm.auditing.CcmRevision.class.getPackage())
.addPackage(org.libreccm.categorization.Categorization.class
.getPackage())
.addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage())
.addPackage(org.libreccm.configuration.Configuration.class
.getPackage())
.addPackage(org.libreccm.core.CcmCore.class.getPackage())
.addPackage(org.libreccm.jpa.EntityManagerProducer.class
.getPackage())
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
.getPackage())
.addPackage(org.libreccm.l10n.LocalizedString.class
.getPackage())
.addPackage(org.libreccm.security.Permission.class.getPackage())
.addPackage(org.libreccm.web.CcmApplication.class.getPackage())
.addPackage(org.libreccm.workflow.Workflow.class.getPackage())
.addPackage(com.arsdigita.bebop.Component.class.getPackage())
.addPackage(com.arsdigita.bebop.util.BebopConstants.class
.getPackage())
.addClass(com.arsdigita.kernel.KernelConfig.class)
.addClass(com.arsdigita.runtime.CCMResourceManager.class)
.addClass(
com.arsdigita.ui.admin.applications.AbstractAppInstanceForm.class)
.addClass(
com.arsdigita.ui.admin.applications.AbstractAppSettingsPane.class)
.addClass(
com.arsdigita.ui.admin.applications.DefaultApplicationInstanceForm.class)
.addClass(
com.arsdigita.ui.admin.applications.DefaultApplicationSettingsPane.class)
.addClass(com.arsdigita.cms.dispatcher.ItemResolver.class)
.addPackage(com.arsdigita.util.Lockable.class.getPackage())
.addPackage(com.arsdigita.web.BaseServlet.class.getPackage())
.addPackage(org.librecms.Cms.class.getPackage())
.addPackage(org.librecms.assets.Asset.class.getPackage())
.addPackage(org.librecms.attachments.AttachmentList.class
.getPackage())
.addPackage(org.librecms.lifecycle.Lifecycle.class.getPackage())
.addPackage(org.librecms.contentsection.ContentSection.class
.getPackage())
.addPackage(org.librecms.contenttypes.Article.class.getPackage()).
addClass(com.arsdigita.kernel.security.SecurityConfig.class)
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
.getPackage())
// .addAsLibraries(getModuleDependencies())
.addAsLibraries(getCcmCoreDependencies())
.addAsResource("configs/shiro.ini", "shiro.ini")
.addAsResource(
"configs/org/librecms/contentsection/ContentItemManagerTest/log4j2.xml",
"log4j2.xml")
.addAsResource("test-persistence.xml",
"META-INF/persistence.xml")
.addAsWebInfResource("test-web.xml", "web.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
}
/**
@ -206,23 +205,23 @@ public class ContentItemManagerTest {
@Test
@InSequence(1100)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet(
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-create-contentitem.xml",
excludeColumns = {"categorization_id",
"id",
"item_uuid",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"uuid",
"timestamp",
"workflow_id"
})
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-create-contentitem.xml",
excludeColumns = {"categorization_id",
"id",
"item_uuid",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"uuid",
"timestamp",
"workflow_id"
})
public void createContentItem() {
final ContentSection section = sectionRepo.findByLabel("info");
final Folder folder = section.getRootDocumentsFolder();
@ -242,10 +241,10 @@ public class ContentItemManagerTest {
article.getWorkflow(), is(not(nullValue())));
final TypedQuery<Long> query = entityManager.createQuery(
"SELECT COUNT(w) FROM Workflow w", Long.class);
"SELECT COUNT(w) FROM Workflow w", Long.class);
final long workflowCount = query.getSingleResult();
assertThat("Expected three workflows in database.",
workflowCount, is(3L));
workflowCount, is(4L));
}
/**
@ -257,9 +256,9 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(1200)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void createItemTypeNotInSection() {
final ContentSection section = sectionRepo.findByLabel("info");
@ -276,9 +275,9 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(1300)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void createItemNameIsNull() {
final ContentSection section = sectionRepo.findByLabel("info");
@ -295,9 +294,9 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(1400)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void createItemNameIsEmpty() {
final ContentSection section = sectionRepo.findByLabel("info");
@ -315,9 +314,9 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(1500)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void createItemFolderIsNull() {
final ContentSection section = sectionRepo.findByLabel("info");
@ -332,37 +331,37 @@ public class ContentItemManagerTest {
@Test
@InSequence(2100)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet(
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/"
+ "after-create-contentitem-with-workflow.xml",
excludeColumns = {"categorization_id",
"id",
"item_uuid",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"timestamp",
"uuid",
"workflow_id"
})
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/"
+ "after-create-contentitem-with-workflow.xml",
excludeColumns = {"categorization_id",
"id",
"item_uuid",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"timestamp",
"uuid",
"workflow_id"
})
public void createContentItemWithWorkflow() {
final ContentSection section = sectionRepo.findByLabel("info");
final Folder folder = section.getRootDocumentsFolder();
final WorkflowTemplate workflowTemplate = workflowTemplateRepo
.findById(-110L);
.findById(-110L);
final Article article = itemManager.createContentItem(
"new-article",
section,
folder,
workflowTemplate,
Article.class);
"new-article",
section,
folder,
workflowTemplate,
Article.class);
assertThat("DisplayName has not the expected value.",
article.getDisplayName(), is(equalTo("new-article")));
@ -374,10 +373,10 @@ public class ContentItemManagerTest {
article.getWorkflow(), is(not(nullValue())));
final TypedQuery<Long> query = entityManager.createQuery(
"SELECT COUNT(w) FROM Workflow w", Long.class);
"SELECT COUNT(w) FROM Workflow w", Long.class);
final long workflowCount = query.getSingleResult();
assertThat("Expected three workflows in database.",
workflowCount, is(3L));
workflowCount, is(4L));
}
/**
@ -389,16 +388,16 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(2200)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void createItemTypeNotInSectionWithWorkflow() {
final ContentSection section = sectionRepo.findByLabel("info");
final Folder folder = section.getRootDocumentsFolder();
final WorkflowTemplate workflowTemplate = workflowTemplateRepo
.findById(-110L);
.findById(-110L);
itemManager.createContentItem("Test",
section,
@ -416,16 +415,16 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(2300)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void createItemNameIsNullWithWorkflow() {
final ContentSection section = sectionRepo.findByLabel("info");
final Folder folder = section.getRootDocumentsFolder();
final WorkflowTemplate workflowTemplate = workflowTemplateRepo
.findById(-110L);
.findById(-110L);
itemManager.createContentItem(null,
section,
@ -443,9 +442,9 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(2400)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void createItemNameIsNullWorkflowIsNull() {
final ContentSection section = sectionRepo.findByLabel("info");
@ -467,15 +466,15 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(2600)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void createItemFolderIsNullWithWorkflow() {
final ContentSection section = sectionRepo.findByLabel("info");
final WorkflowTemplate workflowTemplate = workflowTemplateRepo
.findById(-110L);
.findById(-110L);
itemManager.createContentItem("Test",
section,
@ -491,19 +490,19 @@ public class ContentItemManagerTest {
@Test
@InSequence(3100)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet(
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-move.xml",
excludeColumns = {"categorization_id",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"task_id",
"uuid",
"workflow_id"
})
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-move.xml",
excludeColumns = {"categorization_id",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"task_id",
"uuid",
"workflow_id"
})
public void moveItem() {
final Optional<ContentItem> item = itemRepo.findById(-10100L);
assertThat(item.isPresent(), is(true));
@ -521,23 +520,54 @@ public class ContentItemManagerTest {
@Test
@InSequence(3110)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet(
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-move-to-other-section.xml",
excludeColumns = {"categorization_id",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"task_id",
"uuid",
"workflow_id"
})
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-move-to-other-section.xml",
excludeColumns = {"categorization_id",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"task_id",
"uuid",
"workflow_id"
})
public void moveToOtherContentSection() {
fail("Not implemented yet");
final Optional<ContentItem> item = itemRepo.findById(-10100L);
final Folder targetFolder = folderRepo.findById(-2300L);
assertThat(item.isPresent(), is(true));
assertThat(targetFolder, is(not(nullValue())));
itemManager.move(item.get(), targetFolder);
}
/**
* Verifies that
* {@link ContentItemManager#move(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)
* throws an {@link IllegalArgumentException} if the type of the item to
* copy has not been registered in content section to which the target
* folder belongs.
*/
@Test(expected = IllegalArgumentException.class)
@InSequence(4120)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void moveToOtherContentSectionTypeNotPresent() {
final Optional<ContentItem> item = itemRepo.findById(-10400L);
final Folder targetFolder = folderRepo.findById(-2300L);
assertThat(item.isPresent(), is(true));
assertThat(targetFolder, is(not(nullValue())));
itemManager.move(item.get(), targetFolder);
}
/**
* Verifies that
* {@link ContentItemManager#move(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)}
@ -547,9 +577,9 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(3200)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void moveItemNull() {
final Folder targetFolder = folderRepo.findById(-2120L);
@ -567,11 +597,11 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(3200)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void moveItemFolderNull() {
public void moveItemTargetFolderIsNull() {
final Optional<ContentItem> item = itemRepo.findById(-10100L);
assertThat(item.isPresent(), is(true));
@ -585,23 +615,23 @@ public class ContentItemManagerTest {
@Test
@InSequence(4100)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet(
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-copy-to-other-folder.xml",
excludeColumns = {"categorization_id",
"id",
"item_uuid",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"uuid",
"timestamp",
"workflow_id"
})
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-copy-to-other-folder.xml",
excludeColumns = {"categorization_id",
"id",
"item_uuid",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"uuid",
"timestamp",
"workflow_id"
})
public void copyToOtherFolder() {
final Optional<ContentItem> item = itemRepo.findById(-10100L);
assertThat(item.isPresent(), is(true));
@ -619,25 +649,58 @@ public class ContentItemManagerTest {
@Test
@InSequence(4110)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet(
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-copy-to-folder-in-other-section.xml",
excludeColumns = {"categorization_id",
"id",
"item_uuid",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"uuid",
"timestamp",
"workflow_id"
})
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-copy-to-folder-in-other-section.xml",
excludeColumns = {"categorization_id",
"content_type_id",
"id",
"item_uuid",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"uuid",
"timestamp",
"workflow_id"})
public void copyToFolderInOtherSection() {
fail();
final Optional<ContentItem> source = itemRepo.findById(-10100L);
final Folder targetFolder = folderRepo.findById(-2300L);
assertThat(source.isPresent(), is(true));
assertThat(targetFolder, is(not(nullValue())));
final ContentItem target = itemManager.copy(source.get(), targetFolder);
assertThat(target.getUuid(), is(not(equalTo(source.get().getUuid()))));
assertThat(target.getItemUuid(), is(equalTo(target.getUuid())));
}
/**
* Verifies that
* {@link ContentItemManager#copy(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)}
* throws an {@link IllegalArgumentException} if the type of the item to
* copy has not been registered in content section to which the target
* folder belongs.
*/
@Test(expected = IllegalArgumentException.class)
@InSequence(4120)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void copyToFolderInOtherSectionTypeNotPresent() {
final Optional<ContentItem> source = itemRepo.findById(-10400L);
final Folder targetFolder = folderRepo.findById(-2300L);
assertThat(source.isPresent(), is(true));
assertThat(targetFolder, is(not(nullValue())));
itemManager.copy(source.get(), targetFolder);
}
/**
@ -649,23 +712,23 @@ public class ContentItemManagerTest {
@Test
@InSequence(4200)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet(
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-copy-to-same-folder.xml",
excludeColumns = {"categorization_id",
"id",
"item_uuid",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"timestamp",
"uuid",
"workflow_id"
})
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-copy-to-same-folder.xml",
excludeColumns = {"categorization_id",
"id",
"item_uuid",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"timestamp",
"uuid",
"workflow_id"
})
public void copyToSameFolder() {
final Optional<ContentItem> item = itemRepo.findById(-10100L);
assertThat(item.isPresent(), is(true));
@ -685,10 +748,10 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(4300)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet(
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void copyItemNull() {
final Folder targetFolder = folderRepo.findById(-2120L);
@ -706,10 +769,10 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(4400)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet(
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void copyItemToFolderNull() {
final Optional<ContentItem> item = itemRepo.findById(-10100L);
@ -728,22 +791,22 @@ public class ContentItemManagerTest {
@Test
@InSequence(5100)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet(
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-publish.xml",
excludeColumns = {"categorization_id",
"id",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"timestamp",
"uuid",
"workflow_id"
})
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-publish.xml",
excludeColumns = {"categorization_id",
"id",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"timestamp",
"uuid",
"workflow_id"
})
public void publishItem() {
final Optional<ContentItem> item = itemRepo.findById(-10100L);
assertThat(item.isPresent(), is(true));
@ -763,26 +826,26 @@ public class ContentItemManagerTest {
@Test
@InSequence(5200)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet(
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-publish.xml",
excludeColumns = {"categorization_id",
"id",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"timestamp",
"uuid",
"workflow_id"
})
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-publish.xml",
excludeColumns = {"categorization_id",
"id",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"task_id",
"timestamp",
"uuid",
"workflow_id"
})
public void publishItemWithLifecycle() {
final Optional<ContentItem> item = itemRepo.findById(-10100L);
final LifecycleDefinition lifecycleDef = lifecycleDefinitionRepo
.findById(-200L);
.findById(-200L);
assertThat(item.isPresent(), is(true));
assertThat(lifecycleDef, is(not(nullValue())));
@ -798,29 +861,29 @@ public class ContentItemManagerTest {
@Test
@InSequence(5300)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet(
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-republish.xml",
excludeColumns = {"categorization_id",
"id",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"revend",
"task_id",
"timestamp",
"uuid",
"workflow_id"})
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-republish.xml",
excludeColumns = {"categorization_id",
"id",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"revend",
"task_id",
"timestamp",
"uuid",
"workflow_id"})
public void republishItem() {
final Optional<ContentItem> item = itemRepo.findById(-10200L);
assertThat(item.isPresent(), is(true));
item.get().getName().addValue(Locale.ENGLISH, "article2-edited");
item.get().getTitle()
.addValue(Locale.ENGLISH, "Article has been edited");
.addValue(Locale.ENGLISH, "Article has been edited");
itemRepo.save(item.get());
final Optional<ContentItem> draft = itemRepo.findById(-10200L);
@ -838,9 +901,9 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(5400)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void publishItemNull() {
final ContentItem item = null;
@ -857,11 +920,11 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(5500)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void publishItemLifecycleNull() {
public void publishItemLifecycleIsNull() {
final Optional<ContentItem> draft = itemRepo.findById(-10200L);
itemManager.publish(draft.get(), null);
@ -874,22 +937,22 @@ public class ContentItemManagerTest {
@Test
@InSequence(6000)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet(
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-unpublish.xml",
excludeColumns = {"categorization_id",
"id",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"revend",
"task_id",
"timestamp",
"uuid",
"workflow_id"})
value = "datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/after-unpublish.xml",
excludeColumns = {"categorization_id",
"id",
"lifecycle_id",
"object_id",
"object_order",
"phase_id",
"rev",
"revend",
"task_id",
"timestamp",
"uuid",
"workflow_id"})
public void unpublishItem() {
final Optional<ContentItem> item = itemRepo.findById(-10200L);
assertThat(item.isPresent(), is(true));
@ -905,9 +968,9 @@ public class ContentItemManagerTest {
@Test
@InSequence(6100)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
public void unpublishNonLiveItem() {
final Optional<ContentItem> item = itemRepo.findById(-10300L);
assertThat(item.isPresent(), is(true));
@ -924,9 +987,9 @@ public class ContentItemManagerTest {
@Test(expected = IllegalArgumentException.class)
@InSequence(6200)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldThrowException(IllegalArgumentException.class)
public void unpublishItemNull() {
final ContentItem item = null;
@ -941,9 +1004,9 @@ public class ContentItemManagerTest {
@Test
@InSequence(7000)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
public void isLive() {
final Optional<ContentItem> item1 = itemRepo.findById(-10100L);
final Optional<ContentItem> item2 = itemRepo.findById(-10200L);
@ -971,9 +1034,9 @@ public class ContentItemManagerTest {
@Test
@InSequence(8000)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
public void getLiveVersion() {
final Optional<ContentItem> draft1 = itemRepo.findById(-10100L);
final Optional<ContentItem> draft2 = itemRepo.findById(-10200L);
@ -986,7 +1049,7 @@ public class ContentItemManagerTest {
ContentItem.class).isPresent(),
is(false));
final Optional<Article> liveVersion = itemManager.getLiveVersion(
draft2.get(), Article.class);
draft2.get(), Article.class);
assertThat(liveVersion.isPresent(),
is(true));
assertThat(liveVersion.get().getObjectId(),
@ -1003,7 +1066,7 @@ public class ContentItemManagerTest {
is(false));
final Optional<ContentItem> fromLive = itemManager.getLiveVersion(
live2.get(), ContentItem.class);
live2.get(), ContentItem.class);
assertThat(fromLive.isPresent(),
is(true));
assertThat(fromLive.get().getObjectId(),
@ -1022,9 +1085,9 @@ public class ContentItemManagerTest {
@Test
@InSequence(8100)
@UsingDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
+ "ContentItemManagerTest/data.xml")
+ "ContentItemManagerTest/data.xml")
// getDraftVersion
public void getDraftVersion() {
final Optional<ContentItem> draft1 = itemRepo.findById(-10100L);
@ -1048,7 +1111,7 @@ public class ContentItemManagerTest {
final Optional<ContentItem> live2 = itemRepo.findById(-99200L);
final ContentItem draftVersion = itemManager.getDraftVersion(
live2.get(), ContentItem.class);
live2.get(), ContentItem.class);
assertThat(draftVersion, is(not(nullValue())));
assertThat(draftVersion.getObjectId(), is(-10200L));

View File

@ -58,8 +58,10 @@ public class DatasetsTest extends DatasetsVerifier {
"/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem.xml",
"/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem-with-workflow.xml",
"/datasets/org/librecms/contentsection/ContentItemManagerTest/after-move.xml",
"/datasets/org/librecms/contentsection/ContentItemManagerTest/after-move-to-other-section.xml",
"/datasets/org/librecms/contentsection/ContentItemManagerTest/after-copy-to-other-folder.xml",
"/datasets/org/librecms/contentsection/ContentItemManagerTest/after-copy-to-same-folder.xml",
"/datasets/org/librecms/contentsection/ContentItemManagerTest/after-copy-to-folder-in-other-section.xml",
"/datasets/org/librecms/contentsection/ContentItemManagerTest/after-publish.xml",
"/datasets/org/librecms/contentsection/ContentItemManagerTest/after-republish.xml",
"/datasets/org/librecms/contentsection/ContentItemManagerTest/after-unpublish.xml",

View File

@ -237,6 +237,10 @@
<ccm_core.resource_titles object_id="-1100"
locale="en"
localized_value="info" />
<ccm_core.resource_titles object_id="-1200"
locale="en"
localized_value="projects" />
<ccm_core.applications object_id="-1200"
application_type="org.librecms.contentsection.ContentSection"
primary_url="projects" />
@ -275,6 +279,10 @@
content_section_id="-1100" />
<ccm_cms.folder_content_section_map folder_id="-2200"
content_section_id="-1100" />
<ccm_cms.folder_content_section_map folder_id="-2300"
content_section_id="-1200" />
<ccm_cms.folder_content_section_map folder_id="-2400"
content_section_id="-1200" />
<ccm_cms.content_section_workflow_templates
content_section_id="-1100"

View File

@ -237,6 +237,9 @@
<ccm_core.resource_titles object_id="-1100"
locale="en"
localized_value="info" />
<ccm_core.resource_titles object_id="-1200"
locale="en"
localized_value="projects" />
<ccm_core.applications object_id="-1100"
application_type="org.librecms.contentsection.ContentSection"