use of com.centurylink.mdw.plugin.designer.Importer in project mdw-designer by CenturyLinkCloud.
the class ImportAttributesWizard method performImportExport.
void performImportExport(ProgressMonitor progressMonitor) throws IOException, XmlException, DataAccessException, ValidationException, ActionCancelledException {
progressMonitor.progress(10);
progressMonitor.subTask("Reading XML file");
byte[] bytes = readFile(getPage().getFilePath());
progressMonitor.progress(20);
if (progressMonitor.isCanceled())
throw new ActionCancelledException();
progressMonitor.subTask("Performing Import");
Importer importer = new Importer(getProject().getDataAccess(), getShell());
importer.importAttributes(getProcess() == null ? getPackage() : getProcess(), new String(bytes), progressMonitor, prefix);
getProject().getDesignerProxy().getCacheRefresh().doRefresh(true);
progressMonitor.progress(30);
}
use of com.centurylink.mdw.plugin.designer.Importer in project mdw-designer by CenturyLinkCloud.
the class ImportTaskTemplatesWizard method performImportExport.
void performImportExport(ProgressMonitor progressMonitor) throws IOException, XmlException, DataAccessException, ValidationException, ActionCancelledException {
Importer importer = new Importer(getProject().getDataAccess(), getShell());
progressMonitor.progress(10);
progressMonitor.subTask("Reading XML file");
byte[] bytes = readFile(getPage().getFilePath());
if (progressMonitor.isCanceled())
throw new ActionCancelledException();
progressMonitor.subTask("Performing Import");
WorkflowPackage pkg = getPackage();
if (pkg == null)
throw new ValidationException("No package found.");
importer.importTaskTemplates(pkg, new String(bytes), progressMonitor);
progressMonitor.progress(30);
}
use of com.centurylink.mdw.plugin.designer.Importer 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.Importer in project mdw-designer by CenturyLinkCloud.
the class ImportProcessWizard method performImportExport.
void performImportExport(ProgressMonitor progressMonitor) throws IOException, XmlException, DataAccessException, ValidationException, ActionCancelledException {
DesignerProxy designerProxy = getProject().getDesignerProxy();
Importer importer = new Importer(designerProxy.getPluginDataAccess(), getShell());
progressMonitor.progress(10);
progressMonitor.subTask("Reading XML file");
byte[] bytes = readFile(getPage().getFilePath());
progressMonitor.progress(20);
if (progressMonitor.isCanceled())
throw new ActionCancelledException();
progressMonitor.subTask("Performing Import");
WorkflowProcess newProc = importer.importProcess(getPackage(), getProcess(), new String(bytes));
setElement(newProc);
progressMonitor.progress(30);
designerProxy.toggleProcessLock(newProc, true);
designerProxy.savePackage(newProc.getPackage());
}
Aggregations