2 * ============LICENSE_START==========================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * ============LICENSE_END=============================================
20 * ====================================================================
22 package org.onap.music.rest;
26 import java.util.HashMap;
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;
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;
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;
55 import io.swagger.annotations.Api;
56 import io.swagger.annotations.ApiOperation;
57 import io.swagger.annotations.ApiParam;
59 //@Path("/v{version: [0-9]+}/priorityq/")
62 public class RestMusicQAPI {
64 private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
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);
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);
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);
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);
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);
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{
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);
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);