Search in sources :

Example 6 with MiniLangRuntimeException

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

the class SetNonpkFields 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);
    }
    Map<String, ? extends Object> theMap = mapFma.get(methodContext.getEnvMap());
    if (theMap == null) {
        throw new MiniLangRuntimeException("Map not found with name: " + mapFma, this);
    }
    boolean setIfNull = !"false".equals(setIfNullFse.expand(methodContext.getEnvMap()));
    value.setNonPKFields(theMap, setIfNull);
    return true;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException)

Example 7 with MiniLangRuntimeException

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

the class RemoveList 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.removeAll(values);
    } 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 : GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException)

Example 8 with MiniLangRuntimeException

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

the class SetCurrentUserLogin method exec.

@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
    GenericValue userLogin = valueFma.get(methodContext.getEnvMap());
    if (userLogin == null) {
        throw new MiniLangRuntimeException("Entity value not found with name: " + valueFma, this);
    }
    methodContext.setUserLogin(userLogin, this.simpleMethod.getUserLoginEnvName());
    return true;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException)

Example 9 with MiniLangRuntimeException

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

the class SetPkFields 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);
    }
    Map<String, ? extends Object> theMap = mapFma.get(methodContext.getEnvMap());
    if (theMap == null) {
        throw new MiniLangRuntimeException("Map not found with name: " + mapFma, this);
    }
    boolean setIfNull = !"false".equals(setIfNullFse.expand(methodContext.getEnvMap()));
    value.setPKFields(theMap, setIfNull);
    return true;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException)

Example 10 with MiniLangRuntimeException

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

the class RegexpCondition method checkCondition.

@Override
public boolean checkCondition(MethodContext methodContext) throws MiniLangException {
    Object fieldVal = fieldFma.get(methodContext.getEnvMap());
    if (fieldVal == null) {
        fieldVal = "";
    } else if (!(fieldVal instanceof String)) {
        try {
            fieldVal = MiniLangUtil.convertType(fieldVal, String.class, methodContext.getLocale(), methodContext.getTimeZone(), null);
        } catch (Exception e) {
            throw new MiniLangRuntimeException(e, this);
        }
    }
    String regExp = exprFse.expandString(methodContext.getEnvMap());
    Pattern pattern = null;
    try {
        pattern = PatternFactory.createOrGetPerl5CompiledPattern(regExp, true);
    } catch (MalformedPatternException e) {
        Debug.logError(e, "Regular Expression [" + regExp + "] is mal-formed: " + e.toString(), module);
        throw new MiniLangRuntimeException(e, this);
    }
    PatternMatcher matcher = new Perl5Matcher();
    if (matcher.matches((String) fieldVal, pattern)) {
        // Debug.logInfo("The string [" + fieldVal + "] matched the pattern expr [" + pattern.getPattern() + "]", module);
        return true;
    } else {
        // Debug.logInfo("The string [" + fieldVal + "] did NOT match the pattern expr [" + pattern.getPattern() + "]", module);
        return false;
    }
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException) MiniLangException(org.apache.ofbiz.minilang.MiniLangException)

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