From bedaafd781b63dc567db7edbdaa736b5a6869aab Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Mon, 11 Dec 2006 16:07:10 +0000 Subject: [PATCH] . Files in the submit dialog list are now matched against the regular expressions provided for web project workflow definitions . Configuring the workflow file match regular expression has been moved into the Configure Workflow screen git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4569 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/messages/webclient.properties | 2 + .../web/bean/wcm/CreateWebsiteWizard.java | 17 +++++- .../web/bean/wcm/FormWorkflowDialog.java | 57 ++++++++++++++++++- .../alfresco/web/bean/wcm/SubmitDialog.java | 51 ++++++++++++++++- .../create-website-wizard/form-workflow.jsp | 12 ++++ .../wcm/create-website-wizard/settings.jsp | 2 +- 6 files changed, 133 insertions(+), 8 deletions(-) diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index a00716b4e0..3d028c61bf 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -863,6 +863,8 @@ edit_website_title=Edit Web Project Wizard edit_website_desc=This wizard helps you modify the settings for a web project space. edit_website_finish_instruction=To close this wizard and save the modified settings for your web project space click Finish. To review or change your selections click Back. edit_website=Edit Web Project Settings +workflow_settings=Workflow Settings +error_filename_pattern=Error with workflow filename pattern: {0} # Invite web users wizard messages invite_website_users=Invite Web Project Users diff --git a/source/java/org/alfresco/web/bean/wcm/CreateWebsiteWizard.java b/source/java/org/alfresco/web/bean/wcm/CreateWebsiteWizard.java index 7c399178bf..219d045087 100644 --- a/source/java/org/alfresco/web/bean/wcm/CreateWebsiteWizard.java +++ b/source/java/org/alfresco/web/bean/wcm/CreateWebsiteWizard.java @@ -63,13 +63,16 @@ import org.apache.commons.logging.LogFactory; */ public class CreateWebsiteWizard extends BaseWizardBean { - private static final String COMPONENT_FORMLIST = "form-list"; - private static final String COMPONENT_WORKFLOWLIST = "workflow-list"; private static final String MSG_DESCRIPTION = "description"; private static final String MSG_NAME = "name"; private static final String MSG_USERROLES = "create_website_summary_users"; private static final String MSG_FORM_SUMMARY = "website_form_summary"; private static final String MSG_NONE = "value_not_set"; + + private static final String COMPONENT_FORMLIST = "form-list"; + private static final String COMPONENT_WORKFLOWLIST = "workflow-list"; + + private static final String MATCH_DEFAULT = ".*"; private static final String WEBAPP_DEFAULT = "ROOT"; @@ -661,7 +664,8 @@ public class CreateWebsiteWizard extends BaseWizardBean if (index != -1) { WorkflowDefinition workflow = (WorkflowDefinition)this.workflowsList.get(index).getValue(); - this.workflows.add(new WorkflowWrapper(workflow.getName(), workflow.getTitle(), workflow.getDescription())); + this.workflows.add(new WorkflowWrapper( + workflow.getName(), workflow.getTitle(), workflow.getDescription(), MATCH_DEFAULT)); } } @@ -946,6 +950,13 @@ public class CreateWebsiteWizard extends BaseWizardBean private Map params; public WorkflowWrapper(String name, String title, String description) + { + this.name = name; + this.title = title; + this.description = description; + } + + public WorkflowWrapper(String name, String title, String description, String filenamePattern) { this.name = name; this.title = title; diff --git a/source/java/org/alfresco/web/bean/wcm/FormWorkflowDialog.java b/source/java/org/alfresco/web/bean/wcm/FormWorkflowDialog.java index 0c2f0f6f80..a27e7d9666 100644 --- a/source/java/org/alfresco/web/bean/wcm/FormWorkflowDialog.java +++ b/source/java/org/alfresco/web/bean/wcm/FormWorkflowDialog.java @@ -16,13 +16,18 @@ */ package org.alfresco.web.bean.wcm; +import java.text.MessageFormat; import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import javax.faces.context.FacesContext; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.service.cmr.workflow.WorkflowDefinition; import org.alfresco.service.cmr.workflow.WorkflowService; import org.alfresco.service.cmr.workflow.WorkflowTaskDefinition; +import org.alfresco.web.app.Application; import org.alfresco.web.bean.dialog.BaseDialogBean; import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.repository.TransientNode; @@ -39,8 +44,12 @@ import org.apache.commons.logging.LogFactory; */ public class FormWorkflowDialog extends BaseDialogBean { + private static final String MSG_ERROR_FILENAME_PATTERN = "error_filename_pattern"; + private static final Log logger = LogFactory.getLog(FormWorkflowDialog.class); + private String filenamePattern; + protected WorkflowService workflowService; protected CreateWebsiteWizard websiteWizard; protected TransientNode workflowNode; @@ -62,6 +71,29 @@ public class FormWorkflowDialog extends BaseDialogBean this.websiteWizard = wizard; } + /** + * @return Returns the filename pattern. + */ + public String getFilenamePattern() + { + if (this.filenamePattern == null) + { + this.filenamePattern = getActionWorkflow().getFilenamePattern(); + } + return this.filenamePattern; + } + + /** + * @param filenamePattern The filename pattern to set. + */ + public void setFilenamePattern(String filenamePattern) + { + if (this.filenamePattern != null && this.filenamePattern.length() != 0) + { + this.filenamePattern = filenamePattern; + } + } + /** * @see org.alfresco.web.bean.dialog.BaseDialogBean#init(java.util.Map) */ @@ -70,6 +102,7 @@ public class FormWorkflowDialog extends BaseDialogBean { super.init(parameters); + this.filenamePattern = null; this.workflowNode = null; WorkflowWrapper workflow = getActionWorkflow(); if (workflow != null && workflow.getParams() != null) @@ -86,11 +119,29 @@ public class FormWorkflowDialog extends BaseDialogBean @Override protected String finishImpl(FacesContext context, String outcome) throws Exception { - // push serialized params back into workflow object if (this.workflowNode != null) { - getActionWorkflow().setParams( WorkflowUtil.prepareTaskParams(this.workflowNode) ); - getActionWorkflow().setType(this.workflowNode.getType()); + // push serialized params back into workflow object + WorkflowWrapper wf = getActionWorkflow(); + wf.setParams(WorkflowUtil.prepareTaskParams(this.workflowNode)); + wf.setType(this.workflowNode.getType()); + + if (this.filenamePattern != null && this.filenamePattern.length() != 0) + { + // check the filename pattern compiles and display an error if a problem occurs + try + { + Pattern.compile(this.filenamePattern); + } + catch (PatternSyntaxException pax) + { + throw new AlfrescoRuntimeException( + MessageFormat.format( + Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_FILENAME_PATTERN), + pax.getMessage()), pax); + } + wf.setFilenamePattern(this.filenamePattern); + } } return outcome; } diff --git a/source/java/org/alfresco/web/bean/wcm/SubmitDialog.java b/source/java/org/alfresco/web/bean/wcm/SubmitDialog.java index 293aac1f01..5975517275 100644 --- a/source/java/org/alfresco/web/bean/wcm/SubmitDialog.java +++ b/source/java/org/alfresco/web/bean/wcm/SubmitDialog.java @@ -25,6 +25,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.regex.Pattern; import javax.faces.context.FacesContext; @@ -287,13 +288,38 @@ public class SubmitDialog extends BaseDialogBean NodeRef websiteRef = this.avmBrowseBean.getWebsite().getNodeRef(); List webWorkflowRefs = this.nodeService.getChildAssocs( websiteRef, WCMAppModel.ASSOC_WEBWORKFLOWDEFAULTS, RegexQNamePattern.MATCH_ALL); + List workflowMatchers = new ArrayList(webWorkflowRefs.size()); for (ChildAssociationRef ref : webWorkflowRefs) { NodeRef wfDefaultsRef = ref.getChildRef(); String wfName = (String)this.nodeService.getProperty(wfDefaultsRef, WCMAppModel.PROP_WORKFLOW_NAME); Map params = (Map)AVMWorkflowUtil.deserializeWorkflowParams( wfDefaultsRef); - this.workflows.add(new FormWorkflowWrapper(wfName, params)); + String matchPattern = (String)this.nodeService.getProperty( + wfDefaultsRef, WCMAppModel.PROP_FILENAMEPATTERN); + if (matchPattern != null) + { + // add to temp list with the file name pattern + workflowMatchers.add(new FormWorkflowWrapper(wfName, params, matchPattern)); + } + } + + // perform match on each submitted file against available workflows + for (ItemWrapper wrapper : this.submitItems) + { + String path = wrapper.getPath(); + for (int i=0; i Params; + private Pattern filenamePattern; FormWorkflowWrapper(String name, Map params) { this.Name = name; this.Params = params; } + + FormWorkflowWrapper(String name, Map params, String filenamePattern) + { + this.Name = name; + this.Params = params; + if (filenamePattern != null) + { + this.filenamePattern = Pattern.compile(filenamePattern); + } + } + boolean matchesPath(String path) + { + if (filenamePattern != null) + { + return filenamePattern.matcher(path).matches(); + } + else + { + return false; + } + } + @Override public int hashCode() { diff --git a/source/web/jsp/wcm/create-website-wizard/form-workflow.jsp b/source/web/jsp/wcm/create-website-wizard/form-workflow.jsp index 3d06be32b5..d13367675e 100644 --- a/source/web/jsp/wcm/create-website-wizard/form-workflow.jsp +++ b/source/web/jsp/wcm/create-website-wizard/form-workflow.jsp @@ -26,3 +26,15 @@ + + + + + + + + + + + diff --git a/source/web/jsp/wcm/create-website-wizard/settings.jsp b/source/web/jsp/wcm/create-website-wizard/settings.jsp index 72945f6769..52be48cc53 100644 --- a/source/web/jsp/wcm/create-website-wizard/settings.jsp +++ b/source/web/jsp/wcm/create-website-wizard/settings.jsp @@ -53,7 +53,7 @@ - +