Search in sources :

Example 41 with DataAccessException

use of com.centurylink.mdw.common.exception.DataAccessException 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)

Example 42 with DataAccessException

use of com.centurylink.mdw.common.exception.DataAccessException in project mdw-designer by CenturyLinkCloud.

the class Importer method importTaskTemplates.

public void importTaskTemplates(final WorkflowPackage pkg, final String xml, final ProgressMonitor progressMonitor) throws XmlException, DataAccessException {
    progressMonitor.subTask(PARSING_XML);
    PackageDocument pkgDoc = PackageDocument.Factory.parse(xml);
    MDWPackage packageDef = pkgDoc.getPackage();
    if (!pkg.getName().equals(packageDef.getName()))
        throw new DataAccessException("Expected package: " + pkg.getName() + " in tasks XML but found: " + packageDef.getName());
    com.centurylink.mdw.task.TaskTemplatesDocument.TaskTemplates templates = packageDef.getTaskTemplates();
    PackageVO packageVO = new PackageVO();
    if (packageDef.getName() != null)
        packageVO.setPackageName(packageDef.getName());
    else
        packageVO.setPackageName("package");
    packageVO.setVersion(PackageVO.parseVersion(packageDef.getVersion()));
    List<TaskVO> packageTaskTemplates = new ArrayList<>();
    for (com.centurylink.mdw.task.TaskTemplate template : templates.getTaskList()) {
        TaskVO taskTemplateVO = new TaskVO(template);
        taskTemplateVO.setPackageName(packageVO.getPackageName());
        String v = template.getVersion();
        if (v != null && !v.equals("0"))
            taskTemplateVO.setVersion(RuleSetVO.parseVersion(v));
        String assetName = template.getAssetName();
        if (assetName != null && !assetName.isEmpty())
            taskTemplateVO.setName(assetName);
        packageTaskTemplates.add(taskTemplateVO);
    }
    packageVO.setTaskTemplates(packageTaskTemplates);
    if (!packageTaskTemplates.isEmpty())
        dataAccess.getDesignerDataAccess().savePackage(packageVO, ProcessPersister.PersistType.IMPORT);
    for (TaskVO taskVo : packageVO.getTaskTemplates()) {
        TaskTemplate existing = null;
        for (TaskTemplate taskTemplate : pkg.getTaskTemplates()) {
            if (taskTemplate.getLogicalId().equals(taskVo.getLogicalId())) {
                existing = taskTemplate;
                break;
            }
        }
        if (existing == null) {
            TaskTemplate newTemplate = new TaskTemplate(taskVo, pkg.getPackage());
            pkg.addTaskTemplate(newTemplate);
        } else {
            existing.setTaskVO(taskVo);
        }
    }
}
Also used : TaskTemplate(com.centurylink.mdw.plugin.designer.model.TaskTemplate) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ArrayList(java.util.ArrayList) MDWPackage(com.centurylink.mdw.bpm.MDWPackage) PackageDocument(com.centurylink.mdw.bpm.PackageDocument) TaskVO(com.centurylink.mdw.model.value.task.TaskVO) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 43 with DataAccessException

use of com.centurylink.mdw.common.exception.DataAccessException in project mdw-designer by CenturyLinkCloud.

the class DesignerDataModel method reloadPriviledges.

public void reloadPriviledges(DesignerDataAccess dao, String cuid) throws DataAccessException, RemoteException {
    if (dao.noDatabase()) {
        user = new UserVO();
        user.setCuid(cuid);
        user.setName(cuid);
        user.addRoleForGroup(UserGroupVO.COMMON_GROUP, UserRoleVO.PROCESS_DESIGN);
        user.addRoleForGroup(UserGroupVO.SITE_ADMIN_GROUP, UserRoleVO.PROCESS_DESIGN);
    } else {
        user = dao.getUser(cuid);
        if (user == null) {
            if (allowAnyUserToRead) {
                user = new UserVO();
                user.setCuid(cuid);
                user.setName(cuid);
                if (UserGroupVO.DEFAULT_ALL_ROLES)
                    user.addRoleForGroup(UserGroupVO.COMMON_GROUP, UserRoleVO.VIEW_ONLY);
            } else {
                throw new DataAccessException("You are not authorized to access this site");
            }
        }
    }
}
Also used : UserVO(com.centurylink.mdw.model.value.user.UserVO) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 44 with DataAccessException

use of com.centurylink.mdw.common.exception.DataAccessException in project mdw-designer by CenturyLinkCloud.

the class DesignerDataModel method getRuleSet.

public RuleSetVO getRuleSet(DesignerDataAccess dao, Long id) throws DataAccessException, RemoteException {
    RuleSetVO found = findRuleSet(id);
    if (found != null) {
        if (!found.isLoaded()) {
            RuleSetVO loaded = dao.getRuleSet(id);
            found.setLanguage(loaded.getLanguage());
            found.setRuleSet(loaded.getRuleSet());
            found.setVersion(loaded.getVersion());
            found.setModifyingUser(loaded.getModifyingUser());
            found.setModifyDate(loaded.getModifyDate());
        }
        return found;
    }
    throw new DataAccessException("Rule Set with ID " + id + " does not exist");
}
Also used : DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Example 45 with DataAccessException

use of com.centurylink.mdw.common.exception.DataAccessException 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)

Aggregations

DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)61 IOException (java.io.IOException)32 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)25 JSONException (org.json.JSONException)21 XmlException (org.apache.xmlbeans.XmlException)19 RemoteException (java.rmi.RemoteException)18 JSONObject (org.json.JSONObject)12 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)10 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)10 HttpHelper (com.centurylink.mdw.common.utilities.HttpHelper)8 FileNotFoundException (java.io.FileNotFoundException)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)7 RestfulServer (com.centurylink.mdw.designer.utils.RestfulServer)6 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)5 Graph (com.centurylink.mdw.designer.display.Graph)4 SubGraph (com.centurylink.mdw.designer.display.SubGraph)4 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)4 File (java.io.File)4 MDWStatusMessageDocument (com.centurylink.mdw.bpm.MDWStatusMessageDocument)3