import static java.util.Objects.requireNonNull;
-import java.util.Optional;
+import javax.ws.rs.GET;
import javax.ws.rs.Path;
-import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
-import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfOperationsService;
-import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
/**
- * Implementation of {@link RestconfOperationsService}.
+ * Container that provides access to the data-model specific operations supported by the server.
*/
@Path("/")
-public class RestconfOperationsServiceImpl implements RestconfOperationsService {
- private final DatabindProvider databindProvider;
- private final DOMMountPointService mountPointService;
+public final class RestconfOperationsServiceImpl {
+ private final MdsalRestconfServer server;
/**
* Set {@link DatabindProvider} for getting actual {@link EffectiveModelContext}.
*
- * @param databindProvider a {@link DatabindProvider}
- * @param mountPointService a {@link DOMMountPointService}
+ * @param server a {@link MdsalRestconfServer}
*/
- public RestconfOperationsServiceImpl(final DatabindProvider databindProvider,
- final DOMMountPointService mountPointService) {
- this.databindProvider = requireNonNull(databindProvider);
- this.mountPointService = requireNonNull(mountPointService);
+ public RestconfOperationsServiceImpl(final MdsalRestconfServer server) {
+ this.server = requireNonNull(server);
}
- @Override
+ /**
+ * List RPC and action operations in RFC7951 format.
+ *
+ * @return A string containing a JSON document conforming to both RFC8040 and RFC7951.
+ */
+ @GET
+ @Path("/operations")
+ @Produces({ MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON })
public String getOperationsJSON() {
- return OperationsContent.JSON.bodyFor(databindProvider.currentContext().modelContext());
+ return OperationsContent.JSON.bodyFor(server.bindRequestRoot().inference());
}
- @Override
- public String getOperationJSON(final String identifier) {
- final var identifierContext = ParserIdentifier.toInstanceIdentifier(identifier,
- databindProvider.currentContext().modelContext(), Optional.of(mountPointService));
- return OperationsContent.JSON.bodyFor(identifierContext);
+ /**
+ * Retrieve list of operations and actions supported by the server or device in JSON format.
+ *
+ * @param identifier path parameter to identify device and/or operation
+ * @return A string containing a JSON document conforming to both RFC8040 and RFC7951.
+ */
+ @GET
+ @Path("/operations/{identifier:.+}")
+ @Produces({ MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON })
+ public String getOperationJSON(@PathParam("identifier") final String identifier) {
+ return OperationsContent.JSON.bodyFor(server.bindRequestPath(identifier).inference());
}
- @Override
+ /**
+ * List RPC and action operations in RFC8040 XML format.
+ *
+ * @return A string containing an XML document conforming to both RFC8040 section 11.3.1 and page 84.
+ */
+ @GET
+ @Path("/operations")
+ @Produces({ MediaTypes.APPLICATION_YANG_DATA_XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public String getOperationsXML() {
- return OperationsContent.XML.bodyFor(databindProvider.currentContext().modelContext());
+ return OperationsContent.XML.bodyFor(server.bindRequestRoot().inference());
}
- @Override
- public String getOperationXML(final String identifier) {
- final var identifierContext = ParserIdentifier.toInstanceIdentifier(identifier,
- databindProvider.currentContext().modelContext(), Optional.of(mountPointService));
- return OperationsContent.XML.bodyFor(identifierContext);
+ /**
+ * Retrieve list of operations and actions supported by the server or device in XML format.
+ *
+ * @param identifier path parameter to identify device and/or operation
+ * @return A string containing an XML document conforming to both RFC8040 section 11.3.1 and page 84.
+ */
+ @GET
+ @Path("/operations/{identifier:.+}")
+ @Produces({ MediaTypes.APPLICATION_YANG_DATA_XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ public String getOperationXML(@PathParam("identifier") final String identifier) {
+ return OperationsContent.XML.bodyFor(server.bindRequestPath(identifier).inference());
}
}