CCM NG: Some work on the ContentItemManager and related classes (not finished yet)
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4294 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
cb0a19410e
commit
df09ad3f5c
|
|
@ -99,7 +99,7 @@ public class ContentItemManager {
|
|||
|
||||
/**
|
||||
* Creates a new content item in the provided content section and folder
|
||||
* with the default lifecycle and workflow.
|
||||
* with the workflow.
|
||||
*
|
||||
* The folder must be a subfolder of the
|
||||
* {@link ContentSection#rootDocumentsFolder} of the provided content
|
||||
|
|
@ -134,30 +134,29 @@ public class ContentItemManager {
|
|||
section,
|
||||
folder,
|
||||
contentType.get().getDefaultWorkflow(),
|
||||
contentType.get().getDefaultLifecycle(),
|
||||
type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new content item in the provided content section and folder
|
||||
* with the provided lifecycle and workflow.
|
||||
* with specific workflow.
|
||||
*
|
||||
* The folder must be a subfolder of the
|
||||
* {@link ContentSection#rootDocumentsFolder} of the provided content
|
||||
* section. Otherwise an {@link IllegalArgumentException} is thrown.
|
||||
*
|
||||
* Likewise the provided {@link LifecycleDefinition} and
|
||||
* {@link WorkflowTemplate} must be defined in the provided content section.
|
||||
* Otherwise an {@link IllegalArgumentException} is thrown.
|
||||
* Likewise the provided {@link WorkflowTemplate} must be defined in the
|
||||
* provided content section. Otherwise an {@link IllegalArgumentException}
|
||||
* is thrown.
|
||||
*
|
||||
* @param <T> The type of the content item.
|
||||
* @param name The name (URL stub) of the new content item.
|
||||
* @param section The content section in which the item is
|
||||
* generated.
|
||||
* @param folder The folder in which in the item is stored.
|
||||
* @param workflowTemplate
|
||||
* @param lifecycleDefinition
|
||||
* @param type The type of the new content item.
|
||||
* @param <T> The type of the content item.
|
||||
* @param name The name (URL stub) of the new content item.
|
||||
* @param section The content section in which the item is
|
||||
* generated.
|
||||
* @param folder The folder in which in the item is stored.
|
||||
* @param workflowTemplate The template for the workflow to apply to the new
|
||||
* item.
|
||||
* @param type The type of the new content item.
|
||||
*
|
||||
* @return The new content item.
|
||||
*/
|
||||
|
|
@ -167,7 +166,6 @@ public class ContentItemManager {
|
|||
final ContentSection section,
|
||||
final Category folder,
|
||||
final WorkflowTemplate workflowTemplate,
|
||||
final LifecycleDefinition lifecycleDefinition,
|
||||
final Class<T> type) {
|
||||
|
||||
final Optional<ContentType> contentType = typeRepo
|
||||
|
|
@ -206,11 +204,6 @@ public class ContentItemManager {
|
|||
item.setVersion(ContentItemVersion.DRAFT);
|
||||
item.setContentType(contentType.get());
|
||||
|
||||
if (lifecycleDefinition != null) {
|
||||
final Lifecycle lifecycle = lifecycleManager.createLifecycle(
|
||||
lifecycleDefinition);
|
||||
item.setLifecycle(lifecycle);
|
||||
}
|
||||
if (workflowTemplate != null) {
|
||||
final Workflow workflow = workflowManager.createWorkflow(
|
||||
workflowTemplate);
|
||||
|
|
@ -302,20 +295,23 @@ public class ContentItemManager {
|
|||
|
||||
final ContentItem copy;
|
||||
try {
|
||||
copy = item.getClass().newInstance();
|
||||
copy = draftItem.getClass().newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
copy.setContentType(contentType.get());
|
||||
|
||||
final Lifecycle lifecycle = lifecycleManager.createLifecycle(
|
||||
contentType.get().getDefaultLifecycle());
|
||||
final Workflow workflow = workflowManager.createWorkflow(contentType
|
||||
.get().getDefaultWorkflow());
|
||||
|
||||
copy.setLifecycle(lifecycle);
|
||||
copy.setWorkflow(workflow);
|
||||
if (draftItem.getWorkflow() != null) {
|
||||
final WorkflowTemplate template = draftItem.getWorkflow()
|
||||
.getTemplate();
|
||||
final Workflow copyWorkflow = workflowManager.createWorkflow(
|
||||
template);
|
||||
copy.setWorkflow(copyWorkflow);
|
||||
}
|
||||
|
||||
draftItem.getCategories().forEach(categorization -> categoryManager
|
||||
.addObjectToCategory(copy, categorization.getCategory()));
|
||||
|
|
@ -360,7 +356,7 @@ public class ContentItemManager {
|
|||
if (writeMethod == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (LocalizedString.class.equals(propType)) {
|
||||
final LocalizedString source;
|
||||
final LocalizedString target;
|
||||
|
|
@ -474,14 +470,49 @@ public class ContentItemManager {
|
|||
|
||||
/**
|
||||
* Creates a live version of content item or updates the live version of a
|
||||
* content item if there already a live version.
|
||||
* content item if there already a live version using the default lifecycle
|
||||
* for the content type of the provided item.
|
||||
*
|
||||
* @param item The content item to publish.
|
||||
*
|
||||
* @return The published content item.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ContentItem publish(final ContentItem item) {
|
||||
if (item == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"The item to publish can't be null.");
|
||||
}
|
||||
|
||||
final LifecycleDefinition lifecycleDefinition = item.getContentType()
|
||||
.getDefaultLifecycle();
|
||||
|
||||
return publish(item, lifecycleDefinition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a live version of content item or updates the live version of a
|
||||
* content item if there already a live version.
|
||||
*
|
||||
* @param item The content item to publish.
|
||||
* @param lifecycleDefinition The definition of the lifecycle to use for the
|
||||
* new item.
|
||||
*
|
||||
* @return The published content item.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ContentItem publish(final ContentItem item,
|
||||
final LifecycleDefinition lifecycleDefinition) {
|
||||
if (item == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"The item to publish can't be null.");
|
||||
}
|
||||
|
||||
if (lifecycleDefinition == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"The lifecycle definition for the "
|
||||
+ "lifecycle of the item to publish can't be null.");
|
||||
}
|
||||
|
||||
final ContentItem draftItem = getDraftVersion(item, ContentItem.class);
|
||||
final ContentItem liveItem;
|
||||
|
||||
|
|
@ -496,7 +527,11 @@ public class ContentItemManager {
|
|||
}
|
||||
|
||||
liveItem.setContentType(draftItem.getContentType());
|
||||
liveItem.setLifecycle(draftItem.getLifecycle());
|
||||
|
||||
final Lifecycle lifecycle = lifecycleManager.createLifecycle(
|
||||
lifecycleDefinition);
|
||||
|
||||
liveItem.setLifecycle(lifecycle);
|
||||
liveItem.setWorkflow(draftItem.getWorkflow());
|
||||
|
||||
draftItem.getCategories().forEach(categorization -> categoryManager
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ import org.libreccm.workflow.WorkflowTemplate;
|
|||
import org.libreccm.workflow.WorkflowTemplateRepository;
|
||||
import org.librecms.contenttypes.Article;
|
||||
import org.librecms.contenttypes.Event;
|
||||
import org.librecms.lifecycle.LifecycleDefinition;
|
||||
import org.librecms.lifecycle.LifecycleDefinitionRepository;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -254,8 +253,6 @@ public class ContentItemManagerTest {
|
|||
assertThat("Name has not the expected value.",
|
||||
article.getName().getValue(locale),
|
||||
is(equalTo("new-article")));
|
||||
assertThat("lifecycle was not added to content item.",
|
||||
article.getLifecycle(), is(not(nullValue())));
|
||||
assertThat("workflow was not added to content item.",
|
||||
article.getWorkflow(), is(not(nullValue())));
|
||||
|
||||
|
|
@ -333,7 +330,7 @@ public class ContentItemManagerTest {
|
|||
@ShouldMatchDataSet(
|
||||
value = "datasets/org/librecms/contentsection/"
|
||||
+ "ContentItemManagerTest/"
|
||||
+ "after-create-contentitem-with-lifecycle-and-workflow.xml",
|
||||
+ "after-create-contentitem-with-workflow.xml",
|
||||
excludeColumns = {"categorization_id",
|
||||
"lifecycle_id",
|
||||
"object_id",
|
||||
|
|
@ -343,21 +340,18 @@ public class ContentItemManagerTest {
|
|||
"uuid",
|
||||
"workflow_id"
|
||||
})
|
||||
public void createContentItemWithLifecycleAndWorkflow() {
|
||||
public void createContentItemWithWorkflow() {
|
||||
final ContentSection section = sectionRepo.findByLabel("info");
|
||||
final Category folder = section.getRootDocumentsFolder();
|
||||
|
||||
final WorkflowTemplate workflowTemplate = workflowTemplateRepo
|
||||
.findById(-110L);
|
||||
final LifecycleDefinition lifecycleDefinition = lifecycleDefinitionRepo
|
||||
.findById(-210L);
|
||||
|
||||
|
||||
final Article article = itemManager.createContentItem(
|
||||
"new-article",
|
||||
section,
|
||||
folder,
|
||||
workflowTemplate,
|
||||
lifecycleDefinition,
|
||||
Article.class);
|
||||
|
||||
assertThat("DisplayName has not the expected value.",
|
||||
|
|
@ -366,8 +360,6 @@ public class ContentItemManagerTest {
|
|||
assertThat("Name has not the expected value.",
|
||||
article.getName().getValue(locale),
|
||||
is(equalTo("new-article")));
|
||||
assertThat("lifecycle was not added to content item.",
|
||||
article.getLifecycle(), is(not(nullValue())));
|
||||
assertThat("workflow was not added to content item.",
|
||||
article.getWorkflow(), is(not(nullValue())));
|
||||
|
||||
|
|
@ -390,20 +382,17 @@ public class ContentItemManagerTest {
|
|||
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
|
||||
+ "ContentItemManagerTest/data.xml")
|
||||
@ShouldThrowException(IllegalArgumentException.class)
|
||||
public void createItemTypeNotInSectionWithLifecycleAndWorkflow() {
|
||||
public void createItemTypeNotInSectionWithWorkflow() {
|
||||
final ContentSection section = sectionRepo.findByLabel("info");
|
||||
final Category folder = section.getRootDocumentsFolder();
|
||||
|
||||
final WorkflowTemplate workflowTemplate = workflowTemplateRepo
|
||||
.findById(-110L);
|
||||
final LifecycleDefinition lifecycleDefinition = lifecycleDefinitionRepo
|
||||
.findById(-210L);
|
||||
|
||||
itemManager.createContentItem("Test",
|
||||
section,
|
||||
folder,
|
||||
workflowTemplate,
|
||||
lifecycleDefinition,
|
||||
Event.class);
|
||||
}
|
||||
|
||||
|
|
@ -414,20 +403,17 @@ public class ContentItemManagerTest {
|
|||
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
|
||||
+ "ContentItemManagerTest/data.xml")
|
||||
@ShouldThrowException(IllegalArgumentException.class)
|
||||
public void createItemNameIsNullWithLifecycleAndWorkflow() {
|
||||
public void createItemNameIsNullWithWorkflow() {
|
||||
final ContentSection section = sectionRepo.findByLabel("info");
|
||||
final Category folder = section.getRootDocumentsFolder();
|
||||
|
||||
final WorkflowTemplate workflowTemplate = workflowTemplateRepo
|
||||
.findById(-110L);
|
||||
final LifecycleDefinition lifecycleDefinition = lifecycleDefinitionRepo
|
||||
.findById(-210L);
|
||||
|
||||
itemManager.createContentItem(null,
|
||||
section,
|
||||
folder,
|
||||
workflowTemplate,
|
||||
lifecycleDefinition,
|
||||
Article.class);
|
||||
}
|
||||
|
||||
|
|
@ -442,37 +428,10 @@ public class ContentItemManagerTest {
|
|||
final ContentSection section = sectionRepo.findByLabel("info");
|
||||
final Category folder = section.getRootDocumentsFolder();
|
||||
|
||||
final LifecycleDefinition lifecycleDefinition = lifecycleDefinitionRepo
|
||||
.findById(-210L);
|
||||
|
||||
itemManager.createContentItem(null,
|
||||
section,
|
||||
folder,
|
||||
null,
|
||||
lifecycleDefinition,
|
||||
Article.class);
|
||||
}
|
||||
|
||||
// Create content item with lifecycle and workflow name empty
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@InSequence(2500)
|
||||
@UsingDataSet("datasets/org/librecms/contentsection/"
|
||||
+ "ContentItemManagerTest/data.xml")
|
||||
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
|
||||
+ "ContentItemManagerTest/data.xml")
|
||||
@ShouldThrowException(IllegalArgumentException.class)
|
||||
public void createItemNoLifecycle() {
|
||||
final ContentSection section = sectionRepo.findByLabel("info");
|
||||
final Category folder = section.getRootDocumentsFolder();
|
||||
|
||||
final WorkflowTemplate workflowTemplate = workflowTemplateRepo
|
||||
.findById(-110L);
|
||||
|
||||
itemManager.createContentItem(null,
|
||||
section,
|
||||
folder,
|
||||
workflowTemplate,
|
||||
null,
|
||||
Article.class);
|
||||
}
|
||||
|
||||
|
|
@ -483,19 +442,16 @@ public class ContentItemManagerTest {
|
|||
@ShouldMatchDataSet("datasets/org/librecms/contentsection/"
|
||||
+ "ContentItemManagerTest/data.xml")
|
||||
@ShouldThrowException(IllegalArgumentException.class)
|
||||
public void createItemFolderIsNullWithLifecycleAndWorkflow() {
|
||||
public void createItemFolderIsNullWithWorkflow() {
|
||||
final ContentSection section = sectionRepo.findByLabel("info");
|
||||
|
||||
final WorkflowTemplate workflowTemplate = workflowTemplateRepo
|
||||
.findById(-110L);
|
||||
final LifecycleDefinition lifecycleDefinition = lifecycleDefinitionRepo
|
||||
.findById(-210L);
|
||||
|
||||
itemManager.createContentItem("Test",
|
||||
section,
|
||||
null,
|
||||
workflowTemplate,
|
||||
lifecycleDefinition,
|
||||
Article.class);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,10 +48,12 @@ public class DatasetsTest extends DatasetsVerifier {
|
|||
"/datasets/org/librecms/contentsection/ContentSectionManagerTest/after-create.xml",
|
||||
"/datasets/org/librecms/contentsection/ContentSectionManagerTest/after-remove-role.xml",
|
||||
"/datasets/org/librecms/contentsection/ContentSectionManagerTest/after-rename.xml",
|
||||
|
||||
"/datasets/org/librecms/contentsection/ContentItemRepositoryTest/data.xml",
|
||||
|
||||
"/datasets/org/librecms/contentsection/ContentItemManagerTest/data.xml",
|
||||
"/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem.xml",
|
||||
"/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem-with-lifecycle-and-workflow.xml",
|
||||
"/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem-with-workflow.xml",
|
||||
"/datasets/org/librecms/contentsection/ContentItemManagerTest/move-before.xml",
|
||||
"/datasets/org/librecms/contentsection/ContentItemManagerTest/move-after.xml",
|
||||
"/datasets/org/librecms/contentsection/ContentItemManagerTest/copy-to-other-folder-after.xml",
|
||||
|
|
|
|||
|
|
@ -1457,6 +1457,7 @@ create table CCM_CMS.ARTICLE_LEADS (
|
|||
|
||||
create table CCM_CORE.WORKFLOWS (
|
||||
WORKFLOW_ID bigint not null,
|
||||
TEMPLATE_ID bigint,
|
||||
primary key (WORKFLOW_ID)
|
||||
);
|
||||
|
||||
|
|
@ -2753,4 +2754,9 @@ create sequence hibernate_sequence start with 1 increment by 1;
|
|||
alter table CCM_CMS.CONTENT_SECTION_WORKFLOW_TEMPLATES
|
||||
add constraint FK6kuejkcl9hcbkr8q6bdlatt8q
|
||||
foreign key (CONTENT_SECTION_ID)
|
||||
references CCM_CMS.CONTENT_SECTIONS;
|
||||
references CCM_CMS.CONTENT_SECTIONS;
|
||||
|
||||
alter table CCM_CORE.WORKFLOWS
|
||||
add constraint FKol71r1t83h0qe65gglq43far2
|
||||
foreign key (TEMPLATE_ID)
|
||||
references CCM_CORE.WORKFLOW_TEMPLATES;
|
||||
|
|
@ -1457,6 +1457,7 @@ CREATE SCHEMA ccm_cms;
|
|||
|
||||
create table CCM_CORE.WORKFLOWS (
|
||||
WORKFLOW_ID int8 not null,
|
||||
TEMPLATE_ID int8,
|
||||
primary key (WORKFLOW_ID)
|
||||
);
|
||||
|
||||
|
|
@ -2753,4 +2754,9 @@ create sequence hibernate_sequence start 1 increment 1;
|
|||
alter table CCM_CMS.CONTENT_SECTION_WORKFLOW_TEMPLATES
|
||||
add constraint FK6kuejkcl9hcbkr8q6bdlatt8q
|
||||
foreign key (CONTENT_SECTION_ID)
|
||||
references CCM_CMS.CONTENT_SECTIONS;
|
||||
references CCM_CMS.CONTENT_SECTIONS;
|
||||
|
||||
alter table CCM_CORE.WORKFLOWS
|
||||
add constraint FKol71r1t83h0qe65gglq43far2
|
||||
foreign key (template_id)
|
||||
references CCM_CORE.WORKFLOW_TEMPLATES;
|
||||
|
|
@ -94,14 +94,14 @@
|
|||
localized_value="The only phase"
|
||||
locale="en" />
|
||||
|
||||
<ccm_cms.lifecycles lifecycle_id="-300"
|
||||
<!--<ccm_cms.lifecycles lifecycle_id="-300"
|
||||
started="false"
|
||||
finished="false"
|
||||
definition_id="-210" />
|
||||
|
||||
<ccm_cms.lifecyle_phases phase_id="-300100"
|
||||
started="false"
|
||||
finished="false" />
|
||||
finished="false" />-->
|
||||
|
||||
<ccm_core.ccm_objects object_id="-1100"
|
||||
display_name="info"
|
||||
|
|
@ -104,7 +104,7 @@
|
|||
localized_value="The only phase"
|
||||
locale="en" />
|
||||
|
||||
<ccm_cms.lifecycles lifecycle_id="-300"
|
||||
<!--<ccm_cms.lifecycles lifecycle_id="-300"
|
||||
started="false"
|
||||
finished="false"
|
||||
definition_id="-200" />
|
||||
|
|
@ -114,7 +114,7 @@
|
|||
finished="false" />
|
||||
<ccm_cms.lifecyle_phases phase_id="-300200"
|
||||
started="false"
|
||||
finished="false" />
|
||||
finished="false" />-->
|
||||
|
||||
<ccm_core.ccm_objects object_id="-1100"
|
||||
display_name="info"
|
||||
|
|
|
|||
Loading…
Reference in New Issue