Search in sources :

Example 26 with MiniLangException

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

the class Loop method exec.

@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
    String countStr = this.countFse.expandString(methodContext.getEnvMap());
    int count = 0;
    try {
        count = Double.valueOf(countStr).intValue();
    } catch (NumberFormatException e) {
        throw new MiniLangRuntimeException("Error while converting \"" + countStr + "\" to a number: " + e.getMessage(), this);
    }
    if (count < 0) {
        throw new MiniLangRuntimeException("Unable to execute loop operation because the count is negative: " + countStr, this);
    }
    for (int i = 0; i < count; i++) {
        this.fieldFma.put(methodContext.getEnvMap(), i);
        try {
            for (MethodOperation methodOperation : subOps) {
                if (!methodOperation.exec(methodContext)) {
                    return false;
                }
            }
        } catch (MiniLangException e) {
            if (e instanceof BreakElementException) {
                break;
            }
            if (e instanceof ContinueElementException) {
                continue;
            }
            throw e;
        }
    }
    return true;
}
Also used : MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException) MethodOperation(org.apache.ofbiz.minilang.method.MethodOperation) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) BreakElementException(org.apache.ofbiz.minilang.method.envops.Break.BreakElementException) ContinueElementException(org.apache.ofbiz.minilang.method.envops.Continue.ContinueElementException)

Example 27 with MiniLangException

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

the class SimpleMethodTest method run.

@Override
public void run(TestResult result) {
    result.startTest(this);
    try {
        // define request
        Security security = SecurityFactory.getInstance(delegator);
        MockServletContext servletContext = new MockServletContext();
        request.setAttribute("security", security);
        request.setAttribute("servletContext", servletContext);
        request.setAttribute("delegator", delegator);
        request.setAttribute("dispatcher", dispatcher);
        Map<String, Object> serviceResult = SimpleMethod.runSimpleService(methodLocation, methodName, dispatcher.getDispatchContext(), UtilMisc.toMap("test", this, "testResult", result, "locale", Locale.getDefault(), "request", request, "response", response));
        // do something with the errorMessage
        String errorMessage = (String) serviceResult.get(ModelService.ERROR_MESSAGE);
        if (UtilValidate.isNotEmpty(errorMessage)) {
            result.addFailure(this, new AssertionFailedError(errorMessage));
        }
        // do something with the errorMessageList
        List<Object> errorMessageList = UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_LIST));
        if (UtilValidate.isNotEmpty(errorMessageList)) {
            for (Object message : errorMessageList) {
                result.addFailure(this, new AssertionFailedError(message.toString()));
            }
        }
        // do something with the errorMessageMap
        Map<String, Object> errorMessageMap = UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_MAP));
        if (!UtilValidate.isEmpty(errorMessageMap)) {
            for (Map.Entry<String, Object> entry : errorMessageMap.entrySet()) {
                result.addFailure(this, new AssertionFailedError(entry.getKey() + ": " + entry.getValue()));
            }
        }
    } catch (MiniLangException e) {
        result.addError(this, e);
    } catch (SecurityConfigurationException e) {
        result.addError(this, e);
    }
    result.endTest(this);
}
Also used : SecurityConfigurationException(org.apache.ofbiz.security.SecurityConfigurationException) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) Security(org.apache.ofbiz.security.Security) AssertionFailedError(junit.framework.AssertionFailedError) Map(java.util.Map) MockServletContext(org.springframework.mock.web.MockServletContext)

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