Introduce restconf.server.{api,spi,mdsal}
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / impl / RestconfOperationsServiceImpl.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import javax.ws.rs.GET;
13 import javax.ws.rs.Path;
14 import javax.ws.rs.PathParam;
15 import javax.ws.rs.Produces;
16 import javax.ws.rs.core.MediaType;
17 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
18 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
19 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
20
21 /**
22  * Container that provides access to the data-model specific operations supported by the server.
23  */
24 @Path("/")
25 public final class RestconfOperationsServiceImpl {
26     private final MdsalRestconfServer server;
27
28     /**
29      * Set {@link DatabindProvider} for getting actual {@link EffectiveModelContext}.
30      *
31      * @param server a {@link MdsalRestconfServer}
32      */
33     public RestconfOperationsServiceImpl(final MdsalRestconfServer server) {
34         this.server = requireNonNull(server);
35     }
36
37     /**
38      * List RPC and action operations in RFC7951 format.
39      *
40      * @return A string containing a JSON document conforming to both RFC8040 and RFC7951.
41      */
42     @GET
43     @Path("/operations")
44     @Produces({ MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON })
45     public String getOperationsJSON() {
46         return OperationsContent.JSON.bodyFor(server.bindRequestRoot().inference());
47     }
48
49     /**
50      * Retrieve list of operations and actions supported by the server or device in JSON format.
51      *
52      * @param identifier path parameter to identify device and/or operation
53      * @return A string containing a JSON document conforming to both RFC8040 and RFC7951.
54      */
55     @GET
56     @Path("/operations/{identifier:.+}")
57     @Produces({ MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON })
58     public String getOperationJSON(@PathParam("identifier") final String identifier) {
59         return OperationsContent.JSON.bodyFor(server.bindRequestPath(identifier).inference());
60     }
61
62     /**
63      * List RPC and action operations in RFC8040 XML format.
64      *
65      * @return A string containing an XML document conforming to both RFC8040 section 11.3.1 and page 84.
66      */
67     @GET
68     @Path("/operations")
69     @Produces({ MediaTypes.APPLICATION_YANG_DATA_XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
70     public String getOperationsXML() {
71         return OperationsContent.XML.bodyFor(server.bindRequestRoot().inference());
72     }
73
74     /**
75      * Retrieve list of operations and actions supported by the server or device in XML format.
76      *
77      * @param identifier path parameter to identify device and/or operation
78      * @return A string containing an XML document conforming to both RFC8040 section 11.3.1 and page 84.
79      */
80     @GET
81     @Path("/operations/{identifier:.+}")
82     @Produces({ MediaTypes.APPLICATION_YANG_DATA_XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
83     public String getOperationXML(@PathParam("identifier") final String identifier) {
84         return OperationsContent.XML.bodyFor(server.bindRequestPath(identifier).inference());
85     }
86 }