use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.
the class IconFactory method loadIcon.
private byte[] loadIcon(String file) throws RemoteException, IOException, DataAccessException {
RuleSetVO ruleset = dao == null ? null : dao.getRuleSet(file, null, 0);
byte[] bytes;
if (ruleset != null) {
if (ruleset.isRaw()) {
bytes = ruleset.getRawContent();
} else {
String content = ruleset.getRuleSet();
int k = content.indexOf('\n');
bytes = RuleSetVO.decode(content.substring(k + 1));
}
} else {
String resource = "/images/" + file;
InputStream is = Icon.class.getResourceAsStream(resource);
if (is == null)
is = Icon.class.getResourceAsStream(file);
if (is != null) {
bytes = FileHelper.readFromResourceStream(is);
} else
bytes = null;
}
return bytes;
}
use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.
the class AutomatedTestView method updateTreeAndProgressBar.
private synchronized void updateTreeAndProgressBar(boolean done) {
int completedCases = 0;
int erroredCases = 0;
int failedCases = 0;
int casePercents = 0;
boolean loadTest = testSuite.isLoadTest();
for (AutomatedTestCase testCase : testSuite.getTestCases()) {
String oldStatus = testCaseStatuses.get(testCase);
boolean statusChanged = done || oldStatus == null || !oldStatus.equals(testCase.getStatus());
if (statusChanged) {
testSuite.getProject().fireTestCaseStatusChange(testCase, testCase.getStatus());
testCaseStatuses.put(testCase, testCase.getStatus());
}
int casePercent = 0;
if (testCase.isFinished()) {
if (statusChanged && !done && testSuite.isCreateReplaceResults() && // only applies for VCS assets
testCase.isSuccess()) {
if (testCase.isLegacy()) {
// trigger
testCase.setTestCase(testCase.getTestCase());
// results
if (testCase.getLegacyExpectedResults() != null) {
for (LegacyExpectedResults legacyResults : testCase.getLegacyExpectedResults()) {
legacyResults.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, legacyResults);
testSuite.getProject().fireElementChangeEvent(ChangeType.ELEMENT_CREATE, legacyResults);
}
}
} else {
try {
// create asset from newly-created results and
// refresh process explorer (only for VCS assets)
String resAssetName = testCase.getTestCase().getCaseName() + RuleSetVO.getFileExtension(RuleSetVO.YAML);
if (testCase.isPostman() && testCase.getItemName() != null)
resAssetName = testCase.getItemName().replace('/', '_') + RuleSetVO.getFileExtension(RuleSetVO.YAML);
File resFile = new File(testSuite.getProject().getProjectDir() + "/" + testCase.getPackage().getVcsAssetPath() + "/" + resAssetName);
if (// may not exist if test case
resFile.exists()) // does not launch any
// processes
{
byte[] bytes = PluginUtil.readFile(resFile);
WorkflowAsset existing = testSuite.getProject().getAsset(testCase.getPackage().getName() + "/" + resAssetName);
if (existing == null) {
// create (waiting a second or two for the
// results file to have been created)
RuleSetVO newRuleSet = new RuleSetVO();
newRuleSet.setName(resAssetName);
newRuleSet.setLanguage(RuleSetVO.YAML);
newRuleSet.setRaw(true);
newRuleSet.setRawFile(resFile);
newRuleSet.setRawContent(bytes);
WorkflowAsset newAsset = WorkflowAssetFactory.createAsset(newRuleSet, testCase.getPackage());
newAsset.setPackage(testCase.getPackage());
newAsset.setId(new Long(-1));
newAsset.setCreateUser(testSuite.getProject().getUser().getUsername());
newAsset.setLockingUser(testSuite.getProject().getUser().getUsername());
designerProxy.saveWorkflowAsset(newAsset, true);
testSuite.getProject().getDataAccess().getDesignerDataModel().addRuleSet(newAsset.getRuleSetVO());
newAsset.getPackage().addAsset(newAsset);
designerProxy.savePackage(newAsset.getPackage());
newAsset.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, newAsset);
} else {
// increment version
existing.getRuleSetVO().setRawContent(bytes);
existing.setVersion(existing.getNextMinorVersion());
existing.setRevisionComment("Auto-created");
testSuite.getProject().getDesignerProxy().saveWorkflowAsset(existing, true);
existing.fireElementChangeEvent(ChangeType.VERSION_CHANGE, existing.getVersion());
}
}
} catch (Exception ex) {
PluginMessages.uiError(ex, "Create/Replace Test Results", testSuite.getProject());
}
}
}
updateExpectedResults(testCase);
if (loadTest) {
completedCases = testCase.getTestCase().getNumberPrepared();
casePercents = testCase.getTestCase().getNumberPrepared() * 100;
} else {
completedCases++;
casePercent = 100;
}
} else {
casePercent = testCase.getTotalSteps() == 0 ? 0 : (testCase.getStepsCompleted() * 100) / testCase.getTotalSteps();
}
if (!loadTest)
casePercents += casePercent;
if (testCase.isErrored()) {
if (loadTest)
erroredCases = testCase.getTestCase().getNumberPrepared();
else
erroredCases++;
} else if (testCase.isFailed()) {
if (loadTest)
failedCases = testCase.getTestCase().getNumberPrepared();
else
failedCases++;
}
if (statusChanged)
try {
testSuite.writeTestCaseResults(testCase);
} catch (Exception ex) {
PluginMessages.uiError(ex, "Create/Replace Test Results", testSuite.getProject());
}
}
if (done) {
testSuite.setRunning(false);
updateCounterPanel(testSuite.getTestCases().size(), erroredCases, failedCases, true);
updateProgressBar(100, testSuite.hasErrors() || testSuite.hasFailures(), testSuite.isStopped());
} else {
int count = testSuite.getTestCases().size();
if (loadTest)
count = testSuite.getRunCount();
int totalPercents = count * 100;
if (counterData.completed < completedCases) {
updateCounterPanel(completedCases, erroredCases, failedCases, false);
float percentComplete = totalPercents == 0 ? 0 : (casePercents * 100) / totalPercents;
updateProgressBar(Math.round(percentComplete * 90 / 100) + 10, erroredCases + failedCases > 0, testSuite.isStopped());
}
}
refreshOutputFromSelection();
}
use of com.centurylink.mdw.model.value.attribute.RuleSetVO 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.model.value.attribute.RuleSetVO 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.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.
the class DesignerProxy method saveProcessWithProgress.
public void saveProcessWithProgress(final WorkflowProcess process, final FlowchartPage flowchartPage, final PersistType persistType, final int version, final boolean validate, final boolean keepLocked) {
String progressMsg = SAVING + process.getName() + "'";
String errorMsg = "Save Process";
designerRunner = new DesignerRunner(progressMsg, errorMsg, project) {
public void perform() throws ValidationException, DataAccessException, RemoteException {
WorkflowProcess oldProcess = null;
if (persistType == PersistType.NEW_VERSION) {
RuleSetVO existing = null;
if (process.isInRuleSet())
existing = dataAccess.getDesignerDataAccess().getRuleSet(process.getName(), RuleSetVO.PROCESS, version);
if (existing != null)
throw new DataAccessException("\n" + process.getLabel() + ALREADY_EXISTS);
process.getProcessVO().setProcessId(-1L);
// preserve the old version for the process tree
ProcessVO oldProcessVoStub = new ProcessVO();
oldProcessVoStub.setProcessId(process.getId());
oldProcessVoStub.setProcessName(process.getName());
oldProcessVoStub.setVersion(process.getProcessVO().getVersion());
oldProcess = new WorkflowProcess(process.getProject(), oldProcessVoStub);
oldProcess.setPackage(process.getPackage());
oldProcess.setTopLevelVersion(process.getTopLevelVersion());
if (// temp attribute to avoid API
project.isFilePersist())
// change
process.setAttribute("previousProcessVersion", oldProcess.getVersionString());
}
saveProcess(process, flowchartPage, persistType, version, validate, keepLocked);
if (process.getTopLevelVersion() != null)
process.getTopLevelVersion().setProcessVO(process.getProcessVO());
if (persistType == PersistType.NEW_VERSION && process.isInRuleSet()) {
RuleSetVO procRs = dataAccess.getRuleSet(process.getId());
if (procRs == null)
dataAccess.getAllRuleSets(false).add(process.getProcessVO());
}
}
};
designerRunner.run();
}
Aggregations