summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorNelson,Thomas(tn1381)(arthurdent3) <tn1381@att.com>2018-03-27 19:50:44 -0400
committerNelson,Thomas(tn1381)(arthurdent3) <tn1381@att.com>2018-03-27 19:50:44 -0400
commit9cd6659574e58aae87a8aa40feaad492b2f3bde7 (patch)
tree4fcdc8dc6942dbc30e30d3c9469b3f9adacb3307 /src/main
parent621572bcc14ef8fed700e7c07f7927c5db22531a (diff)
Code Coverage, Auth ID, Docker
Change-Id: If9212aea5a643f2db6c18090f17cd2da71f5a968 Issue-ID: MUSIC-44, MUSIC-65, MUSIC-56 Signed-off-by: Nelson,Thomas(tn1381)(arthurdent3) <tn1381@att.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/music/datastore/MusicDataStore.java7
-rw-r--r--src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java53
-rwxr-xr-xsrc/main/java/org/onap/music/main/CachingUtil.java15
-rw-r--r--src/main/java/org/onap/music/main/MusicCore.java8
-rwxr-xr-xsrc/main/java/org/onap/music/main/MusicUtil.java19
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicAdminAPI.java317
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicDataAPI.java725
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicQAPI.java389
8 files changed, 795 insertions, 738 deletions
diff --git a/src/main/java/org/onap/music/datastore/MusicDataStore.java b/src/main/java/org/onap/music/datastore/MusicDataStore.java
index c64a96b3..278cf768 100644
--- a/src/main/java/org/onap/music/datastore/MusicDataStore.java
+++ b/src/main/java/org/onap/music/datastore/MusicDataStore.java
@@ -375,11 +375,12 @@ public class MusicDataStore {
}
logger.info(EELFLoggerDelegate.applicationLogger,
"Executing Eventual get query:" + queryObject.getQuery());
- PreparedStatement preparedEventualGet = session.prepare(queryObject.getQuery());
- preparedEventualGet.setConsistencyLevel(ConsistencyLevel.ONE);
+
ResultSet results = null;
try {
- results = session.execute(preparedEventualGet.bind(queryObject.getValues().toArray()));
+ PreparedStatement preparedEventualGet = session.prepare(queryObject.getQuery());
+ preparedEventualGet.setConsistencyLevel(ConsistencyLevel.ONE);
+ results = session.execute(preparedEventualGet.bind(queryObject.getValues().toArray()));
} catch (Exception ex) {
logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(),AppMessages.UNKNOWNERROR+ "[" + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
diff --git a/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java b/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java
new file mode 100644
index 00000000..14a23d1f
--- /dev/null
+++ b/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java
@@ -0,0 +1,53 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=============================================
+ * ====================================================================
+ */
+package org.onap.music.exceptions;
+
+import java.io.EOFException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+import org.codehaus.jackson.map.exc.UnrecognizedPropertyException;
+import org.onap.music.main.ResultType;
+import org.onap.music.response.jsonobjects.JsonResponse;
+
+@Provider
+public class MusicExceptionMapper implements ExceptionMapper<Exception> {
+ @Override
+ public Response toResponse(Exception exception) {
+ if(exception instanceof UnrecognizedPropertyException) {
+ return Response.status(Response.Status.BAD_REQUEST).
+ entity(new JsonResponse(ResultType.FAILURE).setError("Unknown field :"+((UnrecognizedPropertyException) exception).getUnrecognizedPropertyName()).toMap()).
+ build();
+ }
+ else if(exception instanceof EOFException) {
+ return Response.status(Response.Status.BAD_REQUEST).
+ entity(new JsonResponse(ResultType.FAILURE).setError("Request body cannot be empty").toMap()).
+ build();
+ }
+ else {
+ return Response.status(Response.Status.BAD_REQUEST).
+ entity(new JsonResponse(ResultType.FAILURE).setError(exception.getMessage()).toMap()).
+ build();
+ }
+ }
+}
diff --git a/src/main/java/org/onap/music/main/CachingUtil.java b/src/main/java/org/onap/music/main/CachingUtil.java
index 2a105c24..b59e81b3 100755
--- a/src/main/java/org/onap/music/main/CachingUtil.java
+++ b/src/main/java/org/onap/music/main/CachingUtil.java
@@ -45,6 +45,7 @@ import com.att.eelf.configuration.EELFLogger;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
+import com.datastax.driver.core.exceptions.InvalidQueryException;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
@@ -241,7 +242,13 @@ public class CachingUtil implements Runnable {
pQuery.appendQueryString(
"SELECT is_aaf from admin.keyspace_master where application_name = '"
+ namespace + "' allow filtering");
- Row rs = MusicCore.get(pQuery).one();
+ Row rs = null;
+ try {
+ rs = MusicCore.get(pQuery).one();
+ } catch(InvalidQueryException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,"Exception admin keyspace not configured."+e.getMessage());
+ throw new MusicServiceException("Please make sure admin.keyspace_master table is configured.");
+ }
try {
isAAF = String.valueOf(rs.getBool("is_aaf"));
if(isAAF != null)
@@ -333,7 +340,11 @@ public class CachingUtil implements Runnable {
e.printStackTrace();
resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
return resultMap;
- }
+ } catch (InvalidQueryException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,"Exception admin keyspace not configured."+e.getMessage());
+ resultMap.put("Exception", "Please make sure admin.keyspace_master table is configured.");
+ return resultMap;
+ }
if (rs == null) {
logger.error(EELFLoggerDelegate.errorLogger,"Application is not onboarded. Please contact admin.");
resultMap.put("Exception", "Application is not onboarded. Please contact admin.");
diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java
index abeedf6f..d38a4d6a 100644
--- a/src/main/java/org/onap/music/main/MusicCore.java
+++ b/src/main/java/org/onap/music/main/MusicCore.java
@@ -890,7 +890,13 @@ public class MusicCore {
operation);
if (!resultMap.isEmpty())
return resultMap;
- String isAAFApp = CachingUtil.isAAFApplication(nameSpace);
+ String isAAFApp = null;
+ try {
+ isAAFApp= CachingUtil.isAAFApplication(nameSpace);
+ } catch(MusicServiceException e) {
+ resultMap.put("Exception", e.getMessage());
+ return resultMap;
+ }
if(isAAFApp == null) {
resultMap.put("Exception", "Namespace: "+nameSpace+" doesn't exist. Please make sure ns(appName)"
+ " is correct and Application is onboarded.");
diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java
index c0b968be..b6cc1902 100755
--- a/src/main/java/org/onap/music/main/MusicUtil.java
+++ b/src/main/java/org/onap/music/main/MusicUtil.java
@@ -25,15 +25,12 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.UUID;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.exceptions.MusicServiceException;
-
import com.datastax.driver.core.DataType;
/**
@@ -51,21 +48,22 @@ public class MusicUtil {
public static final String EVENTUAL = "eventual";
public static final String CRITICAL = "critical";
public static final String ATOMICDELETELOCK = "atomic_delete_lock";
-
public static final String DEFAULTKEYSPACENAME = "TBD";
+ private static final String LOCALHOST = "localhost";
+ private static final String PROPERTIES_FILE = "/opt/app/music/etc/music.properties";
private static int myId = 0;
private static ArrayList<String> allIds = new ArrayList<>();
private static String publicIp = "";
private static ArrayList<String> allPublicIps = new ArrayList<>();
- private static String myZkHost = "localhost";
- private static String myCassaHost = "localhost";
- private static String defaultMusicIp = "localhost";
+ private static String myZkHost = LOCALHOST;
+ private static String myCassaHost = LOCALHOST;
+ private static String defaultMusicIp = LOCALHOST;
private static boolean debug = true;
private static String version = "2.3.0";
- private static String musicRestIp = "localhost";
- private static String musicPropertiesFilePath = "/opt/app/music/etc/music.properties";
+ private static String musicRestIp = LOCALHOST;
+ private static String musicPropertiesFilePath = PROPERTIES_FILE;
private static long defaultLockLeasePeriod = 6000;
private static final String[] propKeys = new String[] { "zookeeper.host", "cassandra.host", "music.ip", "debug",
"version", "music.rest.ip", "music.properties", "lock.lease.period", "id", "all.ids", "public.ip",
@@ -424,9 +422,10 @@ public class MusicUtil {
* @param colType
* @param valueObj
* @return
+ * @throws MusicTypeConversionException
* @throws Exception
*/
- public static Object convertToActualDataType(DataType colType, Object valueObj) throws Exception{
+ public static Object convertToActualDataType(DataType colType, Object valueObj) throws Exception {
String valueObjString = valueObj + "";
switch (colType.getName()) {
case UUID:
diff --git a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
index 2d7aa833..c66944cb 100755
--- a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
@@ -27,15 +27,16 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonOnboard;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
@@ -46,18 +47,19 @@ import org.onap.music.main.CachingUtil;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
-
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
-@Path("/v{version: [0-9]+}/admin")
+@Path("/v2/admin")
+// @Path("/v{version: [0-9]+}/admin")
// @Path("/admin")
@Api(value = "Admin Api", hidden = true)
public class RestMusicAdminAPI {
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicAdminAPI.class);
+ private static EELFLoggerDelegate logger =
+ EELFLoggerDelegate.getLogger(RestMusicAdminAPI.class);
/*
* API to onboard an application with MUSIC. This is the mandatory first step.
@@ -68,20 +70,20 @@ public class RestMusicAdminAPI {
@ApiOperation(value = "Onboard application", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> onboardAppWithMusic(JsonOnboard jsonObj,
- @Context HttpServletResponse response) throws Exception {
+ public Response onboardAppWithMusic(JsonOnboard jsonObj) throws Exception {
+ ResponseBuilder response =
+ Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
Map<String, Object> resultMap = new HashMap<>();
String appName = jsonObj.getAppname();
String userId = jsonObj.getUserId();
String isAAF = jsonObj.getIsAAF();
String password = jsonObj.getPassword();
- response.addHeader("X-latestVersion", MusicUtil.getVersion());
if (appName == null || userId == null || isAAF == null || password == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO,
+ ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
resultMap.put("Exception",
"Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.");
- response.setStatus(401);
- return resultMap;
+ return Response.status(Status.UNAUTHORIZED).entity(resultMap).build();
}
PreparedQueryObject pQuery = new PreparedQueryObject();
@@ -92,8 +94,7 @@ public class RestMusicAdminAPI {
if (!rs.all().isEmpty()) {
resultMap.put("Exception", "Application " + appName
+ " has already been onboarded. Please contact admin.");
- response.setStatus(400);
- return resultMap;
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
pQuery = new PreparedQueryObject();
@@ -114,37 +115,34 @@ public class RestMusicAdminAPI {
if (returnStr.contains("Failure")) {
resultMap.put("Exception",
"Oops. Something wrong with onboarding process. Please retry later or contact admin.");
- response.setStatus(400);
- return resultMap;
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
CachingUtil.updateisAAFCache(appName, isAAF);
resultMap.put("Success", "Your application " + appName + " has been onboarded with MUSIC.");
resultMap.put("Generated AID", uuid);
- return resultMap;
+ return Response.status(Status.OK).entity(resultMap).build();
}
-
-
+
+
@POST
@Path("/search")
@ApiOperation(value = "Search Onboard application", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> getOnboardedInfoSearch(
- JsonOnboard jsonObj,
- @Context HttpServletResponse response) throws Exception {
+ public Response getOnboardedInfoSearch(JsonOnboard jsonObj) throws Exception {
Map<String, Object> resultMap = new HashMap<>();
-
- response.addHeader("X-latestVersion", MusicUtil.getVersion());
+ ResponseBuilder response =
+ Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
String appName = jsonObj.getAppname();
String uuid = jsonObj.getAid();
String isAAF = jsonObj.getIsAAF();
-
+
if (appName == null && uuid == null && isAAF == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO,
+ ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
resultMap.put("Exception",
"Unauthorized: Please check the request parameters. Enter atleast one of the following parameters: appName(ns), aid, isAAF.");
- response.setStatus(401);
- return resultMap;
+ return Response.status(Status.UNAUTHORIZED).entity(resultMap).build();
}
PreparedQueryObject pQuery = new PreparedQueryObject();
@@ -153,12 +151,12 @@ public class RestMusicAdminAPI {
cql = cql + "application_name = ? AND ";
if (uuid != null)
cql = cql + "uuid = ? AND ";
- if(isAAF != null)
- cql = cql + "is_aaf = ?";
-
- if(cql.endsWith("AND "))
- cql = cql.trim().substring(0, cql.length()-4);
- System.out.println("Query is: "+cql);
+ if (isAAF != null)
+ cql = cql + "is_aaf = ?";
+
+ if (cql.endsWith("AND "))
+ cql = cql.trim().substring(0, cql.length() - 4);
+ System.out.println("Query is: " + cql);
cql = cql + " allow filtering";
System.out.println("Get OnboardingInfo CQL: " + cql);
pQuery.appendQueryString(cql);
@@ -167,26 +165,26 @@ public class RestMusicAdminAPI {
if (uuid != null)
pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
if (isAAF != null)
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), Boolean.parseBoolean(isAAF)));
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(),
+ Boolean.parseBoolean(isAAF)));
ResultSet rs = MusicCore.get(pQuery);
Iterator<Row> it = rs.iterator();
while (it.hasNext()) {
Row row = (Row) it.next();
- resultMap.put( row.getUUID("uuid").toString(),row.getString("keyspace_name"));
+ resultMap.put(row.getUUID("uuid").toString(), row.getString("keyspace_name"));
}
if (resultMap.isEmpty()) {
- if(uuid != null) {
- resultMap.put("Exception", "Please make sure Aid is correct and application is onboarded.");
- response.setStatus(400);
- return resultMap;
- }else {
+ if (uuid != null) {
resultMap.put("Exception",
- "Application is not onboarded. Please make sure all the information is correct.");
- response.setStatus(400);
- return resultMap;
+ "Please make sure Aid is correct and application is onboarded.");
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
+ } else {
+ resultMap.put("Exception",
+ "Application is not onboarded. Please make sure all the information is correct.");
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
}
- return resultMap;
+ return Response.status(Status.OK).entity(resultMap).build();
}
@@ -195,53 +193,52 @@ public class RestMusicAdminAPI {
@ApiOperation(value = "Delete Onboard application", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> deleteOnboardApp(JsonOnboard jsonObj,
- @Context HttpServletResponse response) throws Exception {
+ public Response deleteOnboardApp(JsonOnboard jsonObj) throws Exception {
Map<String, Object> resultMap = new HashMap<>();
- response.addHeader("X-latestVersion", MusicUtil.getVersion());
+ ResponseBuilder response =
+ Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
String appName = jsonObj.getAppname();
String aid = jsonObj.getAid();
PreparedQueryObject pQuery = new PreparedQueryObject();
String consistency = MusicUtil.EVENTUAL;;
if (appName == null && aid == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
resultMap.put("Exception", "Please make sure either appName(ns) or Aid is present");
- response.setStatus(400);
- return resultMap;
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
if (aid != null) {
- pQuery.appendQueryString("SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
- UUID.fromString(aid)));
- Row row = MusicCore.get(pQuery).one();
- if(row!=null) {
- String ks = row.getString("keyspace_name");
- if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
- PreparedQueryObject queryObject = new PreparedQueryObject();
- queryObject.appendQueryString("DROP KEYSPACE IF EXISTS " + ks + ";");
- MusicCore.nonKeyRelatedPut(queryObject, consistency);
- }
- }
- pQuery = new PreparedQueryObject();
- pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ? IF EXISTS");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
- UUID.fromString(aid)));
- ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
- if (result==ResultType.SUCCESS) {
- resultMap.put("Success", "Your application has been deleted successfully");
- } else {
- resultMap.put("Exception","Oops. Something went wrong. Please make sure Aid is correct or Application is onboarded");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
+ pQuery.appendQueryString(
+ "SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
+ UUID.fromString(aid)));
+ Row row = MusicCore.get(pQuery).one();
+ if (row != null) {
+ String ks = row.getString("keyspace_name");
+ if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("DROP KEYSPACE IF EXISTS " + ks + ";");
+ MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ }
+ }
+ pQuery = new PreparedQueryObject();
+ pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ? IF EXISTS");
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
+ UUID.fromString(aid)));
+ ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
+ if (result == ResultType.SUCCESS) {
+ resultMap.put("Success", "Your application has been deleted successfully");
+ } else {
+ resultMap.put("Exception",
+ "Oops. Something went wrong. Please make sure Aid is correct or Application is onboarded");
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.INCORRECTDATA,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- return resultMap;
+ }
+ return Response.status(Status.OK).entity(resultMap).build();
}
-
-
-
-
+
pQuery.appendQueryString(
"select uuid from admin.keyspace_master where application_name = ? allow filtering");
pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
@@ -251,35 +248,37 @@ public class RestMusicAdminAPI {
if (rows.size() == 0) {
resultMap.put("Exception",
"Application not found. Please make sure Application exists.");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.INCORRECTDATA,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
} else if (rows.size() == 1) {
uuid = rows.get(0).getUUID("uuid").toString();
pQuery = new PreparedQueryObject();
- pQuery.appendQueryString("SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
- UUID.fromString(uuid)));
- Row row = MusicCore.get(pQuery).one();
- String ks = row.getString("keyspace_name");
- if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
- PreparedQueryObject queryObject = new PreparedQueryObject();
- queryObject.appendQueryString("DROP KEYSPACE " + ks + ";");
- MusicCore.nonKeyRelatedPut(queryObject, consistency);
- }
-
+ pQuery.appendQueryString(
+ "SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
+ UUID.fromString(uuid)));
+ Row row = MusicCore.get(pQuery).one();
+ String ks = row.getString("keyspace_name");
+ if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("DROP KEYSPACE " + ks + ";");
+ MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ }
+
pQuery = new PreparedQueryObject();
pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ?");
pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
UUID.fromString(uuid)));
MusicCore.eventualPut(pQuery);
resultMap.put("Success", "Your application " + appName + " has been deleted.");
- return resultMap;
+ return Response.status(Status.OK).entity(resultMap).build();
} else {
- resultMap.put("Failure", "More than one Aid exists for this application, so please provide Aid.");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MULTIPLERECORDS ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
+ resultMap.put("Failure",
+ "More than one Aid exists for this application, so please provide Aid.");
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MULTIPLERECORDS,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
}
@@ -289,10 +288,10 @@ public class RestMusicAdminAPI {
@ApiOperation(value = "Update Onboard application", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> updateOnboardApp(JsonOnboard jsonObj,
- @Context HttpServletResponse response) throws Exception {
+ public Response updateOnboardApp(JsonOnboard jsonObj) throws Exception {
Map<String, Object> resultMap = new HashMap<>();
- response.addHeader("X-latestVersion", MusicUtil.getVersion());
+ ResponseBuilder response =
+ Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
String aid = jsonObj.getAid();
String appName = jsonObj.getAppname();
String userId = jsonObj.getUserId();
@@ -303,69 +302,69 @@ public class RestMusicAdminAPI {
if (aid == null) {
resultMap.put("Exception", "Please make sure Aid is present");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
if (appName == null && userId == null && password == null && isAAF == null) {
resultMap.put("Exception",
"No parameters found to update. Please update atleast one parameter.");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
-
- if(appName!=null) {
- pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "select uuid from admin.keyspace_master where application_name = ? allow filtering");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- ResultSet rs = MusicCore.get(pQuery);
- if (!rs.all().isEmpty()) {
- resultMap.put("Exception", "Application " + appName
- + " has already been onboarded. Please contact admin.");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.ALREADYEXIST ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
- }
+
+ if (appName != null) {
+ pQuery = new PreparedQueryObject();
+ pQuery.appendQueryString(
+ "select uuid from admin.keyspace_master where application_name = ? allow filtering");
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
+ ResultSet rs = MusicCore.get(pQuery);
+ if (!rs.all().isEmpty()) {
+ resultMap.put("Exception", "Application " + appName
+ + " has already been onboarded. Please contact admin.");
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.ALREADYEXIST,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
+ }
+ }
+
+ pQuery = new PreparedQueryObject();
+ StringBuilder preCql = new StringBuilder("UPDATE admin.keyspace_master SET ");
+ if (appName != null)
+ preCql.append(" application_name = ?,");
+ if (userId != null)
+ preCql.append(" username = ?,");
+ if (password != null)
+ preCql.append(" password = ?,");
+ if (isAAF != null)
+ preCql.append(" is_aaf = ?,");
+ preCql.deleteCharAt(preCql.length() - 1);
+ preCql.append(" WHERE uuid = ? IF EXISTS");
+ pQuery.appendQueryString(preCql.toString());
+ if (appName != null)
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
+ if (userId != null)
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
+ if (password != null)
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
+ if (isAAF != null)
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
+
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), UUID.fromString(aid)));
+ ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
+
+ if (result == ResultType.SUCCESS) {
+ resultMap.put("Success", "Your application has been updated successfully");
+ } else {
+ resultMap.put("Exception",
+ "Oops. Something went wrong. Please make sure Aid is correct and application is onboarded");
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.INCORRECTDATA,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
-
- pQuery = new PreparedQueryObject();
- StringBuilder preCql = new StringBuilder("UPDATE admin.keyspace_master SET ");
- if (appName != null)
- preCql.append(" application_name = ?,");
- if (userId != null)
- preCql.append(" username = ?,");
- if (password != null)
- preCql.append(" password = ?,");
- if (isAAF != null)
- preCql.append(" is_aaf = ?,");
- preCql.deleteCharAt(preCql.length() - 1);
- preCql.append(" WHERE uuid = ? IF EXISTS");
- pQuery.appendQueryString(preCql.toString());
- if (appName != null)
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- if (userId != null)
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- if (password != null)
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
- if (isAAF != null)
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
-
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), UUID.fromString(aid)));
- ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
-
- if (result==ResultType.SUCCESS) {
- resultMap.put("Success", "Your application has been updated successfully");
- } else {
- resultMap.put("Exception",
- "Oops. Something went wrong. Please make sure Aid is correct and application is onboarded");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
- }
-
- return resultMap;
+
+ return Response.status(Status.OK).entity(resultMap).build();
}
}
diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
index 2d095949..53ed9e5b 100755
--- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
@@ -1,16 +1,20 @@
/*
- * ============LICENSE_START========================================== org.onap.music
- * =================================================================== Copyright (c) 2017 AT&T
- * Intellectual Property ===================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*
* ============LICENSE_END=============================================
* ====================================================================
@@ -18,11 +22,9 @@
package org.onap.music.rest;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -33,8 +35,12 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonDelete;
@@ -56,7 +62,6 @@ import org.onap.music.main.ResultType;
import org.onap.music.main.ReturnType;
import org.onap.music.response.jsonobjects.JsonResponse;
-import com.att.eelf.configuration.EELFLogger;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
@@ -65,7 +70,9 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
-@Path("/v{version: [0-9]+}/keyspaces")
+/* Version 2 Class */
+//@Path("/v{version: [0-9]+}/keyspaces")
+@Path("/v2/keyspaces")
@Api(value = "Data Api")
public class RestMusicDataAPI {
/*
@@ -82,18 +89,23 @@ public class RestMusicDataAPI {
* be the latest PATCH version of the MINOR requested by the client, or the latest PATCH version
* of the MAJOR (if not specified by the client on the request) - Contains a single position
* value (e.g. if the full version is 1.24.5, X-patchVersion = "5") - Is mandatory for the
- * server on response
+ * server on response (CURRENTLY NOT USED)
*
*** X-latestVersion *** - Used only to communicate an API's latest version - Is mandatory for the
* server on response, and shall include the entire version of the API (e.g. if the full version
* is 1.24.5, X-latestVersion = "1.24.5") - Used in the response to inform clients that they are
- * not using the latest version of the API
+ * not using the latest version of the API (CURRENTLY NOT USED)
*
*/
private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
- private static String xLatestVersion = "X-latestVersion";
-
+ private static final String XLATESTVERSION = "X-latestVersion";
+ private static final String XMINORVERSION = "X-minorVersion";
+ private static final String XPATCHVERSION = "X-patchVersion";
+ private static final String NS = "ns";
+ private static final String USERID = "userId";
+ private static final String PASSWORD = "password";
+
private class RowIdentifier {
public String primarKeyValue;
public StringBuilder rowIdString;
@@ -119,6 +131,37 @@ public class RestMusicDataAPI {
}
return major;
}
+
+ /**
+ * Currently this will build a header with X-latestVersion, X-minorVersion and X-pathcVersion
+ * X-latestVerstion will be equal to the latest full version.
+ * X-minorVersion - will be equal to the latest minor version.
+ * X-pathVersion - will be equal to the latest patch version.
+ * Future plans will change this.
+ * @param response
+ * @param major
+ * @param minor
+ * @param patch
+ * @return
+ */
+ private ResponseBuilder buildVersionResponse(String major, String minor, String patch) {
+ ResponseBuilder response = Response.noContent();
+ String versionIn = buildVersion(major,minor,patch);
+ String version = MusicUtil.getVersion();
+ String[] verArray = version.split("\\.",3);
+ if ( minor != null ) {
+ response.header(XMINORVERSION,minor);
+ } else {
+ response.header(XMINORVERSION,verArray[1]);
+ }
+ if ( patch != null ) {
+ response.header(XPATCHVERSION,patch);
+ } else {
+ response.header(XPATCHVERSION,verArray[2]);
+ }
+ response.header(XLATESTVERSION,version);
+ return response;
+ }
/**
* Create Keyspace REST
@@ -133,53 +176,47 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Create Keyspace", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> createKeySpace(
- @ApiParam(value = "Major Version",
- required = true) @PathParam("version") String version,
- @ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ //public Map<String, Object> createKeySpace(
+ public Response createKeySpace(
+ @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
+ @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
+ @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
- @ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
- @ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
- @ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns,
+ @ApiParam(value = "userId",required = true) @HeaderParam(USERID) String userId,
+ @ApiParam(value = "Password",required = true) @HeaderParam(PASSWORD) String password,
JsonKeySpace kspObject,
- @ApiParam(value = "Keyspace Name",
- required = true) @PathParam("name") String keyspaceName,
- @Context HttpServletResponse response) {
+ @ApiParam(value = "Keyspace Name",required = true) @PathParam("name") String keyspaceName) {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
Map<String, Object> authMap = CachingUtil.verifyOnboarding(ns, userId, password);
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ response.status(Status.UNAUTHORIZED);
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
if(kspObject == null || kspObject.getReplicationInfo() == null) {
- authMap.put(ResultType.EXCEPTION.getResult(), ResultType.BODYMISSING.getResult());
- response.setStatus(401);
- return authMap;
- }
+ authMap.put(ResultType.EXCEPTION.getResult(), ResultType.BODYMISSING.getResult());
+ response.status(Status.BAD_REQUEST);
+ return response.entity(authMap).build();
+ }
try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
- "createKeySpace");
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Unable to authenticate.").toMap();
- }
+ authMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
+ "createKeySpace");
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ response.status(Status.BAD_REQUEST);
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError("Unable to authenticate.").toMap()).build();
+ }
String newAid = null;
if (!authMap.isEmpty()) {
if (authMap.containsKey("aid")) {
newAid = (String) authMap.get("aid");
} else {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ response.status(Status.UNAUTHORIZED);
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
}
@@ -214,8 +251,7 @@ public class RestMusicDataAPI {
logger.info(EELFLoggerDelegate.applicationLogger, "result = " + result);
} catch ( MusicServiceException ex) {
logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("err:" + ex.getMessage()).toMap()).build();
}
try {
@@ -229,7 +265,7 @@ public class RestMusicDataAPI {
queryObject.appendQueryString(";");
MusicCore.nonKeyRelatedPut(queryObject, consistency);
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
}
try {
@@ -250,11 +286,10 @@ public class RestMusicDataAPI {
MusicCore.eventualPut(queryObject);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
+ return response.status(Response.Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
- return new JsonResponse(ResultType.SUCCESS).toMap();
+ return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("Keyspace " + keyspaceName + " Created").toMap()).build();
}
/**
@@ -268,31 +303,23 @@ public class RestMusicDataAPI {
@Path("/{name}")
@ApiOperation(value = "Delete Keyspace", response = String.class)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> dropKeySpace(
- @ApiParam(value = "Major Version",
- required = true) @PathParam("version") String version,
- @ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ //public Map<String, Object> dropKeySpace(
+ public Response dropKeySpace(
+ @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
+ @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
+ @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
- @ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
- @ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
- @ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
- @ApiParam(value = "Keyspace Name",
- required = true) @PathParam("name") String keyspaceName,
- @Context HttpServletResponse response) throws Exception {
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password,
- keyspaceName, aid, "dropKeySpace");
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
+ @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns,
+ @ApiParam(value = "userId",required = true) @HeaderParam(USERID) String userId,
+ @ApiParam(value = "Password",required = true) @HeaderParam(PASSWORD) String password,
+ @ApiParam(value = "Keyspace Name",required = true) @PathParam("name") String keyspaceName) throws Exception {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
+ Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password,keyspaceName, aid, "dropKeySpace");
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- response.setStatus(401);
- return authMap;
+ return response.status(Status.UNAUTHORIZED).entity(authMap).build();
}
String consistency = MusicUtil.EVENTUAL;// for now this needs only
@@ -308,9 +335,9 @@ public class RestMusicDataAPI {
long count = row.getLong(0);
if (count == 0) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Keyspace not found. Please make sure keyspace exists.").toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Keyspace not found. Please make sure keyspace exists.").toMap()).build();
+ // Admin Functions:
} else if (count == 1) {
pQuery = new PreparedQueryObject();
pQuery.appendQueryString(
@@ -328,14 +355,20 @@ public class RestMusicDataAPI {
PreparedQueryObject queryObject = new PreparedQueryObject();
queryObject.appendQueryString("DROP KEYSPACE " + keyspaceName + ";");
- return new JsonResponse(MusicCore.nonKeyRelatedPut(queryObject, consistency)).toMap();
+ ResultType result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ if ( result.equals(ResultType.FAILURE) ) {
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(result).setError("Error Deleteing Keyspace " + keyspaceName).toMap()).build();
+ }
+ return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("Keyspace " + keyspaceName + " Deleted").toMap()).build();
}
/**
*
* @param tableObj
+ * @param version
* @param keyspace
* @param tablename
+ * @param headers
* @return
* @throws Exception
*/
@@ -344,36 +377,26 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Create Table", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> createTable(
- @ApiParam(value = "Major Version",
- required = true) @PathParam("version") String version,
- @ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ //public Map<String, Object> createTable(
+ public Response createTable(
+ @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
+ @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
+ @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
- @ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
- @ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
- @ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
- JsonTable tableObj,
- @ApiParam(value = "Keyspace Name",
- required = true) @PathParam("keyspace") String keyspace,
- @ApiParam(value = "Table Name",
- required = true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) throws Exception {
-
+ @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns,
+ @ApiParam(value = "userId",required = true) @HeaderParam(USERID) String userId,
+ @ApiParam(value = "Password",required = true) @HeaderParam(PASSWORD) String password,
+ JsonTable tableObj,
+ @ApiParam(value = "Keyspace Name",required = true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value = "Table Name",required = true) @PathParam("tablename") String tablename) throws Exception {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
aid, "createTable");
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
String consistency = MusicUtil.EVENTUAL;
// for now this needs only eventual consistency
@@ -386,15 +409,15 @@ public class RestMusicDataAPI {
for (Map.Entry<String, String> entry : fields.entrySet()) {
if (entry.getKey().equals("PRIMARY KEY")) {
- if(! entry.getValue().contains("("))
- primaryKey = entry.getValue();
- else {
- primaryKey = entry.getValue().substring(entry.getValue().indexOf('(') + 1);
- primaryKey = primaryKey.substring(0, primaryKey.indexOf(')'));
- }
- fieldsString.append("" + entry.getKey() + " (" + primaryKey + ")");
+ if(! entry.getValue().contains("("))
+ primaryKey = entry.getValue();
+ else {
+ primaryKey = entry.getValue().substring(entry.getValue().indexOf('(') + 1);
+ primaryKey = primaryKey.substring(0, primaryKey.indexOf(')'));
+ }
+ fieldsString.append("" + entry.getKey() + " (" + primaryKey + ")");
} else
- fieldsString.append("" + entry.getKey() + " " + entry.getValue() + "");
+ fieldsString.append("" + entry.getKey() + " " + entry.getValue() + "");
if (counter == fields.size() - 1)
fieldsString.append(")");
else
@@ -437,12 +460,14 @@ public class RestMusicDataAPI {
try {
result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.MUSICSERVICEERROR);
+ response.status(Status.BAD_REQUEST);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
-
- return new JsonResponse(result).toMap();
+ if ( result.equals(ResultType.FAILURE) ) {
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(result).setError("Error Creating Table " + tablename).toMap()).build();
+ }
+ return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("TableName " + tablename + " Created under keyspace " + keyspace).toMap()).build();
}
/**
@@ -457,36 +482,28 @@ public class RestMusicDataAPI {
@Path("/{keyspace}/tables/{tablename}/index/{field}")
@ApiOperation(value = "Create Index", response = String.class)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> createIndex(
- @ApiParam(value = "Major Version",
- required = true) @PathParam("version") String version,
- @ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ public Response createIndex(
+ @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
+ @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
+ @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
- @ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
- @ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
- @ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
- @ApiParam(value = "Keyspace Name",
- required = true) @PathParam("keyspace") String keyspace,
- @ApiParam(value = "Table Name",
- required = true) @PathParam("tablename") String tablename,
- @ApiParam(value = "Field Name",
- required = true) @PathParam("field") String fieldName,
- @Context UriInfo info, @Context HttpServletResponse response) throws Exception {
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
- aid, "createIndex");
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
+ @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns,
+ @ApiParam(value = "userId",required = true) @HeaderParam(USERID) String userId,
+ @ApiParam(value = "Password",required = true) @HeaderParam(PASSWORD) String password,
+ @ApiParam(value = "Keyspace Name",required = true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value = "Table Name",required = true) @PathParam("tablename") String tablename,
+ @ApiParam(value = "Field Name",required = true) @PathParam("field") String fieldName,
+ @Context UriInfo info) throws Exception {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
+ Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,aid, "createIndex");
+ response.header(XLATESTVERSION, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ response.status(Status.UNAUTHORIZED);
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
MultivaluedMap<String, String> rowParams = info.getQueryParameters();
String indexName = "";
@@ -500,12 +517,15 @@ public class RestMusicDataAPI {
try {
result = MusicCore.nonKeyRelatedPut(query, "eventual");
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.status(Status.BAD_REQUEST);
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
+ }
+ if ( result.equals(ResultType.SUCCESS) ) {
+ return response.entity(new JsonResponse(result).setMessage("Index Created on " + keyspace+"."+tablename+"."+fieldName).toMap()).build();
+ } else {
+ return response.entity(new JsonResponse(result).setError("Unknown Error in create index.").toMap()).build();
}
-
- return new JsonResponse(result).toMap();
}
/**
@@ -521,58 +541,49 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Insert Into Table", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> insertIntoTable(
- @ApiParam(value = "Major Version",
- required = true) @PathParam("version") String version,
- @ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ public Response insertIntoTable(
+ @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
+ @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
+ @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
- @ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
- @ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
- @ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns,
+ @ApiParam(value = "userId",required = true) @HeaderParam(USERID) String userId,
+ @ApiParam(value = "Password",required = true) @HeaderParam(PASSWORD) String password,
JsonInsert insObj,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
- required = true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) {
+ required = true) @PathParam("tablename") String tablename) {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
Map<String, Object> authMap = null;
+
try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+ authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
aid, "insertIntoTable");
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
Map<String, Object> valuesMap = insObj.getValues();
PreparedQueryObject queryObject = new PreparedQueryObject();
TableMetadata tableInfo = null;
- try {
- tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
- if(tableInfo == null) {
- return new JsonResponse(ResultType.FAILURE)
- .setError("Table name doesn't exists. Please check the table name.").toMap();
- }
- } catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
- }
+ try {
+ tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+ if(tableInfo == null) {
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Table name doesn't exists. Please check the table name.").toMap()).build();
+ }
+ } catch (MusicServiceException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
+ }
String primaryKeyName = tableInfo.getPrimaryKey().get(0).getName();
StringBuilder fieldsString = new StringBuilder("(vector_ts,");
String vectorTs =
@@ -594,8 +605,7 @@ public class RestMusicDataAPI {
colType = tableInfo.getColumn(entry.getKey()).getType();
} catch(NullPointerException ex) {
logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage() +" Invalid column name : "+entry.getKey(), AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap()).build();
}
Object formattedValue = null;
@@ -618,9 +628,8 @@ public class RestMusicDataAPI {
}
if(primaryKey == null || primaryKey.length() <= 0) {
- logger.error(EELFLoggerDelegate.errorLogger, "Some required partition key parts are missing: "+primaryKeyName );
- response.setStatus(400);
- return new JsonResponse(ResultType.SYNTAXERROR).setError("Some required partition key parts are missing: "+primaryKeyName).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger, "Some required partition key parts are missing: "+primaryKeyName );
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.SYNTAXERROR).setError("Some required partition key parts are missing: "+primaryKeyName).toMap()).build();
}
queryObject.appendQueryString("INSERT INTO " + keyspace + "." + tablename + " "
@@ -660,11 +669,10 @@ public class RestMusicDataAPI {
if(lockId == null) {
logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
+ " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
- return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
- + "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+ + "and acquire lock or use ATOMIC instead of CRITICAL").toMap()).build();
}
- result = MusicCore.criticalPut(keyspace, tablename, primaryKey, queryObject, lockId,
- null);
+ result = MusicCore.criticalPut(keyspace, tablename, primaryKey, queryObject, lockId,null);
} else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
result = MusicCore.atomicPut(keyspace, tablename, primaryKey, queryObject, null);
@@ -674,17 +682,15 @@ public class RestMusicDataAPI {
}
} catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
if (result==null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap()).build();
}
- return new JsonResponse(result.getResult()).toMap();
+ return response.status(Status.OK).entity(new JsonResponse(result.getResult()).setMessage("Insert Successful").toMap()).build();
}
/**
@@ -701,42 +707,41 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Update Table", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> updateTable(
+ public Response updateTable(
@ApiParam(value = "Major Version",
required = true) @PathParam("version") String version,
@ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
+ required = false) @HeaderParam(XMINORVERSION) String minorVersion,
@ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
@ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
+ required = true) @HeaderParam(NS) String ns,
@ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
+ required = true) @HeaderParam(USERID) String userId,
@ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ required = true) @HeaderParam(PASSWORD) String password,
JsonUpdate updateObj,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
- @Context UriInfo info, @Context HttpServletResponse response) {
+ @Context UriInfo info) {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
Map<String, Object> authMap;
try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+ authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
aid, "updateTable");
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
long startTime = System.currentTimeMillis();
String operationId = UUID.randomUUID().toString();// just for infoging
@@ -750,19 +755,17 @@ public class RestMusicDataAPI {
Map<String, Object> valuesMap = updateObj.getValues();
TableMetadata tableInfo;
- try {
- tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
- } catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
- }
+ try {
+ tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+ } catch (MusicServiceException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
+ }
if (tableInfo == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE)
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
.setError("Table information not found. Please check input for table name= "
- + keyspace + "." + tablename).toMap();
+ + keyspace + "." + tablename).toMap()).build();
}
String vectorTs =
String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
@@ -776,8 +779,7 @@ public class RestMusicDataAPI {
colType = tableInfo.getColumn(entry.getKey()).getType();
} catch(NullPointerException ex) {
logger.error(EELFLoggerDelegate.errorLogger, "Invalid column name : "+entry.getKey());
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap()).build();
}
Object valueString = null;
try {
@@ -819,14 +821,12 @@ public class RestMusicDataAPI {
try {
rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
if(rowId == null || rowId.primarKeyValue.isEmpty()) {
-
- return new JsonResponse(ResultType.FAILURE)
- .setError("Mandatory WHERE clause is missing. Please check the input request.").toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Mandatory WHERE clause is missing. Please check the input request.").toMap()).build();
}
} catch (MusicServiceException ex) {
logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
queryObject.appendQueryString(
@@ -855,9 +855,8 @@ public class RestMusicDataAPI {
if(lockId == null) {
logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
+ " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
- + "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+ + "and acquire lock or use ATOMIC instead of CRITICAL").toMap()).build();
}
operationResult = MusicCore.criticalPut(keyspace, tablename, rowId.primarKeyValue,
queryObject, lockId, conditionInfo);
@@ -867,18 +866,16 @@ public class RestMusicDataAPI {
operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename,
rowId.primarKeyValue, queryObject, conditionInfo);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
} else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
try {
operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
queryObject, conditionInfo);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
}
long actualUpdateCompletionTime = System.currentTimeMillis();
@@ -897,11 +894,16 @@ public class RestMusicDataAPI {
logger.info(EELFLoggerDelegate.applicationLogger, timingString);
if (operationResult==null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"Null result - Please Contact admin", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap()).build();
+ }
+ if ( operationResult.getResult() == ResultType.SUCCESS ) {
+ return response.status(Status.OK).entity(new JsonResponse(operationResult.getResult()).setMessage(operationResult.getMessage()).toMap()).build();
+ } else {
+ logger.error(EELFLoggerDelegate.errorLogger,operationResult.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(operationResult.getResult()).setError(operationResult.getMessage()).toMap()).build();
}
- return new JsonResponse(operationResult.getResult()).toMap();
+
}
/**
@@ -918,48 +920,46 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Delete From table", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> deleteFromTable(
+ public Response deleteFromTable(
@ApiParam(value = "Major Version",
required = true) @PathParam("version") String version,
@ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
+ required = false) @HeaderParam(XMINORVERSION) String minorVersion,
@ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
@ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
+ required = true) @HeaderParam(NS) String ns,
@ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
+ required = true) @HeaderParam(USERID) String userId,
@ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ required = true) @HeaderParam(PASSWORD) String password,
JsonDelete delObj,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
- @Context UriInfo info, @Context HttpServletResponse response) {
+ @Context UriInfo info) {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
Map<String, Object> authMap = null;
- try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
- aid, "deleteFromTable");
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
- }
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
+ try {
+ authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+ aid, "deleteFromTable");
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
+ }
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
if(delObj == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.WARN, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Required HTTP Request body is missing.").toMap();
- }
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.WARN, ErrorTypes.DATAERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Required HTTP Request body is missing.").toMap()).build();
+ }
PreparedQueryObject queryObject = new PreparedQueryObject();
StringBuilder columnString = new StringBuilder();
@@ -979,9 +979,8 @@ public class RestMusicDataAPI {
try {
rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
String rowSpec = rowId.rowIdString.toString();
@@ -1016,39 +1015,41 @@ public class RestMusicDataAPI {
ReturnType operationResult = null;
try {
- if (consistency.equalsIgnoreCase(MusicUtil.EVENTUAL))
- operationResult = MusicCore.eventualPut(queryObject);
- else if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
- String lockId = delObj.getConsistencyInfo().get("lockId");
- if(lockId == null) {
+ if (consistency.equalsIgnoreCase(MusicUtil.EVENTUAL))
+ operationResult = MusicCore.eventualPut(queryObject);
+ else if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
+ String lockId = delObj.getConsistencyInfo().get("lockId");
+ if(lockId == null) {
logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
+ " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
- + "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+ + "and acquire lock or use ATOMIC instead of CRITICAL").toMap()).build();
}
- operationResult = MusicCore.criticalPut(keyspace, tablename, rowId.primarKeyValue,
- queryObject, lockId, conditionInfo);
- } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
- operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
- queryObject, conditionInfo);
- }
- else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
- operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename, rowId.primarKeyValue,
- queryObject, conditionInfo);
- }
+ operationResult = MusicCore.criticalPut(keyspace, tablename, rowId.primarKeyValue,
+ queryObject, lockId, conditionInfo);
+ } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
+ operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
+ queryObject, conditionInfo);
+ }
+ else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
+ operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename, rowId.primarKeyValue,
+ queryObject, conditionInfo);
+ }
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE)
- .setError("Unable to perform Delete operation. Exception from music").toMap();
- }
- if (operationResult.getResult().equals(ResultType.FAILURE)) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(operationResult.getMessage()).toMap();
- }
- return new JsonResponse(operationResult.getResult()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unable to perform Delete operation. Exception from music").toMap()).build();
+ }
+ if (operationResult==null) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap()).build();
+ }
+ if (operationResult.getResult().equals(ResultType.SUCCESS)) {
+ return response.status(Status.OK).entity(new JsonResponse(operationResult.getResult()).setMessage(operationResult.getMessage()).toMap()).build();
+ } else {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(operationResult.getMessage()).toMap()).build();
+ }
}
/**
@@ -1062,45 +1063,43 @@ public class RestMusicDataAPI {
@Path("/{keyspace}/tables/{tablename}")
@ApiOperation(value = "Drop Table", response = String.class)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> dropTable(
+ public Response dropTable(
@ApiParam(value = "Major Version",
required = true) @PathParam("version") String version,
@ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
+ required = false) @HeaderParam(XMINORVERSION) String minorVersion,
@ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
@ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
+ required = true) @HeaderParam(NS) String ns,
@ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
+ required = true) @HeaderParam(USERID) String userId,
@ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ required = true) @HeaderParam(PASSWORD) String password,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
- required = true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) throws Exception {
+ required = true) @PathParam("tablename") String tablename) throws Exception {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
Map<String, Object> authMap =
MusicCore.autheticateUser(ns, userId, password, keyspace, aid, "dropTable");
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
String consistency = "eventual";// for now this needs only eventual
// consistency
PreparedQueryObject query = new PreparedQueryObject();
query.appendQueryString("DROP TABLE " + keyspace + "." + tablename + ";");
try {
- return new JsonResponse(MusicCore.nonKeyRelatedPut(query, consistency)).toMap();
+ return response.status(Status.OK).entity(new JsonResponse(MusicCore.nonKeyRelatedPut(query, consistency)).toMap()).build();
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
}
@@ -1118,35 +1117,34 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Select Critical", response = Map.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> selectCritical(
+ public Response selectCritical(
@ApiParam(value = "Major Version",
required = true) @PathParam("version") String version,
@ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
+ required = false) @HeaderParam(XMINORVERSION) String minorVersion,
@ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
@ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
+ required = true) @HeaderParam(NS) String ns,
@ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
+ required = true) @HeaderParam(USERID) String userId,
@ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ required = true) @HeaderParam(PASSWORD) String password,
JsonInsert selObj,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
- @Context UriInfo info, @Context HttpServletResponse response) throws Exception {
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
- aid, "selectCritical");
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
+ @Context UriInfo info) throws Exception {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
+ Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,aid, "selectCritical");
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
logger.error(EELFLoggerDelegate.errorLogger,"Error while authentication... ", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
String lockId = selObj.getConsistencyInfo().get("lockId");
@@ -1156,9 +1154,8 @@ public class RestMusicDataAPI {
try {
rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
queryObject.appendQueryString(
"SELECT * FROM " + keyspace + "." + tablename + " WHERE " + rowId.rowIdString + ";");
@@ -1168,12 +1165,11 @@ public class RestMusicDataAPI {
String consistency = selObj.getConsistencyInfo().get("type");
if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
- if(lockId == null) {
+ if(lockId == null) {
logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
+ " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
- + "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+ + "and acquire lock or use ATOMIC instead of CRITICAL").toMap()).build();
}
results = MusicCore.criticalGet(keyspace, tablename, rowId.primarKeyValue, queryObject,
lockId);
@@ -1185,7 +1181,7 @@ public class RestMusicDataAPI {
results = MusicCore.atomicGetWithDeleteLock(keyspace, tablename, rowId.primarKeyValue, queryObject);
}
- return new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).toMap();
+ return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).toMap()).build();
}
/**
@@ -1200,34 +1196,34 @@ public class RestMusicDataAPI {
@Path("/{keyspace}/tables/{tablename}/rows")
@ApiOperation(value = "Select All or Select Specific", response = Map.class)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> select(
+ public Response select(
@ApiParam(value = "Major Version",
required = true) @PathParam("version") String version,
@ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
+ required = false) @HeaderParam(XMINORVERSION) String minorVersion,
@ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
@ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
+ required = true) @HeaderParam(NS) String ns,
@ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
+ required = true) @HeaderParam(USERID) String userId,
@ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ required = true) @HeaderParam(PASSWORD) String password,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
- @Context UriInfo info, @Context HttpServletResponse response) throws Exception {
+ @Context UriInfo info) throws Exception {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
Map<String, Object> authMap =
MusicCore.autheticateUser(ns, userId, password, keyspace, aid, "select");
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
PreparedQueryObject queryObject = new PreparedQueryObject();
@@ -1239,19 +1235,17 @@ public class RestMusicDataAPI {
queryObject = selectSpecificQuery(version, minorVersion, patchVersion, aid, ns,
userId, password, keyspace, tablename, info, limit);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
}
try {
ResultSet results = MusicCore.get(queryObject);
- return new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).toMap();
+ return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).toMap()).build();
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.ERROR, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.ERROR, ErrorTypes.MUSICSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
}
@@ -1314,9 +1308,10 @@ public class RestMusicDataAPI {
String keyName = entry.getKey();
List<String> valueList = entry.getValue();
String indValue = valueList.get(0);
- DataType colType = tableInfo.getColumn(entry.getKey()).getType();
+ DataType colType = null;
Object formattedValue = null;
try {
+ colType = tableInfo.getColumn(entry.getKey()).getType();
formattedValue = MusicUtil.convertToActualDataType(colType, indValue);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
diff --git a/src/main/java/org/onap/music/rest/RestMusicQAPI.java b/src/main/java/org/onap/music/rest/RestMusicQAPI.java
index 39233dc5..e08adaf7 100755
--- a/src/main/java/org/onap/music/rest/RestMusicQAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicQAPI.java
@@ -26,7 +26,6 @@ package org.onap.music.rest;
import java.util.HashMap;
import java.util.Map;
-import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -38,6 +37,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.onap.music.datastore.jsonobjects.JsonDelete;
@@ -47,8 +47,6 @@ import org.onap.music.datastore.jsonobjects.JsonUpdate;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.main.MusicCore;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
import org.onap.music.datastore.PreparedQueryObject;
import com.datastax.driver.core.ResultSet;
@@ -60,199 +58,194 @@ import io.swagger.annotations.ApiParam;
@Path("/priorityq/")
@Api(value="Q Api")
public class RestMusicQAPI {
-
- private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
-
-
- /**
- *
- * @param tableObj
- * @param keyspace
- * @param tablename
- * @throws Exception
- */
-
- @POST
- @Path("/keyspaces/{keyspace}/{qname}")
- @ApiOperation(value = "", response = Void.class)
- @Consumes(MediaType.APPLICATION_JSON)
- public Map<String,Object> createQ(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
- @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonTable tableObj,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) throws Exception{
- return new RestMusicDataAPI().createTable(version,minorVersion,patchVersion,aid, ns, userId, password, tableObj, keyspace, tablename,response);
- }
-
- /**
- *
- * @param insObj
- * @param keyspace
- * @param tablename
- * @throws Exception
- */
- @POST
- @Path("/keyspaces/{keyspace}/{qname}/rows")
- @ApiOperation(value = "", response = Void.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> insertIntoQ(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonInsert insObj,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) throws Exception{
- return new RestMusicDataAPI().insertIntoTable(version,minorVersion,patchVersion,aid, ns, userId, password, insObj, keyspace, tablename,response);
- }
-
- /**
- *
- * @param updateObj
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @PUT
- @Path("/keyspaces/{keyspace}/{qname}/rows")
- @ApiOperation(value = "", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> updateQ(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonUpdate updateObj,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context UriInfo info,
- @Context HttpServletResponse response) throws Exception{
- return new RestMusicDataAPI().updateTable(version,minorVersion,patchVersion,aid, ns, userId, password, updateObj, keyspace, tablename, info,response);
- }
-
- /**
- *
- * @param delObj
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @DELETE
- @Path("/keyspaces/{keyspace}/{qname}/rows")
- @ApiOperation(value = "", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> deleteFromQ(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
- @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonDelete delObj,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context UriInfo info,
- @Context HttpServletResponse response) throws Exception{
- return new RestMusicDataAPI().deleteFromTable(version,minorVersion,patchVersion,aid, ns, userId, password, delObj, keyspace, tablename, info,response);
- }
-
- /**
- *
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @GET
- @Path("/keyspaces/{keyspace}/{qname}/peek")
- @ApiOperation(value = "", response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String, HashMap<String, Object>> peek(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
- @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context UriInfo info) throws Exception{
- int limit =1; //peek must return just the top row
- PreparedQueryObject query = new RestMusicDataAPI().selectSpecificQuery(version,minorVersion,patchVersion,aid, ns, userId, password,keyspace,tablename,info,limit);
- ResultSet results = MusicCore.get(query);
- return MusicCore.marshallResults(results);
-
- }
-
- /**
- *
- *
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @GET
- @Path("/keyspaces/{keyspace}/{qname}/filter")
- @ApiOperation(value = "", response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String, HashMap<String, Object>> filter(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
- @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context UriInfo info) throws Exception{
- int limit =-1;
- PreparedQueryObject query = new RestMusicDataAPI().selectSpecificQuery(version,minorVersion,patchVersion,aid, ns, userId, password,keyspace,tablename,info,limit);
- ResultSet results = MusicCore.get(query);
- return MusicCore.marshallResults(results);
- }
-
- /**
- *
- * @param tabObj
- * @param keyspace
- * @param tablename
- * @throws Exception
- */
- @DELETE
- @ApiOperation(value = "", response = Void.class)
- @Path("/keyspaces/{keyspace}/{qname}")
- public Map<String,Object> dropQ(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
- @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonTable tabObj,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) throws Exception{
- return new RestMusicDataAPI().dropTable(version,minorVersion,patchVersion,aid, ns, userId, password, keyspace, tablename,response);
- }
+
+ private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
+
+
+ /**
+ *
+ * @param tableObj
+ * @param keyspace
+ * @param tablename
+ * @throws Exception
+ */
+
+ @POST
+ @Path("/keyspaces/{keyspace}/{qname}")
+ @ApiOperation(value = "", response = Void.class)
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response createQ(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
+ @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonTable tableObj,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename) throws Exception{
+ return new RestMusicDataAPI().createTable(version,minorVersion,patchVersion,aid, ns, userId, password, tableObj, keyspace, tablename);
+ }
+
+ /**
+ *
+ * @param insObj
+ * @param keyspace
+ * @param tablename
+ * @throws Exception
+ */
+ @POST
+ @Path("/keyspaces/{keyspace}/{qname}/rows")
+ @ApiOperation(value = "", response = Void.class)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response insertIntoQ(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonInsert insObj,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename) throws Exception{
+ return new RestMusicDataAPI().insertIntoTable(version,minorVersion,patchVersion,aid, ns, userId, password, insObj, keyspace, tablename);
+ }
+
+ /**
+ *
+ * @param updateObj
+ * @param keyspace
+ * @param tablename
+ * @param info
+ * @return
+ * @throws Exception
+ */
+ @PUT
+ @Path("/keyspaces/{keyspace}/{qname}/rows")
+ @ApiOperation(value = "", response = String.class)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateQ(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonUpdate updateObj,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
+ @Context UriInfo info) throws Exception{
+ return new RestMusicDataAPI().updateTable(version,minorVersion,patchVersion,aid, ns, userId, password, updateObj, keyspace, tablename, info);
+ }
+
+ /**
+ *
+ * @param delObj
+ * @param keyspace
+ * @param tablename
+ * @param info
+ * @return
+ * @throws Exception
+ */
+ @DELETE
+ @Path("/keyspaces/{keyspace}/{qname}/rows")
+ @ApiOperation(value = "", response = String.class)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response deleteFromQ(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
+ @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonDelete delObj,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
+ @Context UriInfo info) throws Exception{
+ return new RestMusicDataAPI().deleteFromTable(version,minorVersion,patchVersion,aid, ns, userId, password, delObj, keyspace, tablename, info);
+ }
+
+ /**
+ *
+ * @param keyspace
+ * @param tablename
+ * @param info
+ * @return
+ * @throws Exception
+ */
+ @GET
+ @Path("/keyspaces/{keyspace}/{qname}/peek")
+ @ApiOperation(value = "", response = Map.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Map<String, HashMap<String, Object>> peek(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
+ @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
+ @Context UriInfo info) throws Exception{
+ int limit =1; //peek must return just the top row
+ PreparedQueryObject query = new RestMusicDataAPI().selectSpecificQuery(version,minorVersion,patchVersion,aid, ns, userId, password,keyspace,tablename,info,limit);
+ ResultSet results = MusicCore.get(query);
+ return MusicCore.marshallResults(results);
+
+ }
+
+ /**
+ *
+ *
+ * @param keyspace
+ * @param tablename
+ * @param info
+ * @return
+ * @throws Exception
+ */
+ @GET
+ @Path("/keyspaces/{keyspace}/{qname}/filter")
+ @ApiOperation(value = "", response = Map.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Map<String, HashMap<String, Object>> filter(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
+ @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
+ @Context UriInfo info) throws Exception{
+ int limit =-1;
+ PreparedQueryObject query = new RestMusicDataAPI().selectSpecificQuery(version,minorVersion,patchVersion,aid, ns, userId, password,keyspace,tablename,info,limit);
+ ResultSet results = MusicCore.get(query);
+ return MusicCore.marshallResults(results);
+ }
+
+ /**
+ *
+ * @param tabObj
+ * @param keyspace
+ * @param tablename
+ * @throws Exception
+ */
+ @DELETE
+ @ApiOperation(value = "", response = Void.class)
+ @Path("/keyspaces/{keyspace}/{qname}")
+ public Response dropQ(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
+ @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonTable tabObj,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename) throws Exception{
+ return new RestMusicDataAPI().dropTable(version,minorVersion,patchVersion,aid, ns, userId, password, keyspace, tablename);
+ }
}