/** * Invokes the action for the object (checking it is visible) and then delegates to the {@link * org.apache.isis.viewer.restfulobjects.rendering.service.RepresentationService} to render a * representation of the result of that action. * * <p>The action must have {@link ActionSemantics.Of#isSafeInNature()} safe/request-cacheable} * semantics otherwise an error response is thrown. */ public Response invokeActionQueryOnly(final String actionId, final JsonRepresentation arguments) { final ObjectAdapterAccessHelper accessHelper = new ObjectAdapterAccessHelper(representationServiceContext, objectAdapter); final ObjectAction action = accessHelper.getObjectActionThatIsVisibleForIntent( actionId, ObjectAdapterAccessHelper.Intent.MUTATE); final ActionSemantics.Of actionSemantics = action.getSemantics(); if (!actionSemantics.isSafeInNature()) { throw RestfulObjectsApplicationException.createWithMessage( RestfulResponse.HttpStatusCode.METHOD_NOT_ALLOWED, "Method not allowed; action '%s' does not have safe semantics", action.getId()); } return invokeActionUsingAdapters(action, arguments, ActionResultReprRenderer.SelfLink.INCLUDED); }
void appendObjectActionInvokePath( final ObjectSpecification objectSpec, final ObjectAction objectAction) { final String objectType = objectTypeFor(objectSpec); final String actionId = objectAction.getId(); final List<ObjectActionParameter> parameters = objectAction.getParameters(); final Path path = new Path(); swagger.path( String.format("/objects/%s/{objectId}/actions/%s/invoke", objectType, actionId), path); final String tag = tagFor(objectType, null); final Operation invokeOperation = new Operation() .tag(tag) .description( Util.roSpec("19.1") + ": (invoke) resource of " + objectType + "#" + actionId) .parameter(new PathParameter().name("objectId").type("string")) .produces("application/json;profile=urn:org.apache.isis/v1") .produces("application/json;profile=urn:org.apache.isis/v1;suppress=true") .produces("application/json;profile=urn:org.restfulobjects:repr-types/action-result"); final ActionSemantics.Of semantics = objectAction.getSemantics(); if (semantics.isSafeInNature()) { path.get(invokeOperation); for (final ObjectActionParameter parameter : parameters) { invokeOperation.parameter( new QueryParameter() .name(parameter.getId()) .description( Util.roSpec("2.9.1") + (!Strings.isNullOrEmpty(parameter.getDescription()) ? (": " + parameter.getDescription()) : "")) .required(false) .type("string")); } if (!parameters.isEmpty()) { invokeOperation.parameter( new QueryParameter() .name("x-isis-querystring") .description( Util.roSpec("2.10") + ": all (formal) arguments as base64 encoded string") .required(false) .type("string")); } } else { if (semantics.isIdempotentInNature()) { path.put(invokeOperation); } else { path.post(invokeOperation); } final ModelImpl bodyParam = new ModelImpl().type("object"); for (final ObjectActionParameter parameter : parameters) { final ObjectSpecification specification = parameter.getSpecification(); final Property valueProperty = specification.isValue() ? modelFor(specification) : refToLinkModel(); bodyParam.property( parameter.getId(), new ObjectProperty().property("value", valueProperty)); } invokeOperation .consumes("application/json") .parameter(new BodyParameter().name("body").schema(bodyParam)); } invokeOperation.response( 200, new Response() .description(objectType + "#" + actionId) .schema(actionReturnTypeFor(objectAction))); }
void appendServiceActionInvokePath( final ObjectSpecification serviceSpec, final ObjectAction serviceAction) { final String serviceId = serviceIdFor(serviceSpec); final String actionId = serviceAction.getId(); final List<ObjectActionParameter> parameters = serviceAction.getParameters(); final Path path = new Path(); swagger.path(String.format("/services/%s/actions/%s/invoke", serviceId, actionId), path); final String tag = tagFor(serviceId, "> services"); final Operation invokeOperation = new Operation() .tag(tag) .description( Util.roSpec("19.1") + ": (invoke) resource of " + serviceId + "#" + actionId) .produces("application/json;profile=urn:org.apache.isis/v1") .produces("application/json;profile=urn:org.apache.isis/v1;suppress=true") .produces("application/json;profile=urn:org.restfulobjects:repr-types/action-result"); final ActionSemantics.Of semantics = serviceAction.getSemantics(); if (semantics.isSafeInNature()) { path.get(invokeOperation); for (final ObjectActionParameter parameter : parameters) { invokeOperation.parameter( new QueryParameter() .name(parameter.getId()) .description( Util.roSpec("2.9.1") + (!Strings.isNullOrEmpty(parameter.getDescription()) ? (": " + parameter.getDescription()) : "")) .required(false) .type("string")); } if (!parameters.isEmpty()) { invokeOperation.parameter( new QueryParameter() .name("x-isis-querystring") .description( Util.roSpec("2.10") + ": all (formal) arguments as base64 encoded string") .required(false) .type("string")); } } else { if (semantics.isIdempotentInNature()) { path.put(invokeOperation); } else { path.post(invokeOperation); } final ModelImpl bodyParam = new ModelImpl().type("object"); for (final ObjectActionParameter parameter : parameters) { final Property valueProperty; // TODO: need to switch on parameter's type and create appropriate impl of valueProperty // if(parameter.getSpecification().isValue()) ... valueProperty = stringProperty(); bodyParam.property( parameter.getId(), new ObjectProperty().property("value", valueProperty)); } invokeOperation .consumes("application/json") .parameter(new BodyParameter().name("body").schema(bodyParam)); } invokeOperation.response( 200, new Response() .description( serviceId + "#" + actionId + " , if Accept: application/json;profile=urn:org.apache.isis/v1") .schema(actionReturnTypeFor(serviceAction))); }