use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.
the class Exporter method exportPackages.
public String exportPackages(List<WorkflowPackage> packages, boolean exportJson, boolean includeTaskTemplates, ProgressMonitor progressMonitor) throws DataAccessException, ActionCancelledException, JSONException, XmlException {
String export = null;
progressMonitor.progress(10);
int schemaVersion = designerDataAccess.getDatabaseSchemaVersion();
List<PackageVO> pkgVos = new ArrayList<>();
for (WorkflowPackage pv : packages) pkgVos.add(pv.getPackageVO());
export = designerDataAccess.exportPackages(pkgVos, schemaVersion, exportJson, includeTaskTemplates, progressMonitor);
for (WorkflowPackage pv : packages) pv.setExported(true);
return export;
}
use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.
the class WorkflowProject method findArchivedPackages.
/**
* Returns all top-level archived (non-latest) packages, populated with
* their descendants which include the appropriate process versions. Uses
* 10% of progressMonitor.
*/
private Folder findArchivedPackages(ProgressMonitor progressMonitor, boolean visiblePkgsOnly) {
CodeTimer timer = new CodeTimer("findAuthorizedArchivedPackages()");
if (progressMonitor != null)
progressMonitor.subTask("Organizing packages");
Folder archivedPkgFolder = new Folder("Archive", this);
archivedPkgFolder.setIcon("archive.gif");
List<WorkflowPackage> topLevelArchivedPackageList = new ArrayList<>();
List<WorkflowPackage> allArchivedPackages = new ArrayList<>();
for (PackageVO packageVO : getDataAccess().getPackages(false)) {
if (isShowDefaultPackage() || !packageVO.isDefaultPackage()) {
WorkflowPackage potentialArchived = new WorkflowPackage(this, packageVO);
if (!getTopLevelPackages().contains(potentialArchived)) {
potentialArchived.setArchived(true);
potentialArchived.setProcesses(findProcesses(potentialArchived));
potentialArchived.setAssets(findWorkflowAssets(potentialArchived));
potentialArchived.setActivityImpls(findActivityImplementors(potentialArchived));
potentialArchived.setExternalEvents(findExternalEvents(potentialArchived));
potentialArchived.setTaskTemplates(findTaskTemplates(potentialArchived));
allArchivedPackages.add(potentialArchived);
}
}
}
// organize the package version hierarchy
Map<String, WorkflowPackage> topLevelArchivedPackages = new HashMap<>();
for (WorkflowPackage archivedPackage : allArchivedPackages) {
WorkflowPackage topLevel = topLevelArchivedPackages.get(archivedPackage.getName());
if ((!visiblePkgsOnly || (visiblePkgsOnly && archivedPackage.isVisible())) && (topLevel == null || archivedPackage.getPackageVO().getVersion() > topLevel.getPackageVO().getVersion()))
topLevelArchivedPackages.put(archivedPackage.getName(), archivedPackage);
}
for (WorkflowPackage topLevelArchivedPackage : topLevelArchivedPackages.values()) {
for (WorkflowPackage archivedPackage : allArchivedPackages) {
if (topLevelArchivedPackage.getName().equals(archivedPackage.getName()) && (!visiblePkgsOnly || (visiblePkgsOnly && archivedPackage.isVisible()))) {
if (topLevelArchivedPackage.equals(archivedPackage)) {
// clone top-level process for first child
WorkflowPackage firstChild = new WorkflowPackage(topLevelArchivedPackage);
firstChild.setArchived(true);
firstChild.setTopLevelVersion(topLevelArchivedPackage);
firstChild.setProcesses(topLevelArchivedPackage.getProcesses());
firstChild.setAssets(topLevelArchivedPackage.getAssets());
firstChild.setActivityImpls(topLevelArchivedPackage.getActivityImpls());
firstChild.setExternalEvents(topLevelArchivedPackage.getExternalEvents());
firstChild.setTaskTemplates(topLevelArchivedPackage.getTaskTemplates());
topLevelArchivedPackage.addDescendantPackageVersion(firstChild);
} else {
archivedPackage.setTopLevelVersion(topLevelArchivedPackage);
topLevelArchivedPackage.addDescendantPackageVersion(archivedPackage);
}
}
}
topLevelArchivedPackageList.add(topLevelArchivedPackage);
topLevelArchivedPackage.setArchivedFolder(archivedPkgFolder);
}
Collections.sort(topLevelArchivedPackageList);
if (isShowDefaultPackage()) {
// add unpackaged (default package)
PackageVO defaultPackageVO = new PackageVO();
defaultPackageVO.setPackageId(Long.valueOf(0));
defaultPackageVO.setPackageName(PackageVO.DEFAULT_PACKAGE_NAME);
archivedDefaultPackage = new WorkflowPackage(this, defaultPackageVO);
archivedDefaultPackage.setProcesses(findUnpackagedProcesses());
archivedDefaultPackage.setChildFolders(findUnpackagedAssetFolders());
archivedDefaultPackage.setArchived(true);
topLevelArchivedPackageList.add(0, archivedDefaultPackage);
}
List<WorkflowElement> children = new ArrayList<>();
children.addAll(topLevelArchivedPackageList);
archivedPkgFolder.setChildren(children);
if (progressMonitor != null)
progressMonitor.progress(10);
timer.stopAndLog();
return archivedPkgFolder;
}
use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.
the class WorkflowProject method newPackageVersion.
public void newPackageVersion(WorkflowPackage newPkg, WorkflowPackage prevPkg) {
if (isFilePersist()) {
// refresh prevPkg since it's fast
try {
PackageVO pkg = getDesignerDataAccess().loadPackage(prevPkg.getId(), false);
if (// when incrementing by saving non-process
pkg == null)
// pkgs
return;
prevPkg.setPackageVO(pkg);
prevPkg.setProcesses(findProcesses(prevPkg));
prevPkg.setExternalEvents(findExternalEvents(prevPkg));
prevPkg.setActivityImpls(findActivityImplementors(prevPkg));
prevPkg.setAssets(findWorkflowAssets(prevPkg));
prevPkg.setTaskTemplates(findTaskTemplates(prevPkg));
// may have been called in response to vcs save new process
// version
prevPkg.syncProcesses();
} catch (Exception ex) {
PluginMessages.log(ex);
}
}
// contents
for (WorkflowElement we : getArchivedUserVisiblePackagesFolder().getChildren()) {
WorkflowPackage pv = (WorkflowPackage) we;
if (pv.getName().equals(prevPkg.getName())) {
List<WorkflowPackage> descendants = pv.getDescendantPackageVersions();
if (descendants == null) {
descendants = new ArrayList<>();
pv.setDescendantPackageVersions(descendants);
}
descendants.add(prevPkg);
prevPkg.setTopLevelVersion(pv);
}
}
}
use of com.centurylink.mdw.model.value.process.PackageVO 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.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.
the class ImportPackageWizard method unzipToLocal.
void unzipToLocal(WorkflowProject wfp, java.io.File zipFile, java.io.File tempDir, java.io.File assetDir, List<WorkflowPackage> importedPackages, ProgressMonitor progressMonitor) throws IOException, DataAccessException, CoreException, JSONException {
VersionControl vcs = new VersionControlGit();
vcs.connect(null, null, null, wfp.getAssetDir());
progressMonitor.subTask("Archive existing assets...");
VcsArchiver archiver = new VcsArchiver(assetDir, tempDir, vcs, progressMonitor);
archiver.backup();
PluginMessages.log("Unzipping " + zipFile + " into: " + assetDir);
ZipHelper.unzip(zipFile, assetDir, null, null, true);
archiver.archive();
ZipHelper.unzip(zipFile, tempDir, null, null, true);
wfp.getSourceProject().refreshLocal(2, null);
java.io.File explodedDir = new java.io.File(tempDir + "/com");
if (explodedDir.isDirectory()) {
List<java.io.File> fileList = FileHelper.getFilesRecursive(explodedDir, "package.json", new ArrayList<java.io.File>());
for (java.io.File file : fileList) {
WorkflowPackage workflowPackage = new WorkflowPackage();
workflowPackage.setProject(wfp);
workflowPackage.setPackageVO(new PackageVO(new JSONObject(FileHelper.getFileContents(file.getPath()))));
importedPackages.add(workflowPackage);
}
FileHelper.deleteRecursive(explodedDir);
}
}
Aggregations