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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations