use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.
the class DesignerDataModel method copyPackage.
public PackageVO copyPackage(PackageVO curPkg, String newname, int newversion) {
PackageVO newPkg = new PackageVO();
newPkg.setPackageName(newname != null ? newname : curPkg.getPackageName());
newPkg.setPackageDescription(curPkg.getPackageDescription());
newPkg.setExported(false);
// newPkg.setPools(pools)
// newPkg.setVariables(variables)
newPkg.setSchemaVersion(DataAccess.currentSchemaVersion);
newPkg.setPackageId(getNewId());
newPkg.setVersion(newversion);
newPkg.setMetaContent(curPkg.getMetaContent());
List<ProcessVO> processes = new ArrayList<ProcessVO>();
newPkg.setProcesses(processes);
if (curPkg.getProcesses() != null) {
for (ProcessVO p : curPkg.getProcesses()) {
processes.add(p);
}
}
if (curPkg.getImplementors() != null) {
List<ActivityImplementorVO> impls = new ArrayList<ActivityImplementorVO>();
newPkg.setImplementors(impls);
for (ActivityImplementorVO a : curPkg.getImplementors()) {
impls.add(a);
}
}
if (curPkg.getExternalEvents() != null) {
List<ExternalEventVO> handlers = new ArrayList<ExternalEventVO>();
newPkg.setExternalEvents(handlers);
for (ExternalEventVO a : curPkg.getExternalEvents()) {
handlers.add(a);
}
}
if (curPkg.getParticipants() != null) {
List<LaneVO> participants = new ArrayList<LaneVO>();
newPkg.setParticipants(participants);
for (LaneVO a : curPkg.getParticipants()) {
participants.add(a);
}
}
if (curPkg.getRuleSets() != null) {
List<RuleSetVO> rulesets = new ArrayList<RuleSetVO>();
newPkg.setRuleSets(rulesets);
for (RuleSetVO a : curPkg.getRuleSets()) {
rulesets.add(a);
}
}
if (curPkg.getAttributes() != null) {
List<AttributeVO> attrs = new ArrayList<AttributeVO>();
newPkg.setAttributes(attrs);
for (AttributeVO a : curPkg.getAttributes()) {
attrs.add(a);
}
}
addPackage(newPkg);
return newPkg;
}
use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.
the class NodeRunner method run.
public void run(final TestCase testCase, DesignerDataAccess dao, boolean verbose, boolean createReplace) throws ServiceException {
PackageVO pkgVo = null;
NodeJS nodeJS = NodeJS.createNodeJS();
try {
pkgVo = dao.getPackage(NODE_PKG);
} catch (DataAccessException e) {
throw new ServiceException(e.getMessage());
}
final V8Object fileObj = new V8Object(nodeJS.getRuntime()).add("file", pkgVo.getRuleSet(RUNNER).getRawFile().getAbsolutePath());
JavaCallback callback = new JavaCallback() {
public Object invoke(V8Object receiver, V8Array parameters) {
return fileObj;
}
};
nodeJS.getRuntime().registerJavaMethod(callback, "getRunner");
final Result parseResult = new Result();
callback = new JavaCallback() {
public Object invoke(V8Object receiver, V8Array parameters) {
V8Object resultObj = parameters.getObject(0);
parseResult.status = resultObj.getString("status");
parseResult.message = resultObj.getString("message");
resultObj.release();
return null;
}
};
nodeJS.getRuntime().registerJavaMethod(callback, "setParseResult");
nodeJS.exec(pkgVo.getRuleSet(PARSER).getRawFile());
while (nodeJS.isRunning()) {
nodeJS.handleMessage();
}
fileObj.release();
nodeJS.release();
if (!parseResult.status.equals("OK"))
throw new ServiceException(PARSER + parseResult);
nodeJS = NodeJS.createNodeJS();
final V8Object testObj = new V8Object(nodeJS.getRuntime());
testObj.add("file", testCase.getCaseFile().getAbsolutePath());
V8Array valueFiles = new V8Array(nodeJS.getRuntime());
// TODO hardcoded
valueFiles.push("localhost.env");
testObj.add("valueFiles", valueFiles);
valueFiles.release();
testObj.add("resultDir", testCase.getResultDirectory().getAbsolutePath());
final Map<String, TestCaseItem> testCaseItems = new HashMap<>();
final V8Array testItems = new V8Array(nodeJS.getRuntime());
for (TestCaseItem item : testCase.getItems()) {
String itemId = item.getName();
V8Object itemObj = new V8Object(nodeJS.getRuntime()).add("name", item.getName());
try {
if (item.getObject().has("request")) {
JSONObject request = item.getObject().getJSONObject("request");
if (request.has("method")) {
itemObj.add("method", request.getString("method"));
itemId = request.getString("method") + ":" + itemId;
}
}
JSONObject options = item.getOptions() == null ? new JSONObject() : item.getOptions();
if (verbose && !options.has("debug"))
options.put("debug", "true");
if (createReplace && !options.has("overwriteExpected"))
options.put("overwriteExpected", "true");
options.put("qualifyLocations", false);
if (JSONObject.getNames(options) != null) {
V8Object json = nodeJS.getRuntime().getObject("JSON");
V8Array params = new V8Array(nodeJS.getRuntime()).push(options.toString());
V8Object jsonObj = json.executeObjectFunction("parse", params);
itemObj.add("options", jsonObj);
params.release();
json.release();
jsonObj.release();
}
if (item.getValues() != null) {
V8Object json = nodeJS.getRuntime().getObject("JSON");
V8Array params = new V8Array(nodeJS.getRuntime()).push(item.getValues().toString());
V8Object jsonObj = json.executeObjectFunction("parse", params);
itemObj.add("values", jsonObj);
params.release();
json.release();
jsonObj.release();
}
} catch (JSONException e) {
e.printStackTrace();
}
testItems.push(itemObj);
testCaseItems.put(itemId, item);
itemObj.release();
}
testObj.add("items", testItems);
testItems.release();
callback = new JavaCallback() {
public Object invoke(V8Object receiver, V8Array parameters) {
return testObj;
}
};
nodeJS.getRuntime().registerJavaMethod(callback, "getTestCase");
callback = new JavaCallback() {
public Object invoke(V8Object receiver, V8Array parameters) {
String itemId = parameters.getString(0);
V8Object resultObj = parameters.getObject(1);
if (itemId == null) {
for (TestCaseItem item : testCase.getItems()) {
updateItem(item, resultObj);
}
}
TestCaseItem item = testCaseItems.get(itemId);
if (item != null) {
updateItem(item, resultObj);
}
resultObj.release();
return null;
}
};
nodeJS.getRuntime().registerJavaMethod(callback, "setTestResult");
final V8 v8 = nodeJS.getRuntime();
callback = new JavaCallback() {
public Object invoke(V8Object receiver, V8Array parameters) {
String itemId = parameters.getString(0);
V8Object responseObj = parameters.getObject(1);
TestCaseItem item = testCaseItems.get(itemId);
if (item != null) {
V8Object json = v8.getObject("JSON");
V8Array params = new V8Array(v8).push(responseObj);
String jsonStr = json.executeStringFunction("stringify", params);
params.release();
json.release();
try {
item.setResponse(new JSONObject(jsonStr));
} catch (JSONException e) {
e.printStackTrace();
}
}
responseObj.release();
return null;
}
};
nodeJS.getRuntime().registerJavaMethod(callback, "setTestResponse");
nodeJS.exec(pkgVo.getRuleSet(RUNNER).getRawFile());
while (nodeJS.isRunning()) {
nodeJS.handleMessage();
}
testObj.release();
nodeJS.release();
}
use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.
the class PluginDataAccess method determineDefaultPackage.
private PackageVO determineDefaultPackage(List<PackageVO> packageList, List<ProcessVO> processes) {
Map<String, PackageVO> processPackage = new HashMap<>();
PackageVO defaultPackage = new PackageVO();
List<ProcessVO> defaultProcesses = new ArrayList<>();
for (PackageVO pkg : packageList) {
for (ProcessVO proc : pkg.getProcesses()) processPackage.put(proc.getProcessName(), pkg);
}
for (ProcessVO proc : processes) {
if (processPackage.get(proc.getProcessName()) == null)
defaultProcesses.add(proc);
}
defaultPackage.setProcesses(defaultProcesses);
defaultPackage.setExternalEvents(new ArrayList<ExternalEventVO>(0));
defaultPackage.setPackageId(Long.valueOf(0));
defaultPackage.setPackageName(PackageVO.DEFAULT_PACKAGE_NAME);
return defaultPackage;
}
use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.
the class DesignerDataAccess method exportAttributes.
public String exportAttributes(String prefix, Long artifactId, int schemaVersion, ProgressMonitor monitor, String exportArtifactType) throws DataAccessException, ActionCancelledException, XmlException {
monitor.subTask("Loading attributes...");
PackageVO packageVO = null;
ProcessVO processVO = null;
if (exportArtifactType.equals(OwnerType.PACKAGE)) {
packageVO = loadPackage(artifactId, true);
if (isVcsPersist()) {
try {
for (ProcessVO process : packageVO.getProcesses()) {
Map<String, String> overrideAttrs = workflowAccessRest.getAttributes(OwnerType.PROCESS, process.getId());
process.applyOverrideAttributes(overrideAttrs);
}
} catch (IOException ex) {
throw new DataAccessOfflineException("Server does not appear to be running.", ex);
}
} else {
for (ProcessVO process : packageVO.getProcesses()) {
if (process.isInRuleSet()) {
Map<String, String> overrideAttrs = getAttributes(OwnerType.PROCESS, process.getId());
process.applyOverrideAttributes(overrideAttrs);
}
}
}
} else {
processVO = getProcess(artifactId, null);
if (isVcsPersist()) {
try {
// need to make sure attributes are retrieved
Map<String, String> overrideAttrs = workflowAccessRest.getAttributes(OwnerType.PROCESS, processVO.getId());
processVO.applyOverrideAttributes(overrideAttrs);
} catch (IOException ex) {
throw new DataAccessOfflineException("Server does not appear to be running.", ex);
}
}
}
monitor.progress(30);
if (monitor.isCanceled())
throw new ActionCancelledException();
if (packageVO != null) {
// -- subprocesses must come after their containing parent processes
Collections.sort(packageVO.getProcesses(), new Comparator<ProcessVO>() {
public int compare(ProcessVO pVO1, ProcessVO pVO2) {
boolean pVO1HasSubProcs = pVO1.getSubProcesses() != null && !pVO1.getSubProcesses().isEmpty();
boolean pVO2HasSubProcs = pVO2.getSubProcesses() != null && !pVO2.getSubProcesses().isEmpty();
if (pVO1HasSubProcs == pVO2HasSubProcs) {
// sort by label
return pVO1.getLabel().compareToIgnoreCase(pVO2.getLabel());
} else if (pVO1HasSubProcs)
return -1;
else
return 1;
}
});
}
if (monitor.isCanceled())
throw new ActionCancelledException();
monitor.progress(5);
monitor.subTask(EXPORTXML);
ProcessExporter exporter = DataAccess.getProcessExporter(schemaVersion, oldNamespaces ? DesignerCompatibility.getInstance() : null);
String xml;
if (packageVO != null)
xml = exporter.exportOverrideAttributes(prefix, packageVO);
else
xml = exporter.exportOverrideAttributes(prefix, processVO, schemaVersion);
monitor.progress(40);
return xml;
}
use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.
the class DesignerDataAccess method exportPackages.
public String exportPackages(List<PackageVO> packages, int schemaVersion, boolean exportJson, boolean includeTaskTemplates, ProgressMonitor monitor) throws DataAccessException, ActionCancelledException, JSONException, XmlException {
if (monitor != null)
monitor.subTask("Loading package(s)...");
List<PackageVO> loadedPackages = new ArrayList<>();
for (PackageVO pkg : packages) {
if (monitor != null)
monitor.subTask("Loading " + pkg.getLabel() + "...");
PackageVO packageVO = loadPackage(pkg.getId(), true);
if (monitor != null)
monitor.progress(30 / packages.size());
if (monitor != null) {
if (monitor.isCanceled())
throw new ActionCancelledException();
else
monitor.subTask("Sorting processes and implementors");
}
if (packageVO.getRuleSets() != null) {
Map<String, CustomAttributeVO> customAttrs = new HashMap<>();
for (RuleSetVO ruleSet : packageVO.getRuleSets()) {
if (ruleSet.getLanguage() != null && !customAttrs.containsKey(ruleSet.getLanguage())) {
CustomAttributeVO custAttrVO = getCustomAttribute("RULE_SET", ruleSet.getLanguage());
if (custAttrVO != null)
customAttrs.put(ruleSet.getLanguage(), custAttrVO);
}
}
List<CustomAttributeVO> customAttributes = new ArrayList<>();
for (CustomAttributeVO customAttr : customAttrs.values()) customAttributes.add(customAttr);
packageVO.setCustomAttributes(customAttributes);
}
loadedPackages.add(packageVO);
}
if (monitor != null && monitor.isCanceled())
throw new ActionCancelledException();
if (monitor != null)
monitor.progress(5);
if (monitor != null)
monitor.subTask(EXPORTXML);
String export;
if (exportJson) {
ImporterExporterJson exporter = new ImporterExporterJson();
export = exporter.exportPackages(loadedPackages);
} else {
ProcessExporter exporter = DataAccess.getProcessExporter(schemaVersion, oldNamespaces ? DesignerCompatibility.getInstance() : null);
export = exporter.exportPackages(loadedPackages, includeTaskTemplates);
}
if (monitor != null)
monitor.progress(25);
for (PackageVO packageVO : loadedPackages) {
packageVO.setExported(true);
persister.persistPackage(packageVO, PersistType.UPDATE);
}
if (monitor != null)
monitor.progress(15);
return export;
}
Aggregations