use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage 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);
}
}
use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage 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.model.WorkflowPackage in project mdw-designer by CenturyLinkCloud.
the class AutoTestPropertyTester method test.
// TODO: support multiple selections
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
ResourceWrapper resourceWrapper = new ResourceWrapper((IAdaptable) receiver);
try {
WorkflowProject workflowProject = resourceWrapper.getOwningWorkflowProject();
if ("canLaunchAutoTest".equals(property)) {
// currently only for
// debug
IFile file = resourceWrapper.getFile();
if (file != null && ("test".equals(file.getFileExtension()) || "postman".equals(file.getFileExtension())) && file.exists() && !file.isDerived() && workflowProject != null) {
WorkflowPackage pkg = workflowProject.getPackage((IFolder) file.getParent());
if (pkg != null)
return pkg.getAsset(file) != null;
}
} else if ("canLaunchAutomatedTests".equals(property)) {
IFolder folder = resourceWrapper.getFolder();
if (folder != null) {
workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(folder.getProject());
if (workflowProject != null && workflowProject.isInitialized()) {
WorkflowPackage pkg = workflowProject.getPackage(folder);
if (pkg != null)
return !pkg.getTestCases().isEmpty();
}
} else {
IProject project = resourceWrapper.getProject();
if (project != null) {
WorkflowProject proj = WorkflowProjectManager.getInstance().getWorkflowProject(project);
if (proj != null && proj.isInitialized()) {
return !proj.getTestCases().isEmpty();
}
}
}
} else if ("canLaunchCucumberTest".equals(property)) {
if (resourceWrapper.getOwningJavaProject() != null) {
IFile file = resourceWrapper.getFile();
if (file != null && "feature".equals(file.getFileExtension()) && file.exists() && !file.isDerived()) {
// exclude mdw automated gherkin tests
if (workflowProject != null && workflowProject.isInitialized()) {
ResourceWrapper parentWrapper = new ResourceWrapper((IAdaptable) file.getParent());
IFolder folder = parentWrapper.getFolder();
if (folder != null && workflowProject.getPackage(folder) != null)
return false;
}
return true;
}
}
} else if ("canLaunchCucumberTests".equals(property) && resourceWrapper.getOwningJavaProject() != null) {
IFolder folder = resourceWrapper.getFolder();
if (folder != null) {
if (workflowProject != null && workflowProject.isInitialized() && workflowProject.getPackage(folder) != null)
return false;
List<CucumberTest> tests = new ArrayList<>();
CucumberTest.findTests(folder, tests);
return !tests.isEmpty();
} else {
return false;
}
}
} catch (CoreException ex) {
PluginMessages.log(ex);
}
return false;
}
use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage in project mdw-designer by CenturyLinkCloud.
the class AutomatedTestContentProvider method getChildren.
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof AutomatedTestSuite) {
AutomatedTestSuite testSuite = (AutomatedTestSuite) parentElement;
List<WorkflowPackage> packages = new ArrayList<WorkflowPackage>();
List<WorkflowElement> legacyTests = new ArrayList<WorkflowElement>();
for (AutomatedTestCase testCase : testSuite.getTestCases()) {
if (testCase.isLegacy()) {
legacyTests.add(testCase);
} else {
WorkflowPackage pkg = testCase.getPackage();
if (!packages.contains(pkg))
packages.add(pkg);
}
}
Folder folder = null;
if (!legacyTests.isEmpty()) {
folder = new Folder("Legacy Tests");
folder.setChildren(legacyTests);
for (WorkflowElement legacyTest : legacyTests) legacyTest.setArchivedFolder(folder);
}
Object[] children = new Object[packages.size() + (folder == null ? 0 : 1)];
for (int i = 0; i < packages.size(); i++) children[i] = packages.get(i);
if (folder != null)
children[children.length - 1] = folder;
return children;
} else if (parentElement instanceof WorkflowPackage) {
WorkflowPackage pkg = (WorkflowPackage) parentElement;
@SuppressWarnings("unchecked") AutomatedTestSuite suite = ((List<AutomatedTestSuite>) treeViewer.getInput()).get(0);
List<AutomatedTestCase> selectedCases = new ArrayList<AutomatedTestCase>();
List<String> testCasesStringList;
try {
testCasesStringList = pkg.getTestCaseStringList();
for (AutomatedTestCase testCase : suite.getTestCases()) {
String path = testCase.getPath();
if (testCase.isPostman())
path = testCase.getItemPath();
if (testCasesStringList.contains(path))
selectedCases.add(testCase);
}
} catch (JSONException e) {
e.printStackTrace();
}
return selectedCases.toArray();
} else if (parentElement instanceof Folder) {
return ((Folder) parentElement).getChildren().toArray();
} else if (parentElement instanceof AutomatedTestCase) {
AutomatedTestCase testCase = (AutomatedTestCase) parentElement;
if (testCase.isLegacy()) {
return testCase.getLegacyExpectedResults().toArray(new LegacyExpectedResults[0]);
} else {
AutomatedTestResults results = testCase.getExpectedResults();
return results == null ? EMPTY_ARRAY : new Object[] { results };
}
} else {
return EMPTY_ARRAY;
}
}
use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage in project mdw-designer by CenturyLinkCloud.
the class AssetLocator method assetFromAttr.
public WorkflowElement assetFromAttr(String attrValue) {
if (attrValue == null || attrValue.isEmpty() || attrValue.startsWith("$") || attrValue.startsWith("#")) {
return null;
}
if (isProcess()) {
int slashIdx = attrValue.indexOf('/');
if (slashIdx <= 0) {
// prefer process in same package
WorkflowProcess proc = getElement().getPackage() == null ? null : getProcessVersion(attrValue, getElement().getPackage().getProcesses());
if (proc != null)
return proc;
else
return getProcessVersion(attrValue, getProject().getAllProcessVersions());
} else {
String pkgName = attrValue.substring(0, slashIdx);
WorkflowPackage pkg = getProject().getPackage(pkgName);
if (pkg == null)
return null;
else
return getProcessVersion(attrValue.substring(slashIdx + 1), pkg.getProcesses());
}
} else if (isTaskTemplate()) {
// no need to handle unqualified attrs
int slashIdx = attrValue.indexOf('/');
String pkgName = slashIdx <= 0 ? null : attrValue.substring(0, slashIdx);
WorkflowPackage pkg = pkgName == null ? null : getProject().getPackage(pkgName);
if (pkg == null)
return null;
else
return getTaskTemplateVersion(attrValue.substring(slashIdx + 1), pkg.getTaskTemplates());
} else {
int slashIdx = attrValue.indexOf('/');
if (slashIdx <= 0) {
// prefer asset in same package
WorkflowAsset pkgDoc = getElement().getPackage() == null ? null : getWorkflowAssetVersion(attrValue, getElement().getPackage().getAssets());
if (pkgDoc != null)
return pkgDoc;
else
return getWorkflowAssetVersion(attrValue, getProject().getAllWorkflowAssets());
} else {
String pkgName = attrValue.substring(0, slashIdx);
WorkflowPackage pkg = getProject().getPackage(pkgName);
if (pkg == null)
return null;
else
return getWorkflowAssetVersion(attrValue.substring(slashIdx + 1), pkg.getAssets());
}
}
}
Aggregations