From 0d95c702cb1021a249f6035da005fdc7ad1ad3ea Mon Sep 17 00:00:00 2001 From: Gavin Cornwell Date: Fri, 15 Jun 2007 19:33:02 +0000 Subject: [PATCH] Added links management to the submit process git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5989 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../workflow/wcm-workflow-messages.properties | 10 + config/alfresco/workflow/wcmWorkflowModel.xml | 453 +++++++++--------- .../linkvalidation/LinkValidationReport.java | 6 +- .../org/alfresco/model/WCMWorkflowModel.java | 1 + .../repo/avm/wf/AVMSubmitLinkChecker.java | 150 ++++++ 5 files changed, 397 insertions(+), 223 deletions(-) create mode 100644 source/java/org/alfresco/repo/avm/wf/AVMSubmitLinkChecker.java diff --git a/config/alfresco/workflow/wcm-workflow-messages.properties b/config/alfresco/workflow/wcm-workflow-messages.properties index 72cbf815de..cf6e0db582 100644 --- a/config/alfresco/workflow/wcm-workflow-messages.properties +++ b/config/alfresco/workflow/wcm-workflow-messages.properties @@ -6,6 +6,10 @@ wcmwf_submit.workflow.title=Web Site Submission wcmwf_submit.workflow.description=Submit changes for approval +wcmwf_submit.node.verifybrokenlinks.transition.abort.title=Abort Submisson +wcmwf_submit.node.verifybrokenlinks.transition.abort.description=Abort Submisson +wcmwf_submit.node.verifybrokenlinks.transition.continue.title=Continue Submission +wcmwf_submit.node.verifybrokenlinks.transition.continue.description=Continue Submisson wcmwf_submit.node.serialreview.transition.reject.title=Reject wcmwf_submit.node.serialreview.transition.reject.description=Reject wcmwf_submit.node.serialreview.transition.approve.title=Approve @@ -28,6 +32,8 @@ wcmwf_submit.node.submitpending.transition.launch.description=Submit Now wcmwf_workflowmodel.type.wcmwf_submitReviewTask.title=Web Site Submission wcmwf_workflowmodel.type.wcmwf_submitReviewTask.description=Submit changes for approval +wcmwf_workflowmodel.type.wcmwf_verifyBrokenLinksTask.title=Verify Broken Links +wcmwf_workflowmodel.type.wcmwf_verifyBrokenLinksTask.description=Verify links that do not point to a live resource wcmwf_workflowmodel.type.wcmwf_reviewTask.title=Review wcmwf_workflowmodel.type.wcmwf_reviewTask.description=Review Documents to approve or reject them wcmwf_workflowmodel.type.wcmwf_rejectedTask.title=Rejected @@ -49,6 +55,10 @@ wcmwf_workflowmodel.property.wcmwf_fromPath.title=Source Folder Path wcmwf_workflowmodel.property.wcmwf_fromPath.description=Folder Path where items have been submitted from wcmwf_workflowmodel.property.wcmwf_label.title=Submission Label wcmwf_workflowmodel.property.wcmwf_label.description=Label associated with the submission +wcmwf_workflowmodel.property.wcmwf_launchDate.title=Launch Date +wcmwf_workflowmodel.property.wcmwf_launchDate.description=Date the content in the submission should be committed +wcmwf_workflowmodel.property.wcmwf_validateLinks.title=Validate Links +wcmwf_workflowmodel.property.wcmwf_validateLinks.description=Whether links should be verified before entering the review cycle wcmwf_workflowmodel.property.wcmwf_reviewerCnt.title=Total Reviewed wcmwf_workflowmodel.property.wcmwf_reviewerCnt.description=Count of people who reviewed wcmwf_workflowmodel.property.wcmwf_approveCnt.title=Total Approved diff --git a/config/alfresco/workflow/wcmWorkflowModel.xml b/config/alfresco/workflow/wcmWorkflowModel.xml index af09650c56..e21295d3c2 100644 --- a/config/alfresco/workflow/wcmWorkflowModel.xml +++ b/config/alfresco/workflow/wcmWorkflowModel.xml @@ -1,70 +1,70 @@ - - - - - - + + + + + + - - - - - - - - - - - - - - Serial - Parallel - - - - - - - - - - - - - - - - - bpm:startTask - - - edit_and_remove_wcm_package_item_actions - - - - - - bpm:workflowTask - - - read_wcm_package_item_actions - - - - - - wcmwf:startTask - - - Serial or Parallel Review - d:text - true - Serial - - - - + + + + + + + + + + + + + + Serial + Parallel + + + + + + + + + + + + + + + + + bpm:startTask + + + edit_and_remove_wcm_package_item_actions + + + + + + bpm:workflowTask + + + read_wcm_package_item_actions + + + + + + wcmwf:startTask + + + Serial or Parallel Review + d:text + true + Serial + + + + @@ -78,93 +78,101 @@ false - - - bpm:assignees - wcmwf:submission - - - - - wcmwf:workflowTask - - - edit_wcm_package_item_actions - - - - - - bpm:assignees - wcmwf:submission - wcmwf:reviewType - - - - - wcmwf:workflowTask - - - edit_and_remove_wcm_package_item_actions - - - - bpm:assignees - wcmwf:reviewType - wcmwf:reviewInfo - - - - - wcmwf:workflowTask - - bpm:assignees - wcmwf:reviewType - wcmwf:reviewInfo - wcmwf:submission - - - - - wcmwf:workflowTask - - bpm:assignees - wcmwf:reviewType - wcmwf:reviewInfo - wcmwf:submission - - - - - wcmwf:workflowTask - - bpm:assignees - wcmwf:reviewType - wcmwf:reviewInfo - wcmwf:submission - - - - - - wcmwf:workflowTask - - bpm:assignees - wcmwf:reviewType - wcmwf:reviewInfo - - - - - wcmwf:startTask - - - d:text - - - - bpm:assignee - + + + bpm:assignees + wcmwf:submission + + + + + wcmwf:workflowTask + + bpm:assignees + wcmwf:submission + + + + + wcmwf:workflowTask + + + edit_wcm_package_item_actions + + + + + + bpm:assignees + wcmwf:submission + wcmwf:reviewType + + + + + wcmwf:workflowTask + + + edit_and_remove_wcm_package_item_actions + + + + bpm:assignees + wcmwf:reviewType + wcmwf:reviewInfo + + + + + wcmwf:workflowTask + + bpm:assignees + wcmwf:reviewType + wcmwf:reviewInfo + wcmwf:submission + + + + + wcmwf:workflowTask + + bpm:assignees + wcmwf:reviewType + wcmwf:reviewInfo + wcmwf:submission + + + + + wcmwf:workflowTask + + bpm:assignees + wcmwf:reviewType + wcmwf:reviewInfo + wcmwf:submission + + + + + + wcmwf:workflowTask + + bpm:assignees + wcmwf:reviewType + wcmwf:reviewInfo + + + + + wcmwf:startTask + + + d:text + + + + bpm:assignee + @@ -191,76 +199,81 @@ bpm:assignee - - - - - - - - - - Source Folder Path - Folder where items have been submitted from - d:text - true - - - Snapshot Label - d:text - true + + + + + + + + + + Source Folder Path + Folder where items have been submitted from + d:text + true + + + Snapshot Label + d:text + true Launch Date Date the content in the submission should be committed d:datetime - - - - - - - - Review Type - d:text - true - - - - - - - - - - - Reviewer Count - d:int - true - - - Approver Count - d:int - true - - - Reviewer Cycle - d:int - false - - - - - - - - Workflow Instance Id - d:text - true - - - - - - + + + Validate Links + Determines whether links should be verified before entering the review cycle + d:boolean + + + + + + + + Review Type + d:text + true + + + + + + + + + + + Reviewer Count + d:int + true + + + Approver Count + d:int + true + + + Reviewer Cycle + d:int + false + + + + + + + + Workflow Instance Id + d:text + true + + + + + + \ No newline at end of file diff --git a/source/java/org/alfresco/linkvalidation/LinkValidationReport.java b/source/java/org/alfresco/linkvalidation/LinkValidationReport.java index 830b69cd60..cd62979d89 100755 --- a/source/java/org/alfresco/linkvalidation/LinkValidationReport.java +++ b/source/java/org/alfresco/linkvalidation/LinkValidationReport.java @@ -44,9 +44,9 @@ import java.util.Map; */ public class LinkValidationReport implements Serializable { - private int numberFilesChecked = 0; - private int numberLinksChecked = 0; - private int numberBrokenLinks = 0; + private int numberFilesChecked = -1; + private int numberLinksChecked = -1; + private int numberBrokenLinks = -1; private boolean successful = true; private Throwable error; diff --git a/source/java/org/alfresco/model/WCMWorkflowModel.java b/source/java/org/alfresco/model/WCMWorkflowModel.java index 3274381310..24584a1e99 100644 --- a/source/java/org/alfresco/model/WCMWorkflowModel.java +++ b/source/java/org/alfresco/model/WCMWorkflowModel.java @@ -36,5 +36,6 @@ public interface WCMWorkflowModel static final QName PROP_FROM_PATH = QName.createQName(NamespaceService.WCMWF_MODEL_1_0_URI, "fromPath"); static final QName PROP_LABEL = QName.createQName(NamespaceService.WCMWF_MODEL_1_0_URI, "label"); static final QName PROP_LAUNCH_DATE = QName.createQName(NamespaceService.WCMWF_MODEL_1_0_URI, "launchDate"); + static final QName PROP_VALIDATE_LINKS = QName.createQName(NamespaceService.WCMWF_MODEL_1_0_URI, "validateLinks"); static final QName ASSOC_WEBPROJECT = QName.createQName(NamespaceService.WCMWF_MODEL_1_0_URI, "webproject"); } diff --git a/source/java/org/alfresco/repo/avm/wf/AVMSubmitLinkChecker.java b/source/java/org/alfresco/repo/avm/wf/AVMSubmitLinkChecker.java new file mode 100644 index 0000000000..f43f3df12b --- /dev/null +++ b/source/java/org/alfresco/repo/avm/wf/AVMSubmitLinkChecker.java @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" */ + +package org.alfresco.repo.avm.wf; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.config.JNDIConstants; +import org.alfresco.linkvalidation.HrefValidationProgress; +import org.alfresco.linkvalidation.LinkValidationAction; +import org.alfresco.linkvalidation.LinkValidationReport; +import org.alfresco.linkvalidation.LinkValidationService; +import org.alfresco.repo.avm.AVMNodeConverter; +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.repo.workflow.jbpm.JBPMNode; +import org.alfresco.repo.workflow.jbpm.JBPMSpringActionHandler; +import org.alfresco.sandbox.SandboxConstants; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.avm.AVMService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.util.Pair; +import org.apache.log4j.Logger; +import org.jbpm.graph.exe.ExecutionContext; +import org.springframework.beans.factory.BeanFactory; + +/** + * Performs a link validaton check for the workflow sandbox being used + * for a submisson process. + * + * @author gavinc + */ +public class AVMSubmitLinkChecker extends JBPMSpringActionHandler +{ + private static final long serialVersionUID = 1442635948148675461L; + + private static Logger logger = Logger.getLogger(AVMSubmitLinkChecker.class); + + /** + * The AVMService. + */ + private AVMService fAVMService; + + /** + * The ActionService. + */ + private ActionService fActionService; + + /** + * Set any bean references necessary. + * @param factory The BeanFactory from which to get beans. + */ + @Override + protected void initialiseHandler(BeanFactory factory) + { + this.fActionService = (ActionService)factory.getBean("ActionService"); + this.fAVMService = (AVMService)factory.getBean("AVMService"); + } + + /** + * Do the actual link validation check. + * + * @param executionContext The jBPM context. + */ + public void execute(ExecutionContext executionContext) throws Exception + { + // retrieve the workflow sandbox (the workflow package) + NodeRef pkg = ((JBPMNode)executionContext.getContextInstance().getVariable("bpm_package")).getNodeRef(); + Pair pkgPath = AVMNodeConverter.ToAVMVersionPath(pkg); + + // remove the trailing www from the path + String path = pkgPath.getSecond(); + path = path.substring(0, (path.length()-JNDIConstants.DIR_DEFAULT_WWW.length())); + NodeRef storePath = AVMNodeConverter.ToNodeRef(-1, path); + + // get the store name + String storeName = pkg.getStoreRef().getIdentifier(); + + if (logger.isDebugEnabled()) + logger.info("Found workflow store to check links for: " + path); + + // create and execute the action in the background + Throwable cause = null; + int brokenLinks = -1; + + try + { + HrefValidationProgress monitor = new HrefValidationProgress(); + Map args = new HashMap(1, 1.0f); + args.put(LinkValidationAction.PARAM_MONITOR, monitor); + Action action = this.fActionService.createAction(LinkValidationAction.NAME, args); + this.fActionService.executeAction(action, storePath, false, false); + + // retrieve the deployment report from the store property + PropertyValue val = this.fAVMService.getStoreProperty(storeName, + SandboxConstants.PROP_LINK_VALIDATION_REPORT); + if (val != null) + { + LinkValidationReport report = (LinkValidationReport)val.getSerializableValue(); + if (report != null && report.wasSuccessful()) + { + brokenLinks = report.getNumberBrokenLinks(); + } + else + { + cause = report.getError(); + } + } + + if (logger.isDebugEnabled()) + logger.debug("Link validation check found " + brokenLinks + " broken links"); + } + catch (Throwable err) + { + cause = err; + } + + // set the number of broken links in a variable + if (brokenLinks == -1) + { + // TODO: Decide how to handle errors, + // for now just return -1 and the workflow can decide + } + + executionContext.setVariable("wcmwf_brokenLinks", brokenLinks); + } +}