Sonar Fixes to increate Coverage on Unit tests
[music.git] / src / main / java / org / onap / music / rest / RestMusicDataAPI.java
index ba0f1a3..0eedbaa 100755 (executable)
@@ -1,20 +1,16 @@
 /*
- * ============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=============================================
  * ====================================================================
@@ -26,7 +22,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
-// import java.util.logging.Level;
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
@@ -41,21 +36,24 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
 import org.onap.music.datastore.PreparedQueryObject;
 import org.onap.music.datastore.jsonobjects.JsonDelete;
 import org.onap.music.datastore.jsonobjects.JsonInsert;
 import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-import org.onap.music.response.jsonobjects.JsonResponse;
 import org.onap.music.datastore.jsonobjects.JsonTable;
 import org.onap.music.datastore.jsonobjects.JsonUpdate;
+import org.onap.music.eelf.logging.EELFLoggerDelegate;
+import org.onap.music.exceptions.MusicLockingException;
+import org.onap.music.exceptions.MusicServiceException;
 import org.onap.music.main.CachingUtil;
 import org.onap.music.main.MusicCore;
+import org.onap.music.main.MusicCore.Condition;
 import org.onap.music.main.MusicUtil;
 import org.onap.music.main.ResultType;
 import org.onap.music.main.ReturnType;
-import org.onap.music.main.MusicCore.Condition;
+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;
@@ -90,13 +88,13 @@ public class RestMusicDataAPI {
      *
      */
 
-
-    private static EELFLogger logger = EELFManager.getInstance().getLogger(RestMusicDataAPI.class);
+    private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
     private static String xLatestVersion = "X-latestVersion";
 
     private class RowIdentifier {
         public String primarKeyValue;
         public StringBuilder rowIdString;
+        @SuppressWarnings("unused")
         public PreparedQueryObject queryObject;// the string with all the row
                                                // identifiers separated by AND
 
@@ -108,6 +106,7 @@ public class RestMusicDataAPI {
         }
     }
 
+    @SuppressWarnings("unused")
     private String buildVersion(String major, String minor, String patch) {
         if (minor != null) {
             major += "." + minor;
@@ -148,15 +147,21 @@ public class RestMusicDataAPI {
                     JsonKeySpace kspObject,
                     @ApiParam(value = "Keyspace Name",
                                     required = true) @PathParam("name") String keyspaceName,
-                    @Context HttpServletResponse response) throws Exception {
+                    @Context HttpServletResponse response) {
         Map<String, Object> resultMap = CachingUtil.verifyOnboarding(ns, userId, password);
         response.addHeader(xLatestVersion, MusicUtil.getVersion());
         if (!resultMap.isEmpty()) {
             return resultMap;
         }
 
-        resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
-                        "createKeySpace");
+        try {
+                       resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
+                                       "createKeySpace");
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.applicationLogger,
+                        "Exception while authenting the user.");
+                       return resultMap;
+               }
         String newAid = null;
         if (!resultMap.isEmpty()) {
             if (resultMap.containsKey("aid")) {
@@ -165,8 +170,9 @@ public class RestMusicDataAPI {
                 return resultMap;
         }
 
-        String consistency = MusicUtil.EVENTUAL;// for now this needs only eventual
-                                        // consistency
+        String consistency = MusicUtil.EVENTUAL;// for now this needs only
+                                                // eventual
+        // consistency
 
         PreparedQueryObject queryObject = new PreparedQueryObject();
         boolean result = false;
@@ -182,25 +188,33 @@ public class RestMusicDataAPI {
 
         queryObject.appendQueryString(";");
         long end = System.currentTimeMillis();
-        logger.info("Time taken for setting up query in create keyspace:" + (end - start));
+        logger.info(EELFLoggerDelegate.applicationLogger,
+                        "Time taken for setting up query in create keyspace:" + (end - start));
 
         try {
             result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
-            logger.debug("resulta = " + result);
+            logger.error(EELFLoggerDelegate.errorLogger, "resulta = " + result);
         } catch (Exception e) {
-            logger.error(e.getMessage());
+            logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+            resultMap.put("Exception", "Couldn't create keyspace. Please make sure all the information is correct.");
 
         }
         logger.debug("result = " + result);
         if (!result) {
             resultMap.put("Status", String.valueOf(result));
-            resultMap.put("Exception", "Keyspace already exists. Please contact admin.");
+            if(!resultMap.containsKey("Exception"))
+               resultMap.put("Exception", "Keyspace already exists. Please contact admin.");
             if (resultMap.get("uuid").equals("new")) {
                 queryObject = new PreparedQueryObject();
                 queryObject.appendQueryString(
                                 "DELETE FROM admin.keyspace_master where uuid = " + newAid);
                 queryObject.appendQueryString(";");
-                result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+                try {
+                                       result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+                               } catch (MusicServiceException e) {
+                                       logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+                                       resultMap.put("Exception", e.getMessage());
+                               }
                 resultMap.remove("aid");
                 resultMap.remove("uuid");
                 return resultMap;
@@ -208,12 +222,24 @@ public class RestMusicDataAPI {
             } else {
                 queryObject = new PreparedQueryObject();
                 queryObject.appendQueryString(
-                                "UPDATE admin.keyspace_master SET keyspace_name=?,password=?,is_api=null where uuid = ?;");
-                queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
+                                "UPDATE admin.keyspace_master SET keyspace_name=? where uuid = ?;");
+                try {
+                       queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
                                 MusicUtil.DEFAULTKEYSPACENAME));
-                queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), null));
-                queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), newAid));
-                result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+                                       queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), newAid));
+                               } catch (Exception e) {
+                                       logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+                                       resultMap.put("Exception", "Unable to process input data. Invalid input data type. "
+                                                       + "Please check keyspace_name and aid.. ");
+                               }
+                try {
+                                       result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+                               } catch (MusicServiceException e) {
+                                       e.printStackTrace();
+                                       logger.error(EELFLoggerDelegate.errorLogger, "Unable to process operation. Error: "+e.getMessage());
+                                       resultMap.put("Exception", "Unable to process operation. Error: "+e.getMessage());
+                                       return resultMap;
+                               }
                 resultMap.remove("aid");
                 resultMap.remove("uuid");
                 return resultMap;
@@ -225,23 +251,24 @@ public class RestMusicDataAPI {
             queryObject.appendQueryString("CREATE ROLE IF NOT EXISTS '" + userId
                             + "' WITH PASSWORD = '" + password + "' AND LOGIN = true;");
             result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
-            if (result) {
-                queryObject = new PreparedQueryObject();
-                queryObject.appendQueryString("GRANT ALL PERMISSIONS on KEYSPACE " + keyspaceName
-                                + " to " + userId);
-                queryObject.appendQueryString(";");
-                result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
-            } else {
-                resultMap.remove("uuid");
-                resultMap.put("Exception", "Exception while creating user.");
-                return resultMap;
-            }
+            queryObject = new PreparedQueryObject();
+            queryObject.appendQueryString("GRANT ALL PERMISSIONS on KEYSPACE " + keyspaceName
+                                + " to '" + userId + "'");
+            queryObject.appendQueryString(";");
+            result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
         } catch (Exception e) {
-            logger.error(e.getMessage());
+            logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
         }
         resultMap.remove("uuid");
-        if (CachingUtil.isAAFApplication(ns))
-            resultMap.remove("aid");
+        try {
+                       if (CachingUtil.isAAFApplication(ns))
+                           resultMap.remove("aid");
+               } catch (MusicServiceException e) {
+                       e.printStackTrace();
+                       logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+                       resultMap.put("Exception", e.getMessage());
+                       return resultMap;
+               }
         resultMap.put("Status", String.valueOf(result));
         return resultMap;
 
@@ -286,8 +313,9 @@ public class RestMusicDataAPI {
             return resultMap;
         }
 
-        String consistency = MusicUtil.EVENTUAL;// for now this needs only eventual
-                                        // consistency
+        String consistency = MusicUtil.EVENTUAL;// for now this needs only
+                                                // eventual
+        // consistency
         String appName = CachingUtil.getAppName(keyspaceName);
         String uuid = CachingUtil.getUuidFromMusicCache(keyspaceName);
         PreparedQueryObject pQuery = new PreparedQueryObject();
@@ -303,10 +331,9 @@ public class RestMusicDataAPI {
         } else if (count == 1) {
             pQuery = new PreparedQueryObject();
             pQuery.appendQueryString(
-                            "UPDATE admin.keyspace_master SET keyspace_name=?,password=?,is_api=null where uuid = ?;");
+                    "UPDATE admin.keyspace_master SET keyspace_name=? where uuid = ?;");
             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(),
-                            MusicUtil.DEFAULTKEYSPACENAME));
-            pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), null));
+                    MusicUtil.DEFAULTKEYSPACENAME));
             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
             MusicCore.nonKeyRelatedPut(pQuery, consistency);
         } else {
@@ -373,11 +400,17 @@ public class RestMusicDataAPI {
         int counter = 0;
         String primaryKey;
         for (Map.Entry<String, String> entry : fields.entrySet()) {
-            fieldsString.append("" + entry.getKey() + " " + entry.getValue() + "");
+            
             if (entry.getKey().equals("PRIMARY KEY")) {
-                primaryKey = entry.getValue().substring(entry.getValue().indexOf('(') + 1);
-                primaryKey = primaryKey.substring(0, primaryKey.indexOf(')'));
-            }
+               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() + "");
             if (counter == fields.size() - 1)
                 fieldsString.append(")");
             else
@@ -395,6 +428,7 @@ public class RestMusicDataAPI {
                 if (ot instanceof String) {
                     value = "'" + value + "'";
                 } else if (ot instanceof Map) {
+                    @SuppressWarnings("unchecked")
                     Map<String, Object> otMap = (Map<String, Object>) ot;
                     value = "{" + MusicUtil.jsonMaptoSqlString(otMap, ",") + "}";
                 }
@@ -407,14 +441,18 @@ public class RestMusicDataAPI {
             }
         }
 
-        queryObject.appendQueryString("CREATE TABLE IF NOT EXISTS " + keyspace + "." + tablename
-                        + " " + fieldsString);
+        queryObject.appendQueryString(
+                        "CREATE TABLE " + keyspace + "." + tablename + " " + fieldsString);
 
         if (propertiesMap != null)
             queryObject.appendQueryString(" WITH " + propertiesString);
 
         queryObject.appendQueryString(";");
-        result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+        try {
+            result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+        } catch (MusicServiceException ex) {
+            return new JsonResponse(false, ex.getMessage(), "").toMap();
+        }
 
         return new JsonResponse(result, "", "").toMap();
     }
@@ -502,9 +540,15 @@ public class RestMusicDataAPI {
                                     required = true) @PathParam("keyspace") String keyspace,
                     @ApiParam(value = "Table Name",
                                     required = true) @PathParam("tablename") String tablename,
-                    @Context HttpServletResponse response) throws Exception {
-        Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
-                        aid, "insertIntoTable");
+                    @Context HttpServletResponse response) {
+        Map<String, Object> resultMap = null;
+        try {
+          resultMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+                          aid, "insertIntoTable");
+        } catch (Exception e) {
+          logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+          return new ReturnType(ResultType.FAILURE, e.getMessage()).toMap();
+        }
         response.addHeader(xLatestVersion, MusicUtil.getVersion());
         if (resultMap.containsKey("aid"))
             resultMap.remove("aid");
@@ -514,7 +558,17 @@ public class RestMusicDataAPI {
         ReturnType result = null;
         Map<String, Object> valuesMap = insObj.getValues();
         PreparedQueryObject queryObject = new PreparedQueryObject();
-        TableMetadata tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+        TableMetadata tableInfo = null;
+               try {
+                       tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+                       if(tableInfo == null) 
+                               throw new MusicServiceException("Table name doesn't exists. Please check the table name.");
+               } catch (MusicServiceException e) {
+                       e.printStackTrace();
+                       logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+                       resultMap.put(ResultType.SYNTAXERROR.getResult(), e.getMessage());
+                       return resultMap;
+               }
         String primaryKeyName = tableInfo.getPrimaryKey().get(0).getName();
         StringBuilder fieldsString = new StringBuilder("(vector_ts,");
         String vectorTs =
@@ -534,7 +588,13 @@ public class RestMusicDataAPI {
 
             DataType colType = tableInfo.getColumn(entry.getKey()).getType();
 
-            Object formattedValue = MusicUtil.convertToActualDataType(colType, valueObj);
+            Object formattedValue = null;
+            try {
+              formattedValue = MusicUtil.convertToActualDataType(colType, valueObj);
+            } catch (Exception e) {
+              logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+              //return new ReturnType(ResultType.FAILURE, e.getMessage()).toMap();
+          }
             valueString.append("?");
             queryObject.addValue(formattedValue);
 
@@ -555,20 +615,20 @@ public class RestMusicDataAPI {
         String timestamp = insObj.getTimestamp();
 
         if ((ttl != null) && (timestamp != null)) {
-            logger.info("both there");
+            logger.info(EELFLoggerDelegate.applicationLogger, "both there");
             queryObject.appendQueryString(" USING TTL ? AND TIMESTAMP ?");
             queryObject.addValue(Integer.parseInt(ttl));
             queryObject.addValue(Long.parseLong(timestamp));
         }
 
         if ((ttl != null) && (timestamp == null)) {
-            logger.info("ONLY TTL there");
+            logger.info(EELFLoggerDelegate.applicationLogger, "ONLY TTL there");
             queryObject.appendQueryString(" USING TTL ?");
             queryObject.addValue(Integer.parseInt(ttl));
         }
 
         if ((ttl == null) && (timestamp != null)) {
-            logger.info("ONLY timestamp there");
+            logger.info(EELFLoggerDelegate.applicationLogger, "ONLY timestamp there");
             queryObject.appendQueryString(" USING TIMESTAMP ?");
             queryObject.addValue(Long.parseLong(timestamp));
         }
@@ -586,12 +646,16 @@ public class RestMusicDataAPI {
             } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
                 result = MusicCore.atomicPut(keyspace, tablename, primaryKey, queryObject, null);
 
+            }
+            else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
+                result = MusicCore.atomicPutWithDeleteLock(keyspace, tablename, primaryKey, queryObject, null);
+
             }
             return (result != null) ? result.toMap()
                             : new ReturnType(ResultType.FAILURE,
                                             "Null result - Please Contact admin").toMap();
         } catch (Exception ex) {
-            logger.error(ex.getMessage());
+            logger.error(EELFLoggerDelegate.applicationLogger, ex.getMessage());
             return new ReturnType(ResultType.FAILURE, ex.getMessage()).toMap();
         }
     }
@@ -629,9 +693,15 @@ public class RestMusicDataAPI {
                                     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> resultMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
-                        aid, "updateTable");
+                    @Context UriInfo info, @Context HttpServletResponse response) {
+        Map<String, Object> resultMap;
+        try {
+          resultMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+                          aid, "updateTable");
+        } catch (Exception e) {
+          logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+          return new ReturnType(ResultType.FAILURE, e.getMessage()).toMap();
+        }
         response.addHeader(xLatestVersion, MusicUtil.getVersion());
         if (resultMap.containsKey("aid"))
             resultMap.remove("aid");
@@ -642,14 +712,27 @@ public class RestMusicDataAPI {
         String operationId = UUID.randomUUID().toString();// just for infoging
                                                           // purposes.
         String consistency = updateObj.getConsistencyInfo().get("type");
-        logger.info("--------------Music " + consistency + " update-" + operationId
-                        + "-------------------------");
+        logger.info(EELFLoggerDelegate.applicationLogger, "--------------Music " + consistency
+                        + " update-" + operationId + "-------------------------");
         // obtain the field value pairs of the update
 
         PreparedQueryObject queryObject = new PreparedQueryObject();
         Map<String, Object> valuesMap = updateObj.getValues();
 
-        TableMetadata tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+        TableMetadata tableInfo;
+               try {
+                       tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+               } catch (MusicServiceException e) {
+                       e.printStackTrace();
+                       logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+                       resultMap.put("Exception", e.getMessage());
+                       return resultMap;
+               }
+        if (tableInfo == null) {
+            return new ReturnType(ResultType.FAILURE,
+                            "Table information not found. Please check input for table name= "
+                                            + keyspace + "." + tablename).toMap();
+        }
         String vectorTs =
                         String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
         StringBuilder fieldValueString = new StringBuilder("vector_ts=?,");
@@ -658,7 +741,13 @@ public class RestMusicDataAPI {
         for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
             Object valueObj = entry.getValue();
             DataType colType = tableInfo.getColumn(entry.getKey()).getType();
-            Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
+            Object valueString = null;
+            try {
+              valueString = MusicUtil.convertToActualDataType(colType, valueObj);
+            } catch (Exception e) {
+              logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+              //return new ReturnType(ResultType.FAILURE, e.getMessage()).toMap();
+            }
             fieldValueString.append(entry.getKey() + "= ?");
             queryObject.addValue(valueString);
             if (counter != valuesMap.size() - 1)
@@ -689,8 +778,17 @@ public class RestMusicDataAPI {
             queryObject.addValue(Long.parseLong(timestamp));
         }
         // get the row specifier
-        RowIdentifier rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(),
-                        queryObject);
+        RowIdentifier rowId = null;
+        try {
+            rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
+            if(rowId == null || rowId.primarKeyValue.isEmpty()) {
+               resultMap.put(ResultType.SYNTAXERROR.getResult(), "Mandatory WHERE clause is missing. Please check the input request.");
+               return resultMap;
+            }
+        } catch (MusicServiceException ex) {
+            logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage());
+            return new ReturnType(ResultType.FAILURE, ex.getMessage()).toMap();
+        }
 
         queryObject.appendQueryString(
                         " SET " + fieldValueString + " WHERE " + rowId.rowIdString + ";");
@@ -701,8 +799,10 @@ public class RestMusicDataAPI {
             conditionInfo = null;
         else {// to avoid parsing repeatedly, just send the select query to
               // obtain row
-            String selectQuery = "SELECT *  FROM " + keyspace + "." + tablename + " WHERE "
-                            + rowId.rowIdString + ";";
+            PreparedQueryObject selectQuery = new PreparedQueryObject();
+            selectQuery.appendQueryString("SELECT *  FROM " + keyspace + "." + tablename + " WHERE "
+                            + rowId.rowIdString + ";");
+            selectQuery.addValue(rowId.primarKeyValue);
             conditionInfo = new MusicCore.Condition(updateObj.getConditions(), selectQuery);
         }
 
@@ -715,14 +815,23 @@ public class RestMusicDataAPI {
             String lockId = updateObj.getConsistencyInfo().get("lockId");
             operationResult = MusicCore.criticalPut(keyspace, tablename, rowId.primarKeyValue,
                             queryObject, lockId, conditionInfo);
-        }
-        else if (consistency.equalsIgnoreCase("atomic_delete_lock")) {
+        } else if (consistency.equalsIgnoreCase("atomic_delete_lock")) {
             // this function is mainly for the benchmarks
-            operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename,
-                            rowId.primarKeyValue, queryObject, conditionInfo);
+            try {
+              operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename,
+                              rowId.primarKeyValue, queryObject, conditionInfo);
+            } catch (MusicLockingException e) {
+                logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+                return new ReturnType(ResultType.FAILURE, e.getMessage()).toMap();
+            }
         } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
-            operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
-                            queryObject, conditionInfo);
+            try {
+              operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
+                              queryObject, conditionInfo);
+            } catch (MusicLockingException e) {
+              logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+              return new ReturnType(ResultType.FAILURE, e.getMessage()).toMap();
+            }
         }
         long actualUpdateCompletionTime = System.currentTimeMillis();
 
@@ -737,7 +846,7 @@ public class RestMusicDataAPI {
             String lockManagementTime = operationResult.getTimingInfo();
             timingString = timingString + lockManagementTime;
         }
-        logger.info(timingString);
+        logger.info(EELFLoggerDelegate.applicationLogger, timingString);
         return (operationResult != null) ? operationResult.toMap()
                         : new ReturnType(ResultType.FAILURE, "Null result - Please Contact admin")
                                         .toMap();
@@ -776,15 +885,25 @@ public class RestMusicDataAPI {
                                     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> resultMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
-                        aid, "deleteFromTable");
+                    @Context UriInfo info, @Context HttpServletResponse response) {
+        Map<String, Object> resultMap = null;
+               try {
+                       resultMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+                                       aid, "deleteFromTable");
+               } catch (Exception e) {
+                       resultMap.put("Exception", e.getMessage());
+                       return resultMap;
+               }
         response.addHeader(xLatestVersion, MusicUtil.getVersion());
         if (resultMap.containsKey("aid"))
             resultMap.remove("aid");
         if (!resultMap.isEmpty()) {
             return resultMap;
         }
+        if(delObj == null) {
+                       resultMap.put("Exception", "Request body is missing. Please check your input data and retry.");
+                       return resultMap;
+               }
         PreparedQueryObject queryObject = new PreparedQueryObject();
         StringBuilder columnString = new StringBuilder();
 
@@ -800,8 +919,12 @@ public class RestMusicDataAPI {
         }
 
         // get the row specifier
-        RowIdentifier rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(),
-                        queryObject);
+        RowIdentifier rowId = null;
+        try {
+            rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
+        } catch (MusicServiceException ex) {
+            return new ReturnType(ResultType.FAILURE, ex.getMessage()).toMap();
+        }
         String rowSpec = rowId.rowIdString.toString();
 
         if ((columnList != null) && (!rowSpec.isEmpty())) {
@@ -825,25 +948,35 @@ public class RestMusicDataAPI {
             conditionInfo = null;
         else {// to avoid parsing repeatedly, just send the select query to
               // obtain row
-            String selectQuery = "SELECT *  FROM " + keyspace + "." + tablename + " WHERE "
-                            + rowId.rowIdString + ";";
+            PreparedQueryObject selectQuery = new PreparedQueryObject();
+            selectQuery.appendQueryString("SELECT *  FROM " + keyspace + "." + tablename + " WHERE "
+                            + rowId.rowIdString + ";");
+            selectQuery.addValue(rowId.primarKeyValue);
             conditionInfo = new MusicCore.Condition(delObj.getConditions(), selectQuery);
         }
 
         String consistency = delObj.getConsistencyInfo().get("type");
 
         ReturnType operationResult = null;
-
-        if (consistency.equalsIgnoreCase(MusicUtil.EVENTUAL))
-            operationResult = MusicCore.eventualPut(queryObject);
-        else if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
-            String lockId = delObj.getConsistencyInfo().get("lockId");
-            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);
-        }
+        try {
+               if (consistency.equalsIgnoreCase(MusicUtil.EVENTUAL))
+                   operationResult = MusicCore.eventualPut(queryObject);
+               else if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
+                   String lockId = delObj.getConsistencyInfo().get("lockId");
+                   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) {
+                       resultMap.put("Exception", "Unable to perform Delete operation. Exception from music: "+e.getMessage());
+                       return resultMap;
+               }
         try {
             return operationResult.toMap();
         } catch (NullPointerException e) {
@@ -861,7 +994,8 @@ public class RestMusicDataAPI {
     @DELETE
     @Path("/{keyspace}/tables/{tablename}")
     @ApiOperation(value = "Drop Table", response = String.class)
-
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
     public Map<String, Object> dropTable(
                     @ApiParam(value = "Major Version",
                                     required = true) @PathParam("version") String version,
@@ -893,8 +1027,13 @@ public class RestMusicDataAPI {
         String consistency = "eventual";// for now this needs only eventual
                                         // consistency
         PreparedQueryObject query = new PreparedQueryObject();
-        query.appendQueryString("DROP TABLE IF EXISTS " + keyspace + "." + tablename + ";");
-        return new JsonResponse(MusicCore.nonKeyRelatedPut(query, consistency), "", "").toMap();
+        query.appendQueryString("DROP TABLE  " + keyspace + "." + tablename + ";");
+        try {
+            return new JsonResponse(MusicCore.nonKeyRelatedPut(query, consistency), "", "").toMap();
+        } catch (MusicServiceException ex) {
+            return new JsonResponse(false, ex.getMessage(), "").toMap();
+        }
+
     }
 
     /**
@@ -946,24 +1085,30 @@ public class RestMusicDataAPI {
         String lockId = selObj.getConsistencyInfo().get("lockId");
 
         PreparedQueryObject queryObject = new PreparedQueryObject();
-        StringBuilder rowSpec = new StringBuilder();
-
-        RowIdentifier rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(),
-                        queryObject);
 
+        RowIdentifier rowId = null;
+        try {
+            rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
+        } catch (MusicServiceException ex) {
+            return MusicUtil.setErrorResponse(ex);
+        }
         queryObject.appendQueryString(
-                        "SELECT *  FROM " + keyspace + "." + tablename + " WHERE " + rowSpec + ";");
+                        "SELECT *  FROM " + keyspace + "." + tablename + " WHERE " + rowId.rowIdString + ";");
 
         ResultSet results = null;
 
         String consistency = selObj.getConsistencyInfo().get("type");
 
-        if (consistency.equalsIgnoreCase("critical")) {
+        if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
             results = MusicCore.criticalGet(keyspace, tablename, rowId.primarKeyValue, queryObject,
                             lockId);
-        } else if (consistency.equalsIgnoreCase("atomic")) {
+        } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
             results = MusicCore.atomicGet(keyspace, tablename, rowId.primarKeyValue, queryObject);
         }
+        
+        else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
+            results = MusicCore.atomicGetWithDeleteLock(keyspace, tablename, rowId.primarKeyValue, queryObject);
+        }
 
         return MusicCore.marshallResults(results);
     }
@@ -1018,11 +1163,21 @@ public class RestMusicDataAPI {
             queryObject.appendQueryString("SELECT *  FROM " + keyspace + "." + tablename + ";");
         else {
             int limit = -1; // do not limit the number of results
-            queryObject = selectSpecificQuery(version, minorVersion, patchVersion, aid, ns, userId,
-                            password, keyspace, tablename, info, limit);
+            try {
+                queryObject = selectSpecificQuery(version, minorVersion, patchVersion, aid, ns,
+                                userId, password, keyspace, tablename, info, limit);
+            } catch (MusicServiceException ex) {
+                return MusicUtil.setErrorResponse(ex);
+            }
         }
-        ResultSet results = MusicCore.get(queryObject);
-        return MusicCore.marshallResults(results);
+
+        try {
+            ResultSet results = MusicCore.get(queryObject);
+            return MusicCore.marshallResults(results);
+        } catch (MusicServiceException ex) {
+            return MusicUtil.setErrorResponse(ex);
+        }
+
     }
 
     /**
@@ -1032,11 +1187,12 @@ public class RestMusicDataAPI {
      * @param info
      * @param limit
      * @return
-     * @throws Exception
+     * @throws MusicServiceException
      */
     public PreparedQueryObject selectSpecificQuery(String version, String minorVersion,
                     String patchVersion, String aid, String ns, String userId, String password,
-                    String keyspace, String tablename, UriInfo info, int limit) {
+                    String keyspace, String tablename, UriInfo info, int limit)
+                    throws MusicServiceException {
 
         PreparedQueryObject queryObject = new PreparedQueryObject();
         StringBuilder rowIdString = getRowIdentifier(keyspace, tablename, info.getQueryParameters(),
@@ -1061,20 +1217,34 @@ public class RestMusicDataAPI {
      * @param rowParams
      * @param queryObject
      * @return
-     * @throws Exception
+     * @throws MusicServiceException
      */
     private RowIdentifier getRowIdentifier(String keyspace, String tablename,
-                    MultivaluedMap<String, String> rowParams, PreparedQueryObject queryObject) {
+                    MultivaluedMap<String, String> rowParams, PreparedQueryObject queryObject)
+                    throws MusicServiceException {
         StringBuilder rowSpec = new StringBuilder();
         int counter = 0;
         TableMetadata tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+        if (tableInfo == null) {
+            logger.error(EELFLoggerDelegate.errorLogger,
+                            "Table information not found. Please check input for table name= "
+                                            + keyspace + "." + tablename);
+            throw new MusicServiceException(
+                            "Table information not found. Please check input for table name= "
+                                            + keyspace + "." + tablename);
+        }
         StringBuilder primaryKey = new StringBuilder();
         for (MultivaluedMap.Entry<String, List<String>> entry : rowParams.entrySet()) {
             String keyName = entry.getKey();
             List<String> valueList = entry.getValue();
             String indValue = valueList.get(0);
             DataType colType = tableInfo.getColumn(entry.getKey()).getType();
-            Object formattedValue = MusicUtil.convertToActualDataType(colType, indValue);
+            Object formattedValue = null;
+            try {
+              formattedValue = MusicUtil.convertToActualDataType(colType, indValue);
+            } catch (Exception e) {
+              logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+            }
             primaryKey.append(indValue);
             rowSpec.append(keyName + "= ?");
             queryObject.addValue(formattedValue);
@@ -1084,5 +1254,4 @@ public class RestMusicDataAPI {
         }
         return new RowIdentifier(primaryKey.toString(), rowSpec, queryObject);
     }
-
 }