use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.
the class Loop method exec.
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
String countStr = this.countFse.expandString(methodContext.getEnvMap());
int count = 0;
try {
count = Double.valueOf(countStr).intValue();
} catch (NumberFormatException e) {
throw new MiniLangRuntimeException("Error while converting \"" + countStr + "\" to a number: " + e.getMessage(), this);
}
if (count < 0) {
throw new MiniLangRuntimeException("Unable to execute loop operation because the count is negative: " + countStr, this);
}
for (int i = 0; i < count; i++) {
this.fieldFma.put(methodContext.getEnvMap(), i);
try {
for (MethodOperation methodOperation : subOps) {
if (!methodOperation.exec(methodContext)) {
return false;
}
}
} catch (MiniLangException e) {
if (e instanceof BreakElementException) {
break;
}
if (e instanceof ContinueElementException) {
continue;
}
throw e;
}
}
return true;
}
use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.
the class SimpleMethodTest method run.
@Override
public void run(TestResult result) {
result.startTest(this);
try {
// define request
Security security = SecurityFactory.getInstance(delegator);
MockServletContext servletContext = new MockServletContext();
request.setAttribute("security", security);
request.setAttribute("servletContext", servletContext);
request.setAttribute("delegator", delegator);
request.setAttribute("dispatcher", dispatcher);
Map<String, Object> serviceResult = SimpleMethod.runSimpleService(methodLocation, methodName, dispatcher.getDispatchContext(), UtilMisc.toMap("test", this, "testResult", result, "locale", Locale.getDefault(), "request", request, "response", response));
// do something with the errorMessage
String errorMessage = (String) serviceResult.get(ModelService.ERROR_MESSAGE);
if (UtilValidate.isNotEmpty(errorMessage)) {
result.addFailure(this, new AssertionFailedError(errorMessage));
}
// do something with the errorMessageList
List<Object> errorMessageList = UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_LIST));
if (UtilValidate.isNotEmpty(errorMessageList)) {
for (Object message : errorMessageList) {
result.addFailure(this, new AssertionFailedError(message.toString()));
}
}
// do something with the errorMessageMap
Map<String, Object> errorMessageMap = UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_MAP));
if (!UtilValidate.isEmpty(errorMessageMap)) {
for (Map.Entry<String, Object> entry : errorMessageMap.entrySet()) {
result.addFailure(this, new AssertionFailedError(entry.getKey() + ": " + entry.getValue()));
}
}
} catch (MiniLangException e) {
result.addError(this, e);
} catch (SecurityConfigurationException e) {
result.addError(this, e);
}
result.endTest(this);
}
Aggregations