use of com.centurylink.mdw.dataaccess.file.ImporterExporterJson 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.dataaccess.file.ImporterExporterJson 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;
}
use of com.centurylink.mdw.dataaccess.file.ImporterExporterJson in project mdw-designer by CenturyLinkCloud.
the class Exporter method exportPackage.
public String exportPackage(String packageName, boolean includeTaskTemplates, boolean isJson) throws DataAccessException, RemoteException, ActionCancelledException, XmlException, JSONException {
int schemaVersion = dataAccess.getDatabaseSchemaVersion();
PackageVO packageVo = dataAccess.getPackage(packageName);
if (isJson) {
List<PackageVO> packages = new ArrayList<>();
packages.add(dataAccess.loadPackage(packageVo.getId(), true));
ImporterExporterJson jsonExporter = new ImporterExporterJson();
return jsonExporter.exportPackages(packages);
} else {
String xml = dataAccess.exportPackage(packageVo.getId(), schemaVersion, includeTaskTemplates, null);
if (!isLocal()) {
packageVo.setExported(true);
dataAccess.savePackage(packageVo);
}
return xml;
}
}
Aggregations