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