Search in sources :

Example 21 with PackageVO

use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.

the class DesignerDataModel method copyPackage.

public PackageVO copyPackage(PackageVO curPkg, String newname, int newversion) {
    PackageVO newPkg = new PackageVO();
    newPkg.setPackageName(newname != null ? newname : curPkg.getPackageName());
    newPkg.setPackageDescription(curPkg.getPackageDescription());
    newPkg.setExported(false);
    // newPkg.setPools(pools)
    // newPkg.setVariables(variables)
    newPkg.setSchemaVersion(DataAccess.currentSchemaVersion);
    newPkg.setPackageId(getNewId());
    newPkg.setVersion(newversion);
    newPkg.setMetaContent(curPkg.getMetaContent());
    List<ProcessVO> processes = new ArrayList<ProcessVO>();
    newPkg.setProcesses(processes);
    if (curPkg.getProcesses() != null) {
        for (ProcessVO p : curPkg.getProcesses()) {
            processes.add(p);
        }
    }
    if (curPkg.getImplementors() != null) {
        List<ActivityImplementorVO> impls = new ArrayList<ActivityImplementorVO>();
        newPkg.setImplementors(impls);
        for (ActivityImplementorVO a : curPkg.getImplementors()) {
            impls.add(a);
        }
    }
    if (curPkg.getExternalEvents() != null) {
        List<ExternalEventVO> handlers = new ArrayList<ExternalEventVO>();
        newPkg.setExternalEvents(handlers);
        for (ExternalEventVO a : curPkg.getExternalEvents()) {
            handlers.add(a);
        }
    }
    if (curPkg.getParticipants() != null) {
        List<LaneVO> participants = new ArrayList<LaneVO>();
        newPkg.setParticipants(participants);
        for (LaneVO a : curPkg.getParticipants()) {
            participants.add(a);
        }
    }
    if (curPkg.getRuleSets() != null) {
        List<RuleSetVO> rulesets = new ArrayList<RuleSetVO>();
        newPkg.setRuleSets(rulesets);
        for (RuleSetVO a : curPkg.getRuleSets()) {
            rulesets.add(a);
        }
    }
    if (curPkg.getAttributes() != null) {
        List<AttributeVO> attrs = new ArrayList<AttributeVO>();
        newPkg.setAttributes(attrs);
        for (AttributeVO a : curPkg.getAttributes()) {
            attrs.add(a);
        }
    }
    addPackage(newPkg);
    return newPkg;
}
Also used : PackageVO(com.centurylink.mdw.model.value.process.PackageVO) AttributeVO(com.centurylink.mdw.model.value.attribute.AttributeVO) CustomAttributeVO(com.centurylink.mdw.model.value.attribute.CustomAttributeVO) ExternalEventVO(com.centurylink.mdw.model.value.event.ExternalEventVO) ArrayList(java.util.ArrayList) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO) ActivityImplementorVO(com.centurylink.mdw.model.value.activity.ActivityImplementorVO) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) LaneVO(com.centurylink.mdw.model.value.process.LaneVO)

Example 22 with PackageVO

use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.

the class NodeRunner method run.

public void run(final TestCase testCase, DesignerDataAccess dao, boolean verbose, boolean createReplace) throws ServiceException {
    PackageVO pkgVo = null;
    NodeJS nodeJS = NodeJS.createNodeJS();
    try {
        pkgVo = dao.getPackage(NODE_PKG);
    } catch (DataAccessException e) {
        throw new ServiceException(e.getMessage());
    }
    final V8Object fileObj = new V8Object(nodeJS.getRuntime()).add("file", pkgVo.getRuleSet(RUNNER).getRawFile().getAbsolutePath());
    JavaCallback callback = new JavaCallback() {

        public Object invoke(V8Object receiver, V8Array parameters) {
            return fileObj;
        }
    };
    nodeJS.getRuntime().registerJavaMethod(callback, "getRunner");
    final Result parseResult = new Result();
    callback = new JavaCallback() {

        public Object invoke(V8Object receiver, V8Array parameters) {
            V8Object resultObj = parameters.getObject(0);
            parseResult.status = resultObj.getString("status");
            parseResult.message = resultObj.getString("message");
            resultObj.release();
            return null;
        }
    };
    nodeJS.getRuntime().registerJavaMethod(callback, "setParseResult");
    nodeJS.exec(pkgVo.getRuleSet(PARSER).getRawFile());
    while (nodeJS.isRunning()) {
        nodeJS.handleMessage();
    }
    fileObj.release();
    nodeJS.release();
    if (!parseResult.status.equals("OK"))
        throw new ServiceException(PARSER + parseResult);
    nodeJS = NodeJS.createNodeJS();
    final V8Object testObj = new V8Object(nodeJS.getRuntime());
    testObj.add("file", testCase.getCaseFile().getAbsolutePath());
    V8Array valueFiles = new V8Array(nodeJS.getRuntime());
    // TODO hardcoded
    valueFiles.push("localhost.env");
    testObj.add("valueFiles", valueFiles);
    valueFiles.release();
    testObj.add("resultDir", testCase.getResultDirectory().getAbsolutePath());
    final Map<String, TestCaseItem> testCaseItems = new HashMap<>();
    final V8Array testItems = new V8Array(nodeJS.getRuntime());
    for (TestCaseItem item : testCase.getItems()) {
        String itemId = item.getName();
        V8Object itemObj = new V8Object(nodeJS.getRuntime()).add("name", item.getName());
        try {
            if (item.getObject().has("request")) {
                JSONObject request = item.getObject().getJSONObject("request");
                if (request.has("method")) {
                    itemObj.add("method", request.getString("method"));
                    itemId = request.getString("method") + ":" + itemId;
                }
            }
            JSONObject options = item.getOptions() == null ? new JSONObject() : item.getOptions();
            if (verbose && !options.has("debug"))
                options.put("debug", "true");
            if (createReplace && !options.has("overwriteExpected"))
                options.put("overwriteExpected", "true");
            options.put("qualifyLocations", false);
            if (JSONObject.getNames(options) != null) {
                V8Object json = nodeJS.getRuntime().getObject("JSON");
                V8Array params = new V8Array(nodeJS.getRuntime()).push(options.toString());
                V8Object jsonObj = json.executeObjectFunction("parse", params);
                itemObj.add("options", jsonObj);
                params.release();
                json.release();
                jsonObj.release();
            }
            if (item.getValues() != null) {
                V8Object json = nodeJS.getRuntime().getObject("JSON");
                V8Array params = new V8Array(nodeJS.getRuntime()).push(item.getValues().toString());
                V8Object jsonObj = json.executeObjectFunction("parse", params);
                itemObj.add("values", jsonObj);
                params.release();
                json.release();
                jsonObj.release();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        testItems.push(itemObj);
        testCaseItems.put(itemId, item);
        itemObj.release();
    }
    testObj.add("items", testItems);
    testItems.release();
    callback = new JavaCallback() {

        public Object invoke(V8Object receiver, V8Array parameters) {
            return testObj;
        }
    };
    nodeJS.getRuntime().registerJavaMethod(callback, "getTestCase");
    callback = new JavaCallback() {

        public Object invoke(V8Object receiver, V8Array parameters) {
            String itemId = parameters.getString(0);
            V8Object resultObj = parameters.getObject(1);
            if (itemId == null) {
                for (TestCaseItem item : testCase.getItems()) {
                    updateItem(item, resultObj);
                }
            }
            TestCaseItem item = testCaseItems.get(itemId);
            if (item != null) {
                updateItem(item, resultObj);
            }
            resultObj.release();
            return null;
        }
    };
    nodeJS.getRuntime().registerJavaMethod(callback, "setTestResult");
    final V8 v8 = nodeJS.getRuntime();
    callback = new JavaCallback() {

        public Object invoke(V8Object receiver, V8Array parameters) {
            String itemId = parameters.getString(0);
            V8Object responseObj = parameters.getObject(1);
            TestCaseItem item = testCaseItems.get(itemId);
            if (item != null) {
                V8Object json = v8.getObject("JSON");
                V8Array params = new V8Array(v8).push(responseObj);
                String jsonStr = json.executeStringFunction("stringify", params);
                params.release();
                json.release();
                try {
                    item.setResponse(new JSONObject(jsonStr));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            responseObj.release();
            return null;
        }
    };
    nodeJS.getRuntime().registerJavaMethod(callback, "setTestResponse");
    nodeJS.exec(pkgVo.getRuleSet(RUNNER).getRawFile());
    while (nodeJS.isRunning()) {
        nodeJS.handleMessage();
    }
    testObj.release();
    nodeJS.release();
}
Also used : V8(com.eclipsesource.v8.V8) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) HashMap(java.util.HashMap) V8Object(com.eclipsesource.v8.V8Object) JavaCallback(com.eclipsesource.v8.JavaCallback) V8Array(com.eclipsesource.v8.V8Array) JSONException(org.json.JSONException) NodeJS(com.eclipsesource.v8.NodeJS) ServiceException(com.centurylink.mdw.common.service.ServiceException) JSONObject(org.json.JSONObject) V8Object(com.eclipsesource.v8.V8Object) JSONObject(org.json.JSONObject) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 23 with PackageVO

use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.

the class PluginDataAccess method determineDefaultPackage.

private PackageVO determineDefaultPackage(List<PackageVO> packageList, List<ProcessVO> processes) {
    Map<String, PackageVO> processPackage = new HashMap<>();
    PackageVO defaultPackage = new PackageVO();
    List<ProcessVO> defaultProcesses = new ArrayList<>();
    for (PackageVO pkg : packageList) {
        for (ProcessVO proc : pkg.getProcesses()) processPackage.put(proc.getProcessName(), pkg);
    }
    for (ProcessVO proc : processes) {
        if (processPackage.get(proc.getProcessName()) == null)
            defaultProcesses.add(proc);
    }
    defaultPackage.setProcesses(defaultProcesses);
    defaultPackage.setExternalEvents(new ArrayList<ExternalEventVO>(0));
    defaultPackage.setPackageId(Long.valueOf(0));
    defaultPackage.setPackageName(PackageVO.DEFAULT_PACKAGE_NAME);
    return defaultPackage;
}
Also used : PackageVO(com.centurylink.mdw.model.value.process.PackageVO) HashMap(java.util.HashMap) ExternalEventVO(com.centurylink.mdw.model.value.event.ExternalEventVO) ArrayList(java.util.ArrayList) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO)

Example 24 with PackageVO

use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method exportAttributes.

public String exportAttributes(String prefix, Long artifactId, int schemaVersion, ProgressMonitor monitor, String exportArtifactType) throws DataAccessException, ActionCancelledException, XmlException {
    monitor.subTask("Loading attributes...");
    PackageVO packageVO = null;
    ProcessVO processVO = null;
    if (exportArtifactType.equals(OwnerType.PACKAGE)) {
        packageVO = loadPackage(artifactId, true);
        if (isVcsPersist()) {
            try {
                for (ProcessVO process : packageVO.getProcesses()) {
                    Map<String, String> overrideAttrs = workflowAccessRest.getAttributes(OwnerType.PROCESS, process.getId());
                    process.applyOverrideAttributes(overrideAttrs);
                }
            } catch (IOException ex) {
                throw new DataAccessOfflineException("Server does not appear to be running.", ex);
            }
        } else {
            for (ProcessVO process : packageVO.getProcesses()) {
                if (process.isInRuleSet()) {
                    Map<String, String> overrideAttrs = getAttributes(OwnerType.PROCESS, process.getId());
                    process.applyOverrideAttributes(overrideAttrs);
                }
            }
        }
    } else {
        processVO = getProcess(artifactId, null);
        if (isVcsPersist()) {
            try {
                // need to make sure attributes are retrieved
                Map<String, String> overrideAttrs = workflowAccessRest.getAttributes(OwnerType.PROCESS, processVO.getId());
                processVO.applyOverrideAttributes(overrideAttrs);
            } catch (IOException ex) {
                throw new DataAccessOfflineException("Server does not appear to be running.", ex);
            }
        }
    }
    monitor.progress(30);
    if (monitor.isCanceled())
        throw new ActionCancelledException();
    if (packageVO != null) {
        // -- subprocesses must come after their containing parent processes
        Collections.sort(packageVO.getProcesses(), new Comparator<ProcessVO>() {

            public int compare(ProcessVO pVO1, ProcessVO pVO2) {
                boolean pVO1HasSubProcs = pVO1.getSubProcesses() != null && !pVO1.getSubProcesses().isEmpty();
                boolean pVO2HasSubProcs = pVO2.getSubProcesses() != null && !pVO2.getSubProcesses().isEmpty();
                if (pVO1HasSubProcs == pVO2HasSubProcs) {
                    // sort by label
                    return pVO1.getLabel().compareToIgnoreCase(pVO2.getLabel());
                } else if (pVO1HasSubProcs)
                    return -1;
                else
                    return 1;
            }
        });
    }
    if (monitor.isCanceled())
        throw new ActionCancelledException();
    monitor.progress(5);
    monitor.subTask(EXPORTXML);
    ProcessExporter exporter = DataAccess.getProcessExporter(schemaVersion, oldNamespaces ? DesignerCompatibility.getInstance() : null);
    String xml;
    if (packageVO != null)
        xml = exporter.exportOverrideAttributes(prefix, packageVO);
    else
        xml = exporter.exportOverrideAttributes(prefix, processVO, schemaVersion);
    monitor.progress(40);
    return xml;
}
Also used : DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) IOException(java.io.IOException) ProcessExporter(com.centurylink.mdw.dataaccess.ProcessExporter)

Example 25 with PackageVO

use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method exportPackages.

public String exportPackages(List<PackageVO> packages, int schemaVersion, boolean exportJson, boolean includeTaskTemplates, ProgressMonitor monitor) throws DataAccessException, ActionCancelledException, JSONException, XmlException {
    if (monitor != null)
        monitor.subTask("Loading package(s)...");
    List<PackageVO> loadedPackages = new ArrayList<>();
    for (PackageVO pkg : packages) {
        if (monitor != null)
            monitor.subTask("Loading " + pkg.getLabel() + "...");
        PackageVO packageVO = loadPackage(pkg.getId(), true);
        if (monitor != null)
            monitor.progress(30 / packages.size());
        if (monitor != null) {
            if (monitor.isCanceled())
                throw new ActionCancelledException();
            else
                monitor.subTask("Sorting processes and implementors");
        }
        if (packageVO.getRuleSets() != null) {
            Map<String, CustomAttributeVO> customAttrs = new HashMap<>();
            for (RuleSetVO ruleSet : packageVO.getRuleSets()) {
                if (ruleSet.getLanguage() != null && !customAttrs.containsKey(ruleSet.getLanguage())) {
                    CustomAttributeVO custAttrVO = getCustomAttribute("RULE_SET", ruleSet.getLanguage());
                    if (custAttrVO != null)
                        customAttrs.put(ruleSet.getLanguage(), custAttrVO);
                }
            }
            List<CustomAttributeVO> customAttributes = new ArrayList<>();
            for (CustomAttributeVO customAttr : customAttrs.values()) customAttributes.add(customAttr);
            packageVO.setCustomAttributes(customAttributes);
        }
        loadedPackages.add(packageVO);
    }
    if (monitor != null && monitor.isCanceled())
        throw new ActionCancelledException();
    if (monitor != null)
        monitor.progress(5);
    if (monitor != null)
        monitor.subTask(EXPORTXML);
    String export;
    if (exportJson) {
        ImporterExporterJson exporter = new ImporterExporterJson();
        export = exporter.exportPackages(loadedPackages);
    } else {
        ProcessExporter exporter = DataAccess.getProcessExporter(schemaVersion, oldNamespaces ? DesignerCompatibility.getInstance() : null);
        export = exporter.exportPackages(loadedPackages, includeTaskTemplates);
    }
    if (monitor != null)
        monitor.progress(25);
    for (PackageVO packageVO : loadedPackages) {
        packageVO.setExported(true);
        persister.persistPackage(packageVO, PersistType.UPDATE);
    }
    if (monitor != null)
        monitor.progress(15);
    return export;
}
Also used : PackageVO(com.centurylink.mdw.model.value.process.PackageVO) HashMap(java.util.HashMap) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) CustomAttributeVO(com.centurylink.mdw.model.value.attribute.CustomAttributeVO) ArrayList(java.util.ArrayList) ProcessExporter(com.centurylink.mdw.dataaccess.ProcessExporter) ImporterExporterJson(com.centurylink.mdw.dataaccess.file.ImporterExporterJson) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Aggregations

PackageVO (com.centurylink.mdw.model.value.process.PackageVO)27 ArrayList (java.util.ArrayList)18 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)11 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)8 RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)7 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)6 IOException (java.io.IOException)6 JSONObject (org.json.JSONObject)6 PackageDocument (com.centurylink.mdw.bpm.PackageDocument)5 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)5 ProcessExporter (com.centurylink.mdw.dataaccess.ProcessExporter)5 ActivityImplementorVO (com.centurylink.mdw.model.value.activity.ActivityImplementorVO)5 AttributeVO (com.centurylink.mdw.model.value.attribute.AttributeVO)5 JSONException (org.json.JSONException)5 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)4 CodeTimer (com.centurylink.mdw.plugin.CodeTimer)4 HashMap (java.util.HashMap)4 ProcessImporter (com.centurylink.mdw.dataaccess.ProcessImporter)3 ImporterExporterJson (com.centurylink.mdw.dataaccess.file.ImporterExporterJson)3 ProcessWorker (com.centurylink.mdw.designer.utils.ProcessWorker)3