e08adaf735f9621485f55da2484492281904ea80
[music.git] / src / main / java / org / onap / music / rest / RestMusicQAPI.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017 AT&T Intellectual Property
6  * ===================================================================
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
10  * 
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  * 
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  */
22 package org.onap.music.rest;
23
24
25
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import javax.ws.rs.Consumes;
30 import javax.ws.rs.DELETE;
31 import javax.ws.rs.GET;
32 import javax.ws.rs.HeaderParam;
33 import javax.ws.rs.POST;
34 import javax.ws.rs.PUT;
35 import javax.ws.rs.Path;
36 import javax.ws.rs.PathParam;
37 import javax.ws.rs.Produces;
38 import javax.ws.rs.core.Context;
39 import javax.ws.rs.core.MediaType;
40 import javax.ws.rs.core.Response;
41 import javax.ws.rs.core.UriInfo;
42
43 import org.onap.music.datastore.jsonobjects.JsonDelete;
44 import org.onap.music.datastore.jsonobjects.JsonInsert;
45 import org.onap.music.datastore.jsonobjects.JsonTable;
46 import org.onap.music.datastore.jsonobjects.JsonUpdate;
47 import org.onap.music.eelf.logging.EELFLoggerDelegate;
48 import org.onap.music.main.MusicCore;
49
50 import org.onap.music.datastore.PreparedQueryObject;
51 import com.datastax.driver.core.ResultSet;
52
53 import io.swagger.annotations.Api;
54 import io.swagger.annotations.ApiOperation;
55 import io.swagger.annotations.ApiParam;
56
57 //@Path("/v{version: [0-9]+}/priorityq/")
58 @Path("/priorityq/")
59 @Api(value="Q Api")
60 public class RestMusicQAPI {
61     
62     private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
63
64
65     /**
66      * 
67      * @param tableObj 
68      * @param keyspace
69      * @param tablename
70      * @throws Exception
71      */
72
73     @POST
74     @Path("/keyspaces/{keyspace}/{qname}")
75     @ApiOperation(value = "", response = Void.class)
76     @Consumes(MediaType.APPLICATION_JSON)
77     public Response createQ( 
78         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
79         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
80         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
81         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
82         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, 
83         @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
84         @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonTable tableObj, 
85         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
86         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename) throws Exception{ 
87         return new RestMusicDataAPI().createTable(version,minorVersion,patchVersion,aid, ns, userId, password, tableObj, keyspace, tablename);
88     }
89
90     /**
91      * 
92      * @param insObj
93      * @param keyspace
94      * @param tablename
95      * @throws Exception
96      */
97     @POST
98     @Path("/keyspaces/{keyspace}/{qname}/rows")
99     @ApiOperation(value = "", response = Void.class)
100     @Consumes(MediaType.APPLICATION_JSON)
101     @Produces(MediaType.APPLICATION_JSON)
102     public Response insertIntoQ(
103         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
104         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
105         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
106         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid, 
107         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
108         @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonInsert insObj, 
109         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
110         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename) throws Exception{
111         return new RestMusicDataAPI().insertIntoTable(version,minorVersion,patchVersion,aid, ns, userId, password, insObj, keyspace, tablename);
112     }
113
114     /**
115      * 
116      * @param updateObj
117      * @param keyspace
118      * @param tablename
119      * @param info
120      * @return
121      * @throws Exception
122      */
123     @PUT
124     @Path("/keyspaces/{keyspace}/{qname}/rows")
125     @ApiOperation(value = "", response = String.class)
126     @Consumes(MediaType.APPLICATION_JSON)
127     @Produces(MediaType.APPLICATION_JSON)
128     public Response updateQ(
129         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
130         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
131         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
132         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid, 
133         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
134         @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonUpdate updateObj, 
135         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
136         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename, 
137         @Context UriInfo info) throws Exception{
138         return new RestMusicDataAPI().updateTable(version,minorVersion,patchVersion,aid, ns, userId, password, updateObj, keyspace, tablename, info);
139     }
140
141     /**
142      * 
143      * @param delObj
144      * @param keyspace
145      * @param tablename
146      * @param info
147      * @return
148      * @throws Exception
149      */
150     @DELETE
151     @Path("/keyspaces/{keyspace}/{qname}/rows")
152     @ApiOperation(value = "", response = String.class)
153     @Consumes(MediaType.APPLICATION_JSON)
154     @Produces(MediaType.APPLICATION_JSON)
155     public Response deleteFromQ(
156         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
157         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
158         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
159         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid, 
160         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, 
161         @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
162         @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonDelete delObj, 
163         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
164         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename, 
165         @Context UriInfo info) throws Exception{ 
166         return new RestMusicDataAPI().deleteFromTable(version,minorVersion,patchVersion,aid, ns, userId, password, delObj, keyspace, tablename, info);
167     }
168
169     /**
170      * 
171      * @param keyspace
172      * @param tablename
173      * @param info
174      * @return
175      * @throws Exception
176      */
177     @GET
178     @Path("/keyspaces/{keyspace}/{qname}/peek")
179     @ApiOperation(value = "", response = Map.class)
180     @Produces(MediaType.APPLICATION_JSON)    
181     public Map<String, HashMap<String, Object>> peek(
182         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
183         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
184         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
185         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid, 
186         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, 
187         @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
188         @ApiParam(value="Password",required=true) @HeaderParam("password") String password,
189         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
190         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename, 
191         @Context UriInfo info) throws Exception{
192         int limit =1; //peek must return just the top row
193         PreparedQueryObject query = new RestMusicDataAPI().selectSpecificQuery(version,minorVersion,patchVersion,aid, ns, userId, password,keyspace,tablename,info,limit);
194         ResultSet results = MusicCore.get(query);
195         return MusicCore.marshallResults(results);
196
197     } 
198     
199     /**
200      * 
201      *
202      * @param keyspace
203      * @param tablename
204      * @param info
205      * @return
206      * @throws Exception
207      */
208     @GET
209     @Path("/keyspaces/{keyspace}/{qname}/filter")
210     @ApiOperation(value = "", response = Map.class)
211     @Produces(MediaType.APPLICATION_JSON)    
212     public Map<String, HashMap<String, Object>> filter(
213         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
214         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
215         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
216         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid, 
217         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, 
218         @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
219         @ApiParam(value="Password",required=true) @HeaderParam("password") String password,
220         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
221         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename, 
222         @Context UriInfo info) throws Exception{
223         int limit =-1; 
224         PreparedQueryObject query = new RestMusicDataAPI().selectSpecificQuery(version,minorVersion,patchVersion,aid, ns, userId, password,keyspace,tablename,info,limit);
225         ResultSet results = MusicCore.get(query);
226         return MusicCore.marshallResults(results);
227     } 
228
229     /**
230      * 
231      * @param tabObj
232      * @param keyspace
233      * @param tablename
234      * @throws Exception
235      */
236     @DELETE
237     @ApiOperation(value = "", response = Void.class)
238     @Path("/keyspaces/{keyspace}/{qname}")
239     public Response dropQ(
240         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
241         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
242         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
243         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid, 
244         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, 
245         @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
246         @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonTable tabObj,
247         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
248         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename) throws Exception{ 
249         return new RestMusicDataAPI().dropTable(version,minorVersion,patchVersion,aid, ns, userId, password, keyspace, tablename);
250     }
251 }