private static List<JsonRepresentation> argListFor(final ObjectAction action, final JsonRepresentation arguments) { final List<JsonRepresentation> argList = Lists.newArrayList(); // ensure that we have no arguments that are not parameters for (final Map.Entry<String, JsonRepresentation> arg : arguments.mapIterable()) { final String argName = arg.getKey(); if(argName.startsWith("x-ro")) { continue; } if (action.getParameterById(argName) == null) { String reason = String.format("Argument '%s' found but no such parameter", argName); arguments.mapPut("x-ro-invalidReason", reason); throw RestfulObjectsApplicationException.createWithBody(RestfulResponse.HttpStatusCode.BAD_REQUEST, arguments, reason); } } // ensure that an argument value has been provided for all non-optional // parameters final List<ObjectActionParameter> parameters = action.getParameters(); for (final ObjectActionParameter param : parameters) { final String paramId = param.getId(); final JsonRepresentation argRepr = arguments.getRepresentation(paramId); if (argRepr == null && !param.isOptional()) { String reason = String.format("No argument found for (mandatory) parameter '%s'", paramId); arguments.mapPut("x-ro-invalidReason", reason); throw RestfulObjectsApplicationException.createWithBody(RestfulResponse.HttpStatusCode.BAD_REQUEST, arguments, reason); } argList.add(argRepr); } return argList; }
private static List<JsonRepresentation> argListFor(final ObjectAction action, final JsonRepresentation arguments) { final List<JsonRepresentation> argList = Lists.newArrayList(); // ensure that we have no arguments that are not parameters for (final Entry<String, JsonRepresentation> arg : arguments.mapIterable()) { final String argName = arg.getKey(); if (action.getParameterById(argName) == null) { String reason = String.format("Argument '%s' found but no such parameter", argName); arguments.mapPut("x-ro-invalidReason", reason); throw RestfulObjectsApplicationException.createWithBody(HttpStatusCode.BAD_REQUEST, arguments, reason); } } // ensure that an argument value has been provided for all non-optional // parameters final List<ObjectActionParameter> parameters = action.getParameters(); for (final ObjectActionParameter param : parameters) { final String paramId = param.getId(); final JsonRepresentation argRepr = arguments.getRepresentation(paramId); if (argRepr == null && !param.isOptional()) { String reason = String.format("No argument found for (mandatory) parameter '%s'", paramId); arguments.mapPut("x-ro-invalidReason", reason); throw RestfulObjectsApplicationException.createWithBody(HttpStatusCode.BAD_REQUEST, arguments, reason); } argList.add(argRepr); } return argList; }
private static List<JsonRepresentation> argListFor(final ObjectAction action, final JsonRepresentation arguments) { final List<JsonRepresentation> argList = Lists.newArrayList(); // ensure that we have no arguments that are not parameters for (final Entry<String, JsonRepresentation> arg : arguments.mapIterable()) { final String argName = arg.getKey(); if (action.getParameterById(argName) == null) { throw RestfulObjectsApplicationException.create(HttpStatusCode.BAD_REQUEST, "Action '%s' does not have a parameter %s but an argument of that name was provided", action.getId(), argName); } } // ensure that an argument value has been provided for all non-optional // parameters final List<ObjectActionParameter> parameters = action.getParameters(); for (final ObjectActionParameter param : parameters) { final String paramId = param.getId(); final JsonRepresentation argRepr = arguments.getRepresentation(paramId); if (argRepr == null && !param.isOptional()) { throw RestfulObjectsApplicationException.create(HttpStatusCode.BAD_REQUEST, "Action '%s', no argument found for (mandatory) parameter '%s'", action.getId(), paramId); } argList.add(argRepr); } return argList; }