aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/music/rest/RestMusicAdminAPI.java')
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicAdminAPI.java317
1 files changed, 158 insertions, 159 deletions
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();
}
}