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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
package com.c2kernel.process.module;
import java.util.ArrayList;
import java.util.Properties;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lifecycle.instance.predefined.entitycreation.Dependency;
import com.c2kernel.lifecycle.instance.predefined.entitycreation.DependencyMember;
import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewAgent;
import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewItem;
import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewRole;
import com.c2kernel.lifecycle.instance.predefined.entitycreation.Outcome;
import com.c2kernel.lookup.RolePath;
import com.c2kernel.process.Bootstrap;
import com.c2kernel.process.Gateway;
import com.c2kernel.scripting.ErrorInfo;
import com.c2kernel.scripting.ScriptingEngineException;
import com.c2kernel.utils.Logger;
import com.c2kernel.utils.Resource;
public class Module {
public String ns, name;
public ModuleInfo info;
public String resURL;
public ModuleImports imports = new ModuleImports();
public ArrayList<ModuleConfig> config = new ArrayList<ModuleConfig>();
public ArrayList<ModuleScript> scripts = new ArrayList<ModuleScript>();
public NewItem moduleItem;
public Module() {
super();
}
public void runScript(String event, boolean isServer) throws ScriptingEngineException {
for (ModuleScript script : scripts) {
if (script.shouldRun(event, isServer)) {
Logger.msg("Running "+script.event+" "+script.target+" script from "+name);
Object result = script.getScript(ns).execute();
if (result instanceof ErrorInfo) {
ErrorInfo error = (ErrorInfo) result;
Logger.error(error.toString());
if (error.getFatal())
throw new ScriptingEngineException("Fatal Script Error");
}
else if (result != null)
Logger.msg(result.toString());
}
}
}
public void addModuleItem(String moduleXML) {
NewItem moduleItem = new NewItem(name, "/desc/modules/", "ModuleWorkflow");
// Module properties
moduleItem.properties.add(new com.c2kernel.property.Property("Namespace", ns));
moduleItem.properties.add(new com.c2kernel.property.Property("Name", name));
moduleItem.properties.add(new com.c2kernel.property.Property("Type", "Module"));
moduleItem.properties.add(new com.c2kernel.property.Property("Version", info.version));
// Add dependency for all children
Dependency children = new Dependency("Contents");
for (ModuleImport thisImport : imports.list) {
String path = thisImport.getPath(ns);
if (path != null)
children.dependencyMemberList.add(
new DependencyMember(path+"/"+thisImport.name));
}
moduleItem.dependencyList.add(children);
// Add moduleXML
Outcome moduleOutcome = new Outcome("Module", 0, "last", null);
moduleOutcome.data = moduleXML;
moduleItem.outcomes.add(moduleOutcome);
imports.list.add(moduleItem);
}
public void importAll(ItemProxy serverEntity, String moduleXML, boolean reset) throws Exception {
addModuleItem(moduleXML);
int systemAgentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath("system").getSysKey();
for (ModuleResource thisRes : imports.getResources()) {
try {
Bootstrap.verifyResource(ns, thisRes.name, thisRes.version, thisRes.resourceType, Resource.getTextResource(ns, thisRes.resourceLocation), reset);
} catch (Exception ex) {
Logger.error(ex);
}
}
for (NewRole thisRole : imports.getRoles()) {
RolePath rolePath;
try {
rolePath = Gateway.getLDAPLookup().getRoleManager().getRolePath(thisRole.name);
if (rolePath.hasJobList() != thisRole.jobList) {
Logger.msg("Module.importAll() - Role '"+thisRole.name+"' has incorrect joblist settings. Correcting.");
rolePath.setHasJobList(thisRole.jobList);
}
} catch (ObjectNotFoundException ex) {
Logger.msg("Module.importAll() - Role '"+thisRole.name+"' not found. Creating.");
thisRole.create(systemAgentId);
}
}
for (NewAgent thisAgent : imports.getAgents()) {
try {
Gateway.getLDAPLookup().getRoleManager().getAgentPath(thisAgent.name);
Logger.msg(3, "Module.importAll() - User '"+thisAgent.name+"' found.");
continue;
} catch (ObjectNotFoundException ex) { }
Logger.msg("Module.importAll() - User '"+thisAgent.name+"' not found. Creating.");
thisAgent.create(systemAgentId);
}
for (NewItem thisItem : imports.getItems()) {
thisItem.setNamespace(ns);
thisItem.create(systemAgentId, reset);
}
}
public Properties getProperties(boolean isServer) {
Properties props = new Properties();
for (ModuleConfig thisProp : config) {
if (thisProp.include(isServer))
props.put(thisProp.name, thisProp.value);
}
return props;
}
public String getNs() {
return ns;
}
public String getName() {
return name;
}
public String getDesc() {
return info.desc;
}
public String getVersion() {
return info.version;
}
public String getResURL() {
return resURL;
}
public ArrayList<String> getDependencies() {
return info.dependency;
}
public boolean hasDependency(String dep) {
return info.dependency.contains(dep);
}
}
|