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 * ====================================================================
23 package org.onap.music.rest;
27 import java.util.HashMap;
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;
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;
51 import org.onap.music.datastore.PreparedQueryObject;
52 import com.datastax.driver.core.ResultSet;
54 import io.swagger.annotations.Api;
55 import io.swagger.annotations.ApiOperation;
56 import io.swagger.annotations.ApiParam;
58 //@Path("/v{version: [0-9]+}/priorityq/")
61 public class RestMusicQAPI {
63 private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
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);
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);
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);
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);
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);
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{
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);
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);