summaryrefslogtreecommitdiff
path: root/src/main/resources/boot/SC/LocalObjectDefCreator.xml
blob: 6ed88e66b52d6b87cd0b5415f9f8c637851305fa (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
54
55
56
57
58
<?xml version="1.0" encoding="UTF-8"?>
<cristalscript>
	<output name="errors" type="com.c2kernel.scripting.ErrorInfo"/>
	<script language="javascript" name="LocalObjectDefCreator"><![CDATA[
		importClass(Packages.com.c2kernel.process.Gateway);
		importClass(Packages.com.c2kernel.utils.Resource);
		importClass(Packages.com.c2kernel.process.Bootstrap);
		importClass(Packages.com.c2kernel.lifecycle.CompositeActivityDef);
		importClass(Packages.com.c2kernel.lifecycle.ActivityDef);
		importClass(Packages.com.c2kernel.lifecycle.instance.stateMachine.Transitions);
	
		var type = job.getActPropString("NewType");
		var name = job.getOutcome().getField("ObjectName");
		var folder = job.getOutcome().getField("SubFolder");
		// Find the root of that object type
		var domPath = Bootstrap.getTypeRoot(type).toString();
		if (folder != null) domPath = domPath + "/" + folder;
		
		var params = new Array(2);
		params[0] = name;
		params[1] = domPath;
		
		// Create the new item
		try {
			agent.execute(item, "CreateItemFromDescription", params);
		} catch (e) {
			throw "Could not create "+name+": "+e.message;
		}
		
		// Store a fresh one in the new item

		var newObj;
		// Activities are serialized new instances
		if (type.equals("EA") || type.equals("CA")) {
			var newAct = type.equals("CA")?new CompositeActivityDef(): new ActivityDef();
			newAct.setName(name);
			newObj = Gateway.getMarshaller().marshall(newAct);
			}
		else { 
			// Empty schemas and scripts are stored as outcomes of the factory.
			var fileType = type.equals("OD")?"Schema":"Script";
			newObj = item.getObject("/ViewPoint/"+fileType+"/last").getOutcome().getData();
		}
		// Store the new object with the 'EditDefinition' activity
		var newPath = new Packages.com.c2kernel.lookup.DomainPath(domPath+"/"+name);
		var newItem = agent.getItem(newPath);
		newItem.requestAction(agent.getSystemKey(), "workflow/domain/EditDefinition", Transitions.DONE, newObj);
		
		// If this script is running in the Cristal GUI, open the new item.
		try {
			var tree = Packages.com.c2kernel.gui.MainFrame.treeBrowser;
			if (tree != null) // open new item in the gui
				tree.push(newPath);
		} catch (e) { // hopefully catch any classloading errors on headless systems. hopefully.
		}
			
		]]></script>
</cristalscript>