Search in sources :

Example 1 with MiniLangRuntimeException

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

the class CallObjectMethod method exec.

@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
    Object methodObject = this.objFieldFma.get(methodContext.getEnvMap());
    if (methodObject == null) {
        throw new MiniLangRuntimeException("Object not found: " + this.objFieldFma, this);
    }
    MiniLangUtil.callMethod(this, methodContext, parameters, methodObject.getClass(), methodObject, methodName, retFieldFma);
    return true;
}
Also used : MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException) StringObject(org.apache.ofbiz.minilang.method.StringObject) FieldObject(org.apache.ofbiz.minilang.method.FieldObject) MethodObject(org.apache.ofbiz.minilang.method.MethodObject)

Example 2 with MiniLangRuntimeException

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

the class SetServiceFields method exec.

@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
    Map<String, ? extends Object> fromMap = mapFma.get(methodContext.getEnvMap());
    if (fromMap == null) {
        if (Debug.verboseOn()) {
            Debug.logVerbose("The from map in set-service-field was not found with name: " + mapFma, module);
        }
        return true;
    }
    String serviceName = serviceNameFse.expandString(methodContext.getEnvMap());
    ModelService modelService = null;
    try {
        modelService = methodContext.getDispatcher().getDispatchContext().getModelService(serviceName);
    } catch (GenericServiceException e) {
        throw new MiniLangRuntimeException("Could not get service definition for service name \"" + serviceName + "\": " + e.getMessage(), this);
    }
    Map<String, Object> toMap = toMapFma.get(methodContext.getEnvMap());
    if (toMap == null) {
        toMap = new HashMap<String, Object>();
        toMapFma.put(methodContext.getEnvMap(), toMap);
    }
    List<Object> errorMessages = new LinkedList<Object>();
    Map<String, Object> validAttributes = modelService.makeValid(fromMap, mode, true, errorMessages, methodContext.getTimeZone(), methodContext.getLocale());
    if (errorMessages.size() > 0) {
        for (Object obj : errorMessages) {
            simpleMethod.addErrorMessage(methodContext, (String) obj);
        }
        throw new MiniLangRuntimeException("Errors encountered while setting service attributes for service name \"" + serviceName + "\"", this);
    }
    toMap.putAll(validAttributes);
    return true;
}
Also used : MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) LinkedList(java.util.LinkedList) ModelService(org.apache.ofbiz.service.ModelService)

Example 3 with MiniLangRuntimeException

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

the class CallSimpleMethod method exec.

@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
    if (UtilValidate.isEmpty(this.methodName)) {
        throw new MiniLangRuntimeException("method-name attribute is empty", this);
    }
    SimpleMethod simpleMethodToCall = SimpleMethod.getSimpleMethod(this.xmlURL, this.methodName);
    if (simpleMethodToCall == null) {
        throw new MiniLangRuntimeException("Could not find <simple-method name=\"" + this.methodName + "\"> in XML document " + this.xmlResource, this);
    }
    MethodContext localContext = methodContext;
    if ("function".equals(this.scope)) {
        Map<String, Object> localEnv = new HashMap<String, Object>();
        localEnv.putAll(methodContext.getEnvMap());
        localEnv.remove(this.simpleMethod.getEventResponseCodeName());
        localEnv.remove(this.simpleMethod.getServiceResponseMessageName());
        localContext = new MethodContext(localEnv, methodContext.getLoader(), methodContext.getMethodType());
    }
    String returnVal = simpleMethodToCall.exec(localContext);
    if (Debug.verboseOn()) {
        Debug.logVerbose("Called simple-method named [" + this.methodName + "] in resource [" + this.xmlResource + "], returnVal is [" + returnVal + "]", module);
    }
    if (simpleMethodToCall.getDefaultErrorCode().equals(returnVal)) {
        if (methodContext.getMethodType() == MethodContext.EVENT) {
            methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode());
        } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
            methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode());
        }
        return false;
    }
    if (methodContext.getMethodType() == MethodContext.EVENT) {
        // FIXME: This doesn't make sense. We are comparing the called method's response code with this method's
        // response code. Since response codes are configurable per method, this code will fail.
        String responseCode = (String) localContext.getEnv(this.simpleMethod.getEventResponseCodeName());
        if (this.simpleMethod.getDefaultErrorCode().equals(responseCode)) {
            Debug.logWarning("Got error [" + responseCode + "] calling inline simple-method named [" + this.methodName + "] in resource [" + this.xmlResource + "], message is " + methodContext.getEnv(this.simpleMethod.getEventErrorMessageName()), module);
            return false;
        }
    } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
        // FIXME: This doesn't make sense. We are comparing the called method's response message with this method's
        // response message. Since response messages are configurable per method, this code will fail.
        String responseMessage = (String) localContext.getEnv(this.simpleMethod.getServiceResponseMessageName());
        if (this.simpleMethod.getDefaultErrorCode().equals(responseMessage)) {
            Debug.logWarning("Got error [" + responseMessage + "] calling inline simple-method named [" + this.methodName + "] in resource [" + this.xmlResource + "], message is " + methodContext.getEnv(this.simpleMethod.getServiceErrorMessageName()) + ", and the error message list is: " + methodContext.getEnv(this.simpleMethod.getServiceErrorMessageListName()), module);
            return false;
        }
    }
    if ("function".equals(this.scope) && this.resultToFieldList != null) {
        Map<String, Object> results = localContext.getResults();
        if (results != null) {
            for (ResultToField resultToField : this.resultToFieldList) {
                resultToField.exec(methodContext.getEnvMap(), results);
            }
        }
    }
    return true;
}
Also used : MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException) HashMap(java.util.HashMap) SimpleMethod(org.apache.ofbiz.minilang.SimpleMethod) MethodContext(org.apache.ofbiz.minilang.method.MethodContext)

Example 4 with MiniLangRuntimeException

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

the class MakeNextSeqId method exec.

@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
    GenericValue value = valueFma.get(methodContext.getEnvMap());
    if (value == null) {
        throw new MiniLangRuntimeException("Entity value not found with name: " + valueFma, this);
    }
    String seqFieldName = seqFieldNameFse.expandString(methodContext.getEnvMap());
    String numericPaddingStr = numericPaddingFse.expandString(methodContext.getEnvMap());
    String incrementByStr = incrementByFse.expandString(methodContext.getEnvMap());
    int numericPadding = 5;
    if (!numericPaddingStr.isEmpty()) {
        try {
            numericPadding = Integer.parseInt(numericPaddingStr);
        } catch (Exception e) {
            throw new MiniLangRuntimeException("Invalid number in \"numeric-padding\" attribute", this);
        }
    }
    int incrementBy = 1;
    if (!incrementByStr.isEmpty()) {
        try {
            incrementBy = Integer.parseInt(incrementByStr);
        } catch (Exception e) {
            throw new MiniLangRuntimeException("Invalid number in \"increment-by\" attribute", this);
        }
    }
    value.getDelegator().setNextSubSeqId(value, seqFieldName, numericPadding, incrementBy);
    return true;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException) MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException) MiniLangException(org.apache.ofbiz.minilang.MiniLangException)

Example 5 with MiniLangRuntimeException

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

the class RemoveByAnd method exec.

@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
    @Deprecated String entityName = entityNameFse.expandString(methodContext.getEnvMap());
    if (entityName.isEmpty()) {
        throw new MiniLangRuntimeException("Entity name not found.", this);
    }
    try {
        Delegator delegator = getDelegator(methodContext);
        delegator.removeByAnd(entityName, mapFma.get(methodContext.getEnvMap()));
    } catch (GenericEntityException e) {
        String errMsg = "Exception thrown while removing entities: " + e.getMessage();
        Debug.logWarning(e, errMsg, module);
        simpleMethod.addErrorMessage(methodContext, errMsg);
        return false;
    }
    return true;
}
Also used : Delegator(org.apache.ofbiz.entity.Delegator) MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException)

Aggregations

MiniLangRuntimeException (org.apache.ofbiz.minilang.MiniLangRuntimeException)26 GenericValue (org.apache.ofbiz.entity.GenericValue)10 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)8 MiniLangException (org.apache.ofbiz.minilang.MiniLangException)8 Delegator (org.apache.ofbiz.entity.Delegator)5 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 SimpleMethod (org.apache.ofbiz.minilang.SimpleMethod)2 FieldObject (org.apache.ofbiz.minilang.method.FieldObject)2 MethodObject (org.apache.ofbiz.minilang.method.MethodObject)2 StringObject (org.apache.ofbiz.minilang.method.StringObject)2 Calendar (com.ibm.icu.util.Calendar)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 Timestamp (java.sql.Timestamp)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1