use of com.centurylink.mdw.bpm.PackageDocument in project mdw-designer by CenturyLinkCloud.
the class DesignerDataAccess method exportTaskTemplates.
public String exportTaskTemplates(Long packageId, ProgressMonitor monitor) throws DataAccessException, ActionCancelledException {
monitor.subTask("Loading package");
PackageVO packageVO = loadPackage(packageId, true);
monitor.progress(30);
if (monitor.isCanceled())
throw new ActionCancelledException();
if (monitor != null)
monitor.progress(5);
if (monitor != null)
monitor.subTask(EXPORTXML);
PackageDocument pkgDoc = PackageDocument.Factory.newInstance();
MDWPackage pkg = pkgDoc.addNewPackage();
pkg.setName(packageVO.getName());
pkg.setVersion(PackageVO.formatVersion(packageVO.getVersion()));
TaskTemplatesDocument.TaskTemplates templates = pkg.addNewTaskTemplates();
if (packageVO.getTaskTemplates() != null) {
for (TaskVO taskVO : packageVO.getTaskTemplates()) {
if (taskVO.getVersion() > 0) {
TaskTemplate templateDef = templates.addNewTask();
templateDef.setLogicalId(taskVO.getLogicalId());
templateDef.setVersion(RuleSetVO.formatVersion(taskVO.getVersion()));
templateDef.setAssetName(taskVO.getName());
templateDef.setName(taskVO.getTaskName());
if (taskVO.getTaskCategory() != null)
templateDef.setCategory(taskVO.getTaskCategory());
if (taskVO.getComment() != null)
templateDef.setDescription(taskVO.getComment());
if (taskVO.getAttributes() != null) {
for (AttributeVO attrVO : taskVO.getAttributes()) {
if (!"TaskDescription".equals(attrVO.getAttributeName())) {
Attribute attr = templateDef.addNewAttribute();
attr.setName(attrVO.getAttributeName());
attr.setStringValue(attrVO.getAttributeValue());
}
}
}
}
}
}
String xml = pkgDoc.xmlText(new XmlOptions().setSavePrettyPrint().setSavePrettyPrintIndent(2));
if (monitor != null && monitor.isCanceled())
throw new ActionCancelledException();
if (monitor != null)
monitor.progress(40);
return xml;
}
use of com.centurylink.mdw.bpm.PackageDocument in project mdw-designer by CenturyLinkCloud.
the class PackageConfigurationSection method updatePackageMetaContent.
private void updatePackageMetaContent() throws XmlException, JSONException, IOException {
if (!workflowPackage.getProject().isOldNamespaces()) {
if (workflowPackage.getMetaContent() != null && workflowPackage.getMetaContent().trim().startsWith("{")) {
PackageVO metaPkg = new PackageVO(new JSONObject(workflowPackage.getMetaContent()));
List<AttributeVO> attributes = null;
if (propertyGroups != null) {
attributes = new ArrayList<>();
for (PropertyGroup propGroup : propertyGroups) {
String group = propGroup.getName();
for (Property prop : propGroup.getPropertyList()) {
AttributeVO attribute = new AttributeVO(prop.getName(), prop.getStringValue());
if (group != null)
attribute.setAttributeGroup(group);
attributes.add(attribute);
}
}
}
metaPkg.setAttributes(attributes);
workflowPackage.setMetaContent(metaPkg.getJson(false).toString(2));
} else if (workflowPackage.getSchemaVersion() >= DataAccess.schemaVersion61) {
List<AttributeVO> attributes = null;
Yaml yaml = new Yaml();
Map<String, Object> map = (Map<String, Object>) yaml.load(workflowPackage.getMetaContent());
PackageVO metaPkg = new PackageVO(map);
if (propertyGroups != null) {
attributes = new ArrayList<>();
for (PropertyGroup propGroup : propertyGroups) {
String group = propGroup.getName();
for (Property prop : propGroup.getPropertyList()) {
AttributeVO attribute = new AttributeVO(prop.getName(), prop.getStringValue());
if (group != null)
attribute.setAttributeGroup(group);
attributes.add(attribute);
}
}
}
metaPkg.setAttributes(attributes);
workflowPackage.setMetaContent(metaPkg.getJson(false).toString(2));
} else {
PackageDocument pkgDefDoc = null;
if (workflowPackage.getMetaContent() == null || workflowPackage.getMetaContent().isEmpty()) {
pkgDefDoc = PackageDocument.Factory.newInstance();
} else {
if (workflowPackage.getMetaContent().startsWith("<bpm:package") || workflowPackage.getMetaContent().startsWith("<package")) {
pkgDefDoc = PackageDocument.Factory.parse(workflowPackage.getMetaContent());
} else {
pkgDefDoc = PackageDocument.Factory.newInstance();
}
}
if (pkgDefDoc.getPackage() == null)
pkgDefDoc.addNewPackage();
if (pkgDefDoc.getPackage().getApplicationProperties() == null)
pkgDefDoc.getPackage().addNewApplicationProperties();
pkgDefDoc.getPackage().getApplicationProperties().setPropertyGroupArray(propertyGroups.toArray(new PropertyGroup[0]));
String procDefStr = pkgDefDoc.xmlText(new XmlOptions().setSavePrettyPrint().setSavePrettyPrintIndent(2));
workflowPackage.setMetaContent(procDefStr);
}
} else {
ProcessDefinitionDocument procDefDoc;
if (workflowPackage.getMetaContent() == null || workflowPackage.getMetaContent().isEmpty())
procDefDoc = ProcessDefinitionDocument.Factory.newInstance();
else
procDefDoc = ProcessDefinitionDocument.Factory.parse(workflowPackage.getMetaContent(), Compatibility.namespaceOptions());
if (procDefDoc.getProcessDefinition() == null)
procDefDoc.addNewProcessDefinition();
if (procDefDoc.getProcessDefinition().getApplicationProperties() == null)
procDefDoc.getProcessDefinition().addNewApplicationProperties();
procDefDoc.getProcessDefinition().getApplicationProperties().setPropertyGroupArray(propertyGroups.toArray(new PropertyGroup[0]));
String procDefStr = DesignerCompatibility.getInstance().getOldProcessDefinition(procDefDoc);
workflowPackage.setMetaContent(procDefStr);
}
}
use of com.centurylink.mdw.bpm.PackageDocument in project mdw-designer by CenturyLinkCloud.
the class PackageConfigurationSection method getPropertyGroups.
private List<PropertyGroup> getPropertyGroups() {
if (// empty
workflowPackage.getMetaContent() == null && !workflowPackage.isDefaultPackage()) // string
// signifies
// already
// loaded
{
try {
PackageVO packageVO = workflowPackage.getProject().getDesignerProxy().getDesignerDataAccess().loadPackage(workflowPackage.getId(), false);
workflowPackage.setMetaContent(packageVO.getMetaContent() == null ? "" : packageVO.getMetaContent());
} catch (Exception ex) {
PluginMessages.uiError(getShell(), ex, "Package Config", workflowPackage.getProject());
}
}
if (workflowPackage.getMetaContent() == null || workflowPackage.getMetaContent().trim().length() == 0) {
return new ArrayList<>();
} else {
ApplicationProperties appProps = null;
try {
if (workflowPackage.getMetaContent().trim().startsWith("{")) {
List<PropertyGroup> propGroups = new ArrayList<>();
PackageVO metaPkg = new PackageVO(new JSONObject(workflowPackage.getMetaContent()));
if (metaPkg.getAttributes() != null) {
Map<String, List<AttributeVO>> groupedAttrs = metaPkg.getAttributesByGroup();
for (Map.Entry<String, List<AttributeVO>> group : groupedAttrs.entrySet()) {
PropertyGroup propGroup = PropertyGroup.Factory.newInstance();
if (group.getKey() != null)
propGroup.setName(group.getKey());
for (AttributeVO groupAttr : group.getValue()) {
Property prop = propGroup.addNewProperty();
prop.setName(groupAttr.getAttributeName());
prop.setStringValue(groupAttr.getAttributeValue());
}
propGroups.add(propGroup);
}
}
return propGroups;
} else if (workflowPackage.getSchemaVersion() >= DataAccess.schemaVersion61) {
List<PropertyGroup> propGroups = new ArrayList<>();
Yaml yaml = new Yaml();
Map<String, Object> map = (Map<String, Object>) yaml.load(workflowPackage.getMetaContent());
PackageVO metaPkg = new PackageVO(map);
if (metaPkg.getAttributes() != null) {
Map<String, List<AttributeVO>> groupedAttrs = metaPkg.getAttributesByGroup();
for (Map.Entry<String, List<AttributeVO>> group : groupedAttrs.entrySet()) {
PropertyGroup propGroup = PropertyGroup.Factory.newInstance();
if (group.getKey() != null)
propGroup.setName(group.getKey());
for (AttributeVO groupAttr : group.getValue()) {
Property prop = propGroup.addNewProperty();
prop.setName(groupAttr.getAttributeName());
prop.setStringValue(groupAttr.getAttributeValue());
}
propGroups.add(propGroup);
}
}
return propGroups;
} else if (workflowPackage.getMetaContent().startsWith("<bpm:package") || workflowPackage.getMetaContent().startsWith("<package")) {
PackageDocument pkgDoc = PackageDocument.Factory.parse(workflowPackage.getMetaContent());
appProps = pkgDoc.getPackage().getApplicationProperties();
} else {
ProcessDefinitionDocument procDefDoc = ProcessDefinitionDocument.Factory.parse(workflowPackage.getMetaContent(), Compatibility.namespaceOptions());
appProps = procDefDoc.getProcessDefinition().getApplicationProperties();
}
} catch (Exception ex) {
PluginMessages.uiError(getShell(), ex, "Package Config", workflowPackage.getProject());
}
if (appProps != null && appProps.getPropertyGroupList() != null)
return appProps.getPropertyGroupList();
// not found or can't parse
return new ArrayList<>();
}
}
use of com.centurylink.mdw.bpm.PackageDocument 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.PackageDocument in project mdw-designer by CenturyLinkCloud.
the class Importer method importTaskTemplates.
public void importTaskTemplates(final WorkflowPackage pkg, final String xml, final ProgressMonitor progressMonitor) throws XmlException, DataAccessException {
progressMonitor.subTask(PARSING_XML);
PackageDocument pkgDoc = PackageDocument.Factory.parse(xml);
MDWPackage packageDef = pkgDoc.getPackage();
if (!pkg.getName().equals(packageDef.getName()))
throw new DataAccessException("Expected package: " + pkg.getName() + " in tasks XML but found: " + packageDef.getName());
com.centurylink.mdw.task.TaskTemplatesDocument.TaskTemplates templates = packageDef.getTaskTemplates();
PackageVO packageVO = new PackageVO();
if (packageDef.getName() != null)
packageVO.setPackageName(packageDef.getName());
else
packageVO.setPackageName("package");
packageVO.setVersion(PackageVO.parseVersion(packageDef.getVersion()));
List<TaskVO> packageTaskTemplates = new ArrayList<>();
for (com.centurylink.mdw.task.TaskTemplate template : templates.getTaskList()) {
TaskVO taskTemplateVO = new TaskVO(template);
taskTemplateVO.setPackageName(packageVO.getPackageName());
String v = template.getVersion();
if (v != null && !v.equals("0"))
taskTemplateVO.setVersion(RuleSetVO.parseVersion(v));
String assetName = template.getAssetName();
if (assetName != null && !assetName.isEmpty())
taskTemplateVO.setName(assetName);
packageTaskTemplates.add(taskTemplateVO);
}
packageVO.setTaskTemplates(packageTaskTemplates);
if (!packageTaskTemplates.isEmpty())
dataAccess.getDesignerDataAccess().savePackage(packageVO, ProcessPersister.PersistType.IMPORT);
for (TaskVO taskVo : packageVO.getTaskTemplates()) {
TaskTemplate existing = null;
for (TaskTemplate taskTemplate : pkg.getTaskTemplates()) {
if (taskTemplate.getLogicalId().equals(taskVo.getLogicalId())) {
existing = taskTemplate;
break;
}
}
if (existing == null) {
TaskTemplate newTemplate = new TaskTemplate(taskVo, pkg.getPackage());
pkg.addTaskTemplate(newTemplate);
} else {
existing.setTaskVO(taskVo);
}
}
}
Aggregations