summaryrefslogtreecommitdiff
path: root/src/main/resources/boot/SC/SetWorkflow.xml
blob: 0b4b68a79ef5bf67a55c58ba867ea090a2e6399b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?xml version="1.0" encoding="UTF-8"?>
<cristalscript>
	<output name="errors" type="org.cristalise.kernel.scripting.ErrorInfo" />
	<script language="javascript" name="SetWorkflow"><![CDATA[
		importClass(org.cristalise.kernel.utils.CastorHashMap);
		
        // Fetch the requested name from the outcome field
        var wfDefName    = job.getOutcome().getField("WorkflowDefinitionName");
        var wfDefVersion = job.getOutcome().getField("WorkflowDefinitionVersion");

        // Look up the description
        var wfItem;
        try {
            wfItem = agent.searchItem(wfDefName);
        } catch (e) {
            throw wfDefName+" is not a valid item; Exception - " + e; 
        }

        // Make sure it has the right properties to be a composite activity desc
        var itemType = wfItem.getProperty("Type");
        var complex  = wfItem.getProperty("Complexity");

        if (!itemType.equals("ActivityDesc"))
            throw wfDefName+" is not an activity description";
        if (!complex.equals("Composite"))
            throw wfDefName+" is not a composite activity description";
            
        // Check that the named version exists
        try {
            var view = wfItem.getViewpoint("CompositeActivityDef", wfDefVersion);
        } catch (e) {
            throw wfDefName + " does not contain a version "+wfDefVersion + "; Exception - " + e;
        }

        // Fetch the 'Workflow' collection
        var coll = item.getCollection("workflow");
        if (coll.size() > 0) { // if there's already a member, remove it
        	var params = new Array(2);
       	 	params[0] = "workflow";
       	 	params[1] = coll.getMembers().list.get(0).getID();
        	agent.execute(item, "RemoveSlotFromCollection", params);
        }

        // add the new member
        var params = new Array(3);
        var newProps = new CastorHashMap();
        newProps.put("Version", wfDefVersion);
        params[0] = "workflow";
        params[1] = wfItem.getPath();
        params[2] = agent.marshall(newProps);
       	agent.execute(item, "AddMemberToCollection", params);

		]]></script>
</cristalscript>