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