use of com.centurylink.mdw.dataaccess.ProcessImporter in project mdw-designer by CenturyLinkCloud.
the class DesignerDataAccess method remoteRetrieveProcess.
public ProcessVO remoteRetrieveProcess(String name, int version) throws DataAccessException {
try {
String path = "Processes?name=" + name;
if (version != 0)
path += "&version=" + RuleSetVO.formatVersion(version);
String pkgXml = ((RestfulServer) currentServer).invokeResourceService(path);
ProcessImporter importer = DataAccess.getProcessImporter(getDatabaseSchemaVersion());
PackageVO pkg = importer.importPackage(pkgXml);
ProcessVO process = pkg.getProcesses().get(0);
process.setPackageName(pkg.getName());
process.setPackageVersion(pkg.getVersionString());
if (isVcsPersist())
process.setId(currentServer.getVersionControl().getId(getLogicalFile(process)));
return process;
} catch (IOException ex) {
throw new DataAccessException("Error retrieving process: " + name + " v" + RuleSetVO.formatVersion(version), ex);
}
}
use of com.centurylink.mdw.dataaccess.ProcessImporter in project mdw-designer by CenturyLinkCloud.
the class WorkflowAccessRest method getProcess.
public ProcessVO getProcess(long processId, boolean json) throws DataAccessException {
try {
if (json) {
String processJson = getServer().invokeResourceService("Workflow?id=" + processId);
JSONObject jsonObj = new JSONObject(processJson);
ProcessVO process = new ProcessVO(jsonObj);
process.setPackageName(jsonObj.getString("package"));
process.setPackageVersion(jsonObj.getString("packageVersion"));
process.setId(jsonObj.getLong("id"));
return process;
} else {
String pkgXml = getServer().invokeResourceService("Processes?id=" + processId);
ProcessImporter importer = DataAccess.getProcessImporter(DataAccess.currentSchemaVersion);
PackageVO pkg = importer.importPackage(pkgXml);
ProcessVO process = pkg.getProcesses().get(0);
process.setPackageName(pkg.getName());
process.setPackageVersion(pkg.getVersionString());
process.setId(processId);
return process;
}
} catch (Exception ex) {
throw new DataAccessException("Error retrieving process: " + processId, ex);
}
}
use of com.centurylink.mdw.dataaccess.ProcessImporter in project mdw-designer by CenturyLinkCloud.
the class Importer method parsePackageContent.
public PackageVO parsePackageContent(String packageContent) throws JSONException, DataAccessException {
if (packageContent.trim().startsWith("{")) {
Map<String, JSONObject> pkgJsonMap = JsonUtil.getJsonObjects(new JSONObject(packageContent).getJSONObject("packages"));
String name = pkgJsonMap.keySet().iterator().next();
PackageVO pkgVO = new PackageVO(pkgJsonMap.get(name));
pkgVO.setName(name);
return pkgVO;
} else {
int schemaVersion = dataAccess.getDesignerDataAccess().getDatabaseSchemaVersion();
ProcessImporter importer = DataAccess.getProcessImporter(schemaVersion);
return importer.importPackage(packageContent);
}
}
use of com.centurylink.mdw.dataaccess.ProcessImporter in project mdw-designer by CenturyLinkCloud.
the class Importer method importProcess.
public WorkflowProcess importProcess(final WorkflowPackage targetPackage, final WorkflowProcess targetProcess, final String xml) throws DataAccessException, RemoteException, XmlException, ValidationException {
CodeTimer timer = new CodeTimer("importProcess()");
ProcessVO importedProcessVO = null;
int schemaVersion = dataAccess.getSchemaVersion();
ProcessImporter importer = DataAccess.getProcessImporter(schemaVersion);
importedProcessVO = importer.importProcess(xml);
if (targetProcess != null && !importedProcessVO.getName().equals(targetProcess.getName()))
throw new ValidationException("Process in XML (" + importedProcessVO.getName() + ") is not " + targetProcess.getName());
for (WorkflowProcess existing : targetPackage.getProject().getAllProcesses()) {
if (existing.getName().equals(importedProcessVO.getName())) {
if (existing.getVersion() == importedProcessVO.getVersion())
throw new ValidationException(existing.getLabel() + " already exists in " + targetPackage.getProject().getLabel() + ".");
if (existing.getVersion() > importedProcessVO.getVersion())
throw new ValidationException(existing.getLabel() + " already exists in " + targetPackage.getProject().getLabel() + " with a version greater than the imported process (v" + importedProcessVO.getVersionString() + ").");
}
}
// designer fix for backward compatibility
ProcessWorker worker = new ProcessWorker();
worker.convert_to_designer(importedProcessVO);
worker.convert_from_designer(importedProcessVO, syncNodeMetaInfo(dataAccess.getDesignerDataModel().getNodeMetaInfo(), importedProcessVO));
if (!importedProcessVO.isInRuleSet()) {
// fix pseudo variables
for (VariableVO varVO : importedProcessVO.getVariables()) varVO.setVariableId(null);
}
importedProcessVO.setPackageName(targetPackage.getName());
WorkflowProcess alreadyInPackage = null;
if (targetPackage.getProject().getProcess(importedProcessVO.getName()) == null)
dataAccess.getDesignerDataAccess().createProcess(importedProcessVO);
else {
alreadyInPackage = targetPackage.getProcess(importedProcessVO.getName());
dataAccess.getDesignerDataAccess().updateProcess(importedProcessVO, importedProcessVO.getVersion(), false);
}
ProcessVO reloaded = dataAccess.getDesignerDataAccess().getProcessDefinition(importedProcessVO.getProcessName(), importedProcessVO.getVersion());
importedProcessVO.setProcessId(reloaded.getProcessId());
if (targetPackage.getProject().getDataAccess().getSupportedSchemaVersion() < DataAccess.schemaVersion52)
updateSubProcessIdAttributes(importedProcessVO);
WorkflowProcess importedProcess = new WorkflowProcess(targetPackage.getProject(), importedProcessVO);
dataAccess.getProcesses(false).add(importedProcess.getProcessVO());
if (alreadyInPackage != null)
targetPackage.removeProcess(alreadyInPackage);
targetPackage.addProcess(importedProcess);
importedProcess.setPackage(targetPackage);
dataAccess.auditLog(Action.Import, importedProcess);
timer.stopAndLog();
return importedProcess;
}
use of com.centurylink.mdw.dataaccess.ProcessImporter in project mdw-designer by CenturyLinkCloud.
the class Importer method importAttributes.
public void importAttributes(final WorkflowElement element, final String xml, final ProgressMonitor progressMonitor, String attrPrefix) throws DataAccessException, XmlException {
progressMonitor.subTask(PARSING_XML);
int schemaVersion = dataAccess.getSchemaVersion();
ProcessImporter importer = DataAccess.getProcessImporter(schemaVersion);
progressMonitor.progress(40);
progressMonitor.subTask("Saving attributes");
ProcessDefinitionDocument procdef = ProcessDefinitionDocument.Factory.parse(xml, Compatibility.namespaceOptions());
if (element instanceof WorkflowPackage && !((WorkflowPackage) element).getName().equals(procdef.getProcessDefinition().getPackageName()))
throw new DataAccessException("Expected package: " + ((WorkflowPackage) element).getName() + " in attributes XML but found: " + procdef.getProcessDefinition().getPackageName());
for (MDWProcess process : procdef.getProcessDefinition().getProcessList()) {
ProcessDefinitionDocument oneProcDef = ProcessDefinitionDocument.Factory.newInstance();
MDWProcessDefinition oneProc = oneProcDef.addNewProcessDefinition();
oneProc.getProcessList().add(process);
ProcessVO importedProc = importer.importProcess(oneProcDef.xmlText());
if (element instanceof WorkflowProcess && !((WorkflowProcess) element).getName().equals(importedProc.getProcessName()))
throw new DataAccessException("Expected process: " + ((WorkflowProcess) element).getName() + " in attributes XML but found: " + importedProc.getName());
ProcessVO proc = dataAccess.getLatestProcess(importedProc.getName());
if (proc == null)
throw new DataAccessException("Process not found: " + importedProc.getName());
Map<String, String> existAttrs = dataAccess.getDesignerDataAccess().getAttributes(OwnerType.PROCESS, proc.getId());
Map<String, String> importedAttrs = importedProc.getOverrideAttributes();
Map<String, String> setAttrs = new HashMap<>();
if (existAttrs != null) {
// retain existing attrs not related to this prefix
for (Map.Entry<String, String> attrs : existAttrs.entrySet()) {
if (!WorkAttributeConstant.isAttrNameFor(attrs.getKey(), attrPrefix))
setAttrs.put(attrs.getKey(), attrs.getValue());
}
}
if (importedAttrs != null) {
for (Map.Entry<String, String> attrs : importedAttrs.entrySet()) {
if (!WorkAttributeConstant.isAttrNameFor(attrs.getKey(), attrPrefix))
throw new DataAccessException("Expected attribute prefix: " + attrPrefix + " in attributes XML but found attribute: " + attrs.getKey());
else
setAttrs.put(attrs.getKey(), attrs.getValue());
}
}
dataAccess.getDesignerDataAccess().setOverrideAttributes(attrPrefix, OwnerType.PROCESS, proc.getId(), setAttrs);
}
}
Aggregations