use of com.centurylink.mdw.plugin.designer.model.File in project mdw-designer by CenturyLinkCloud.
the class ProcessExplorerActionGroup method createRunFromStartPageAction.
private IAction createRunFromStartPageAction() {
IAction action = new Action() {
@Override
public void run() {
if (!runFromPageApplies(getSelection()))
return;
view.setFocus();
Object element = getSelection().getFirstElement();
if (element instanceof AutomatedTestSuite || element instanceof AutomatedTestCase)
actionHandler.test(getSelection());
else if (element instanceof File && ((File) element).getParent() instanceof AutomatedTestCase && TestCase.LEGACY_TEST_CASE_FILENAMES.values().contains(((File) element).getName()))
actionHandler.test(getSelection());
else
actionHandler.runFromPage((WorkflowElement) element);
}
};
ImageDescriptor imageDesc = MdwPlugin.getImageDescriptor(ICON_RUN_GIF);
action.setImageDescriptor(imageDesc);
action.setId(MdwMenuManager.MDW_MENU_PREFIX + "run.start.page");
action.setText("Run Start Page...");
return action;
}
use of com.centurylink.mdw.plugin.designer.model.File in project mdw-designer by CenturyLinkCloud.
the class Discoverer method crawlForPackageFiles.
/**
* Crawls to find any package XML or JSON files.
*/
private void crawlForPackageFiles(Folder parent) throws DiscoveryException, IOException, InterruptedException {
if (progressMonitor.isCanceled())
throw new InterruptedException();
String parentUrl = getFullUrl(parent);
if (httpHelper == null)
httpHelper = new HttpHelper(new URL(parentUrl));
httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
if (// topLevel
!parent.hasParent())
httpHelper.setFollowHtmlHeadMetaRefresh(true);
String content = httpHelper.get();
if (content.startsWith("{")) {
parseJsonPacakges(parent, content);
} else {
if (content.startsWith("<!"))
content = content.substring(content.indexOf('\n') + 1);
if (content.contains(" "))
content = content.replaceAll(" ", "").replace("<HR size=\"1\" noshade=\"noshade\">", "");
if (!parent.hasParent() && httpHelper.getRedirect() != null)
parent.setName(httpHelper.getRedirect().toString());
try {
List<String> links = parseDirectoryResponse(content);
if (!parent.hasParent())
topLevelFolders = links.size();
if (latestVersionsOnly) {
List<String> latestLinks = new ArrayList<>();
String latestDir = null;
for (String link : links) {
if (// snapshots excluded from
!link.startsWith("6") && !link.endsWith("-SNAPSHOT/")) // "latest only"
{
if (link.matches("[0-9.]*/")) {
if ((latestDir == null || latestDir.compareTo(link) < 0))
latestDir = link;
} else {
latestLinks.add(link);
}
}
}
if (latestDir != null)
latestLinks.add(latestDir);
links = latestLinks;
}
for (String link : links) {
if (!link.startsWith("6") && link.endsWith("/") && (MdwPlugin.getSettings().isIncludePreviewBuilds() || !link.endsWith("-SNAPSHOT/"))) {
// directory
if (!parent.hasParent())
progressMonitor.subTask("Scanning " + link);
Folder child = new Folder(link.substring(0, link.length() - 1));
if (link.matches("[0-9.]*/"))
parent.addChild(0, child);
else
parent.addChild(child);
httpHelper = null;
crawlForPackageFiles(child);
if (// topLevel
!parent.hasParent())
progressMonitor.worked(80 / topLevelFolders);
} else if (link.endsWith(".xml") || link.endsWith(".json")) {
// XML or JSON file
File child = new File(parent, link);
parent.addChild(0, child);
child.setUrl(new URL(getFullUrl(child)));
}
}
} catch (InterruptedException iex) {
throw iex;
} catch (Exception ex) {
throw new DiscoveryException("Error crawling: " + parentUrl, ex);
}
}
}
use of com.centurylink.mdw.plugin.designer.model.File 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.plugin.designer.model.File 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.File 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;
}
}
Aggregations