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.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;
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 org.onap.music.datastore.PreparedQueryObject;
51 import com.datastax.driver.core.ResultSet;
53 import io.swagger.annotations.Api;
54 import io.swagger.annotations.ApiOperation;
55 import io.swagger.annotations.ApiParam;
57 //@Path("/v{version: [0-9]+}/priorityq/")
60 public class RestMusicQAPI {
62 private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
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);
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);
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);
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);
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);
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{
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);
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);