use of com.centurylink.mdw.plugin.designer.SwtProgressMonitor in project mdw-designer by CenturyLinkCloud.
the class ImportExportWizard method performFinish.
@Override
public boolean performFinish() {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
ProgressMonitor progressMonitor = new SwtProgressMonitor(monitor);
try {
progressMonitor.start((page.isExport ? "Exporting from " : "Importing into ") + "'" + getProject().getLabel() + "'");
progressMonitor.progress(5);
performImportExport(progressMonitor);
progressMonitor.done();
} catch (ActionCancelledException ex) {
throw new OperationCanceledException();
} catch (Exception ex) {
PluginMessages.log(ex);
throw new InvocationTargetException(ex);
}
}
};
try {
getContainer().run(true, true, op);
postRunUpdates();
return true;
} catch (InvocationTargetException ex) {
if (ex.getCause() instanceof DataAccessOfflineException)
MessageDialog.openError(getShell(), "Export Attributes", "Server appears to be offline: " + ex.getMessage());
else
PluginMessages.uiError(getShell(), ex, page.getTitle(), getProject());
return false;
} catch (Exception ex) {
PluginMessages.uiError(getShell(), ex, page.getTitle(), getProject());
return false;
}
}
use of com.centurylink.mdw.plugin.designer.SwtProgressMonitor in project mdw-designer by CenturyLinkCloud.
the class ProcessExplorerContentProvider method getChildren.
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof WorkflowProject) {
final WorkflowProject workflowProject = (WorkflowProject) parentElement;
if (!workflowProject.isLoaded()) {
try {
IRunnableWithProgress loader = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
ProgressMonitor progressMonitor = new SwtProgressMonitor(monitor);
progressMonitor.start("Loading " + workflowProject.getLabel());
progressMonitor.progress(5);
try {
workflowProject.initialize(progressMonitor);
if (workflowProject.getDataAccess() != null) {
workflowProject.getTopLevelUserVisiblePackages(progressMonitor);
workflowProject.getArchivedUserVisiblePackagesFolder(progressMonitor);
progressMonitor.done();
}
} catch (Exception ex) {
throw new InvocationTargetException(ex);
}
}
};
ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(MdwPlugin.getShell());
progMonDlg.run(true, false, loader);
} catch (InvocationTargetException itx) {
if (itx.getCause() instanceof DataUnavailableException) {
PluginMessages.log(itx);
MessageDialog.openWarning(MdwPlugin.getShell(), LOAD_WF_PROJECT, itx.getCause().getMessage());
} else if (itx.getCause() instanceof DataAccessOfflineException) {
PluginMessages.log(itx);
MessageDialog.openError(MdwPlugin.getShell(), LOAD_WF_PROJECT, itx.getCause().getMessage());
return new WorkflowPackage[0];
} else {
PluginMessages.uiError(itx, LOAD_WF_PROJECT, workflowProject);
return new WorkflowPackage[0];
}
} catch (Exception ex) {
PluginMessages.uiError(ex, LOAD_WF_PROJECT, workflowProject);
return new WorkflowPackage[0];
}
}
if (workflowProject.getDataAccess() == null)
return new WorkflowPackage[0];
List<WorkflowPackage> topLevelPackages = workflowProject.getTopLevelUserVisiblePackages();
Folder archivedPackageFolder = workflowProject.getArchivedUserVisiblePackagesFolder();
int size = topLevelPackages.size();
boolean showArchived = isShowArchivedItems(workflowProject);
if (showArchived)
size++;
AutomatedTestSuite testSuite = workflowProject.getLegacyTestSuite();
if (testSuite != null && !testSuite.isEmpty())
size++;
Object[] objects = new Object[size];
for (int i = 0; i < topLevelPackages.size(); i++) objects[i] = topLevelPackages.get(i);
int cur = topLevelPackages.size();
if (showArchived) {
objects[cur] = archivedPackageFolder;
cur++;
}
if (testSuite != null && !testSuite.isEmpty())
objects[cur] = testSuite;
return objects;
} else if (parentElement instanceof WorkflowPackage) {
WorkflowPackage packageVersion = (WorkflowPackage) parentElement;
if (packageVersion.isArchived() && packageVersion.hasDescendantPackageVersions()) {
return packageVersion.getDescendantPackageVersions().toArray(new WorkflowPackage[0]);
} else {
List<WorkflowElement> elements = new ArrayList<>();
IPreferenceStore prefsStore = MdwPlugin.getDefault().getPreferenceStore();
if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_PROCESSES_IN_PEX))
elements.addAll(packageVersion.getProcesses());
if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_WORKFLOW_ASSETS_IN_PEX))
elements.addAll(packageVersion.getAssets());
if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_EVENT_HANDLERS_IN_PEX))
elements.addAll(packageVersion.getExternalEvents());
if (prefsStore.getBoolean(PreferenceConstants.PREFS_SHOW_ACTIVITY_IMPLEMENTORS_IN_PEX))
elements.addAll(packageVersion.getActivityImpls());
if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_TASK_TEMPLATES_IN_PEX))
elements.addAll(packageVersion.getTaskTemplates());
elements.addAll(packageVersion.getChildFolders());
if (isSortPackageContentsAtoZ()) {
Collections.sort(elements, new Comparator<WorkflowElement>() {
public int compare(WorkflowElement e1, WorkflowElement e2) {
return e1.getLabel().compareToIgnoreCase(e2.getLabel());
}
});
}
return elements.toArray(new Object[0]);
}
} else if (parentElement instanceof WorkflowProcess) {
WorkflowProcess processVersion = (WorkflowProcess) parentElement;
if (processVersion.hasDescendantProcessVersions()) {
return processVersion.getDescendantProcessVersions().toArray(new WorkflowProcess[0]);
} else {
return emptyARRAY;
}
} else if (parentElement instanceof Folder) {
Folder folder = (Folder) parentElement;
return folder.getChildren().toArray(new WorkflowElement[0]);
} else if (parentElement instanceof AutomatedTestSuite) {
AutomatedTestSuite testSuite = (AutomatedTestSuite) parentElement;
return testSuite.getTestCases().toArray(new AutomatedTestCase[0]);
} else if (parentElement instanceof AutomatedTestCase) {
AutomatedTestCase testCase = (AutomatedTestCase) parentElement;
if (!testCase.isLegacy())
return emptyARRAY;
List<LegacyExpectedResults> expectedResults = testCase.getLegacyExpectedResults();
List<File> files = testCase.getFiles();
Object[] objects = new Object[expectedResults.size() + files.size()];
for (int i = 0; i < expectedResults.size(); i++) objects[i] = expectedResults.get(i);
for (int i = expectedResults.size(); i < objects.length; i++) objects[i] = files.get(i - expectedResults.size());
return objects;
} else {
return emptyARRAY;
}
}
use of com.centurylink.mdw.plugin.designer.SwtProgressMonitor in project mdw-designer by CenturyLinkCloud.
the class ImportPackageWizard method importFromMaven.
void importFromMaven(String fileName, WorkflowProject wfp, List<java.io.File> includes, IProgressMonitor monitor) throws IOException {
int index = fileName.indexOf(' ');
String pkg = fileName.substring(0, index);
String artifact = pkg.replace(groupId.replace(".assets", "."), "").replace('.', '-');
java.io.File assetDir = wfp.getAssetDir();
Import importer = new Import(groupId, artifact, fileName.substring(index + 2));
importer.setAssetLoc(assetDir.getPath());
importer.setForce(true);
importer.run(new SwtProgressMonitor(monitor));
if (wfp.isRemote())
includes.add(new java.io.File(assetDir + "/" + pkg.replace('.', '/')));
}
use of com.centurylink.mdw.plugin.designer.SwtProgressMonitor in project mdw-designer by CenturyLinkCloud.
the class ImportPackageWizard method performFinish.
@Override
public boolean performFinish() {
final List<WorkflowPackage> importedPackages = new ArrayList<>();
final List<java.io.File> includes = new ArrayList<>();
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
try {
WorkflowProject wfp = topFolder.getProject();
DesignerProxy designerProxy = wfp.getDesignerProxy();
java.io.File assetDir = wfp.getAssetDir();
java.io.File zipFile = null;
java.io.File tempDir = wfp.getTempDir();
monitor.beginTask("Import Packages", 100 * importPackageSelectPage.getSelectedPackages().size());
monitor.subTask("Importing selected packages...");
monitor.worked(10);
StringBuilder sb = new StringBuilder();
ProgressMonitor progressMonitor = new SwtProgressMonitor(new SubProgressMonitor(monitor, 100));
for (File pkgFile : importPackageSelectPage.getSelectedPackages()) {
if (pkgFile.getContent() == null) {
// discovered
if (pkgFile.getUrl() != null) {
// assets
HttpHelper httpHelper = new HttpHelper(pkgFile.getUrl());
httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
pkgFile.setContent(httpHelper.get());
} else if (mavenDiscovery)
importFromMaven(pkgFile.getName(), wfp, includes, monitor);
else {
getPackageNames(pkgFile.getName(), sb);
}
}
String pkgFileContent = pkgFile.getContent();
if (pkgFileContent != null) {
Importer importer = new Importer(designerProxy.getPluginDataAccess(), wfp.isFilePersist() && wfp.isRemote() ? null : getShell());
WorkflowPackage importedPackage = importer.importPackage(wfp, pkgFileContent, progressMonitor);
if (// canceled
importedPackage == null) {
progressMonitor.done();
break;
} else {
if (upgradeAssets) {
progressMonitor.subTask("Upgrading activity implementors and other assets...");
designerProxy.upgradeAssets(importedPackage);
}
if (// file system eclipse
wfp.isFilePersist())
// sync
wfp.getSourceProject().refreshLocal(2, null);
// TODO refresh Archive in case existing package
// was
// moved there
importedPackages.add(importedPackage);
includes.add(new java.io.File(assetDir + "/" + importedPackage.getName().replace('.', '/')));
}
progressMonitor.done();
}
}
if (sb.length() > 0) {
String url = wfp.getServiceUrl() + "/Services/Assets";
Map<String, String> hdrs = new HashMap<>();
hdrs.put("Content-Type", "application/json");
hdrs.put("request-query-string", "discoveryUrl=" + discoveryUrl + "&discoveryType=distributed");
DesignerHttpHelper httpHelper = new DesignerHttpHelper(new URL(url), wfp.getUser().getJwtToken());
httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
httpHelper.setHeaders(hdrs);
httpHelper.put("{packages: [" + sb.toString() + "]}");
}
if (zipFormat) {
zipFile = importFile;
if (!wfp.isRemote())
unzipToLocal(wfp, zipFile, tempDir, assetDir, importedPackages, progressMonitor);
}
if (!includes.isEmpty()) {
if (!tempDir.exists() && !tempDir.mkdirs()) {
throw new IOException("Unable to create temp directory: " + tempDir);
}
zipFile = new java.io.File(tempDir + "/packages" + StringHelper.filenameDateToString(new Date()) + ".zip");
ZipHelper.zipWith(assetDir, zipFile, includes);
}
if (zipFile != null && wfp.isRemote() && wfp.isFilePersist()) {
uploadToRemoteServer(wfp, zipFile);
if (!zipFile.delete())
PluginMessages.log("Unable to delete the file " + zipFile.getPath());
progressMonitor.done();
}
wfp.getDesignerProxy().getCacheRefresh().doRefresh(true);
} catch (ActionCancelledException ex) {
throw new OperationCanceledException();
} catch (Exception ex) {
PluginMessages.log(ex);
throw new InvocationTargetException(ex);
}
}
};
try {
boolean confirmed = true;
if (topFolder.getProject().checkRequiredVersion(6, 0, 13) && topFolder.getProject().isRemote())
confirmed = MessageDialog.openConfirm(getShell(), "Confirm Import", "This import will impact the remote environment. Are you sure you want to import?");
if (confirmed) {
getContainer().run(true, true, op);
if (!importedPackages.isEmpty())
DesignerPerspective.promptForShowPerspective(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), importedPackages.get(0));
IWorkbenchPage page = MdwPlugin.getActivePage();
ProcessExplorerView processExplorer = (ProcessExplorerView) page.findView(ProcessExplorerView.VIEW_ID);
if (processExplorer != null) {
processExplorer.handleRefresh();
processExplorer.expand(topFolder);
}
}
return true;
} catch (InterruptedException ex) {
MessageDialog.openInformation(getShell(), "Import Package", "Import Cancelled");
return true;
} catch (Exception ex) {
PluginMessages.uiError(getShell(), ex, "Import Package", importPackagePage.getProject());
return false;
}
}
use of com.centurylink.mdw.plugin.designer.SwtProgressMonitor in project mdw-designer by CenturyLinkCloud.
the class ProjectInflator method inflateCliCloudProject.
public void inflateCliCloudProject() {
try {
IRunnableWithProgress loader = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
monitor.beginTask("Inflating Workflow Project", 250);
monitor.worked(5);
// Download the templates
Init init = new Init(new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile() + "/" + workflowProject.getName()));
if (workflowProject.getMdwVersion().indexOf("SNAPSHOT") > -1)
init.setSnapshots(true);
init.setMdwVersion(workflowProject.getMdwVersion());
init.setDiscoveryUrl(MdwPlugin.getSettings().getMdwReleasesUrl());
monitor.subTask("Downloading Templates");
monitor.worked(10);
init.run(new SwtProgressMonitor(monitor));
createGitRepository(monitor);
IProject sourceProject = workflowProject.getSourceProject();
PluginUtil.createFoldersAsNeeded(sourceProject, sourceProject.getFolder("/build/classes"), monitor);
PluginUtil.createFoldersAsNeeded(sourceProject, sourceProject.getFolder("/src/main/java"), monitor);
ProjectUpdater updater = new ProjectUpdater(getProject(), MdwPlugin.getSettings());
updater.updateFrameworkJars(new SubProgressMonitor(monitor, 150));
workflowProject.refreshProject();
} catch (Exception ex) {
throw new InvocationTargetException(ex);
}
}
};
ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(MdwPlugin.getShell());
progMonDlg.run(true, false, loader);
} catch (Exception ex) {
PluginMessages.uiError(ex, "Create Cloud Project", workflowProject);
}
}
Aggregations