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