Push variuos changes
[music.git] / jar / 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
23 package org.onap.music.rest;
24
25
26
27 import java.util.HashMap;
28 import java.util.Map;
29
30 import javax.ws.rs.Consumes;
31 import javax.ws.rs.DELETE;
32 import javax.ws.rs.GET;
33 import javax.ws.rs.HeaderParam;
34 import javax.ws.rs.POST;
35 import javax.ws.rs.PUT;
36 import javax.ws.rs.Path;
37 import javax.ws.rs.PathParam;
38 import javax.ws.rs.Produces;
39 import javax.ws.rs.core.Context;
40 import javax.ws.rs.core.MediaType;
41 import javax.ws.rs.core.Response;
42 import javax.ws.rs.core.UriInfo;
43
44 import org.onap.music.datastore.jsonobjects.JsonDelete;
45 import org.onap.music.datastore.jsonobjects.JsonInsert;
46 import org.onap.music.datastore.jsonobjects.JsonTable;
47 import org.onap.music.datastore.jsonobjects.JsonUpdate;
48 import org.onap.music.eelf.logging.EELFLoggerDelegate;
49 import org.onap.music.main.MusicCore;
50
51 import org.onap.music.datastore.PreparedQueryObject;
52 import com.datastax.driver.core.ResultSet;
53
54 import io.swagger.annotations.Api;
55 import io.swagger.annotations.ApiOperation;
56 import io.swagger.annotations.ApiParam;
57
58 //@Path("/v{version: [0-9]+}/priorityq/")
59 @Path("/priorityq/")
60 @Api(value="Q Api")
61 public class RestMusicQAPI {
62     
63     private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
64
65
66     /**
67      * 
68      * @param tableObj 
69      * @param keyspace
70      * @param tablename
71      * @throws Exception
72      */
73
74     @POST
75     @Path("/keyspaces/{keyspace}/{qname}")
76     @ApiOperation(value = "", response = Void.class)
77     @Consumes(MediaType.APPLICATION_JSON)
78     public Response createQ( 
79         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
80         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
81         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
82         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
83         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, 
84         @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
85         @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonTable tableObj, 
86         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
87         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename) throws Exception{ 
88         return new RestMusicDataAPI().createTable(version,minorVersion,patchVersion,aid, ns, userId, password, tableObj, keyspace, tablename);
89     }
90
91     /**
92      * 
93      * @param insObj
94      * @param keyspace
95      * @param tablename
96      * @throws Exception
97      */
98     @POST
99     @Path("/keyspaces/{keyspace}/{qname}/rows")
100     @ApiOperation(value = "", response = Void.class)
101     @Consumes(MediaType.APPLICATION_JSON)
102     @Produces(MediaType.APPLICATION_JSON)
103     public Response insertIntoQ(
104         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
105         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
106         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
107         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid, 
108         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
109         @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonInsert insObj, 
110         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
111         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename) throws Exception{
112         return new RestMusicDataAPI().insertIntoTable(version,minorVersion,patchVersion,aid, ns, userId, password, insObj, keyspace, tablename);
113     }
114
115     /**
116      * 
117      * @param updateObj
118      * @param keyspace
119      * @param tablename
120      * @param info
121      * @return
122      * @throws Exception
123      */
124     @PUT
125     @Path("/keyspaces/{keyspace}/{qname}/rows")
126     @ApiOperation(value = "", response = String.class)
127     @Consumes(MediaType.APPLICATION_JSON)
128     @Produces(MediaType.APPLICATION_JSON)
129     public Response updateQ(
130         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
131         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
132         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
133         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid, 
134         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
135         @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonUpdate updateObj, 
136         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
137         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename, 
138         @Context UriInfo info) throws Exception{
139         return new RestMusicDataAPI().updateTable(version,minorVersion,patchVersion,aid, ns, userId, password, updateObj, keyspace, tablename, info);
140     }
141
142     /**
143      * 
144      * @param delObj
145      * @param keyspace
146      * @param tablename
147      * @param info
148      * @return
149      * @throws Exception
150      */
151     @DELETE
152     @Path("/keyspaces/{keyspace}/{qname}/rows")
153     @ApiOperation(value = "", response = String.class)
154     @Consumes(MediaType.APPLICATION_JSON)
155     @Produces(MediaType.APPLICATION_JSON)
156     public Response deleteFromQ(
157         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
158         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
159         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
160         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid, 
161         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, 
162         @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
163         @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonDelete delObj, 
164         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
165         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename, 
166         @Context UriInfo info) throws Exception{ 
167         return new RestMusicDataAPI().deleteFromTable(version,minorVersion,patchVersion,aid, ns, userId, password, delObj, keyspace, tablename, info);
168     }
169
170     /**
171      * 
172      * @param keyspace
173      * @param tablename
174      * @param info
175      * @return
176      * @throws Exception
177      */
178     @GET
179     @Path("/keyspaces/{keyspace}/{qname}/peek")
180     @ApiOperation(value = "", response = Map.class)
181     @Produces(MediaType.APPLICATION_JSON)    
182     public Map<String, HashMap<String, Object>> peek(
183         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
184         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
185         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
186         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid, 
187         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, 
188         @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
189         @ApiParam(value="Password",required=true) @HeaderParam("password") String password,
190         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
191         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename, 
192         @Context UriInfo info) throws Exception{
193         int limit =1; //peek must return just the top row
194         PreparedQueryObject query = new RestMusicDataAPI().selectSpecificQuery(version,minorVersion,patchVersion,aid, ns, userId, password,keyspace,tablename,info,limit);
195         ResultSet results = MusicCore.get(query);
196         return MusicCore.marshallResults(results);
197
198     } 
199     
200     /**
201      * 
202      *
203      * @param keyspace
204      * @param tablename
205      * @param info
206      * @return
207      * @throws Exception
208      */
209     @GET
210     @Path("/keyspaces/{keyspace}/{qname}/filter")
211     @ApiOperation(value = "", response = Map.class)
212     @Produces(MediaType.APPLICATION_JSON)    
213     public Map<String, HashMap<String, Object>> filter(
214         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
215         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
216         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
217         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid, 
218         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, 
219         @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
220         @ApiParam(value="Password",required=true) @HeaderParam("password") String password,
221         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
222         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename, 
223         @Context UriInfo info) throws Exception{
224         int limit =-1; 
225         PreparedQueryObject query = new RestMusicDataAPI().selectSpecificQuery(version,minorVersion,patchVersion,aid, ns, userId, password,keyspace,tablename,info,limit);
226         ResultSet results = MusicCore.get(query);
227         return MusicCore.marshallResults(results);
228     } 
229
230     /**
231      * 
232      * @param tabObj
233      * @param keyspace
234      * @param tablename
235      * @throws Exception
236      */
237     @DELETE
238     @ApiOperation(value = "", response = Void.class)
239     @Path("/keyspaces/{keyspace}/{qname}")
240     public Response dropQ(
241         @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
242         @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
243         @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
244         @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid, 
245         @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, 
246         @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId, 
247         @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonTable tabObj,
248         @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace, 
249         @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename) throws Exception{ 
250         return new RestMusicDataAPI().dropTable(version,minorVersion,patchVersion,aid, ns, userId, password, keyspace, tablename);
251     }
252 }