Working implementation of basic WCM submit workflow.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4444 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2006-11-27 11:47:20 +00:00
parent a2a543684b
commit f721bc3e07
9 changed files with 175 additions and 161 deletions

View File

@@ -1,23 +1,17 @@
package org.alfresco.repo.avm.wf;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.workflow.jbpm.JBPMNode;
import org.alfresco.repo.workflow.jbpm.JBPMSpringActionHandler;
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.AVMSyncException;
import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.jbpm.graph.exe.ExecutionContext;
import org.springframework.beans.factory.BeanFactory;
@@ -60,38 +54,48 @@ public class AVMSubmitPackageHandler extends JBPMSpringActionHandler implements
*/
public void execute(ExecutionContext executionContext) throws Exception
{
NodeRef pkg = ((JBPMNode)executionContext.getContextInstance().getVariable("package")).getNodeRef();
List<ChildAssociationRef> children = fNodeService.getChildAssocs(pkg);
List<AVMDifference> diffs = new ArrayList<AVMDifference>();
Map<String, String> storesHit = new HashMap<String, String>();
for (ChildAssociationRef child : children)
{
NodeRef childRef = child.getChildRef();
if (!fNodeService.hasAspect(childRef, ContentModel.ASPECT_REFERENCES_NODE))
{
throw new AVMSyncException("Package node does not have cm:referencesnode.");
}
NodeRef toSubmit = (NodeRef)fNodeService.getProperty(childRef, ContentModel.PROP_NODE_REF);
Pair<Integer, String> versionPath = AVMNodeConverter.ToAVMVersionPath(toSubmit);
String avmPath = versionPath.getSecond();
String [] storePath = avmPath.split(":");
String websiteName = fAVMService.getStoreProperty(storePath[0],
QName.createQName(null, ".website.name")).
getStringValue();
String stagingName = websiteName + "-staging";
AVMDifference diff =
new AVMDifference(-1, avmPath,
-1, stagingName + ":" + storePath[1],
AVMDifference.NEWER);
diffs.add(diff);
storesHit.put(storePath[0], stagingName);
}
// TODO fix update comments if needed.
fAVMSyncService.update(diffs, true, true, false, false, null, null);
for (Map.Entry<String, String> entry : storesHit.entrySet())
{
fAVMSyncService.flatten(entry.getKey() + ":/appBase",
entry.getValue() + ":/appBase");
}
NodeRef pkg = ((JBPMNode)executionContext.getContextInstance().getVariable("bpm_package")).getNodeRef();
Pair<Integer, String> pkgPath = AVMNodeConverter.ToAVMVersionPath(pkg);
AVMNodeDescriptor pkgDesc = fAVMService.lookup(pkgPath.getFirst(), pkgPath.getSecond());
String targetPath = pkgDesc.getIndirection();
List<AVMDifference> diff = fAVMSyncService.compare(pkgPath.getFirst(), pkgPath.getSecond(), -1, targetPath);
fAVMSyncService.update(diff, true, true, false, false, null, null);
String from = (String)executionContext.getContextInstance().getVariable("wf_from");
fAVMSyncService.flatten(from, targetPath);
// List<ChildAssociationRef> children = fNodeService.getChildAssocs(pkg);
// List<AVMDifference> diffs = new ArrayList<AVMDifference>();
// Map<String, String> storesHit = new HashMap<String, String>();
// for (ChildAssociationRef child : children)
// {
// NodeRef childRef = child.getChildRef();
// if (!fNodeService.hasAspect(childRef, ContentModel.ASPECT_REFERENCES_NODE))
// {
// throw new AVMSyncException("Package node does not have cm:referencesnode.");
// }
// NodeRef toSubmit = (NodeRef)fNodeService.getProperty(childRef, ContentModel.PROP_NODE_REF);
// Pair<Integer, String> versionPath = AVMNodeConverter.ToAVMVersionPath(toSubmit);
// String avmPath = versionPath.getSecond();
// String [] storePath = avmPath.split(":");
// String websiteName = fAVMService.getStoreProperty(storePath[0],
// QName.createQName(null, ".website.name")).
// getStringValue();
// String stagingName = websiteName + "-staging";
// AVMDifference diff =
// new AVMDifference(-1, avmPath,
// -1, stagingName + ":" + storePath[1],
// AVMDifference.NEWER);
// diffs.add(diff);
// storesHit.put(storePath[0], stagingName);
// }
// // TODO fix update comments if needed.
// fAVMSyncService.update(diffs, true, true, false, false, null, null);
// for (Map.Entry<String, String> entry : storesHit.entrySet())
// {
// fAVMSyncService.flatten(entry.getKey() + ":/appBase",
// entry.getValue() + ":/appBase");
// }
}
}

View File

@@ -29,9 +29,15 @@ import java.util.List;
import java.util.Map;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
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.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
import org.alfresco.service.cmr.workflow.WorkflowDeployment;
@@ -44,6 +50,7 @@ import org.alfresco.service.cmr.workflow.WorkflowTransition;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.GUID;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.ClassPathResource;
@@ -57,6 +64,9 @@ public class WorkflowInterpreter
// Service dependencies
private WorkflowService workflowService;
private NamespaceService namespaceService;
private NodeService nodeService;
private AVMService avmService;
private AVMSyncService avmSyncService;
private PersonService personService;
/**
@@ -111,7 +121,31 @@ public class WorkflowInterpreter
{
this.workflowService = workflowService;
}
/**
* @param nodeService The Node Service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param avmService The AVM Service
*/
public void setAVMService(AVMService avmService)
{
this.avmService = avmService;
}
/**
* @param avmSyncService The AVM Sync Service
*/
public void setAVMSyncService(AVMSyncService avmSyncService)
{
this.avmSyncService = avmSyncService;
}
/**
* @param namespaceService namespaceService
*/
@@ -661,6 +695,49 @@ public class WorkflowInterpreter
}
out.println("set var " + qname + " = " + vars.get(qname));
}
else if (command[2].equals("avmpackage"))
{
// lookup source folder of changes
AVMNodeDescriptor avmSource = avmService.lookup(-1, command[3]);
if (avmSource == null || !avmSource.isDirectory())
{
return command[3] + " must refer to a directory.";
}
// create container for avm workflow packages
String packagesPath = "workflow-system:/packages";
AVMNodeDescriptor packagesDesc = avmService.lookup(-1, packagesPath);
if (packagesDesc == null)
{
avmService.createAVMStore("workflow-system");
avmService.createDirectory("workflow-system:/", "packages");
}
// create package (layered to target, if target is specified)
String packageName = GUID.generate();
String avmSourceIndirection = avmSource.getIndirection();
if (avmSourceIndirection != null)
{
avmService.createLayeredDirectory(avmSourceIndirection, packagesPath, packageName);
List<AVMDifference> diff = avmSyncService.compare(-1, avmSource.getPath(), -1, packagesPath + "/" + packageName);
avmSyncService.update(diff, true, true, false, false, null, null);
}
else
{
// copy source folder to package folder
avmService.copy(-1, avmSource.getPath(), packagesPath, packageName);
}
// convert package to workflow package
AVMNodeDescriptor packageDesc = avmService.lookup(-1, packagesPath + "/" + packageName);
NodeRef packageNodeRef = workflowService.createPackage(AVMNodeConverter.ToNodeRef(-1, packageDesc.getPath()));
nodeService.setProperty(packageNodeRef, WorkflowModel.PROP_IS_SYSTEM_PACKAGE, true);
QName qname = QName.createQName(command[1], namespaceService);
vars.put(qname, packageNodeRef);
out.println("set var " + qname + " = " + vars.get(qname));
}
else
{
return "Syntax Error.\n";