Search in sources :

Example 16 with MiniLangRuntimeException

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

the class CreateObject method exec.

@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
    Object[] args = null;
    Class<?>[] parameterTypes = null;
    if (parameters != null) {
        args = new Object[parameters.size()];
        parameterTypes = new Class<?>[parameters.size()];
        int i = 0;
        for (MethodObject<?> methodObjectDef : parameters) {
            args[i] = methodObjectDef.getObject(methodContext);
            Class<?> typeClass = null;
            try {
                typeClass = methodObjectDef.getTypeClass(methodContext);
            } catch (ClassNotFoundException e) {
                String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Parameter type not found with name " + methodObjectDef.getTypeName() + "]";
                Debug.logWarning(e, errMsg, module);
                simpleMethod.addErrorMessage(methodContext, errMsg);
                return false;
            }
            parameterTypes[i] = typeClass;
            i++;
        }
    }
    try {
        Constructor<?> constructor = targetClass.getConstructor(parameterTypes);
        fieldFma.put(methodContext.getEnvMap(), constructor.newInstance(args));
    } catch (Exception e) {
        throw new MiniLangRuntimeException(e, this);
    }
    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) MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException) MiniLangException(org.apache.ofbiz.minilang.MiniLangException)

Example 17 with MiniLangRuntimeException

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

the class MakeValue method exec.

@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
    String entityName = entityNameFse.expandString(methodContext.getEnvMap());
    if (entityName.isEmpty()) {
        throw new MiniLangRuntimeException("Entity name not found.", this);
    }
    Delegator delegator = getDelegator(methodContext);
    valueFma.put(methodContext.getEnvMap(), delegator.makeValidValue(entityName, mapFma.get(methodContext.getEnvMap())));
    return true;
}
Also used : Delegator(org.apache.ofbiz.entity.Delegator) MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException)

Example 18 with MiniLangRuntimeException

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

the class GetRelatedOne 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 relationName = relationNameFse.expandString(methodContext.getEnvMap());
    boolean useCache = "true".equals(useCacheFse.expandString(methodContext.getEnvMap()));
    try {
        toValueFma.put(methodContext.getEnvMap(), value.getRelatedOne(relationName, useCache));
    } catch (GenericEntityException e) {
        String errMsg = "Exception thrown while finding related value: " + e.getMessage();
        Debug.logWarning(e, errMsg, module);
        simpleMethod.addErrorMessage(methodContext, errMsg);
        return false;
    }
    return true;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException)

Example 19 with MiniLangRuntimeException

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

the class RemoveRelated 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 relationName = relationNameFse.expandString(methodContext.getEnvMap());
    try {
        value.getDelegator().removeRelated(relationName, value);
    } catch (GenericEntityException e) {
        String errMsg = "Exception thrown while removing related entities: " + e.getMessage();
        Debug.logWarning(e, errMsg, module);
        simpleMethod.addErrorMessage(methodContext, errMsg);
        return false;
    }
    return true;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException)

Example 20 with MiniLangRuntimeException

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

the class StoreList method exec.

@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
    List<GenericValue> values = listFma.get(methodContext.getEnvMap());
    if (values == null) {
        throw new MiniLangRuntimeException("Entity value list not found with name: " + listFma, this);
    }
    try {
        Delegator delegator = getDelegator(methodContext);
        delegator.storeAll(values);
    } catch (GenericEntityException e) {
        String errMsg = "Exception thrown while storing entities: " + e.getMessage();
        Debug.logWarning(e, errMsg, module);
        simpleMethod.addErrorMessage(methodContext, errMsg);
        return false;
    }
    return true;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) 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