use of com.centurylink.mdw.plugin.designer.model.WorkflowAsset in project mdw-designer by CenturyLinkCloud.
the class WorkflowProject method getAllWorkflowAssets.
/**
* Returns all assets regardless of user access, packaging and archive
* status.
*/
public List<WorkflowAsset> getAllWorkflowAssets() {
List<WorkflowAsset> allAssets = new ArrayList<>();
allAssets.addAll(getTopLevelWorkflowAssets());
if (isShowDefaultPackage())
allAssets.addAll(getUnpackagedWorkflowAssets());
Map<String, WorkflowAsset> latestPackaged = new HashMap<>();
for (WorkflowAsset asset : allAssets) {
String key = (asset.isInDefaultPackage() ? "" : asset.getPackage().getName() + "/") + asset.getName() + asset.getVersionLabel();
latestPackaged.put(key, asset);
}
// get archived def docs if they don't match any non-archived version
for (WorkflowElement child : getArchivedPackageFolder().getChildren()) {
WorkflowPackage topLevelArchivedPackage = (WorkflowPackage) child;
if (topLevelArchivedPackage.getDescendantPackageVersions() != null) {
for (WorkflowPackage archivedPackage : topLevelArchivedPackage.getDescendantPackageVersions()) {
for (WorkflowAsset archivedAsset : archivedPackage.getAssets()) {
String key = (archivedAsset.isInDefaultPackage() ? "" : archivedAsset.getPackage().getName() + "/") + archivedAsset.getName() + archivedAsset.getVersionLabel();
WorkflowAsset curPkgMax = latestPackaged.get(key);
if (curPkgMax == null || archivedAsset.getPackage().getVersion() > curPkgMax.getPackage().getVersion())
latestPackaged.put(key, archivedAsset);
}
}
}
}
// reset list to include those added above
allAssets = new ArrayList<>(latestPackaged.values());
// account for assets not visible to user (cached separately)
if (assetsNotForCurrentUser == null) {
assetsNotForCurrentUser = new ArrayList<>();
for (RuleSetVO rs : getDataAccess().getAllRuleSets(false)) {
WorkflowAsset asset = WorkflowAssetFactory.createAsset(rs, findPackage(rs));
if (asset != null && !allAssets.contains(asset))
assetsNotForCurrentUser.add(asset);
}
}
allAssets.addAll(assetsNotForCurrentUser);
return allAssets;
}
use of com.centurylink.mdw.plugin.designer.model.WorkflowAsset in project mdw-designer by CenturyLinkCloud.
the class WorkflowProject method findUnpackagedAssetFolders.
/**
* Returns the folders for unpackaged archived workflow assets. Side-effect:
* If an unpackaged version is later than any package, add to default
* package.
*/
private List<Folder> findUnpackagedAssetFolders() {
CodeTimer timer = new CodeTimer("findUnpackagedAssetFolders()");
Map<String, Folder> upAssetFolders = new HashMap<>();
Map<String, List<RuleSetVO>> nonLatestUnpackaged = new HashMap<>();
for (RuleSetVO ruleSetVO : getDataAccess().getRuleSets(false)) {
if (!isPackaged(ruleSetVO)) {
// if version is later than that in any non-archived package,
// it belongs in the top-level default package
boolean laterThanPackaged = true;
for (WorkflowPackage pkg : getTopLevelPackages()) {
WorkflowAsset packaged = pkg.getAsset(ruleSetVO.getName());
if (packaged != null && packaged.getVersion() >= ruleSetVO.getVersion()) {
laterThanPackaged = false;
break;
}
}
boolean latestUnpackaged = true;
if (laterThanPackaged) {
WorkflowAsset defPkgAsset = getDefaultPackage().getAsset(ruleSetVO.getName());
if (defPkgAsset != null) {
if (defPkgAsset.getVersion() > ruleSetVO.getVersion()) {
latestUnpackaged = false;
} else if (defPkgAsset.getVersion() < ruleSetVO.getVersion()) {
defPkgAsset.removeElementChangeListener(this);
getDefaultPackage().removeAsset(defPkgAsset);
WorkflowAssetFactory.deRegisterAsset(defPkgAsset);
List<RuleSetVO> list = nonLatestUnpackaged.get(ruleSetVO.getName());
if (list == null) {
list = new ArrayList<>();
nonLatestUnpackaged.put(ruleSetVO.getName(), list);
}
list.add(defPkgAsset.getRuleSetVO());
}
}
}
if (laterThanPackaged && latestUnpackaged) {
WorkflowAsset asset = WorkflowAssetFactory.createAsset(ruleSetVO, getDefaultPackage());
if (asset != null) {
asset.addElementChangeListener(this);
getDefaultPackage().addAsset(asset);
WorkflowAssetFactory.registerAsset(asset);
}
} else {
List<RuleSetVO> list = nonLatestUnpackaged.get(ruleSetVO.getName());
if (list == null) {
list = new ArrayList<>();
nonLatestUnpackaged.put(ruleSetVO.getName(), list);
}
list.add(ruleSetVO);
}
}
}
for (String rsName : nonLatestUnpackaged.keySet()) {
List<RuleSetVO> list = nonLatestUnpackaged.get(rsName);
Collections.sort(list, new Comparator<RuleSetVO>() {
public int compare(RuleSetVO rs1, RuleSetVO rs2) {
return rs2.getVersion() - rs1.getVersion();
}
});
for (RuleSetVO rs : list) {
WorkflowAsset asset = WorkflowAssetFactory.createAsset(rs, archivedDefaultPackage);
if (asset != null) {
Folder folder = upAssetFolders.get(asset.getName());
if (folder == null) {
folder = WorkflowAssetFactory.createAssetFolder(asset);
upAssetFolders.put(asset.getName(), folder);
} else {
folder.getChildren().add(asset);
}
}
}
}
List<Folder> folders = new ArrayList<>();
folders.addAll(upAssetFolders.values());
Collections.sort(folders);
timer.stopAndLog();
return folders;
}
use of com.centurylink.mdw.plugin.designer.model.WorkflowAsset in project mdw-designer by CenturyLinkCloud.
the class WorkflowProject method findTopLevelPackages.
/**
* Finds the list of top level packages (including the default if
* supported), populated with the appropriate processes, etc.
*/
private void findTopLevelPackages(ProgressMonitor progressMonitor) {
CodeTimer timer = new CodeTimer("findTopLevelPackages()");
topLevelPackages = new ArrayList<>();
topLevelUserVisiblePackages = new ArrayList<>();
activityImpls.clear();
for (PackageVO packageVO : getTopLevelPackageVOs(progressMonitor)) {
WorkflowPackage topLevelPackage = new WorkflowPackage(this, packageVO);
topLevelPackage.setProcesses(findProcesses(topLevelPackage));
topLevelPackage.setExternalEvents(findExternalEvents(topLevelPackage));
topLevelPackage.setActivityImpls(findActivityImplementors(topLevelPackage));
topLevelPackage.setAssets(findWorkflowAssets(topLevelPackage));
topLevelPackage.setTaskTemplates(findTaskTemplates(topLevelPackage));
topLevelPackages.add(topLevelPackage);
if (topLevelPackage.isVisible())
topLevelUserVisiblePackages.add(topLevelPackage);
// register as a listener so that i can pass on element change
// events
topLevelPackage.addElementChangeListener(this);
for (WorkflowProcess process : topLevelPackage.getProcesses()) process.addElementChangeListener(this);
}
Collections.sort(topLevelPackages);
Collections.sort(topLevelUserVisiblePackages);
File resultsFile = getFunctionTestResultsFile();
if (resultsFile.exists()) {
// update test case statuses
List<TestCase> testCases = new ArrayList<>();
for (WorkflowPackage pkg : topLevelPackages) {
for (WorkflowAsset asset : pkg.getAssets()) {
if (asset instanceof AutomatedTestCase)
testCases.add(((AutomatedTestCase) asset).getTestCase());
}
}
if (!testCases.isEmpty()) {
try {
TestResultsParser parser = new TestResultsParser(resultsFile, testCases);
if (resultsFile.getName().endsWith(".xml"))
parser.parseXml();
else
parser.parseJson(getAssetDir());
} catch (Exception ex) {
PluginMessages.uiError(ex, "Parse Test Results", this);
}
}
}
timer.stopAndLog();
}
use of com.centurylink.mdw.plugin.designer.model.WorkflowAsset in project mdw-designer by CenturyLinkCloud.
the class AssetSearchQuery method run.
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
if (getScopedProjects().isEmpty() && getSelectedPackage() != null)
getScopedProjects().add(getSelectedPackage().getProject());
if (getScopedProjects().isEmpty()) {
String msg = "No MDW projects in search scope.";
showError(msg, "MDW Search", null);
return new Status(IStatus.WARNING, MdwPlugin.getPluginId(), 0, msg, null);
}
for (WorkflowProject project : getScopedProjects()) {
if (getSearchType().equals(SearchType.ENTITY_BY_NAME) || (getSearchType().equals(SearchType.ENTITY_BY_ID) && getPattern().equals("*"))) {
if (getResourceType().equalsIgnoreCase("External Event Handler")) {
for (ExternalEvent eventHandler : project.getAllExternalEvents()) {
String name = isCaseSensitive() ? eventHandler.getName() : eventHandler.getName().toLowerCase();
if ((getPattern().equals("*") || name.indexOf(getPattern()) >= 0) && (getSelectedPackage() == null || (eventHandler.getPackage() != null && eventHandler.getPackage().equals(getSelectedPackage()))))
getSearchResults().addMatchingElement(eventHandler);
}
} else {
for (WorkflowAsset asset : project.getAllWorkflowAssets()) {
if (asset.getLanguage().equalsIgnoreCase(getResourceType())) {
String name = isCaseSensitive() ? asset.getName() : asset.getName().toLowerCase();
if ((getPattern().equals("*") || name.indexOf(getPattern()) >= 0) && (getSelectedPackage() == null || (asset.getPackage() != null && asset.getPackage().equals(getSelectedPackage()))))
getSearchResults().addMatchingElement(asset);
}
}
}
} else if (getSearchType().equals(SearchType.CONTAINING_TEXT)) {
if (getResourceType().equalsIgnoreCase("External Event Handler")) {
for (ExternalEvent eventHandler : project.getAllExternalEvents()) {
String name = isCaseSensitive() ? eventHandler.getName() : eventHandler.getName().toLowerCase();
if ((getPattern().equals("*") || name.indexOf(getPattern()) >= 0) && (getSelectedPackage() == null || (eventHandler.getPackage() != null && eventHandler.getPackage().equals(getSelectedPackage())))) {
// resource name pattern is matched, check for
// contained text
String searchText = isCaseSensitive() ? getContainedText() : getContainedText().toLowerCase();
searchText = searchText.replaceAll("\\*", "");
if (eventHandler.getName().indexOf(searchText) >= 0)
getSearchResults().addMatchingElement(eventHandler);
}
}
} else {
for (WorkflowAsset asset : project.getAllWorkflowAssets()) {
if (asset.getLanguage().equalsIgnoreCase(getResourceType())) {
String name = isCaseSensitive() ? asset.getName() : asset.getName().toLowerCase();
if ((getPattern().equals("*") || name.indexOf(getPattern()) >= 0) && (getSelectedPackage() == null || (asset.getPackage() != null && asset.getPackage().equals(getSelectedPackage())))) {
// resource name pattern is matched, check for
// contained text
asset = asset.getProject().getDesignerProxy().loadWorkflowAsset(asset);
if (!asset.isBinary()) {
String content = isCaseSensitive() ? asset.getContent() : asset.getContent().toLowerCase();
String searchText = isCaseSensitive() ? getContainedText() : getContainedText().toLowerCase();
searchText = searchText.replaceAll("\\*", "");
if (content.indexOf(searchText) >= 0)
getSearchResults().addMatchingElement(asset);
}
}
}
}
}
} else if (getSearchType().equals(SearchType.ENTITY_BY_ID)) {
WorkflowAsset asset = project.getAsset(new Long(getPattern()));
if (asset != null && asset.getLanguage().equalsIgnoreCase(getResourceType()))
getSearchResults().addMatchingElement(asset);
} else {
showError("Unsupported search type: " + getSearchType(), "MDW Search", null);
}
}
if (getSearchResults().getMatchingElements().size() == 0)
return new Status(IStatus.WARNING, MdwPlugin.getPluginId(), 0, "No matching elements found", null);
else
return Status.OK_STATUS;
}
use of com.centurylink.mdw.plugin.designer.model.WorkflowAsset in project mdw-designer by CenturyLinkCloud.
the class JavaSourceHyperlink method linkActivated.
@SuppressWarnings("restriction")
public void linkActivated() {
String linkText = getLinkText();
if (// dynamic java
linkText.startsWith("string:///")) {
try {
WorkflowProject workflowProj = WorkflowProjectManager.getInstance().getWorkflowProject(project);
// package
String path = linkText.substring(10);
int slashIdx = path.indexOf('/');
String pkg = slashIdx > 0 ? path.substring(0, slashIdx) : null;
// asset
int javaIdx = path.indexOf(".java");
String assetName = path.substring(slashIdx > 0 ? slashIdx + 1 : 0, javaIdx);
// lineNum
String lineNum = "";
int i = javaIdx + 6;
while (i < path.length() && Character.isDigit(path.charAt(i))) lineNum += path.charAt(i++);
WorkflowAsset asset = workflowProj.getAsset(pkg, assetName);
if (asset == null) {
cantFindSourceWarning();
} else {
asset.openFile(new NullProgressMonitor());
if (lineNum.length() > 0) {
ITextEditor editor = (ITextEditor) asset.getFileEditor();
if (editor != null) {
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
IRegion lineInfo = document.getLineInformation(Integer.parseInt(lineNum) - 1);
if (lineInfo != null)
editor.selectAndReveal(lineInfo.getOffset(), lineInfo.getLength());
}
}
}
} catch (Exception ex) {
cantFindSourceWarning();
PluginMessages.log(ex);
}
return;
}
int lineNumber = getLineNumber();
// documents start at 0
if (lineNumber > 0)
lineNumber--;
try {
Object sourceElement = getJavaElement(getTypeName());
if (sourceElement != null) {
IDebugModelPresentation presentation = org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin.getDefault().getModelPresentation();
IEditorInput editorInput = presentation.getEditorInput(sourceElement);
if (editorInput != null) {
String editorId = presentation.getEditorId(editorInput, sourceElement);
if (editorId != null) {
IEditorPart editorPart = org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin.getActivePage().openEditor(editorInput, editorId);
if (editorPart instanceof ITextEditor && lineNumber >= 0) {
ITextEditor textEditor = (ITextEditor) editorPart;
IDocumentProvider provider = textEditor.getDocumentProvider();
provider.connect(editorInput);
IDocument document = provider.getDocument(editorInput);
try {
IRegion line = document.getLineInformation(lineNumber);
textEditor.selectAndReveal(line.getOffset(), line.getLength());
} catch (BadLocationException e) {
}
provider.disconnect(editorInput);
}
return;
}
}
}
} catch (CoreException ex) {
cantFindSourceWarning();
PluginMessages.log(ex);
return;
}
// did not find source
cantFindSourceWarning();
}
Aggregations