- public Response callbackOps(final JSONObject inputJsonObj) {
- ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
- Map<String, Object> resultMap = new HashMap<>();
- new Thread(new Runnable() {
- public void run() {
- makeAsyncCall(inputJsonObj);
- }
- }).start();
-
- return response.status(Status.OK).entity(resultMap).build();
- }
-
- private Response makeAsyncCall(JSONObject inputJsonObj) {
- ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
- Map<String, Object> resultMap = new HashMap<>();
- try {
- logger.info(EELFLoggerDelegate.applicationLogger, "Got notification: " + inputJsonObj.getData());
- logger.info("Got notification: " + inputJsonObj.getData());
- String dataStr = inputJsonObj.getData();
- JSONCallbackResponse jsonResponse = mapper.readValue(dataStr, JSONCallbackResponse.class);
- String operation = jsonResponse.getOperation();
- Map<String, String> changeValueMap = jsonResponse.getChangeValue();
- String ksTableName = jsonResponse.getFull_table(); //conductor.plans
- if("admin.notification_master".equals(ksTableName)) {
- CachingUtil.updateCallbackNotifyList(new ArrayList<String>());
- return response.status(Status.OK).entity(resultMap).build();
- }
- List<String> inputUpdateList = jsonResponse.getUpdateList();
-
- String field_value = null;
- List<String> notifiyList = CachingUtil.getCallbackNotifyList();
- if(notifiyList == null || notifiyList.isEmpty()) {
- logger.info("Is cache empty? reconstructing Object from cache..");
- constructJsonCallbackFromCache();
- }
- notifiyList = CachingUtil.getCallbackNotifyList();
- JsonCallback baseRequestObj = null;
-
- if("update".equals(operation)) {
- for(String element: inputUpdateList) {
- baseRequestObj = CachingUtil.getCallBackCache(element);
- if(baseRequestObj != null) {
- logger.info("Found the element that was changed... "+element);
- break;
- }
- }
-
- List<String> updateList = jsonResponse.getUpdateList();
- for(String element : updateList) {
- if(notifiyList.contains(element)) {
- logger.info("Found the notifyOn property: "+element);
- field_value = element;
- break;
- }
- }
- if(baseRequestObj == null || field_value == null) {
- for(String element: inputUpdateList) {
- String[] elementArr = element.split(":");
- String newElement = null;
- if(elementArr.length >= 2) {
- newElement = elementArr[0]+":"+elementArr[1];
- }
- baseRequestObj = CachingUtil.getCallBackCache(newElement);
- if(baseRequestObj != null) {
- logger.info("Found the element that was changed... "+newElement);
- break;
- }
- }
- for(String element : updateList) {
- String[] elementArr = element.split(":");
- String newElement = null;
- if(elementArr.length >= 2) {
- newElement = elementArr[0]+":"+elementArr[1];
- }
- if(notifiyList.contains(newElement)) {
- logger.info("Found the notifyOn property: "+newElement);
- field_value = newElement;
- break;
- }
- }
- }
- } else {
- field_value = jsonResponse.getFull_table();
- baseRequestObj = CachingUtil.getCallBackCache(field_value);
- }
-
- if(baseRequestObj == null || field_value == null) {
- resultMap.put("Exception",
- "Oops. Something went wrong. Please make sure Callback properties are onboarded.");
- logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.INCORRECTDATA,
- ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- return response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- logger.info(EELFLoggerDelegate.applicationLogger, "Going through list: "+operation+ " && List: "+jsonResponse.getUpdateList());
-
- String key = "admin" + "." + "notification_master" + "." + baseRequestObj.getUuid();
- String lockId = MusicCore.createLockReference(key);
- ReturnType lockAcqResult = MusicCore.acquireLock(key, lockId);
- if(!"SUCCESS".equals(lockAcqResult.getResult().toString())) {
- logger.error(EELFLoggerDelegate.errorLogger, "Some other node is notifying the caller..: ");
- }
-
- logger.info(EELFLoggerDelegate.applicationLogger, operation+ ": Operation :: changeValue: "+changeValueMap);
- if("update".equals(operation)) {
- String notifyWhenChangeIn = baseRequestObj.getNotifyWhenChangeIn(); // conductor.plans.status
- if(null!=field_value && field_value.equals(notifyWhenChangeIn)) {
- notifyCallBackAppl(jsonResponse, baseRequestObj);
- }
- } else if("delete".equals(operation)) {
- String notifyWhenDeletesIn = baseRequestObj.getNotifyWhenDeletesIn(); // conductor.plans.status
- if(null!=field_value && field_value.equals(notifyWhenDeletesIn)) {
- notifyCallBackAppl(jsonResponse, baseRequestObj);
- }
- } else if("insert".equals(operation)) {
- String notifyWhenInsertsIn = baseRequestObj.getNotifyWhenInsertsIn(); // conductor.plans.status
- if(null!=field_value && field_value.equals(notifyWhenInsertsIn)) {
- notifyCallBackAppl(jsonResponse, baseRequestObj);
- }
- }
- MusicCore.releaseLock(lockId, true);
- } catch(Exception e) {
- e.printStackTrace();
- logger.error(EELFLoggerDelegate.errorLogger, "Exception while notifying...."+e.getMessage());