Search in sources :

Example 1 with MDWProcess

use of com.centurylink.mdw.bpm.MDWProcess in project mdw-designer by CenturyLinkCloud.

the class GraphFragment method toString.

@Override
public String toString() {
    ProcessDefinitionDocument defnDoc = ProcessDefinitionDocument.Factory.newInstance();
    MDWProcessDefinition procDefn = defnDoc.addNewProcessDefinition();
    MDWProcess process = procDefn.addNewProcess();
    process.setId(sourceProcessId.toString());
    for (Node node : nodes) {
        exportActivity(node.nodet, process.addNewActivity());
    }
    for (Link link : links) {
        exportTransition(link.conn, process.addNewTransition());
    }
    for (SubGraph subgraph : subgraphs) {
        MDWProcess subproc = process.addNewSubProcess();
        subproc.setId(subgraph.getId().toString());
        subproc.setName(subgraph.getName());
        for (Node node : subgraph.nodes) {
            exportActivity(node.nodet, subproc.addNewActivity());
        }
        for (Link link : subgraph.links) {
            exportTransition(link.conn, subproc.addNewTransition());
        }
    }
    return defnDoc.xmlText(new XmlOptions().setSavePrettyPrint());
}
Also used : XmlOptions(org.apache.xmlbeans.XmlOptions) MDWProcessDefinition(com.centurylink.mdw.bpm.MDWProcessDefinition) ProcessDefinitionDocument(com.centurylink.mdw.bpm.ProcessDefinitionDocument) MDWProcess(com.centurylink.mdw.bpm.MDWProcess)

Example 2 with MDWProcess

use of com.centurylink.mdw.bpm.MDWProcess 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

MDWProcess (com.centurylink.mdw.bpm.MDWProcess)2 MDWProcessDefinition (com.centurylink.mdw.bpm.MDWProcessDefinition)2 ProcessDefinitionDocument (com.centurylink.mdw.bpm.ProcessDefinitionDocument)2 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)1 ProcessImporter (com.centurylink.mdw.dataaccess.ProcessImporter)1 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)1 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)1 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 XmlOptions (org.apache.xmlbeans.XmlOptions)1