Use AsyncResponse in deleteData/patchData
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / api / RestconfDataService.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.api;
9
10 import javax.ws.rs.Consumes;
11 import javax.ws.rs.DELETE;
12 import javax.ws.rs.Encoded;
13 import javax.ws.rs.GET;
14 import javax.ws.rs.POST;
15 import javax.ws.rs.PUT;
16 import javax.ws.rs.Path;
17 import javax.ws.rs.PathParam;
18 import javax.ws.rs.Produces;
19 import javax.ws.rs.container.AsyncResponse;
20 import javax.ws.rs.container.Suspended;
21 import javax.ws.rs.core.Context;
22 import javax.ws.rs.core.MediaType;
23 import javax.ws.rs.core.Response;
24 import javax.ws.rs.core.UriInfo;
25 import org.opendaylight.restconf.common.patch.Patch;
26 import org.opendaylight.restconf.common.patch.PatchContext;
27 import org.opendaylight.restconf.common.patch.PatchStatusContext;
28 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
29 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
30
31 /**
32  * The "{+restconf}/data" subtree represents the datastore resource type, which
33  * is a collection of configuration data and state data nodes.
34  *
35  */
36 public interface RestconfDataService {
37     /**
38      * Get target data resource.
39      *
40      * @param identifier
41      *            path to target
42      * @param uriInfo
43      *            URI info
44      * @return {@link NormalizedNodePayload}
45      */
46     @GET
47     @Path("/data/{identifier:.+}")
48     @Produces({
49         MediaTypes.APPLICATION_YANG_DATA_JSON,
50         MediaTypes.APPLICATION_YANG_DATA_XML,
51         MediaType.APPLICATION_JSON,
52         MediaType.APPLICATION_XML,
53         MediaType.TEXT_XML
54     })
55     Response readData(@Encoded @PathParam("identifier") String identifier, @Context UriInfo uriInfo);
56
57     /**
58      * Get target data resource from data root.
59      *
60      * @param uriInfo
61      *            URI info
62      * @return {@link NormalizedNodePayload}
63      */
64     @GET
65     @Path("/data")
66     @Produces({
67         MediaTypes.APPLICATION_YANG_DATA_JSON,
68         MediaTypes.APPLICATION_YANG_DATA_XML,
69         MediaType.APPLICATION_JSON,
70         MediaType.APPLICATION_XML,
71         MediaType.TEXT_XML
72     })
73     Response readData(@Context UriInfo uriInfo);
74
75     /**
76      * Create or replace the target data resource.
77      *
78      * @param identifier
79      *            path to target
80      * @param payload
81      *            data node for put to config DS
82      * @return {@link Response}
83      */
84     @PUT
85     @Path("/data/{identifier:.+}")
86     @Consumes({
87         MediaTypes.APPLICATION_YANG_DATA_JSON,
88         MediaTypes.APPLICATION_YANG_DATA_XML,
89         MediaType.APPLICATION_JSON,
90         MediaType.APPLICATION_XML,
91         MediaType.TEXT_XML
92     })
93     Response putData(@Encoded @PathParam("identifier") String identifier, NormalizedNodePayload payload,
94             @Context UriInfo uriInfo);
95
96     /**
97      * Create a data resource in target.
98      *
99      * @param identifier
100      *            path to target
101      * @param payload
102      *            new data
103      * @param uriInfo
104      *            URI info
105      * @return {@link Response}
106      */
107     @POST
108     @Path("/data/{identifier:.+}")
109     @Consumes({
110         MediaTypes.APPLICATION_YANG_DATA_JSON,
111         MediaTypes.APPLICATION_YANG_DATA_XML,
112         MediaType.APPLICATION_JSON,
113         MediaType.APPLICATION_XML,
114         MediaType.TEXT_XML
115     })
116     Response postData(@Encoded @PathParam("identifier") String identifier, NormalizedNodePayload payload,
117             @Context UriInfo uriInfo);
118
119     /**
120      * Create a data resource.
121      *
122      * @param payload
123      *            new data
124      * @param uriInfo
125      *            URI info
126      * @return {@link Response}
127      */
128     @POST
129     @Path("/data")
130     @Consumes({
131         MediaTypes.APPLICATION_YANG_DATA_JSON,
132         MediaTypes.APPLICATION_YANG_DATA_XML,
133         MediaType.APPLICATION_JSON,
134         MediaType.APPLICATION_XML,
135         MediaType.TEXT_XML
136     })
137     Response postData(NormalizedNodePayload payload, @Context UriInfo uriInfo);
138
139     /**
140      * Delete the target data resource.
141      *
142      * @param identifier path to target
143      * @param ar {@link AsyncResponse} which needs to be completed
144      */
145     @DELETE
146     @Path("/data/{identifier:.+}")
147     void deleteData(@Encoded @PathParam("identifier") String identifier, @Suspended AsyncResponse ar);
148
149     /**
150      * Ordered list of edits that are applied to the target datastore by the
151      * server.
152      *
153      * @param identifier
154      *            path to target
155      * @param context
156      *            edits
157      * @param uriInfo
158      *            URI info
159      * @return {@link PatchStatusContext}
160      */
161     @Patch
162     @Path("/data/{identifier:.+}")
163     @Consumes({
164         MediaTypes.APPLICATION_YANG_PATCH_JSON,
165         MediaTypes.APPLICATION_YANG_PATCH_XML
166     })
167     @Produces({
168         MediaTypes.APPLICATION_YANG_DATA_JSON,
169         MediaTypes.APPLICATION_YANG_DATA_XML
170     })
171     PatchStatusContext patchData(@Encoded @PathParam("identifier") String identifier, PatchContext context,
172                                  @Context UriInfo uriInfo);
173
174     /**
175      * Ordered list of edits that are applied to the datastore by the server.
176      *
177      * @param context
178      *            edits
179      * @param uriInfo
180      *            URI info
181      * @return {@link PatchStatusContext}
182      */
183     @Patch
184     @Path("/data")
185     @Consumes({
186         MediaTypes.APPLICATION_YANG_PATCH_JSON,
187         MediaTypes.APPLICATION_YANG_PATCH_XML
188     })
189     @Produces({
190         MediaTypes.APPLICATION_YANG_DATA_JSON,
191         MediaTypes.APPLICATION_YANG_DATA_XML
192     })
193     PatchStatusContext patchData(PatchContext context, @Context UriInfo uriInfo);
194
195     /**
196      * Partially modify the target data resource.
197      *
198      * @param identifier path to target
199      * @param payload data node for put to config DS
200      * @param ar {@link AsyncResponse} which needs to be completed
201      */
202     @Patch
203     @Path("/data/{identifier:.+}")
204     @Consumes({
205         MediaTypes.APPLICATION_YANG_DATA_JSON,
206         MediaTypes.APPLICATION_YANG_DATA_XML,
207         MediaType.APPLICATION_JSON,
208         MediaType.APPLICATION_XML,
209         MediaType.TEXT_XML
210     })
211     void patchData(@Encoded @PathParam("identifier") String identifier, NormalizedNodePayload payload,
212                    @Context UriInfo uriInfo, @Suspended AsyncResponse ar);
213 }