use of com.centurylink.mdw.plugin.CodeTimer in project mdw-designer by CenturyLinkCloud.
the class DesignerProxy method loadProcess.
public DesignerCanvas loadProcess(WorkflowProcess processVersion, FlowchartPage flowchartPage) {
CodeTimer timer = new CodeTimer("loadProcess()");
Graph graph = flowchartPage.loadProcess(processVersion.getId(), null);
flowchartPage.setProcess(graph);
if (project.isRemote() && project.isFilePersist()) {
graph.setReadonly(true);
}
processVersion.setProcessVO(graph.getProcessVO());
processVersion.setReadOnly(graph.isReadonly());
timer.stopAndLog();
return flowchartPage.canvas;
}
use of com.centurylink.mdw.plugin.CodeTimer in project mdw-designer by CenturyLinkCloud.
the class DesignerProxy method savePackage.
public void savePackage(WorkflowPackage packageVersion, boolean newVersion) throws DataAccessException, RemoteException {
if (packageVersion.isDefaultPackage())
return;
CodeTimer timer = new CodeTimer("savePackage()");
packageVersion.syncProcessVos();
if (packageVersion.getPackageVO().getImplementors() != null) {
// remove non-existent activity impls
List<ActivityImplementorVO> toRemove = new ArrayList<>();
for (ActivityImplementorVO activityImpl : packageVersion.getPackageVO().getImplementors()) {
if (dataAccess.getActivityImplementor(activityImpl.getImplementorClassName()) == null)
toRemove.add(activityImpl);
}
for (ActivityImplementorVO remove : toRemove) packageVersion.getPackageVO().getImplementors().remove(remove);
}
WorkflowPackage prevPkg = new WorkflowPackage(packageVersion.getProject(), new PackageVO());
prevPkg.getPackageVO().setId(packageVersion.getId());
prevPkg.setName(packageVersion.getName());
prevPkg.getPackageVO().setVersion(packageVersion.getVersion());
prevPkg.setTags(packageVersion.getTags());
prevPkg.setModifyDate(packageVersion.getModifyDate());
if (packageVersion.getPackageVO() != null && packageVersion.getPackageVO().getAttributes() != null) {
for (AttributeVO attr : packageVersion.getPackageVO().getAttributes()) {
prevPkg.setAttribute(attr.getAttributeName(), attr.getAttributeValue());
}
}
Long pkgId;
if (// do not
!packageVersion.isLatest() || packageVersion.isArchived())
// create
// new
// version
pkgId = dataAccess.getDesignerDataAccess().savePackage(packageVersion.getPackageVO(), ProcessPersister.PersistType.UPDATE);
else
pkgId = dataAccess.getDesignerDataAccess().savePackage(packageVersion.getPackageVO());
if (prevPkg.getId() == null || newVersion || (pkgId.longValue() != prevPkg.getId().longValue())) {
packageVersion.getPackageVO().setPackageId(pkgId);
prevPkg.setArchived(true);
dataAccess.getPackages(false).add(packageVersion.getPackageVO());
packageVersion.getProject().newPackageVersion(packageVersion, prevPkg);
// update the tree
packageVersion.getProject().fireElementChangeEvent(packageVersion, ChangeType.VERSION_CHANGE, packageVersion.getVersionString());
// update other listeners
packageVersion.fireElementChangeEvent(ChangeType.VERSION_CHANGE, packageVersion.getVersionString());
}
timer.stopAndLog();
}
use of com.centurylink.mdw.plugin.CodeTimer in project mdw-designer by CenturyLinkCloud.
the class DesignerProxy method saveProcess.
/**
* Relies on classic designer page to update the processVO with the reloaded
* data.
*/
public void saveProcess(WorkflowProcess process, FlowchartPage flowchartPage, PersistType persistType, int version, boolean validate, boolean lock) throws ValidationException, DataAccessException, RemoteException {
CodeTimer timer = new CodeTimer("saveProcess()");
Graph graph = flowchartPage.getProcess();
graph.save_temp_vars();
// refresh variable type cache since Designer Classic uses a single,
// static cache
// calls
dataAccess.loadVariableTypes();
if (validate)
new ProcessValidator(process.getProcessVO()).validate(getNodeMetaInfo());
if (!process.getProject().checkRequiredVersion(5, 5))
flowchartPage.setProcessVersions(flowchartPage.getProcess(), // not
!process.getProject().checkRequiredVersion(5, 2));
// sure
// why
// this
// was
// ever
// needed
Map<String, String> overrideAttributes = null;
if (process.getProcessVO() != null && process.getProject().isFilePersist() && process.overrideAttributesApplied())
overrideAttributes = process.getProcessVO().getOverrideAttributes();
Graph reloaded = null;
try {
reloaded = flowchartPage.saveProcess(graph, mainFrame, persistType, version, lock);
} catch (ValidationException ex) {
graph.setDirtyLevel(Graph.DIRTY);
if (ex.getMessage() != null && ex.getMessage().contains(ORA_02292))
throw new ValidationException("There are instances associated with this process version.\n Please increment the version when saving.");
else
throw ex;
}
process.setProcessVO(reloaded.getProcessVO());
flowchartPage.setProcess(reloaded);
WorkflowPackage pkg = process.getPackage();
if (pkg != null && !pkg.isDefaultPackage() && persistType == PersistType.NEW_VERSION) {
if (project.isFilePersist()) {
pkg.setVersion(pkg.getVersion() + 1);
// exported not relevant for vcs
pkg.setExported(false);
// processes since pkg will be archived
// anyway
savePackage(pkg, true);
} else {
savePackage(pkg);
}
}
if (process.getProject().isFilePersist() && version != 0 && persistType == PersistType.NEW_VERSION && overrideAttributes != null && !overrideAttributes.isEmpty() && MdwPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREFS_CARRY_FORWARD_OVERRIDE_ATTRS)) {
if (!process.overrideAttributesApplied())
throw new DataAccessException("Override attributes not applied");
reloaded.getProcessVO().applyOverrideAttributes(overrideAttributes);
getDesignerDataAccess().setOverrideAttributes(reloaded.getProcessVO());
}
cacheRefresh.fireRefresh(reloaded.getProcessVO().hasDynamicJavaActivity());
timer.stopAndLog();
}
use of com.centurylink.mdw.plugin.CodeTimer in project mdw-designer by CenturyLinkCloud.
the class DesignerProxy method loadProcessInstance.
public RunTimeDesignerCanvas loadProcessInstance(WorkflowProcess processVersion, ProcessInstancePage processInstancePage) {
CodeTimer timer = new CodeTimer("loadProcessInstance()");
ProcessInstanceVO processInstanceInfo = processVersion.getProcessInstance();
ProcessInstanceLoader instanceLoadThread = new ProcessInstanceLoader(processInstanceInfo, processInstancePage);
String errorMessage = null;
try {
Graph processGraph = dataAccess.getDesignerDataModel().findProcessGraph(processVersion.getId(), null);
if (processGraph == null)
processGraph = processInstancePage.loadProcess(processInstanceInfo.getProcessId(), null);
processVersion.setProcessVO(processGraph.getProcessVO());
DesignerDataAccess dao = processVersion.getDesignerDataAccess() == null ? processInstancePage.frame.dao : processVersion.getDesignerDataAccess();
Graph procInstGraph = instanceLoadThread.loadCompletionMap(processGraph.getProcessVO(), processInstanceInfo, dao);
ProcessInstanceTreeModel model = instanceLoadThread.createOrUpdateModel(null);
model.getCurrentProcess().setGraph(procInstGraph);
processInstancePage.setData(model, processInstancePage);
Map<Long, List<TaskInstanceVO>> taskInstances = new HashMap<>();
// embedded subprocesses
List<ProcessInstanceVO> embeddedSubs = new ArrayList<>();
if (procInstGraph.subgraphs != null) {
for (SubGraph instSubGraph : procInstGraph.subgraphs) {
if (instSubGraph.getInstances() != null) {
if (instSubGraph.nodes != null) {
List<Long> taskActivityIds = new ArrayList<>();
for (Node node : instSubGraph.nodes) {
if (node.isTaskActivity()) {
for (ProcessInstanceVO embeddedProcInst : instSubGraph.getInstances()) {
if (!embeddedProcInst.getActivityInstances(node.getActivityId()).isEmpty())
taskActivityIds.add(node.getActivityId());
}
}
}
if (!taskActivityIds.isEmpty()) {
for (ProcessInstanceVO embeddedProcInst : instSubGraph.getInstances()) {
ProcessVO embeddedProc = instSubGraph.getGraph().getProcessVO();
Map<Long, List<TaskInstanceVO>> embeddedTaskInsts = dao.getTaskInstances(embeddedProc, embeddedProcInst, taskActivityIds);
for (Map.Entry<Long, List<TaskInstanceVO>> embeddedTaskInst : embeddedTaskInsts.entrySet()) {
if (taskInstances.get(embeddedTaskInst.getKey()) == null)
taskInstances.put(embeddedTaskInst.getKey(), new ArrayList<TaskInstanceVO>());
taskInstances.get(embeddedTaskInst.getKey()).addAll(embeddedTaskInst.getValue());
}
}
}
}
embeddedSubs.addAll(instSubGraph.getInstances());
}
}
}
processVersion.setEmbeddedSubProcessInstances(embeddedSubs);
// manual task instances
if (processGraph.nodes != null) {
List<Long> taskActivityIds = new ArrayList<>();
for (Node node : processGraph.nodes) {
if (node.isTaskActivity() && !processInstanceInfo.getActivityInstances(node.getActivityId()).isEmpty())
taskActivityIds.add(node.getActivityId());
}
if (!taskActivityIds.isEmpty()) {
Map<Long, List<TaskInstanceVO>> taskInsts = dao.getTaskInstances(processVersion.getProcessVO(), processInstanceInfo, taskActivityIds);
for (Map.Entry<Long, List<TaskInstanceVO>> taskInst : taskInsts.entrySet()) {
if (taskInstances.get(taskInst.getKey()) == null)
taskInstances.put(taskInst.getKey(), new ArrayList<TaskInstanceVO>());
taskInstances.get(taskInst.getKey()).addAll(taskInst.getValue());
}
}
}
processVersion.setTaskInstances(taskInstances);
} catch (Exception ex) {
PluginMessages.log(ex);
errorMessage = PluginMessages.getUserMessage(ex);
}
if (errorMessage == null)
errorMessage = instanceLoadThread.getErrorMessage();
if (errorMessage != null) {
PluginMessages.uiError(errorMessage, "Load Process Instance");
}
timer.stopAndLog();
return processInstancePage.canvas;
}
use of com.centurylink.mdw.plugin.CodeTimer in project mdw-designer by CenturyLinkCloud.
the class Importer method importPackage.
public WorkflowPackage importPackage(final WorkflowProject project, final String content, final ProgressMonitor progressMonitor) throws DataAccessException, RemoteException, ActionCancelledException, JSONException, XmlException {
CodeTimer timer = new CodeTimer("importPackage()");
int preexistingVersion = -1;
importedPackageVO = null;
progressMonitor.start("Importing Package into: '" + project.getLabel() + "'");
progressMonitor.progress(5);
progressMonitor.subTask(PARSING_XML);
boolean isJson = content.trim().startsWith("{");
importedPackageVO = parsePackageContent(content);
progressMonitor.subTask("Importing " + importedPackageVO.getLabel());
progressMonitor.progress(10);
final WorkflowPackage existing = project.getPackage(importedPackageVO.getPackageName());
if (existing != null) {
if (existing.getVersion() == importedPackageVO.getVersion()) {
final String msg = project.getName() + " already contains Package '" + importedPackageVO.getPackageName() + "' v" + importedPackageVO.getVersionString();
if (shell != null) {
shell.getDisplay().syncExec(new Runnable() {
public void run() {
if (!MessageDialog.openConfirm(shell, "Import Package", msg + ".\nImport this package?"))
importedPackageVO = null;
}
});
} else {
PluginMessages.log(msg);
}
if (importedPackageVO != null) {
// overwrite existing
importedPackageVO.setPackageId(existing.getId());
if (!isLocal())
importedPackageVO.setVersion(0);
preexistingVersion = existing.getVersion();
}
} else if (existing.getVersion() > importedPackageVO.getVersion()) {
final String msg = project.getName() + " already contains Package '" + importedPackageVO.getPackageName() + "' v" + existing.getVersionString() + ", whose version is greater than that of the imported package. Cannot continue.";
if (shell != null) {
shell.getDisplay().syncExec(new Runnable() {
public void run() {
MessageDialog.openError(shell, "Import Package", msg);
importedPackageVO = null;
}
});
} else {
PluginMessages.log(msg);
}
}
if (importedPackageVO == null)
return null;
}
if (shell != null && progressMonitor.isCanceled())
throw new ActionCancelledException();
progressMonitor.progress(10);
progressMonitor.subTask("Checking elements");
final List<WorkflowElement> conflicts = new ArrayList<>();
final List<WorkflowElement> conflictsWithDifferences = new ArrayList<>();
final List<ProcessVO> existingProcessVOs = new ArrayList<>();
List<ProcessVO> processVOsToBeImported = new ArrayList<>();
ProcessExporter exporter = null;
for (ProcessVO importedProcessVO : importedPackageVO.getProcesses()) {
WorkflowProcess existingProcess = project.getProcess(importedProcessVO.getProcessName(), importedProcessVO.getVersionString());
if (existingProcess != null) {
conflicts.add(existingProcess);
if (project.getDataAccess().getSupportedSchemaVersion() >= DataAccess.schemaVersion52 && MdwPlugin.getSettings().isCompareConflictingAssetsDuringImport()) {
progressMonitor.subTask("Comparing processes (can be disabled in prefs)");
// content comparison
if (exporter == null)
exporter = DataAccess.getProcessExporter(project.getDataAccess().getSchemaVersion(), project.isOldNamespaces() ? DesignerCompatibility.getInstance() : null);
String existingProcessXml = project.getDataAccess().loadRuleSet(existingProcess.getId()).getRuleSet();
String importedProcessXml = isJson ? importedProcessVO.getJson().toString(2) : exporter.exportProcess(importedProcessVO, project.getDataAccess().getSchemaVersion(), null);
if (project.getDataAccess().getSupportedSchemaVersion() < DataAccess.schemaVersion55) {
// may need to replace old namespace prefix in existing
// to avoid false positives in 5.2
String oldNamespaceDecl = "xmlns:xs=\"http://mdw.qwest.com/XMLSchema\"";
int oldNsIdx = existingProcessXml.indexOf(oldNamespaceDecl);
if (oldNsIdx > 0) {
String newNamespaceDecl = "xmlns:bpm=\"http://mdw.qwest.com/XMLSchema\"";
existingProcessXml = existingProcessXml.substring(0, oldNsIdx) + newNamespaceDecl + importedProcessXml.substring(oldNsIdx + oldNamespaceDecl.length() + 2);
existingProcessXml = existingProcessXml.replaceAll("<xs:", "<bpm:");
existingProcessXml = existingProcessXml.replaceAll("</xs:", "</bpm:");
}
}
// avoid false positives
existingProcessXml = existingProcessXml.replaceAll("\\s*<bpm:Attribute Name=\"REFERENCED_ACTIVITIES\".*/>", "");
existingProcessXml = existingProcessXml.replaceAll("\\s*<bpm:Attribute Name=\"REFERENCED_PROCESSES\".*/>", "");
existingProcessXml = existingProcessXml.replaceFirst(" packageVersion=\"0.0\"", "");
existingProcessXml = existingProcessXml.replaceAll("\\s*<bpm:Attribute Name=\"processid\".*/>", "");
if (!existingProcessXml.equals(importedProcessXml))
conflictsWithDifferences.add(existingProcess);
}
if (isLocal())
processVOsToBeImported.add(importedProcessVO);
else
existingProcessVOs.add(existingProcess.getProcessVO());
} else {
if (project.getDataAccess().getSupportedSchemaVersion() >= DataAccess.schemaVersion52)
// not optional
importedProcessVO.setInRuleSet(true);
processVOsToBeImported.add(importedProcessVO);
}
for (ProcessVO subProcVO : importedProcessVO.getSubProcesses()) {
WorkflowProcess existingSubProc = project.getProcess(subProcVO.getProcessName(), subProcVO.getVersionString());
if (existingSubProc != null) {
conflicts.add(existingSubProc);
existingProcessVOs.add(existingSubProc.getProcessVO());
if (!isLocal())
existingProcessVOs.add(existingSubProc.getProcessVO());
}
}
}
if (shell != null && progressMonitor.isCanceled())
throw new ActionCancelledException();
progressMonitor.progress(10);
final List<RuleSetVO> existingRuleSets = new ArrayList<>();
List<RuleSetVO> ruleSetsToBeImported = new ArrayList<>();
final List<RuleSetVO> emptyRuleSets = new ArrayList<>();
if (importedPackageVO.getRuleSets() != null) {
for (RuleSetVO importedRuleSet : importedPackageVO.getRuleSets()) {
WorkflowAsset existingAsset = null;
if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion55)
existingAsset = project.getAsset(importedPackageVO.getName(), importedRuleSet.getName(), importedRuleSet.getLanguage(), importedRuleSet.getVersion());
else
existingAsset = project.getAsset(importedRuleSet.getName(), importedRuleSet.getLanguage(), importedRuleSet.getVersion());
if (existingAsset != null) {
conflicts.add(existingAsset);
if (project.getDataAccess().getSupportedSchemaVersion() >= DataAccess.schemaVersion52 && MdwPlugin.getSettings().isCompareConflictingAssetsDuringImport() && !existingAsset.isBinary()) {
progressMonitor.subTask("Comparing assets (can be disabled in prefs)");
// content comparison
existingAsset = project.getDesignerProxy().loadWorkflowAsset(existingAsset);
String existingAssetStr = existingAsset.getRuleSetVO().getRuleSet().trim();
String importedAssetStr = importedRuleSet.getRuleSet().trim();
if (!existingAsset.isBinary()) {
existingAssetStr = existingAssetStr.replaceAll("\r", "");
importedAssetStr = importedAssetStr.replaceAll("\r", "");
}
if (!existingAssetStr.equals(importedAssetStr))
conflictsWithDifferences.add(existingAsset);
}
if (isLocal())
ruleSetsToBeImported.add(importedRuleSet);
else
existingRuleSets.add(existingAsset.getRuleSetVO());
} else if (importedRuleSet.getRuleSet().trim().isEmpty()) {
emptyRuleSets.add(importedRuleSet);
} else {
ruleSetsToBeImported.add(importedRuleSet);
}
}
}
if (MdwPlugin.getSettings().isCompareConflictingAssetsDuringImport() && existing != null && importedPackageVO.getTaskTemplates() != null && existing.getTaskTemplates() != null) {
for (TaskVO importedTask : importedPackageVO.getTaskTemplates()) {
for (TaskTemplate taskTemplate : existing.getTaskTemplates()) {
if (taskTemplate.getName().equals(importedTask.getName()) && taskTemplate.getVersion() == importedTask.getVersion()) {
conflicts.add(taskTemplate);
String existingTemplStr = taskTemplate.getTaskVO().toTemplate().xmlText();
String importedTemplStr = importedTask.toTemplate().xmlText();
if (!existingTemplStr.equals(importedTemplStr))
conflictsWithDifferences.add(taskTemplate);
}
}
}
}
if (progressMonitor.isCanceled())
throw new ActionCancelledException();
progressMonitor.progress(10);
if (!conflicts.isEmpty()) {
Collections.sort(conflicts, new Comparator<WorkflowElement>() {
public int compare(WorkflowElement we1, WorkflowElement we2) {
return we1.getLabel().compareToIgnoreCase(we2.getLabel());
}
});
final String msg;
if (isLocal())
msg = "The following versions exist locally in '" + importedPackageVO.getPackageName() + "'.\nThese files in project '" + project.getName() + "' will be overwritten.\n";
else
msg = "The following versions from package '" + importedPackageVO.getPackageName() + "' will not be imported.\nThe same versions already exist in the '" + project.getName() + "' project.\n";
if (shell != null) {
shell.getDisplay().syncExec(new Runnable() {
public void run() {
String msg2 = msg;
if (project.checkRequiredVersion(5, 2) && MdwPlugin.getSettings().isCompareConflictingAssetsDuringImport())
msg2 += "(Asterisk * indicates content differs.)\n";
int res = PluginMessages.uiList(shell, msg2, "Package Import", conflicts, conflictsWithDifferences);
if (res == Dialog.CANCEL)
importedPackageVO = null;
}
});
} else {
StringBuilder msg2 = new StringBuilder(msg);
msg2.append(" (");
if (project.checkRequiredVersion(5, 2))
msg2.append(" -- * indicates content differs");
msg2.append(").\n");
for (WorkflowElement we : conflicts) {
String flag = conflictsWithDifferences.contains(we) ? " *" : "";
msg2.append(" ").append(we.getLabel()).append(flag).append("\n");
}
PluginMessages.log(msg2.toString());
}
if (importedPackageVO == null)
return null;
}
if (!emptyRuleSets.isEmpty()) {
final String msg = "The following assets from package '" + importedPackageVO.getPackageName() + "' will not be imported because they're empty.\n";
if (shell != null) {
shell.getDisplay().syncExec(new Runnable() {
public void run() {
int res = PluginMessages.uiList(shell, msg, "Package Import", emptyRuleSets);
if (res == Dialog.CANCEL)
importedPackageVO = null;
}
});
} else {
StringBuilder msg2 = new StringBuilder(msg);
for (RuleSetVO rs : emptyRuleSets) msg2.append(" ").append(rs.getLabel()).append("\n");
PluginMessages.log(msg2.toString());
}
if (importedPackageVO == null)
return null;
}
importedPackageVO.setProcesses(processVOsToBeImported);
importedPackageVO.setRuleSets(ruleSetsToBeImported);
// designer fix for backward compatibility
ProcessWorker worker = new ProcessWorker();
if (importedPackageVO.getProcesses() != null) {
NodeMetaInfo syncedNodeMetaInfo = syncNodeMetaInfo(dataAccess.getDesignerDataModel().getNodeMetaInfo(), importedPackageVO);
for (ProcessVO p : importedPackageVO.getProcesses()) {
worker.convert_to_designer(p);
worker.convert_from_designer(p, syncedNodeMetaInfo);
}
}
if (shell != null && progressMonitor.isCanceled())
throw new ActionCancelledException();
progressMonitor.progress(10);
progressMonitor.subTask("Saving package");
ProcessPersister.PersistType persistType = ProcessPersister.PersistType.IMPORT;
if (isJson && !project.checkRequiredVersion(6, 1, 1))
persistType = ProcessPersister.PersistType.IMPORT_JSON;
Long packageId = dataAccess.getDesignerDataAccess().savePackage(importedPackageVO, persistType);
if (preexistingVersion > 0)
// reset version
importedPackageVO.setVersion(preexistingVersion);
// for overwrite
progressMonitor.progress(10);
progressMonitor.subTask("Reloading processes");
if (importedPackageVO.getProcesses() != null) {
for (ProcessVO importedProcessVO : importedPackageVO.getProcesses()) {
ProcessVO reloaded = dataAccess.getDesignerDataAccess().getProcessDefinition(importedProcessVO.getProcessName(), importedProcessVO.getVersion());
importedProcessVO.setProcessId(reloaded.getProcessId());
}
if (project.getDataAccess().getSupportedSchemaVersion() < DataAccess.schemaVersion52) {
for (ProcessVO importedProcessVO : importedPackageVO.getProcesses()) updateSubProcessIdAttributes(importedProcessVO);
}
}
if (!existingProcessVOs.isEmpty()) {
// add back existing processes
importedPackageVO.getProcesses().addAll(existingProcessVOs);
dataAccess.getDesignerDataAccess().savePackage(importedPackageVO);
}
progressMonitor.progress(10);
progressMonitor.subTask("Reloading workflow assets");
if (importedPackageVO.getRuleSets() != null) {
for (RuleSetVO importedRuleSet : importedPackageVO.getRuleSets()) {
RuleSetVO reloaded;
if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion55) {
reloaded = dataAccess.getDesignerDataAccess().getRuleSet(importedPackageVO.getId(), importedRuleSet.getName());
if (// TODO: verify whether the above is
reloaded == null)
// even needed
reloaded = dataAccess.getDesignerDataAccess().getRuleSet(importedRuleSet.getId());
} else {
reloaded = dataAccess.getDesignerDataAccess().getRuleSet(importedRuleSet.getName(), importedRuleSet.getLanguage(), importedRuleSet.getVersion());
}
importedRuleSet.setId(reloaded.getId());
}
}
if (!existingRuleSets.isEmpty()) {
importedPackageVO.getRuleSets().addAll(existingRuleSets);
progressMonitor.subTask("Saving Package");
dataAccess.getDesignerDataAccess().savePackage(importedPackageVO);
}
if (preexistingVersion > 0 && existingProcessVOs.isEmpty() && existingRuleSets.isEmpty()) {
progressMonitor.subTask("Saving Package");
// force
dataAccess.getDesignerDataAccess().savePackage(importedPackageVO);
// associate
// processes
}
progressMonitor.progress(10);
progressMonitor.subTask("Loading package");
PackageVO newPackageVO = dataAccess.getDesignerDataAccess().loadPackage(packageId, false);
WorkflowPackage importedPackage = new WorkflowPackage(project, newPackageVO);
List<WorkflowProcess> processVersions = new ArrayList<>();
for (ProcessVO processVO : newPackageVO.getProcesses()) {
WorkflowProcess processVersion = new WorkflowProcess(project, processVO);
processVersion.setPackage(importedPackage);
processVersions.add(processVersion);
}
Collections.sort(processVersions);
importedPackage.setProcesses(processVersions);
List<ExternalEvent> externalEvents = new ArrayList<>();
for (ExternalEventVO externalEventVO : newPackageVO.getExternalEvents()) {
ExternalEvent externalEvent = new ExternalEvent(externalEventVO, importedPackage);
externalEvents.add(externalEvent);
}
Collections.sort(externalEvents);
importedPackage.setExternalEvents(externalEvents);
List<TaskTemplate> taskTemplates = new ArrayList<>();
if (newPackageVO.getTaskTemplates() != null) {
for (TaskVO taskVO : newPackageVO.getTaskTemplates()) {
TaskTemplate taskTemplate = new TaskTemplate(taskVO, importedPackage);
taskTemplates.add(taskTemplate);
}
Collections.sort(taskTemplates);
importedPackage.setTaskTemplates(taskTemplates);
}
List<ActivityImpl> activityImpls = new ArrayList<>();
if (newPackageVO.getImplementors() != null) {
for (ActivityImplementorVO activityImplVO : newPackageVO.getImplementors()) {
if (importedPackageVO.getImplementors() != null) {
// attrs not included in reload -- take from original XML
ActivityImplementorVO xmlImplVO = null;
for (ActivityImplementorVO implVO : importedPackageVO.getImplementors()) {
if (activityImplVO.getImplementorClassName().equals(implVO.getImplementorClassName()))
xmlImplVO = implVO;
}
if (xmlImplVO != null) {
activityImplVO.setBaseClassName(xmlImplVO.getBaseClassName());
activityImplVO.setIconName(xmlImplVO.getIconName());
activityImplVO.setShowInToolbox(xmlImplVO.isShowInToolbox());
activityImplVO.setLabel(xmlImplVO.getLabel());
activityImplVO.setAttributeDescription(xmlImplVO.getAttributeDescription());
}
}
ActivityImpl activityImpl = new ActivityImpl(activityImplVO, importedPackage);
activityImpls.add(activityImpl);
}
Collections.sort(activityImpls);
importedPackage.setActivityImpls(activityImpls);
}
if (newPackageVO.getRuleSets() != null) {
List<WorkflowAsset> assets = new ArrayList<>();
for (RuleSetVO ruleSet : newPackageVO.getRuleSets()) {
WorkflowAsset asset = WorkflowAssetFactory.createAsset(ruleSet, importedPackage);
assets.add(asset);
}
Collections.sort(assets);
importedPackage.setAssets(assets);
}
if (existing != null) {
// deregister old assets
if (existing.getAssets() != null) {
for (WorkflowAsset oldAsset : existing.getAssets()) WorkflowAssetFactory.deRegisterAsset(oldAsset);
}
project.removePackage(existing);
}
// register new assets
if (importedPackage.getAssets() != null) {
for (WorkflowAsset newAsset : importedPackage.getAssets()) WorkflowAssetFactory.registerAsset(newAsset);
}
project.addPackage(importedPackage);
progressMonitor.progress(10);
dataAccess.auditLog(Action.Import, importedPackage);
dataAccess.getPackages(true);
dataAccess.getProcesses(true);
dataAccess.getRuleSets(true);
dataAccess.getActivityImplementors(true);
project.findActivityImplementors(importedPackage);
progressMonitor.progress(5);
timer.stopAndLog();
return importedPackage;
}
Aggregations