+
+ @POST
+ @Path("/onboard")
+ @ApiOperation(value = "Onboard application", response = String.class)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public MusicResponse onboard(JsonOnboard jsonObj,
+ @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
+ logger.info(EELFLoggerDelegate.errorLogger, "oboarding app");
+ MusicResponse response = new MusicResponse();
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.info(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ response.setResposne("fail", "auth error");
+ }
+ PreparedQueryObject pQurey = new PreparedQueryObject();
+ pQurey.appendQueryString("Describe keyspace + ?");
+ pQurey.addValue(MusicUtil.convertToActualDataType(DataType.text(),jsonObj.getKeyspace()));
+ KeyspaceMetadata keyspaceInfo = null;
+ //authenticator.checkOnbaordUserAccess(jsonObj.getUserId(), jsonObj.getAppname());
+ try {
+ keyspaceInfo = MusicDataStoreHandle.returnkeyspaceMetadata(jsonObj.getKeyspace());
+ }catch (Exception e) {
+ logger.info(EELFLoggerDelegate.applicationLogger,"Application onbaord failed for "+ jsonObj.getKeyspace());
+
+ }
+ if(keyspaceInfo == null) {
+ logger.info(EELFLoggerDelegate.applicationLogger,"Keyspace does not exist, contact music support to create a keyspace and onbaord again");
+ response.setResposne("fail", "Keyspace does not exist, contact music support to create a keyspace and onboard again");
+ return response;
+ }
+ Response result = null;
+ try {
+ result = onboardAppWithMusic(jsonObj, authorization);
+ if(result.getStatus()!= 200) {
+ response.setResposne("fail", result.getEntity().toString());
+ }else {
+ response.setResposne("success", "Onboard Success");
+ }
+ }catch(Exception ex) {
+ response.setResposne("fail", ex.getMessage());
+ return response;
+
+ }
+ return response;
+ }
+
+ @POST
+ @Path("/disable")
+ @ApiOperation(value = "Onboard application", response = String.class)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public MusicResponse disableApplicationAccess(@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
+ @ApiParam(value = "uuid", required = true) @HeaderParam("uuid") String uuid) throws Exception {
+ logger.info(EELFLoggerDelegate.errorLogger, "oboarding app");
+ MusicResponse response = new MusicResponse();
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.info(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ response.setResposne("fail", "Authorization failed for music admin");
+ }
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("SELECT * from admin.keyspace_master where uuid = ?");
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
+ Row row = MusicDataStoreHandle.getDSHandle().executeGet(queryObject, "eventual").one();
+ boolean toggleAccess = row.getBool("is_api");
+ queryObject = null;
+ queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("UPDATE admin.keyspace_master SET is_api = ? WHERE uuid = ?");
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), !toggleAccess));
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
+ try {
+ MusicDataStoreHandle.getDSHandle().executePut(queryObject, "eventual");
+ response.setResposne("success","Access toggle success");
+ }catch(Exception ex) {
+ response.setResposne("fail", ex.getMessage());
+ }
+
+ return response;
+ }
+
+ @POST
+ @Path("/editApplication")
+ @ApiOperation(value = "Onboard application", response = String.class)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public MusicResponse editApplication(JsonOnboard jsonObj,
+ @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
+ logger.info(EELFLoggerDelegate.errorLogger, "oboarding app");
+ MusicResponse response = new MusicResponse();
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.info(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ response.setResposne("fail", "auth error");
+ }
+ KeyspaceMetadata keyspaceInfo = null;
+ try {
+ keyspaceInfo = MusicDataStoreHandle.returnkeyspaceMetadata(jsonObj.getKeyspace());
+ }catch (Exception e) {
+ logger.info(EELFLoggerDelegate.applicationLogger,"Application Update failed for "+ jsonObj.getKeyspace());
+
+ }
+ if(keyspaceInfo == null) {
+ logger.info(EELFLoggerDelegate.applicationLogger,"Keyspace does not exist, contact music support to create a keyspace and onbaord again");
+ response.setResposne("fail", "Keyspace does not exist, contact music support to create a keyspace and update again");
+ return response;
+ }
+
+ try {
+ Response res = updateOnboardApp(jsonObj, authorization);
+ if(res.getStatus() != 200) {
+ response.setResposne("fail", res.getEntity().toString());
+ }else
+ response.setResposne("success", "Update success");
+ }catch(Exception ex){
+ logger.info(EELFLoggerDelegate.errorLogger,"Exception while updating application");
+ logger.info(EELFLoggerDelegate.errorLogger,ex.getMessage());
+ response.setResposne("fail", ex.getMessage());
+
+ }
+ return response;
+ }
+
+