Search in sources :

Example 6 with MiniLangException

use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.

the class ModelTestSuite method parseTestElement.

private void parseTestElement(String caseName, Element testElement) {
    String nodeName = testElement.getNodeName();
    if ("junit-test-suite".equals(nodeName)) {
        String className = testElement.getAttribute("class-name");
        try {
            @SuppressWarnings("unchecked") Class<? extends TestCase> clz = (Class<? extends TestCase>) ObjectType.loadClass(className);
            TestSuite suite = new TestSuite();
            suite.addTestSuite(clz);
            Enumeration<?> testEnum = suite.tests();
            int testsAdded = 0;
            int casesAdded = 0;
            while (testEnum.hasMoreElements()) {
                Test tst = (Test) testEnum.nextElement();
                this.testList.add(tst);
                casesAdded += tst.countTestCases();
                testsAdded++;
            }
            Debug.logInfo("Added " + testsAdded + " tests [" + casesAdded + " cases] from the class: " + className, module);
        } catch (Exception e) {
            String errMsg = "Unable to load test suite class : " + className;
            Debug.logError(e, errMsg, module);
        }
    } else if ("groovy-test-suite".equals(nodeName)) {
        try {
            Class testClass = GroovyUtil.getScriptClassFromLocation(testElement.getAttribute("location"));
            TestCase groovyTestCase = (GroovyScriptTestCase) testClass.newInstance();
            this.testList.add(new TestSuite(testClass, testElement.getAttribute("name")));
        } catch (GeneralException | InstantiationException | IllegalAccessException e) {
            Debug.logError(e, module);
        }
    } else if ("service-test".equals(nodeName)) {
        this.testList.add(new ServiceTest(caseName, testElement));
    } else if ("simple-method-test".equals(nodeName)) {
        if (UtilValidate.isNotEmpty(testElement.getAttribute("name"))) {
            this.testList.add(new SimpleMethodTest(caseName, testElement));
        } else {
            String methodLocation = testElement.getAttribute("location");
            List<SimpleMethod> simpleMethods;
            try {
                simpleMethods = SimpleMethod.getSimpleMethodsList(methodLocation, null);
                for (SimpleMethod simpleMethod : simpleMethods) {
                    String methodName = simpleMethod.getMethodName();
                    if (methodName.startsWith("test")) {
                        this.testList.add(new SimpleMethodTest(caseName + "." + methodName, methodLocation, methodName));
                    }
                }
            } catch (MiniLangException e) {
                Debug.logError(e, module);
            }
        }
    } else if ("webdriver-test".equals(nodeName)) {
        try {
            String className = "org.apache.ofbiz.testtools.WebDriverTest";
            Class<?> cl;
            cl = Class.forName(className);
            Constructor<?> con = cl.getConstructor(String.class, Element.class);
            this.testList.add((Test) con.newInstance(caseName, testElement));
        } catch (Exception e) {
            Debug.logError(e, module);
        }
    } else if ("entity-xml".equals(nodeName)) {
        this.testList.add(new EntityXmlAssertTest(caseName, testElement));
    } else if ("entity-xml-assert".equals(nodeName)) {
        // this is the old, deprecated name for the element, changed because it now does assert or load
        this.testList.add(new EntityXmlAssertTest(caseName, testElement));
    }
}
Also used : SimpleMethod(org.apache.ofbiz.minilang.SimpleMethod) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) GeneralException(org.apache.ofbiz.base.util.GeneralException) TestSuite(junit.framework.TestSuite) EntityTestCase(org.apache.ofbiz.entity.testtools.EntityTestCase) TestCase(junit.framework.TestCase) OFBizTestCase(org.apache.ofbiz.service.testtools.OFBizTestCase) Test(junit.framework.Test) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with MiniLangException

use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.

the class UploadContentAndImage method processContentUpload.

public static String processContentUpload(Map<String, Object> passedParams, String suffix, HttpServletRequest request) throws GenericServiceException {
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    HttpSession session = request.getSession();
    GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
    Map<String, Object> ftlContext = new HashMap<String, Object>();
    String contentPurposeString = (String) passedParams.get("contentPurposeString" + suffix);
    if (UtilValidate.isEmpty(contentPurposeString)) {
        contentPurposeString = (String) passedParams.get("contentPurposeString");
    }
    List<String> contentPurposeList = StringUtil.split(contentPurposeString, "|");
    ftlContext.put("contentPurposeList", contentPurposeList);
    String targetOperationString = (String) passedParams.get("targetOperationString" + suffix);
    if (UtilValidate.isEmpty(targetOperationString)) {
        targetOperationString = (String) passedParams.get("targetOperationString");
    }
    List<String> targetOperationList = StringUtil.split(targetOperationString, "|");
    ftlContext.put("targetOperationList", targetOperationList);
    ftlContext.put("userLogin", userLogin);
    Object objSequenceNum = passedParams.get("caSequenceNum");
    if (objSequenceNum != null) {
        if (objSequenceNum instanceof String) {
            Long sequenceNum = null;
            try {
                sequenceNum = Long.valueOf((String) objSequenceNum);
            } catch (NumberFormatException e) {
                String msg = "Caught an exception : " + e.toString();
                Debug.logError(e, msg);
                request.setAttribute("_ERROR_MESSAGE_", msg);
                List<String> errorMsgList = UtilGenerics.checkList(request.getAttribute("_EVENT_MESSAGE_LIST_"));
                if (errorMsgList == null) {
                    errorMsgList = new LinkedList<String>();
                    request.setAttribute("errorMessageList", errorMsgList);
                }
                errorMsgList.add(msg);
                return "error";
            }
            passedParams.put("caSequenceNum", sequenceNum);
        }
    }
    ModelEntity modelEntity = delegator.getModelEntity("ContentAssocDataResourceViewFrom");
    List<String> fieldNames = modelEntity.getAllFieldNames();
    Map<String, Object> ftlContext2 = new HashMap<String, Object>();
    Map<String, Object> ftlContext3 = new HashMap<String, Object>();
    for (String keyName : fieldNames) {
        Object obj = passedParams.get(keyName + suffix);
        ftlContext2.put(keyName, obj);
    }
    if (Debug.infoOn()) {
        Debug.logInfo("[UploadContentStuff]ftlContext2:" + ftlContext2, module);
    }
    List<Object> errorMessages = new LinkedList<Object>();
    Locale loc = Locale.getDefault();
    try {
        SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentIn", ftlContext2, ftlContext3, errorMessages, loc);
        SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentOut", ftlContext3, ftlContext, errorMessages, loc);
        ftlContext3 = new HashMap<String, Object>();
        SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "dataResourceIn", ftlContext2, ftlContext3, errorMessages, loc);
        SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "dataResourceOut", ftlContext3, ftlContext, errorMessages, loc);
        ftlContext3 = new HashMap<String, Object>();
        SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentAssocIn", ftlContext2, ftlContext3, errorMessages, loc);
        SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentAssocOut", ftlContext3, ftlContext, errorMessages, loc);
    } catch (MiniLangException e) {
        throw new GenericServiceException(e.getMessage());
    }
    ftlContext.put("textData", passedParams.get("textData" + suffix));
    byte[] bytes = (byte[]) passedParams.get("imageData" + suffix);
    ftlContext.put("imageData", bytes);
    if (Debug.infoOn()) {
        Debug.logInfo("[UploadContentStuff]ftlContext:" + ftlContext, module);
    }
    Map<String, Object> ftlResults = null;
    try {
        ftlResults = dispatcher.runSync("persistContentAndAssoc", ftlContext);
    } catch (ServiceAuthException e) {
        String msg = e.getMessage();
        request.setAttribute("_ERROR_MESSAGE_", msg);
        List<String> errorMsgList = UtilGenerics.checkList(request.getAttribute("_EVENT_MESSAGE_LIST_"));
        if (Debug.infoOn()) {
            Debug.logInfo("[UploadContentStuff]errorMsgList:" + errorMsgList, module);
        }
        if (Debug.infoOn()) {
            Debug.logInfo("[UploadContentStuff]msg:" + msg, module);
        }
        if (errorMsgList == null) {
            errorMsgList = new LinkedList<String>();
            request.setAttribute("errorMessageList", errorMsgList);
        }
        errorMsgList.add(msg);
        return "error";
    }
    if (ServiceUtil.isError(ftlResults)) {
        String msg = ServiceUtil.getErrorMessage(ftlResults);
        request.setAttribute("_ERROR_MESSAGE_", msg);
        List<String> errorMsgList = UtilGenerics.checkList(request.getAttribute("_EVENT_MESSAGE_LIST_"));
        if (errorMsgList == null) {
            errorMsgList = new LinkedList<String>();
            request.setAttribute("errorMessageList", errorMsgList);
        }
        errorMsgList.add(msg);
        return "error";
    }
    String returnedContentId = (String) ftlResults.get("contentId");
    if (Debug.infoOn()) {
        Debug.logInfo("returnedContentId:" + returnedContentId, module);
    }
    request.setAttribute("contentId" + suffix, ftlResults.get("contentId"));
    request.setAttribute("caContentIdTo" + suffix, ftlResults.get("contentIdTo"));
    request.setAttribute("caContentIdStart" + suffix, ftlResults.get("contentIdTo"));
    request.setAttribute("caContentAssocTypeId" + suffix, ftlResults.get("contentAssocTypeId"));
    request.setAttribute("caFromDate" + suffix, ftlResults.get("fromDate"));
    request.setAttribute("drDataResourceId" + suffix, ftlResults.get("dataResourceId"));
    request.setAttribute("caContentId" + suffix, ftlResults.get("contentId"));
    String caContentIdTo = (String) passedParams.get("caContentIdTo");
    if (UtilValidate.isNotEmpty(caContentIdTo)) {
        Map<String, Object> resequenceContext = new HashMap<String, Object>();
        resequenceContext.put("contentIdTo", caContentIdTo);
        resequenceContext.put("userLogin", userLogin);
        try {
            ftlResults = dispatcher.runSync("resequence", resequenceContext);
            if (ServiceUtil.isError(ftlResults)) {
                String errorMessage = ServiceUtil.getErrorMessage(ftlResults);
                request.setAttribute("_ERROR_MESSAGE_", errorMessage);
                Debug.logError(errorMessage, module);
                return "error";
            }
        } catch (ServiceAuthException e) {
            String msg = e.getMessage();
            request.setAttribute("_ERROR_MESSAGE_", msg);
            List<String> errorMsgList = UtilGenerics.checkList(request.getAttribute("_EVENT_MESSAGE_LIST_"));
            if (Debug.infoOn()) {
                Debug.logInfo("[UploadContentStuff]errorMsgList:" + errorMsgList, module);
            }
            if (Debug.infoOn()) {
                Debug.logInfo("[UploadContentStuff]msg:" + msg, module);
            }
            if (errorMsgList == null) {
                errorMsgList = new LinkedList<String>();
                request.setAttribute("errorMessageList", errorMsgList);
            }
            errorMsgList.add(msg);
            return "error";
        }
    }
    return "success";
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) ServiceAuthException(org.apache.ofbiz.service.ServiceAuthException) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) LinkedList(java.util.LinkedList) Delegator(org.apache.ofbiz.entity.Delegator) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) LinkedList(java.util.LinkedList) List(java.util.List) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) ModelEntity(org.apache.ofbiz.entity.model.ModelEntity)

Example 8 with MiniLangException

use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.

the class ContentWorker method selectKids.

public static void selectKids(Map<String, Object> currentNode, Map<String, Object> ctx) {
    Delegator delegator = (Delegator) ctx.get("delegator");
    GenericValue parentContent = (GenericValue) currentNode.get("value");
    String contentAssocTypeId = (String) ctx.get("contentAssocTypeId");
    String contentTypeId = (String) ctx.get("contentTypeId");
    String mapKey = (String) ctx.get("mapKey");
    String parentContentId = (String) parentContent.get("contentId");
    Map<String, Object> whenMap = UtilGenerics.checkMap(ctx.get("whenMap"));
    List<Map<String, Object>> kids = new LinkedList<Map<String, Object>>();
    currentNode.put("kids", kids);
    String direction = (String) ctx.get("direction");
    if (UtilValidate.isEmpty(direction)) {
        direction = "From";
    }
    List<String> assocTypeList = StringUtil.split(contentAssocTypeId, " ");
    List<String> contentTypeList = StringUtil.split(contentTypeId, " ");
    String contentAssocPredicateId = null;
    Boolean nullThruDatesOnly = Boolean.TRUE;
    Map<String, Object> results = null;
    try {
        results = ContentServicesComplex.getAssocAndContentAndDataResourceCacheMethod(delegator, parentContentId, mapKey, direction, null, null, assocTypeList, contentTypeList, nullThruDatesOnly, contentAssocPredicateId, null);
    } catch (GenericEntityException e) {
        throw new RuntimeException(e.getMessage());
    } catch (MiniLangException e2) {
        throw new RuntimeException(e2.getMessage());
    }
    List<GenericValue> relatedViews = UtilGenerics.checkList(results.get("entityList"));
    for (GenericValue assocValue : relatedViews) {
        Map<String, Object> thisNode = ContentWorker.makeNode(assocValue);
        checkConditions(delegator, thisNode, null, whenMap);
        boolean isPick = booleanDataType(thisNode.get("isPick"));
        kids.add(thisNode);
        if (isPick) {
            Integer count = (Integer) currentNode.get("count");
            if (count == null) {
                count = Integer.valueOf(1);
            } else {
                count = Integer.valueOf(count.intValue() + 1);
            }
            currentNode.put("count", count);
        }
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) LinkedList(java.util.LinkedList) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with MiniLangException

use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.

the class ContentWorker method checkConditions.

public static void checkConditions(Delegator delegator, Map<String, Object> trailNode, Map<String, Object> contentAssoc, Map<String, Object> whenMap) {
    Map<String, Object> context = new HashMap<String, Object>();
    GenericValue content = (GenericValue) trailNode.get("value");
    if (content != null) {
        context.put("content", content);
        List<Object> purposes = getPurposes(content);
        context.put("purposes", purposes);
        List<Object> sections = getSections(content);
        context.put("sections", sections);
        List<Object> topics = getTopics(content);
        context.put("topics", topics);
        String contentTypeId = (String) content.get("contentTypeId");
        List<String> contentTypeAncestry = new LinkedList<String>();
        try {
            getContentTypeAncestry(delegator, contentTypeId, contentTypeAncestry);
        } catch (GenericEntityException e) {
            Debug.logError(e.getMessage(), module);
        }
        context.put("typeAncestry", contentTypeAncestry);
        if (contentAssoc == null && (content.getEntityName().indexOf("Assoc") >= 0)) {
            contentAssoc = delegator.makeValue("ContentAssoc");
            try {
                // TODO: locale needs to be gotten correctly
                SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentAssocIn", content, contentAssoc, new LinkedList<Object>(), Locale.getDefault());
                context.put("contentAssocTypeId", contentAssoc.get("contentAssocTypeId"));
                context.put("contentAssocPredicateId", contentAssoc.get("contentAssocPredicateId"));
                context.put("mapKey", contentAssoc.get("mapKey"));
            } catch (MiniLangException e) {
                Debug.logError(e.getMessage(), module);
            }
        } else {
            context.put("contentAssocTypeId", null);
            context.put("contentAssocPredicateId", null);
            context.put("mapKey", null);
        }
    }
    boolean isReturnBefore = checkWhen(context, (String) whenMap.get("returnBeforePickWhen"), false);
    trailNode.put("isReturnBefore", Boolean.valueOf(isReturnBefore));
    boolean isPick = checkWhen(context, (String) whenMap.get("pickWhen"), true);
    trailNode.put("isPick", Boolean.valueOf(isPick));
    boolean isFollow = checkWhen(context, (String) whenMap.get("followWhen"), true);
    trailNode.put("isFollow", Boolean.valueOf(isFollow));
    boolean isReturnAfter = checkWhen(context, (String) whenMap.get("returnAfterPickWhen"), false);
    trailNode.put("isReturnAfter", Boolean.valueOf(isReturnAfter));
    trailNode.put("checked", Boolean.TRUE);
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) HashMap(java.util.HashMap) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) LinkedList(java.util.LinkedList)

Example 10 with MiniLangException

use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.

the class LayoutEvents method createLayoutSubContent.

public static String createLayoutSubContent(HttpServletRequest request, HttpServletResponse response) {
    try {
        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
        HttpSession session = request.getSession();
        Map<String, Object> paramMap = UtilHttp.getParameterMap(request);
        String contentIdTo = (String) paramMap.get("contentIdTo");
        String mapKey = (String) paramMap.get("mapKey");
        if (Debug.verboseOn()) {
            Debug.logVerbose("in createSubContent, contentIdTo:" + contentIdTo, module);
            Debug.logVerbose("in createSubContent, mapKey:" + mapKey, module);
        }
        Map<String, Object> context = new HashMap<String, Object>();
        List<Object> errorMessages = new LinkedList<>();
        Locale loc = (Locale) request.getSession().getServletContext().getAttribute("locale");
        if (loc == null) {
            loc = Locale.getDefault();
        }
        GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
        context.put("userLogin", userLogin);
        String rootDir = request.getSession().getServletContext().getRealPath("/");
        context.put("rootDir", rootDir);
        try {
            SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentIn", paramMap, context, errorMessages, loc);
            SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "dataResourceIn", paramMap, context, errorMessages, loc);
            SimpleMapProcessor.runSimpleMapProcessor("component://content/minilang/ContentManagementMapProcessors.xml", "contentAssocIn", paramMap, context, errorMessages, loc);
        } catch (MiniLangException e) {
            request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
            return "error";
        }
        context.put("dataResourceName", context.get("contentName"));
        String contentPurposeTypeId = (String) paramMap.get("contentPurposeTypeId");
        if (UtilValidate.isNotEmpty(contentPurposeTypeId)) {
            context.put("contentPurposeList", UtilMisc.toList(contentPurposeTypeId));
        }
        context.put("contentIdTo", paramMap.get("contentIdTo"));
        context.put("mapKey", paramMap.get("mapKey"));
        context.put("textData", paramMap.get("textData"));
        context.put("contentAssocTypeId", "SUB_CONTENT");
        if (Debug.verboseOn()) {
            Debug.logVerbose("in createSubContent, context:" + context, module);
        }
        Map<String, Object> result = dispatcher.runSync("persistContentAndAssoc", context);
        if (ServiceUtil.isError(result)) {
            String errorMessage = ServiceUtil.getErrorMessage(result);
            request.setAttribute("_ERROR_MESSAGE_", errorMessage);
            Debug.logError(errorMessage, module);
            return "error";
        }
        if (Debug.verboseOn()) {
            Debug.logVerbose("in createLayoutFile, result:" + result, module);
        }
        String contentId = (String) result.get("contentId");
        String dataResourceId = (String) result.get("dataResourceId");
        request.setAttribute("contentId", contentId);
        request.setAttribute("drDataResourceId", dataResourceId);
        request.setAttribute("currentEntityName", "SubContentDataResourceId");
        Map<String, Object> context2 = new HashMap<String, Object>();
        context2.put("activeContentId", contentId);
        context2.put("contentAssocTypeId", "SUB_CONTENT");
        context2.put("fromDate", result.get("fromDate"));
        context2.put("contentIdTo", contentIdTo);
        context2.put("mapKey", mapKey);
        context2.put("userLogin", userLogin);
        Map<String, Object> serviceResult = new HashMap<String, Object>();
        serviceResult = dispatcher.runSync("deactivateAssocs", context2);
        if (ServiceUtil.isError(serviceResult)) {
            String errorMessage = ServiceUtil.getErrorMessage(serviceResult);
            request.setAttribute("_ERROR_MESSAGE_", errorMessage);
            Debug.logError(errorMessage, module);
            return "error";
        }
    } catch (GenericServiceException e) {
        request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
        return "error";
    }
    return "success";
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) LinkedList(java.util.LinkedList)

Aggregations

MiniLangException (org.apache.ofbiz.minilang.MiniLangException)27 GenericValue (org.apache.ofbiz.entity.GenericValue)13 Locale (java.util.Locale)9 HashMap (java.util.HashMap)8 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)8 MiniLangRuntimeException (org.apache.ofbiz.minilang.MiniLangRuntimeException)8 LinkedList (java.util.LinkedList)7 Delegator (org.apache.ofbiz.entity.Delegator)7 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)6 HttpSession (javax.servlet.http.HttpSession)5 SimpleMethod (org.apache.ofbiz.minilang.SimpleMethod)5 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)5 Timestamp (java.sql.Timestamp)4 Map (java.util.Map)4 IOException (java.io.IOException)3 MethodOperation (org.apache.ofbiz.minilang.method.MethodOperation)3 BreakElementException (org.apache.ofbiz.minilang.method.envops.Break.BreakElementException)3 ContinueElementException (org.apache.ofbiz.minilang.method.envops.Continue.ContinueElementException)3 FileNotFoundException (java.io.FileNotFoundException)2 HashSet (java.util.HashSet)2