final String override = context.getParameter("_" + RESULT_OVERRIDE);
String resultName = context.getParameter("_" + RESULT_NAME);
final String message = context.getParameter("_" + MESSAGE);
resultName = resultName == null ? RequestContext.RESULT : resultName;
FormState entryState = null;
try {
final ObjectAdapter object = MethodsUtils.findObject(context, objectId);
// FIXME need to find method based on the set of parameters. otherwise overloaded method may be incorrectly
// selected.
final ObjectAction action = MethodsUtils.findAction(object, methodName);
entryState = validateParameters(context, action, object);
final AuthenticationSession session = context.getSession();
if (session == null && action.isUsable(new AnonymousSession(), object).isVetoed()) {
throw new NotLoggedInException();
}
object.checkLock(context.getVersion(version));
/*
* Version adapterVersion = object.getVersion(); if (adapterVersion.different(context.getVersion(version)))
* {
*
* IsisContext.getMessageBroker().addMessage("The " + object.getSpecification().getSingularName() +
* " was edited " + "by another user (" + adapterVersion.getUser() +
* "). Please make your changes based on their changes.");
*
* entryState.setForm(objectId + ":" + methodName); context.addVariable(ENTRY_FIELDS, entryState,
* Scope.REQUEST); context.addVariable(resultName, objectId, Scope.REQUEST); if (override != null) {
* context.addVariable(resultName, override, Scope.REQUEST); } final String error = entryState.getError();
* if (error != null) { context.addVariable(RequestContext.ERROR, error, Scope.REQUEST); }
*
* String view = context.getParameter(ERRORS); context.setRequestPath(view, Dispatcher.ACTION);
*
* } else
*/
if (entryState.isValid()) {
final boolean hasResult = invokeMethod(context, resultName, object, action, entryState);
String view = context.getParameter(hasResult ? "_" + VIEW : "_" + VOID);
// context.clearVariables(Scope.REQUEST);
final int questionMark = view == null ? -1 : view.indexOf("?");
if (questionMark > -1) {
final String params[] = view.substring(questionMark + 1).split("&");
for (final String param : params) {
final int equals = param.indexOf("=");
context.addVariable(param.substring(0, equals), param.substring(equals + 1), Scope.REQUEST);
view = view.substring(0, questionMark);
}
}
context.setRequestPath(view);
if (message != null) {
final MessageBroker messageBroker = IsisContext.getMessageBroker();
messageBroker.addMessage(message);
}
if (override != null) {
context.addVariable(resultName, override, Scope.REQUEST);
}
if (context.getVariable(resultName) == null) {
context.addVariable(resultName, objectId, Scope.REQUEST);
}
} else {
entryState.setForm(formId);
context.addVariable(ENTRY_FIELDS, entryState, Scope.REQUEST);
context.addVariable(resultName, objectId, Scope.REQUEST);
if (override != null) {
context.addVariable(resultName, override, Scope.REQUEST);
}
final String error = entryState.getError();
/*
* if (error != null) { context.addVariable(RequestContext.ERROR, error, Scope.REQUEST); }
*/
final String view = context.getParameter("_" + ERRORS);
context.setRequestPath(view, Dispatcher.ACTION);
final MessageBroker messageBroker = IsisContext.getMessageBroker();
messageBroker.addWarning(error);
}
} catch (final ConcurrencyException e) {
IsisContext.getMessageBroker().addMessage(e.getMessage());
entryState.setForm(formId);
context.addVariable(ENTRY_FIELDS, entryState, Scope.REQUEST);
context.addVariable(resultName, objectId, Scope.REQUEST);
if (override != null) {
context.addVariable(resultName, override, Scope.REQUEST);
}
final String error = entryState.getError();
if (error != null) {
context.addVariable(RequestContext.ERROR, error, Scope.REQUEST);
}
final String view = context.getParameter("_" + ERRORS);