diff --git a/source/java/org/alfresco/web/bean/wcm/AVMWorkflowUtil.java b/source/java/org/alfresco/web/bean/wcm/AVMWorkflowUtil.java new file mode 100644 index 0000000000..9ca57850ad --- /dev/null +++ b/source/java/org/alfresco/web/bean/wcm/AVMWorkflowUtil.java @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2005 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + */ +package org.alfresco.web.bean.wcm; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; + +import javax.faces.context.FacesContext; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.model.WCMAppModel; +import org.alfresco.repo.content.MimetypeMap; +import org.alfresco.service.cmr.avm.AVMNodeDescriptor; +import org.alfresco.service.cmr.avm.AVMService; +import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.util.GUID; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.workflow.WorkflowUtil; + +/** + * AVM Specific workflow related helper methods. + * + * @author Kevin Roast + */ +public class AVMWorkflowUtil extends WorkflowUtil +{ + private static final String STORE_WORKFLOW_SYSTEM = "workflow-system"; + private static final String FOLDER_PACKAGES = "packages"; + + /** + * Return the AVM workflow package root folder path - creating the default + * store and root folder if required. + * + * @param avmService AVMService to use + * + * @return AVM Root package path + */ + public static String getAVMPackageRoot(AVMService avmService) + { + String packagesRoot = STORE_WORKFLOW_SYSTEM + ":/" + FOLDER_PACKAGES; + AVMNodeDescriptor packagesDesc = avmService.lookup(-1, packagesRoot); + if (packagesDesc == null) + { + avmService.createAVMStore(STORE_WORKFLOW_SYSTEM); + avmService.createDirectory(STORE_WORKFLOW_SYSTEM + ":/", FOLDER_PACKAGES); + } + return packagesRoot; + } + + /** + * Create an AVM layered workflow package against the specified sandbox path. + * + * @param avmService AVMService to use + * @param sandboxPath The sandbox path to layer the package over + * + * @return Path to the layered package. + */ + public static String createAVMLayeredPackage(AVMService avmService, String sandboxPath) + { + String packagesRoot = getAVMPackageRoot(avmService); + String packageName = GUID.generate(); + avmService.createLayeredDirectory(sandboxPath, packagesRoot, packageName); + + return packagesRoot + "/" + packageName; + } + + /** + * Serialize the workflow params to a content stream + * + * @param params Serializable workflow params + * @param workflowRef The noderef to write the property too + */ + public static void serializeWorkflowParams(Serializable params, NodeRef workflowRef) + { + try + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(params); + oos.close(); + // write the serialized Map as a binary content stream - like database blob! + ContentService cs = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getContentService(); + ContentWriter writer = cs.getWriter(workflowRef, WCMAppModel.PROP_WORKFLOWDEFAULTS, true); + writer.setMimetype(MimetypeMap.MIMETYPE_BINARY); + writer.putContent(new ByteArrayInputStream(baos.toByteArray())); + } + catch (IOException ioerr) + { + throw new AlfrescoRuntimeException("Unable to serialize workflow default parameters: " + ioerr.getMessage()); + } + } + + /** + * Deserialize the default workflow params from a content stream + * + * @param workflowRef The noderef to write the property too + * + * @return Serializable workflow params + */ + public static Serializable deserializeWorkflowParams(NodeRef workflowRef) + { + try + { + // restore the serialized Map from a binary content stream - like database blob! + Serializable params = null; + ContentService cs = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getContentService(); + ContentReader reader = cs.getReader(workflowRef, WCMAppModel.PROP_WORKFLOWDEFAULTS); + if (reader != null) + { + ObjectInputStream ois = new ObjectInputStream(reader.getContentInputStream()); + params = (Serializable)ois.readObject(); + ois.close(); + } + return params; + } + catch (IOException ioErr) + { + throw new AlfrescoRuntimeException("Unable to deserialize workflow default parameters: " + ioErr.getMessage()); + } + catch (ClassNotFoundException classErr) + { + throw new AlfrescoRuntimeException("Unable to deserialize workflow default parameters: " + classErr.getMessage()); + } + } +} diff --git a/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java b/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java index 46a9a0aaea..b48ed34c11 100644 --- a/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java +++ b/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java @@ -16,12 +16,12 @@ */ package org.alfresco.web.bean.wcm; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.ResourceBundle; import javax.faces.context.FacesContext; import javax.faces.event.ValueChangeEvent; @@ -30,17 +30,23 @@ import javax.faces.model.SelectItem; import org.alfresco.config.Config; import org.alfresco.config.ConfigElement; import org.alfresco.config.ConfigService; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.model.WCMAppModel; import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.workflow.WorkflowModel; +import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.avmsync.AVMDifference; import org.alfresco.service.cmr.avmsync.AVMSyncService; -import org.alfresco.service.cmr.repository.*; -import org.alfresco.service.cmr.workflow.*; -import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.workflow.WorkflowDefinition; +import org.alfresco.service.cmr.workflow.WorkflowPath; +import org.alfresco.service.cmr.workflow.WorkflowService; +import org.alfresco.service.cmr.workflow.WorkflowTask; +import org.alfresco.service.cmr.workflow.WorkflowTaskState; import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.web.app.Application; @@ -55,7 +61,6 @@ import org.alfresco.web.forms.FormInstanceDataImpl; import org.alfresco.web.forms.FormProcessor; import org.alfresco.web.forms.FormsService; import org.alfresco.web.forms.Rendition; -import org.alfresco.web.forms.RenditionImpl; import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.wcm.component.UIUserSandboxes; import org.apache.commons.logging.Log; @@ -123,6 +128,7 @@ public class CreateWebContentWizard extends BaseContentWizard this.avmBrowseBean = avmBrowseBean; } + // ------------------------------------------------------------------------------ // Wizard implementation @@ -228,94 +234,112 @@ public class CreateWebContentWizard extends BaseContentWizard { WorkflowDefinition wd = null; Map parameters = null; - + // get the workflow definition and parameters - { - final Node website = this.avmBrowseBean.getWebsite(); - final List webFormRefs = this.nodeService.getChildAssocs( + final Node website = this.avmBrowseBean.getWebsite(); + final List webFormRefs = this.nodeService.getChildAssocs( website.getNodeRef(), WCMAppModel.ASSOC_WEBFORM, RegexQNamePattern.MATCH_ALL); - for (ChildAssociationRef ref : webFormRefs) + for (ChildAssociationRef ref : webFormRefs) + { + final String formName = (String) + this.nodeService.getProperty(ref.getChildRef(), WCMAppModel.PROP_FORMNAME); + if (formName.equals(this.getForm().getName())) { - final String formName = (String) - this.nodeService.getProperty(ref.getChildRef(), WCMAppModel.PROP_FORMNAME); - if (formName.equals(this.getForm().getName())) + if (LOGGER.isDebugEnabled()) + LOGGER.debug("loading workflowRefs for " + formName); + + final List workflowRefs = + this.nodeService.getChildAssocs(ref.getChildRef(), + WCMAppModel.ASSOC_WORKFLOWDEFAULTS, + RegexQNamePattern.MATCH_ALL); + if (workflowRefs.size() == 0) { - System.err.println("loading workflowRefs for " + formName); - final List workflowRefs = - this.nodeService.getChildAssocs(ref.getChildRef(), - WCMAppModel.ASSOC_WORKFLOWDEFAULTS, - RegexQNamePattern.MATCH_ALL); - if (workflowRefs.size() == 0) - { - throw new RuntimeException("no workflow parameters found for form " + formName); - } - if (workflowRefs.size() > 1) - { - throw new RuntimeException("found more than one workflow parameters node for " + formName); - } - - final NodeRef workflowRef = workflowRefs.get(0).getChildRef(); - final String workflowName = (String)this.nodeService.getProperty(workflowRef, WCMAppModel.PROP_WORKFLOW_NAME); - if (workflowName == null) - { - throw new RuntimeException("no workflow found for form " + formName); - } - System.err.println("using workflow " + workflowName + " for form " + formName); - wd = this.workflowService.getDefinitionByName("jbpm$" + workflowName); - - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - final ContentReader cr = this.contentService.getReader(workflowRef, WCMAppModel.PROP_WORKFLOWDEFAULTS); - if (cr == null) - { - parameters = new HashMap(); - } - else - { - cr.getContent(baos); - - final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - final ObjectInputStream ois = new ObjectInputStream(bais); - parameters = (Map)ois.readObject(); - } - break; + throw new AlfrescoRuntimeException("no workflow parameters found for form " + formName); + } + if (workflowRefs.size() > 1) + { + throw new AlfrescoRuntimeException("found more than one workflow parameters node for " + formName); + } + + final NodeRef workflowRef = workflowRefs.get(0).getChildRef(); + final String workflowName = (String)this.nodeService.getProperty(workflowRef, WCMAppModel.PROP_WORKFLOW_NAME); + + if (LOGGER.isDebugEnabled()) + LOGGER.debug("using workflow " + workflowName + " for form " + formName); + wd = this.workflowService.getDefinitionByName("jbpm$" + workflowName); + + // deserialize the workflow parameters + parameters = (Map)AVMWorkflowUtil.deserializeWorkflowParams(workflowRef); + + break; + } + } + + if (LOGGER.isDebugEnabled()) + LOGGER.debug("creating workflow package"); + + // create package paths (layered to user sandbox area as target) + String webapp = (String)website.getProperties().get(WCMAppModel.PROP_DEFAULTWEBAPP); + String sandboxPath = AVMConstants.buildAVMStoreRootPath(this.avmBrowseBean.getSandbox()); + String packagesPath = AVMWorkflowUtil.createAVMLayeredPackage(this.avmService, sandboxPath); + + // construct diffs for selected items for submission + List diffs = new ArrayList(8); + for (Rendition rendition : this.getRenditions()) + { + String renditionPath = AVMNodeConverter.ToAVMVersionPath(rendition.getNodeRef()).getSecond(); + int webappIndex = renditionPath.indexOf('/' + webapp); + renditionPath = renditionPath.substring(webappIndex); + String srcPath = sandboxPath + renditionPath; + String destPath = packagesPath + renditionPath; + AVMDifference diff = new AVMDifference(-1, srcPath, -1, destPath, AVMDifference.NEWER); + diffs.add(diff); + } + String instancePath = AVMNodeConverter.ToAVMVersionPath(this.formInstanceData.getNodeRef()).getSecond(); + int webappIndex = instancePath.indexOf('/' + webapp); + instancePath = instancePath.substring(webappIndex); + String srcPath = sandboxPath + instancePath; + String destPath = packagesPath + instancePath; + AVMDifference diff = new AVMDifference(-1, srcPath, -1, destPath, AVMDifference.NEWER); + diffs.add(diff); + + // write changes to layer so files are marked as modified + this.avmSyncService.update(diffs, null, true, true, false, false, null, null); + + // convert package to workflow package + AVMNodeDescriptor packageDesc = this.avmService.lookup(-1, packagesPath); + NodeRef packageNodeRef = this.workflowService.createPackage( + AVMNodeConverter.ToNodeRef(-1, packageDesc.getPath())); + this.nodeService.setProperty(packageNodeRef, WorkflowModel.PROP_IS_SYSTEM_PACKAGE, true); + parameters.put(WorkflowModel.ASSOC_PACKAGE, packageNodeRef); + + if (LOGGER.isDebugEnabled()) + LOGGER.debug("starting workflow " + wd + " with parameters " + parameters); + + // start the workflow to get access to the start task + WorkflowPath path = this.workflowService.startWorkflow(wd.id, parameters); + if (path != null) + { + // extract the start task + List tasks = this.workflowService.getTasksForWorkflowPath(path.id); + if (tasks.size() == 1) + { + WorkflowTask startTask = tasks.get(0); + + if (startTask.state == WorkflowTaskState.IN_PROGRESS) + { + // end the start task to trigger the first 'proper' task in the workflow + this.workflowService.endTask(startTask.id, null); } } } - - System.err.println("creating workflow package"); - final NodeRef workflowPackageNodeRef = this.workflowService.createPackage(null); -// doesn't work yet. need to use ASPECT_REFERENCES_NODE to get it to deal with avm nodes -// and we need some fixes from dave before we can enable. -// QName qn = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, -// QName.createValidLocalName(this.formInstanceData.getName())); -// String s = AVMNodeConverter.ToAVMVersionPath(this.formInstanceData.getNodeRef()).getSecond(); -// s = s.replaceFirst(AVMConstants.STORE_PREVIEW, AVMConstants.STORE_MAIN); -// System.err.println("adding " + s + " to workflow package with qname" + qn); -// this.nodeService.addChild(workflowPackageNodeRef, -// AVMNodeConverter.ToNodeRef(-1, s), -// ContentModel.ASSOC_CONTAINS, -// qn); -// for (Rendition rendition : this.getRenditions()) -// { -// qn = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, -// QName.createValidLocalName(rendition.getName())); -// s = AVMNodeConverter.ToAVMVersionPath(rendition.getNodeRef()).getSecond(); -// s = s.replaceFirst(AVMConstants.STORE_PREVIEW, AVMConstants.STORE_MAIN); -// System.err.println("adding " + s + " to workflow package with qname " + qn); -// -// this.nodeService.addChild(workflowPackageNodeRef, -// AVMNodeConverter.ToNodeRef(-1, s), -// ContentModel.ASSOC_CONTAINS, -// qn); -// } - parameters.put(WorkflowModel.ASSOC_PACKAGE, workflowPackageNodeRef); - System.err.println("starting workflow " + wd + " with parameters " + parameters); - final WorkflowPath wp = this.workflowService.startWorkflow(wd.getId(), parameters); } else { - System.err.println("************* not starting workflow"); + if (LOGGER.isDebugEnabled()) + LOGGER.debug("************* not starting workflow"); } + // return the default outcome return outcome; } @@ -351,7 +375,6 @@ public class CreateWebContentWizard extends BaseContentWizard path = path.replaceFirst(AVMConstants.STORE_MAIN, AVMConstants.STORE_PREVIEW); if (MimetypeMap.MIMETYPE_XML.equals(this.mimeType) && this.formName != null) { - final Document formInstanceData = fs.parseXML(this.content); path = this.getForm().getOutputPathForFormInstanceData(path, this.fileName, formInstanceData); @@ -360,7 +383,6 @@ public class CreateWebContentWizard extends BaseContentWizard this.fileName = sb[1]; } - if (LOGGER.isDebugEnabled()) LOGGER.debug("reseting layer " + path.split(":")[0] + ":/" + AVMConstants.DIR_APPBASE); @@ -574,6 +596,7 @@ public class CreateWebContentWizard extends BaseContentWizard return this.startWorkflow; } + // ------------------------------------------------------------------------------ // Action event handlers diff --git a/source/java/org/alfresco/web/bean/wcm/CreateWebsiteWizard.java b/source/java/org/alfresco/web/bean/wcm/CreateWebsiteWizard.java index a98fdb36cd..05d3ca10ed 100644 --- a/source/java/org/alfresco/web/bean/wcm/CreateWebsiteWizard.java +++ b/source/java/org/alfresco/web/bean/wcm/CreateWebsiteWizard.java @@ -16,10 +16,6 @@ */ package org.alfresco.web.bean.wcm; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; import java.io.Serializable; import java.text.MessageFormat; import java.util.ArrayList; @@ -37,11 +33,8 @@ import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ApplicationModel; import org.alfresco.model.ContentModel; import org.alfresco.model.WCMAppModel; -import org.alfresco.repo.content.MimetypeMap; import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.model.FileInfo; -import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.workflow.WorkflowDefinition; import org.alfresco.service.cmr.workflow.WorkflowService; @@ -162,6 +155,7 @@ public class CreateWebsiteWizard extends BaseWizardBean if (logger.isDebugEnabled()) logger.debug("Created website folder node with name: " + this.name); + // TODO: check that this dns is unique by querying existing store properties for a match String avmStore = DNSNameMangler.MakeDNSName(this.dnsName); // apply the uifacets aspect - icon, title and description props @@ -255,7 +249,7 @@ public class CreateWebsiteWizard extends BaseWizardBean // persist workflow default params if (workflow.getParams() != null) { - serializeWorkflowParams((Serializable)workflow.getParams(), workflowRef); + AVMWorkflowUtil.serializeWorkflowParams((Serializable)workflow.getParams(), workflowRef); } } @@ -294,7 +288,7 @@ public class CreateWebsiteWizard extends BaseWizardBean // persist workflow default params if (workflow.getParams() != null) { - serializeWorkflowParams((Serializable)workflow.getParams(), workflowRef); + AVMWorkflowUtil.serializeWorkflowParams((Serializable)workflow.getParams(), workflowRef); } // add filename pattern aspect if a filename pattern has been applied @@ -306,32 +300,6 @@ public class CreateWebsiteWizard extends BaseWizardBean } } } - - /** - * Serialize the workflow params to a content stream - * - * @param params Serializable workflow params - * @param workflowRef The noderef to write the property too - */ - public static void serializeWorkflowParams(Serializable params, NodeRef workflowRef) - { - try - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(params); - oos.close(); - // write the serialized Map as a binary content stream - like database blob! - ContentService cs = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getContentService(); - ContentWriter writer = cs.getWriter(workflowRef, WCMAppModel.PROP_WORKFLOWDEFAULTS, true); - writer.setMimetype(MimetypeMap.MIMETYPE_BINARY); - writer.putContent(new ByteArrayInputStream(baos.toByteArray())); - } - catch (IOException ioerr) - { - throw new AlfrescoRuntimeException("Unable to serialize workflow default parameters: " + ioerr.getMessage()); - } - } // ------------------------------------------------------------------------------ diff --git a/source/java/org/alfresco/web/bean/wcm/EditWebsiteWizard.java b/source/java/org/alfresco/web/bean/wcm/EditWebsiteWizard.java index 32c29b5fca..82733b215a 100644 --- a/source/java/org/alfresco/web/bean/wcm/EditWebsiteWizard.java +++ b/source/java/org/alfresco/web/bean/wcm/EditWebsiteWizard.java @@ -16,26 +16,20 @@ */ package org.alfresco.web.bean.wcm; -import java.io.IOException; -import java.io.ObjectInputStream; import java.io.Serializable; import java.util.List; import java.util.Map; import javax.faces.context.FacesContext; -import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.model.WCMAppModel; import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.workflow.WorkflowDefinition; import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.web.app.AlfrescoNavigationHandler; -import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.forms.Form; import org.alfresco.web.forms.FormsService; import org.alfresco.web.forms.RenderingEngineTemplate; @@ -109,7 +103,7 @@ public class EditWebsiteWizard extends CreateWebsiteWizard if (wfDef != null) { WorkflowWrapper wfWrapper = new WorkflowWrapper(wfName, wfDef.getTitle()); - wfWrapper.setParams((Map)deserializeWorkflowParams(wfRef)); + wfWrapper.setParams((Map)AVMWorkflowUtil.deserializeWorkflowParams(wfRef)); if (wfDef.startTaskDefinition != null) { wfWrapper.setType(wfDef.startTaskDefinition.metadata.getName()); @@ -154,7 +148,7 @@ public class EditWebsiteWizard extends CreateWebsiteWizard if (wfDef != null) { WorkflowWrapper wfWrapper = new WorkflowWrapper(wfName, wfDef.getTitle()); - wfWrapper.setParams((Map)deserializeWorkflowParams(wfRef)); + wfWrapper.setParams((Map)AVMWorkflowUtil.deserializeWorkflowParams(wfRef)); wfWrapper.setFilenamePattern((String)this.nodeService.getProperty( wfRef, WCMAppModel.PROP_FILENAMEPATTERN)); if (wfDef.startTaskDefinition != null) @@ -213,37 +207,4 @@ public class EditWebsiteWizard extends CreateWebsiteWizard this.nodeService.removeChild(nodeRef, ref.getChildRef()); } } - - /** - * Deserialize the default workflow params from a content stream - * - * @param workflowRef The noderef to write the property too - * - * @return Serializable workflow params - */ - public static Serializable deserializeWorkflowParams(NodeRef workflowRef) - { - try - { - // restore the serialized Map from a binary content stream - like database blob! - Serializable params = null; - ContentService cs = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getContentService(); - ContentReader reader = cs.getReader(workflowRef, WCMAppModel.PROP_WORKFLOWDEFAULTS); - if (reader != null) - { - ObjectInputStream ois = new ObjectInputStream(reader.getContentInputStream()); - params = (Serializable)ois.readObject(); - ois.close(); - } - return params; - } - catch (IOException ioErr) - { - throw new AlfrescoRuntimeException("Unable to deserialize workflow default parameters: " + ioErr.getMessage()); - } - catch (ClassNotFoundException classErr) - { - throw new AlfrescoRuntimeException("Unable to deserialize workflow default parameters: " + classErr.getMessage()); - } - } } diff --git a/source/java/org/alfresco/web/bean/wcm/SubmitDialog.java b/source/java/org/alfresco/web/bean/wcm/SubmitDialog.java index 85e3a15389..864027e508 100644 --- a/source/java/org/alfresco/web/bean/wcm/SubmitDialog.java +++ b/source/java/org/alfresco/web/bean/wcm/SubmitDialog.java @@ -45,8 +45,8 @@ import org.alfresco.service.cmr.workflow.WorkflowTask; import org.alfresco.service.cmr.workflow.WorkflowTaskState; import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; -import org.alfresco.util.GUID; import org.alfresco.util.ISO8601DateFormat; +import org.alfresco.util.NameMatcher; import org.alfresco.web.app.servlet.DownloadContentServlet; import org.alfresco.web.bean.dialog.BaseDialogBean; import org.alfresco.web.ui.common.Utils; @@ -72,6 +72,7 @@ public class SubmitDialog extends BaseDialogBean protected AVMBrowseBean avmBrowseBean; protected WorkflowService workflowService; protected AVMSyncService avmSyncService; + protected NameMatcher nameMatcher; /** * @param avmService The AVM Service to set. @@ -105,6 +106,14 @@ public class SubmitDialog extends BaseDialogBean this.workflowService = workflowService; } + /** + * @param nameMatcher The nameMatcher to set. + */ + public void setNameMatcher(NameMatcher nameMatcher) + { + this.nameMatcher = nameMatcher; + } + /** * @see org.alfresco.web.bean.dialog.BaseDialogBean#init(java.util.Map) */ @@ -135,7 +144,7 @@ public class SubmitDialog extends BaseDialogBean { NodeRef wfDefaultsRef = wfRefs.get(0).getChildRef(); String wfName = (String)this.nodeService.getProperty(wfDefaultsRef, WCMAppModel.PROP_WORKFLOW_NAME); - Map params = (Map)EditWebsiteWizard.deserializeWorkflowParams( + Map params = (Map)AVMWorkflowUtil.deserializeWorkflowParams( wfDefaultsRef); this.formWorkflowMap.put(form, new FormWorkflowWrapper(wfName, params)); } @@ -239,7 +248,6 @@ public class SubmitDialog extends BaseDialogBean */ public String[] getWorkflowSelectedValue() { - // TODO: select default! return this.workflowSelectedValue; } @@ -259,7 +267,7 @@ public class SubmitDialog extends BaseDialogBean if (this.workflowItems == null) { // ensure all workflows have been collected from any form generated assets - calculateSubmitItems(); + calcluateListItemsAndWorkflows(); // add the list of workflows for the website itself to the set NodeRef websiteRef = this.avmBrowseBean.getWebsite().getNodeRef(); @@ -269,7 +277,7 @@ public class SubmitDialog extends BaseDialogBean { NodeRef wfDefaultsRef = ref.getChildRef(); String wfName = (String)this.nodeService.getProperty(wfDefaultsRef, WCMAppModel.PROP_WORKFLOW_NAME); - Map params = (Map)EditWebsiteWizard.deserializeWorkflowParams( + Map params = (Map)AVMWorkflowUtil.deserializeWorkflowParams( wfDefaultsRef); this.workflows.add(new FormWorkflowWrapper(wfName, params)); } @@ -285,7 +293,7 @@ public class SubmitDialog extends BaseDialogBean item.setDescription(workflowDef.getDescription()); item.setImage(WebResources.IMAGE_WORKFLOW_32); items.add(item); - // add first as default TODO: what is correct here? + // add first workflow as default selection if (workflowSelectedValue == null) { workflowSelectedValue = new String[]{workflowDef.getName()}; @@ -297,37 +305,52 @@ public class SubmitDialog extends BaseDialogBean return this.workflowItems; } + /** + * @return the List of bean items to show in the Submit list + */ public List getSubmitItems() { if (this.submitItems == null) { // this method builds all submit and warning item data structures - calculateSubmitItems(); + calcluateListItemsAndWorkflows(); } return this.submitItems; } + /** + * @return size of the submit list + */ public int getSubmitItemsSize() { return getSubmitItems().size(); } + /** + * @return the List of bean items to show in the Warning list + */ public List getWarningItems() { if (this.warningItems == null) { // this method builds all submit and warning item data structures - calculateSubmitItems(); + calcluateListItemsAndWorkflows(); } return this.warningItems; } + /** + * @return size of the warning list + */ public int getWarningItemsSize() { return this.getWarningItems().size(); } - private void calculateSubmitItems() + /** + * Calculate the lists of Submittable Items, Warning items and the list of available workflows. + */ + private void calcluateListItemsAndWorkflows() { // TODO: start txn here? List selected; @@ -335,8 +358,7 @@ public class SubmitDialog extends BaseDialogBean { String userStore = this.avmBrowseBean.getSandbox() + ":/"; String stagingStore = this.avmBrowseBean.getStagingStore() + ":/"; - // TODO Pass the globalPathExcluder NameMatcher instead of null. - List diffs = avmSyncService.compare(-1, userStore, -1, stagingStore, null); + List diffs = avmSyncService.compare(-1, userStore, -1, stagingStore, nameMatcher); selected = new ArrayList(diffs.size()); for (AVMDifference diff : diffs) { @@ -356,8 +378,8 @@ public class SubmitDialog extends BaseDialogBean { if (hasAssociatedWorkflow(AVMNodeConverter.ToNodeRef(-1, node.getPath())) == false) { - // TODO: lookup if this item was created via a FORM - then need to lookup the workflow defaults - // for that form (and associated artifacts!) and then save that in list of workflows + // lookup if this item was created via a frm - then lookup the workflow defaults + // for that form and store into the list of available workflows NodeRef ref = AVMNodeConverter.ToNodeRef(-1, node.getPath()); if (this.nodeService.hasAspect(ref, WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) { @@ -399,24 +421,13 @@ public class SubmitDialog extends BaseDialogBean */ private NodeRef createWorkflowPackage() { - // TODO: add to common util class for all AVM workflows - String packagesRoot = "workflow-system:/packages"; - AVMNodeDescriptor packagesDesc = avmService.lookup(-1, packagesRoot); - if (packagesDesc == null) - { - avmService.createAVMStore("workflow-system"); - avmService.createDirectory("workflow-system:/", "packages"); - } - List items = getSubmitItems(); // create package paths (layered to user sandbox area as target) - String sandboxPath = AVMConstants.buildAVMStoreRootPath(avmBrowseBean.getSandbox()); - String packageName = GUID.generate(); - String packagesPath = packagesRoot + "/" + packageName; - avmService.createLayeredDirectory(sandboxPath, packagesRoot, packageName); + String sandboxPath = AVMConstants.buildAVMStoreRootPath(this.avmBrowseBean.getSandbox()); + String packagesPath = AVMWorkflowUtil.createAVMLayeredPackage(this.avmService, sandboxPath); - // construct diffs for selected items + // construct diffs for selected items for submission List diffs = new ArrayList(this.submitItems.size()); for (ItemWrapper wrapper : this.submitItems) { @@ -427,12 +438,13 @@ public class SubmitDialog extends BaseDialogBean } // write changes to layer so files are marked as modified - avmSyncService.update(diffs, null, true, true, false, false, null, null); + this.avmSyncService.update(diffs, null, true, true, false, false, null, null); // convert package to workflow package - AVMNodeDescriptor packageDesc = avmService.lookup(-1, packagesPath); - NodeRef packageNodeRef = workflowService.createPackage(AVMNodeConverter.ToNodeRef(-1, packageDesc.getPath())); - nodeService.setProperty(packageNodeRef, WorkflowModel.PROP_IS_SYSTEM_PACKAGE, true); + AVMNodeDescriptor packageDesc = this.avmService.lookup(-1, packagesPath); + NodeRef packageNodeRef = this.workflowService.createPackage( + AVMNodeConverter.ToNodeRef(-1, packageDesc.getPath())); + this.nodeService.setProperty(packageNodeRef, WorkflowModel.PROP_IS_SYSTEM_PACKAGE, true); return packageNodeRef; } diff --git a/source/java/org/alfresco/web/bean/workflow/WorkflowUtil.java b/source/java/org/alfresco/web/bean/workflow/WorkflowUtil.java index dc91913f9d..8fbc606e45 100644 --- a/source/java/org/alfresco/web/bean/workflow/WorkflowUtil.java +++ b/source/java/org/alfresco/web/bean/workflow/WorkflowUtil.java @@ -178,8 +178,7 @@ public class WorkflowUtil // marshal the properties and associations captured by the property sheet // back into a Map to pass to the workflow service - // go through all the properties in the transient node and add them to - // params map + // go through all the properties in the transient node and add them to params map Map props = node.getProperties(); for (String propName : props.keySet()) { diff --git a/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java b/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java index 80b7daa667..f8f8ab3a74 100644 --- a/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java +++ b/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java @@ -47,6 +47,7 @@ import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.RegexQNamePattern; +import org.alfresco.util.NameMatcher; import org.alfresco.web.app.Application; import org.alfresco.web.app.servlet.DownloadContentServlet; import org.alfresco.web.bean.BrowseBean; @@ -490,8 +491,9 @@ public class UIUserSandboxes extends SelfRenderingComponent String id = getClientId(fc); // use the sync service to get the list of diffs between the stores - // TODO Need to pass the global exclude NameMatcher. - List diffs = avmSyncService.compare(-1, userStore, -1, stagingStore, null); + NameMatcher matcher = (NameMatcher)FacesContextUtils.getRequiredWebApplicationContext(fc).getBean( + "globalPathExcluder"); + List diffs = avmSyncService.compare(-1, userStore, -1, stagingStore, matcher); if (diffs.size() != 0) { // store lookup of username to list of modified nodes diff --git a/source/web/WEB-INF/faces-config-beans.xml b/source/web/WEB-INF/faces-config-beans.xml index 1495fd5f69..762f8ca573 100644 --- a/source/web/WEB-INF/faces-config-beans.xml +++ b/source/web/WEB-INF/faces-config-beans.xml @@ -2753,6 +2753,10 @@ nodeService #{NodeService} + + nameMatcher + #{globalPathExcluder} + diff --git a/source/web/jsp/wcm/create-website-wizard/details.jsp b/source/web/jsp/wcm/create-website-wizard/details.jsp index 6359313c66..30c830d9f5 100644 --- a/source/web/jsp/wcm/create-website-wizard/details.jsp +++ b/source/web/jsp/wcm/create-website-wizard/details.jsp @@ -127,7 +127,7 @@ + disabled="true" /> <%-- disabled="#{WizardManager.bean.editMode}" --%> diff --git a/source/web/jsp/wcm/submit-dialog.jsp b/source/web/jsp/wcm/submit-dialog.jsp index 0a0152d974..4d2a969aac 100644 --- a/source/web/jsp/wcm/submit-dialog.jsp +++ b/source/web/jsp/wcm/submit-dialog.jsp @@ -23,6 +23,17 @@ <%@ page buffer="32kb" contentType="text/html;charset=UTF-8" %> <%@ page isELIgnored="false" %> + + + +