use of com.centurylink.mdw.bpm.MDWProcessDefinition in project mdw-designer by CenturyLinkCloud.
the class GraphFragment method toString.
@Override
public String toString() {
ProcessDefinitionDocument defnDoc = ProcessDefinitionDocument.Factory.newInstance();
MDWProcessDefinition procDefn = defnDoc.addNewProcessDefinition();
MDWProcess process = procDefn.addNewProcess();
process.setId(sourceProcessId.toString());
for (Node node : nodes) {
exportActivity(node.nodet, process.addNewActivity());
}
for (Link link : links) {
exportTransition(link.conn, process.addNewTransition());
}
for (SubGraph subgraph : subgraphs) {
MDWProcess subproc = process.addNewSubProcess();
subproc.setId(subgraph.getId().toString());
subproc.setName(subgraph.getName());
for (Node node : subgraph.nodes) {
exportActivity(node.nodet, subproc.addNewActivity());
}
for (Link link : subgraph.links) {
exportTransition(link.conn, subproc.addNewTransition());
}
}
return defnDoc.xmlText(new XmlOptions().setSavePrettyPrint());
}
use of com.centurylink.mdw.bpm.MDWProcessDefinition in project mdw-designer by CenturyLinkCloud.
the class ImportPackagePage method populateTopFolder.
public Folder populateTopFolder(String discoveryUrl, String groupId, boolean latestVersionsOnly, IProgressMonitor progressMonitor) throws Exception {
Folder folder = null;
getImportPackageWizard().getImportPackageSelectPage().clear();
if (discoveryUrl != null || groupId != null) {
if (discoveryUrl != null) {
if (getProject().checkRequiredVersion(6, 0, 13))
folder = new Discoverer(new URL(discoveryUrl), getProject().getHttpHelper(discoveryUrl)).getAssetTopFolder(latestVersionsOnly, progressMonitor);
else
folder = new Discoverer(new URL(discoveryUrl)).getAssetTopFolder(latestVersionsOnly, progressMonitor);
}
if (groupId != null)
folder = new Discoverer(groupId).getAssetTopFolder(latestVersionsOnly, progressMonitor);
if (getProject().isRemote() && getProject().isGitVcs()) {
List<Folder> emptyFolders = removeGitVersionedPackages(folder);
List<Folder> emptyParents = new ArrayList<>();
for (Folder emptyFolder : emptyFolders) {
if (emptyFolder.getParent() instanceof Folder) {
Folder parent = emptyFolder.getParent();
parent.getChildren().remove(emptyFolder);
// go one more level up
if (parent.getChildren().isEmpty() && !emptyParents.contains(parent))
emptyParents.add(parent);
}
}
for (Folder emptyParent : emptyParents) {
if (emptyParent.getParent() instanceof Folder)
(emptyParent.getParent()).getChildren().remove(emptyParent);
}
}
} else {
String filepath = filePathText.getText().trim();
String contents = FileHelper.getFileContents(filepath);
folder = new Folder(filepath);
boolean hasOldImpls = false;
if (contents.trim().startsWith("{")) {
ImporterExporterJson importer = new ImporterExporterJson();
List<PackageVO> packages = importer.importPackages(contents);
for (PackageVO pkg : packages) {
if (getProject().isRemote() && getProject().isGitVcs()) {
for (WorkflowPackage existingVcs : getProject().getTopLevelPackages()) {
if (existingVcs.getName().equals(pkg.getName()))
getImportPackageWizard().getImportPackageSelectPage().setError(PKG_EXISTS + pkg.getName());
}
}
File aFile = new File(folder, pkg.getName() + " v" + pkg.getVersionString());
ImporterExporterJson jsonExporter = new ImporterExporterJson();
List<PackageVO> pkgs = new ArrayList<>();
pkgs.add(pkg);
JSONObject pkgJson = new JSONObject(jsonExporter.exportPackages(pkgs));
pkgJson.put("name", pkg.getName());
aFile.setContent(pkgJson.toString(2));
folder.addChild(aFile);
}
preselected = folder;
} else {
try {
// try and parse as multiple packages
PackageDocument pkgDoc = PackageDocument.Factory.parse(contents);
QName docElement = new QName("http://mdw.centurylink.com/bpm", "processDefinition");
for (MDWProcessDefinition pkgDef : pkgDoc.getPackage().getProcessDefinitionList()) {
if (getProject().isRemote() && getProject().isGitVcs()) {
for (WorkflowPackage existingVcs : getProject().getTopLevelPackages()) {
if (existingVcs.getName().equals(pkgDef.getPackageName()))
getImportPackageWizard().getImportPackageSelectPage().setError(PKG_EXISTS + pkgDef.getPackageName());
}
}
if (!hasOldImpls && getProject().isFilePersist() && !getProject().isRemote())
hasOldImpls = checkForOldImplementors(pkgDef);
File aFile = new File(folder, pkgDef.getPackageName() + " v" + pkgDef.getPackageVersion());
aFile.setContent(pkgDef.xmlText(new XmlOptions().setSaveOuter().setSaveSyntheticDocumentElement(docElement)));
folder.addChild(aFile);
}
preselected = folder;
} catch (XmlException ex) {
// unparseable -- assume single package
if (getProject().isRemote() && getProject().isGitVcs()) {
MDWProcessDefinition procDef = ProcessDefinitionDocument.Factory.parse(contents, Compatibility.namespaceOptions()).getProcessDefinition();
for (WorkflowPackage existingVcs : getProject().getTopLevelPackages()) {
if (existingVcs.getName().equals(procDef.getPackageName()))
getImportPackageWizard().getImportPackageSelectPage().setError(PKG_EXISTS + procDef.getPackageName());
}
}
if (getProject().isFilePersist() && !getProject().isRemote())
hasOldImpls = checkForOldImplementors(ProcessDefinitionDocument.Factory.parse(contents, Compatibility.namespaceOptions()).getProcessDefinition());
File file = new File(folder, filepath);
file.setContent(contents);
folder.addChild(file);
preselected = file;
}
}
getImportPackageWizard().setHasOldImplementors(hasOldImpls);
}
return folder;
}
use of com.centurylink.mdw.bpm.MDWProcessDefinition 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