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-94f89814c4dfpull/2/head
parent
325c6fbc80
commit
938f44f106
|
|
@ -83,6 +83,12 @@ public class ContentItemManager {
|
|||
@Inject
|
||||
private CategoryManager categoryManager;
|
||||
|
||||
@Inject
|
||||
private FolderManager folderManager;
|
||||
|
||||
@Inject
|
||||
private ContentSectionManager sectionManager;
|
||||
|
||||
@Inject
|
||||
private ContentItemRepository contentItemRepo;
|
||||
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -117,8 +116,8 @@ public class ContentItemManagerTest {
|
|||
public static WebArchive createDeployment() {
|
||||
return ShrinkWrap
|
||||
.create(WebArchive.class,
|
||||
"LibreCCM-org.librecms.contentsection.ContentItemManagerTest.war").
|
||||
addPackage(org.libreccm.auditing.CcmRevision.class.getPackage())
|
||||
"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())
|
||||
|
|
@ -140,14 +139,14 @@ public class ContentItemManagerTest {
|
|||
.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)
|
||||
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())
|
||||
|
|
@ -245,7 +244,7 @@ public class ContentItemManagerTest {
|
|||
"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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -377,7 +376,7 @@ public class ContentItemManagerTest {
|
|||
"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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -535,9 +534,40 @@ public class ContentItemManagerTest {
|
|||
"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)}
|
||||
|
|
@ -571,7 +601,7 @@ public class ContentItemManagerTest {
|
|||
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
|
||||
+ "ContentItemManagerTest/data.xml")
|
||||
@ShouldThrowException(IllegalArgumentException.class)
|
||||
public void moveItemFolderNull() {
|
||||
public void moveItemTargetFolderIsNull() {
|
||||
final Optional<ContentItem> item = itemRepo.findById(-10100L);
|
||||
assertThat(item.isPresent(), is(true));
|
||||
|
||||
|
|
@ -624,6 +654,7 @@ public class ContentItemManagerTest {
|
|||
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",
|
||||
|
|
@ -634,10 +665,42 @@ public class ContentItemManagerTest {
|
|||
"task_id",
|
||||
"uuid",
|
||||
"timestamp",
|
||||
"workflow_id"
|
||||
})
|
||||
"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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -861,7 +924,7 @@ public class ContentItemManagerTest {
|
|||
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
|
||||
+ "ContentItemManagerTest/data.xml")
|
||||
@ShouldThrowException(IllegalArgumentException.class)
|
||||
public void publishItemLifecycleNull() {
|
||||
public void publishItemLifecycleIsNull() {
|
||||
final Optional<ContentItem> draft = itemRepo.findById(-10200L);
|
||||
|
||||
itemManager.publish(draft.get(), null);
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue