001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *        http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 */
019package org.apache.isis.viewer.restfulobjects.applib.domainobjects;
020
021import java.io.InputStream;
022
023import javax.ws.rs.Consumes;
024import javax.ws.rs.GET;
025import javax.ws.rs.POST;
026import javax.ws.rs.PUT;
027import javax.ws.rs.Path;
028import javax.ws.rs.PathParam;
029import javax.ws.rs.Produces;
030import javax.ws.rs.QueryParam;
031import javax.ws.rs.core.MediaType;
032import javax.ws.rs.core.Response;
033
034import org.apache.isis.viewer.restfulobjects.applib.RestfulMediaType;
035import org.jboss.resteasy.annotations.ClientResponseType;
036
037@Path("/services")
038public interface DomainServiceResource {
039
040    @GET
041    @Path("/")
042    @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_LIST, RestfulMediaType.APPLICATION_JSON_ERROR })
043    @ClientResponseType(entityType = String.class)
044    public Response services();
045
046    // //////////////////////////////////////////////////////////
047    // domain service
048    // //////////////////////////////////////////////////////////
049
050    @GET
051    @Path("/{serviceId}")
052    @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_OBJECT, RestfulMediaType.APPLICATION_JSON_ERROR })
053    @ClientResponseType(entityType = String.class)
054    public Response service(@PathParam("serviceId") final String serviceId);
055
056    // //////////////////////////////////////////////////////////
057    // domain service property
058    // //////////////////////////////////////////////////////////
059
060    @GET
061    @Path("/{serviceId}/properties/{propertyId}")
062    @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_OBJECT_PROPERTY, RestfulMediaType.APPLICATION_JSON_ERROR })
063    public Response propertyDetails(@PathParam("serviceId") final String serviceId, @PathParam("propertyId") final String propertyId);
064
065    // //////////////////////////////////////////////////////////
066    // domain service action
067    // //////////////////////////////////////////////////////////
068
069    @GET
070    @Path("/{serviceId}/actions/{actionId}")
071    @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_OBJECT_ACTION, RestfulMediaType.APPLICATION_JSON_ERROR })
072    @ClientResponseType(entityType = String.class)
073    public Response actionPrompt(@PathParam("serviceId") final String serviceId, @PathParam("actionId") final String actionId);
074
075    // //////////////////////////////////////////////////////////
076    // domain service action invoke
077    // //////////////////////////////////////////////////////////
078
079    /**
080     * Because it isn't possible with the RestEasy client-side framework to specify a query string nor to pass arbitrary query params; instead 
081     * we provide an additional syntax of passing an Isis-defined query param <tt>x-isis-querystring</tt>.
082     * 
083     * <p>
084     * The content of this is taken to be the URL encoded map of arguments.
085     */
086    @GET
087    @Path("/{serviceId}/actions/{actionId}/invoke")
088    @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ACTION_RESULT, RestfulMediaType.APPLICATION_JSON_ERROR })
089    @ClientResponseType(entityType = String.class)
090    public Response invokeActionQueryOnly(@PathParam("serviceId") final String serviceId, @PathParam("actionId") final String actionId, @QueryParam("x-isis-querystring") final String xIsisQueryString);
091
092    @PUT
093    @Path("/{serviceId}/actions/{actionId}/invoke")
094    @Consumes({ MediaType.APPLICATION_JSON })
095    @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ACTION_RESULT, RestfulMediaType.APPLICATION_JSON_ERROR })
096    @ClientResponseType(entityType = String.class)
097    public Response invokeActionIdempotent(@PathParam("serviceId") final String serviceId, @PathParam("actionId") final String actionId, final InputStream arguments);
098
099    @POST
100    @Path("/{serviceId}/actions/{actionId}/invoke")
101    @Consumes({ MediaType.APPLICATION_JSON })
102    @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ACTION_RESULT, RestfulMediaType.APPLICATION_JSON_ERROR })
103    @ClientResponseType(entityType = String.class)
104    public Response invokeAction(@PathParam("serviceId") final String serviceId, @PathParam("actionId") final String actionId, final InputStream arguments);
105}