Search in sources :

Example 1 with ProcessImporter

use of com.centurylink.mdw.dataaccess.ProcessImporter in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method remoteRetrieveProcess.

public ProcessVO remoteRetrieveProcess(String name, int version) throws DataAccessException {
    try {
        String path = "Processes?name=" + name;
        if (version != 0)
            path += "&version=" + RuleSetVO.formatVersion(version);
        String pkgXml = ((RestfulServer) currentServer).invokeResourceService(path);
        ProcessImporter importer = DataAccess.getProcessImporter(getDatabaseSchemaVersion());
        PackageVO pkg = importer.importPackage(pkgXml);
        ProcessVO process = pkg.getProcesses().get(0);
        process.setPackageName(pkg.getName());
        process.setPackageVersion(pkg.getVersionString());
        if (isVcsPersist())
            process.setId(currentServer.getVersionControl().getId(getLogicalFile(process)));
        return process;
    } catch (IOException ex) {
        throw new DataAccessException("Error retrieving process: " + name + " v" + RuleSetVO.formatVersion(version), ex);
    }
}
Also used : PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) ProcessImporter(com.centurylink.mdw.dataaccess.ProcessImporter) RestfulServer(com.centurylink.mdw.designer.utils.RestfulServer) IOException(java.io.IOException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 2 with ProcessImporter

use of com.centurylink.mdw.dataaccess.ProcessImporter in project mdw-designer by CenturyLinkCloud.

the class WorkflowAccessRest method getProcess.

public ProcessVO getProcess(long processId, boolean json) throws DataAccessException {
    try {
        if (json) {
            String processJson = getServer().invokeResourceService("Workflow?id=" + processId);
            JSONObject jsonObj = new JSONObject(processJson);
            ProcessVO process = new ProcessVO(jsonObj);
            process.setPackageName(jsonObj.getString("package"));
            process.setPackageVersion(jsonObj.getString("packageVersion"));
            process.setId(jsonObj.getLong("id"));
            return process;
        } else {
            String pkgXml = getServer().invokeResourceService("Processes?id=" + processId);
            ProcessImporter importer = DataAccess.getProcessImporter(DataAccess.currentSchemaVersion);
            PackageVO pkg = importer.importPackage(pkgXml);
            ProcessVO process = pkg.getProcesses().get(0);
            process.setPackageName(pkg.getName());
            process.setPackageVersion(pkg.getVersionString());
            process.setId(processId);
            return process;
        }
    } catch (Exception ex) {
        throw new DataAccessException("Error retrieving process: " + processId, ex);
    }
}
Also used : JSONObject(org.json.JSONObject) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) ProcessImporter(com.centurylink.mdw.dataaccess.ProcessImporter) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) IOException(java.io.IOException) JSONException(org.json.JSONException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 3 with ProcessImporter

use of com.centurylink.mdw.dataaccess.ProcessImporter in project mdw-designer by CenturyLinkCloud.

the class Importer method parsePackageContent.

public PackageVO parsePackageContent(String packageContent) throws JSONException, DataAccessException {
    if (packageContent.trim().startsWith("{")) {
        Map<String, JSONObject> pkgJsonMap = JsonUtil.getJsonObjects(new JSONObject(packageContent).getJSONObject("packages"));
        String name = pkgJsonMap.keySet().iterator().next();
        PackageVO pkgVO = new PackageVO(pkgJsonMap.get(name));
        pkgVO.setName(name);
        return pkgVO;
    } else {
        int schemaVersion = dataAccess.getDesignerDataAccess().getDatabaseSchemaVersion();
        ProcessImporter importer = DataAccess.getProcessImporter(schemaVersion);
        return importer.importPackage(packageContent);
    }
}
Also used : JSONObject(org.json.JSONObject) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ProcessImporter(com.centurylink.mdw.dataaccess.ProcessImporter)

Example 4 with ProcessImporter

use of com.centurylink.mdw.dataaccess.ProcessImporter in project mdw-designer by CenturyLinkCloud.

the class Importer method importProcess.

public WorkflowProcess importProcess(final WorkflowPackage targetPackage, final WorkflowProcess targetProcess, final String xml) throws DataAccessException, RemoteException, XmlException, ValidationException {
    CodeTimer timer = new CodeTimer("importProcess()");
    ProcessVO importedProcessVO = null;
    int schemaVersion = dataAccess.getSchemaVersion();
    ProcessImporter importer = DataAccess.getProcessImporter(schemaVersion);
    importedProcessVO = importer.importProcess(xml);
    if (targetProcess != null && !importedProcessVO.getName().equals(targetProcess.getName()))
        throw new ValidationException("Process in XML (" + importedProcessVO.getName() + ") is not " + targetProcess.getName());
    for (WorkflowProcess existing : targetPackage.getProject().getAllProcesses()) {
        if (existing.getName().equals(importedProcessVO.getName())) {
            if (existing.getVersion() == importedProcessVO.getVersion())
                throw new ValidationException(existing.getLabel() + " already exists in " + targetPackage.getProject().getLabel() + ".");
            if (existing.getVersion() > importedProcessVO.getVersion())
                throw new ValidationException(existing.getLabel() + " already exists in " + targetPackage.getProject().getLabel() + " with a version greater than the imported process (v" + importedProcessVO.getVersionString() + ").");
        }
    }
    // designer fix for backward compatibility
    ProcessWorker worker = new ProcessWorker();
    worker.convert_to_designer(importedProcessVO);
    worker.convert_from_designer(importedProcessVO, syncNodeMetaInfo(dataAccess.getDesignerDataModel().getNodeMetaInfo(), importedProcessVO));
    if (!importedProcessVO.isInRuleSet()) {
        // fix pseudo variables
        for (VariableVO varVO : importedProcessVO.getVariables()) varVO.setVariableId(null);
    }
    importedProcessVO.setPackageName(targetPackage.getName());
    WorkflowProcess alreadyInPackage = null;
    if (targetPackage.getProject().getProcess(importedProcessVO.getName()) == null)
        dataAccess.getDesignerDataAccess().createProcess(importedProcessVO);
    else {
        alreadyInPackage = targetPackage.getProcess(importedProcessVO.getName());
        dataAccess.getDesignerDataAccess().updateProcess(importedProcessVO, importedProcessVO.getVersion(), false);
    }
    ProcessVO reloaded = dataAccess.getDesignerDataAccess().getProcessDefinition(importedProcessVO.getProcessName(), importedProcessVO.getVersion());
    importedProcessVO.setProcessId(reloaded.getProcessId());
    if (targetPackage.getProject().getDataAccess().getSupportedSchemaVersion() < DataAccess.schemaVersion52)
        updateSubProcessIdAttributes(importedProcessVO);
    WorkflowProcess importedProcess = new WorkflowProcess(targetPackage.getProject(), importedProcessVO);
    dataAccess.getProcesses(false).add(importedProcess.getProcessVO());
    if (alreadyInPackage != null)
        targetPackage.removeProcess(alreadyInPackage);
    targetPackage.addProcess(importedProcess);
    importedProcess.setPackage(targetPackage);
    dataAccess.auditLog(Action.Import, importedProcess);
    timer.stopAndLog();
    return importedProcess;
}
Also used : ValidationException(com.centurylink.mdw.designer.utils.ValidationException) ProcessWorker(com.centurylink.mdw.designer.utils.ProcessWorker) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) VariableVO(com.centurylink.mdw.model.value.variable.VariableVO) ProcessImporter(com.centurylink.mdw.dataaccess.ProcessImporter) CodeTimer(com.centurylink.mdw.plugin.CodeTimer) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess)

Example 5 with ProcessImporter

use of com.centurylink.mdw.dataaccess.ProcessImporter in project mdw-designer by CenturyLinkCloud.

the class Importer method importAttributes.

public void importAttributes(final WorkflowElement element, final String xml, final ProgressMonitor progressMonitor, String attrPrefix) throws DataAccessException, XmlException {
    progressMonitor.subTask(PARSING_XML);
    int schemaVersion = dataAccess.getSchemaVersion();
    ProcessImporter importer = DataAccess.getProcessImporter(schemaVersion);
    progressMonitor.progress(40);
    progressMonitor.subTask("Saving attributes");
    ProcessDefinitionDocument procdef = ProcessDefinitionDocument.Factory.parse(xml, Compatibility.namespaceOptions());
    if (element instanceof WorkflowPackage && !((WorkflowPackage) element).getName().equals(procdef.getProcessDefinition().getPackageName()))
        throw new DataAccessException("Expected package: " + ((WorkflowPackage) element).getName() + " in attributes XML but found: " + procdef.getProcessDefinition().getPackageName());
    for (MDWProcess process : procdef.getProcessDefinition().getProcessList()) {
        ProcessDefinitionDocument oneProcDef = ProcessDefinitionDocument.Factory.newInstance();
        MDWProcessDefinition oneProc = oneProcDef.addNewProcessDefinition();
        oneProc.getProcessList().add(process);
        ProcessVO importedProc = importer.importProcess(oneProcDef.xmlText());
        if (element instanceof WorkflowProcess && !((WorkflowProcess) element).getName().equals(importedProc.getProcessName()))
            throw new DataAccessException("Expected process: " + ((WorkflowProcess) element).getName() + " in attributes XML but found: " + importedProc.getName());
        ProcessVO proc = dataAccess.getLatestProcess(importedProc.getName());
        if (proc == null)
            throw new DataAccessException("Process not found: " + importedProc.getName());
        Map<String, String> existAttrs = dataAccess.getDesignerDataAccess().getAttributes(OwnerType.PROCESS, proc.getId());
        Map<String, String> importedAttrs = importedProc.getOverrideAttributes();
        Map<String, String> setAttrs = new HashMap<>();
        if (existAttrs != null) {
            // retain existing attrs not related to this prefix
            for (Map.Entry<String, String> attrs : existAttrs.entrySet()) {
                if (!WorkAttributeConstant.isAttrNameFor(attrs.getKey(), attrPrefix))
                    setAttrs.put(attrs.getKey(), attrs.getValue());
            }
        }
        if (importedAttrs != null) {
            for (Map.Entry<String, String> attrs : importedAttrs.entrySet()) {
                if (!WorkAttributeConstant.isAttrNameFor(attrs.getKey(), attrPrefix))
                    throw new DataAccessException("Expected attribute prefix: " + attrPrefix + " in attributes XML but found attribute: " + attrs.getKey());
                else
                    setAttrs.put(attrs.getKey(), attrs.getValue());
            }
        }
        dataAccess.getDesignerDataAccess().setOverrideAttributes(attrPrefix, OwnerType.PROCESS, proc.getId(), setAttrs);
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) HashMap(java.util.HashMap) MDWProcessDefinition(com.centurylink.mdw.bpm.MDWProcessDefinition) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) ProcessImporter(com.centurylink.mdw.dataaccess.ProcessImporter) ProcessDefinitionDocument(com.centurylink.mdw.bpm.ProcessDefinitionDocument) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) Map(java.util.Map) HashMap(java.util.HashMap) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) MDWProcess(com.centurylink.mdw.bpm.MDWProcess)

Aggregations

ProcessImporter (com.centurylink.mdw.dataaccess.ProcessImporter)6 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)4 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)3 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)3 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)2 IOException (java.io.IOException)2 JSONObject (org.json.JSONObject)2 MDWProcess (com.centurylink.mdw.bpm.MDWProcess)1 MDWProcessDefinition (com.centurylink.mdw.bpm.MDWProcessDefinition)1 ProcessDefinitionDocument (com.centurylink.mdw.bpm.ProcessDefinitionDocument)1 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)1 ProcessWorker (com.centurylink.mdw.designer.utils.ProcessWorker)1 RestfulServer (com.centurylink.mdw.designer.utils.RestfulServer)1 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)1 VariableVO (com.centurylink.mdw.model.value.variable.VariableVO)1 CodeTimer (com.centurylink.mdw.plugin.CodeTimer)1 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JSONException (org.json.JSONException)1