From dd52779f3c44b7491af47453c389b384a4a7a2fa Mon Sep 17 00:00:00 2001 From: quasi Date: Wed, 18 Apr 2012 09:29:52 +0000 Subject: [PATCH] =?UTF-8?q?Default=20Workflows=20f=C3=BCr=20ContentSection?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Es wird jetzt der Standard-Arbeitsablauf richtig gesetzt und gespeichert Es ist ein DB-Update notwendig git-svn-id: https://svn.libreccm.org/ccm/trunk@1602 8810af33-2d31-482b-a856-94f89814c4df --- .../content-section/ContentSection.pdl | 3 + .../src/com/arsdigita/cms/ContentSection.java | 68 ++++++++++++++++++- .../contentsection/ContentSectionSetup.java | 7 +- .../AbstractContentTypeLoader.java | 8 +-- 4 files changed, 76 insertions(+), 10 deletions(-) diff --git a/ccm-cms/pdl/com/arsdigita/content-section/ContentSection.pdl b/ccm-cms/pdl/com/arsdigita/content-section/ContentSection.pdl index 49f4a6e4f..c66cf649e 100755 --- a/ccm-cms/pdl/com/arsdigita/content-section/ContentSection.pdl +++ b/ccm-cms/pdl/com/arsdigita/content-section/ContentSection.pdl @@ -239,6 +239,9 @@ association { to section_workflow_template_map.section_id, join section_workflow_template_map.wf_template_id to cw_process_definitions.process_def_id; + + // Save the default workflow template for a content section + Boolean[1..1] isDefault = section_workflow_template_map.is_default; } diff --git a/ccm-cms/src/com/arsdigita/cms/ContentSection.java b/ccm-cms/src/com/arsdigita/cms/ContentSection.java index 303c3c62a..cf3fb87fd 100755 --- a/ccm-cms/src/com/arsdigita/cms/ContentSection.java +++ b/ccm-cms/src/com/arsdigita/cms/ContentSection.java @@ -90,6 +90,7 @@ import org.apache.log4j.Logger; * * @author Michael Pih * @author Jack Chung + * @author Sören Bernstein (quasi@barkhof.uni-bremen.de) * @version $Revision: #37 $ $DateTime: 2004/08/17 23:15:09 $ * @version $Id: ContentSection.java 2209 2011-06-22 07:59:10Z pboy $ */ @@ -899,7 +900,11 @@ public class ContentSection extends Application { * @param template The workflow template */ public void addWorkflowTemplate(WorkflowTemplate template) { - template.addToAssociation(getWorkflowTemplatesAssociation()); + this.addWorkflowTemplate(template, false); + } + public void addWorkflowTemplate(WorkflowTemplate template, boolean isDefault) { + DataObject link = template.addToAssociation(getWorkflowTemplatesAssociation()); + link.set("isDefault", isDefault); } /** @@ -911,6 +916,67 @@ public class ContentSection extends Application { template.removeFromAssociation(getWorkflowTemplatesAssociation()); } + /** + * Set a WorkflowTemplate as default for this ContentSection by label + * + * @param wf The label of a workflow template to set as new default workflow template + */ + public void setDefaultWorkflowTemplate(String wf) { + TaskCollection taskColl = getWorkflowTemplates(); + while (taskColl.next()) { + if(((WorkflowTemplate) taskColl.getTask()).getLabel().equals(wf)) { + ((DataObject) taskColl.get("link")).set("isDefault", true); + } else { + ((DataObject) taskColl.get("link")).set("isDefault", false); + } + } + } + + /** + * Set a WorkflowTemplate as default for this ContentSection + * + * @param wf The workflow template to set as new default workflow template + */ + public void setDefaultWorkflowTemplate(WorkflowTemplate wf) { + TaskCollection taskColl = getWorkflowTemplates(); + while (taskColl.next()) { + if(((WorkflowTemplate) taskColl.getTask()).equals(wf)) { + ((DataObject) taskColl.get("link")).set("isDefault", true); + } else { + ((DataObject) taskColl.get("link")).set("isDefault", false); + } + } + } + + /** + * Get the default workflow template for this content section + * + * @return the default workflow template or null, if this method fails + */ + public WorkflowTemplate getDefaultWorkflowTemplate() { + TaskCollection taskColl = getWorkflowTemplates(); + while(taskColl.next()) { + if(((Boolean) taskColl.get("link.isDefault"))) { + WorkflowTemplate wf = (WorkflowTemplate) taskColl.getTask(); + taskColl.close(); + return wf; + } + } + + // If we get here, there is no default workflow template set for this section + // To solve this, we fetch the first item and set it as default + taskColl = getWorkflowTemplates(); + while(taskColl.next()) { + WorkflowTemplate wf = (WorkflowTemplate) taskColl.getTask(); + ((DataObject) taskColl.get("link")).set("isDefault", true); + taskColl.close(); + return wf; + } + + // OK, now we're screwed + return null; + } + private DataAssociation getWorkflowTemplatesAssociation() { return (DataAssociation) get(WF_TEMPLATES); } diff --git a/ccm-cms/src/com/arsdigita/cms/contentsection/ContentSectionSetup.java b/ccm-cms/src/com/arsdigita/cms/contentsection/ContentSectionSetup.java index 3abece69e..904c1dabe 100644 --- a/ccm-cms/src/com/arsdigita/cms/contentsection/ContentSectionSetup.java +++ b/ccm-cms/src/com/arsdigita/cms/contentsection/ContentSectionSetup.java @@ -112,7 +112,7 @@ public final class ContentSectionSetup { // Setup the access controls setup.registerRoles(defaultRoles); - setup.registerWorkflows(defaultWorkflows); + setup.registerWorkflowTemplates(defaultWorkflows); setup.registerViewers(isPubliclyViewable); setup.registerPublicationCycles(); setup.registerResolvers(itemResolverClassName, templateResolverClassName); @@ -322,7 +322,7 @@ public final class ContentSectionSetup { m_section.save(); } - private void registerWorkflows(List workflows) { + private void registerWorkflowTemplates(List workflows) { Iterator workflowsIter = workflows.iterator(); @@ -399,6 +399,7 @@ public final class ContentSectionSetup { // If this workflow should be the default or is the first one // save it for easy access in registerContentType if(m_wf == null || (workflow.containsKey("isDefault") && workflow.get("isDefault").equals("true"))) { + m_section.setDefaultWorkflowTemplate(wf); m_wf = wf; } } @@ -416,7 +417,7 @@ public final class ContentSectionSetup { ContentSectionConfig config = new ContentSectionConfig(); config.load(); - registerWorkflows(config.getDefaultWorkflows()); + registerWorkflowTemplates(config.getDefaultWorkflows()); } diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeLoader.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeLoader.java index 450f86ad1..9fc08b7ca 100755 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeLoader.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/AbstractContentTypeLoader.java @@ -55,6 +55,7 @@ import org.apache.log4j.Logger; * that can be used by content types to reduce code duplication. * * @author Rafael H. Schloming <rhs@mit.edu> + * @authro Sören Bernstein (quasi@barkhof.uni-bremen.de) * @version $Revision: #754 $ $Date: 2005/09/02 $ $Author: pboy $ **/ public abstract class AbstractContentTypeLoader extends PackageLoader { @@ -111,12 +112,7 @@ public abstract class AbstractContentTypeLoader extends PackageLoader { ldc.close(); } - TaskCollection tc = section.getWorkflowTemplates(); - WorkflowTemplate wf = null; - if (tc.next()) { - wf = (WorkflowTemplate) tc.getTask(); - tc.close(); - } + WorkflowTemplate wf = section.getDefaultWorkflowTemplate(); for (Iterator it = types.iterator(); it.hasNext();) { final ContentType type = (ContentType) it.next();