Update junit test
[music.git] / src / main / java / org / onap / music / authentication / CachingUtil.java
index 80eed1e..dba2319 100755 (executable)
@@ -28,13 +28,16 @@ package org.onap.music.authentication;
 import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import javax.ws.rs.core.MediaType;
 
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.jcs.JCS;
 import org.apache.commons.jcs.access.CacheAccess;
+import org.apache.commons.jcs.engine.CompositeCacheAttributes;
+import org.apache.commons.jcs.engine.ElementAttributes;
+import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes;
+import org.apache.commons.jcs.engine.behavior.IElementAttributes;
 import org.mindrot.jbcrypt.BCrypt;
 import org.onap.music.authentication.MusicAuthenticator.Operation;
 import org.onap.music.datastore.PreparedQueryObject;
@@ -46,7 +49,6 @@ import org.onap.music.exceptions.MusicServiceException;
 import org.onap.music.main.MusicCore;
 import org.onap.music.main.MusicUtil;
 import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.PreparedStatement;
 import com.datastax.driver.core.ResultSet;
 import com.datastax.driver.core.Row;
 import com.datastax.driver.core.exceptions.InvalidQueryException;
@@ -72,7 +74,6 @@ public class CachingUtil implements Runnable {
     private static CacheAccess<String, Map<String, String>> musicValidateCache = JCS.getInstance("musicValidateCache");
     private static Map<String, Number> userAttempts = new HashMap<>();
     private static Map<String, Calendar> lastFailedTime = new HashMap<>();
-    private static CacheAccess<String, PreparedStatement> queryBank = JCS.getInstance("statementBank");
     private static CacheAccess<String, String> adminUserCache = JCS.getInstance("adminUserCache");
     
     public static CacheAccess<String, String> getAdminUserCache() {
@@ -83,19 +84,6 @@ public class CachingUtil implements Runnable {
         adminUserCache.put(authorization,userId);
     }
     
-    
-    public static  void updateStatementBank(String query,PreparedStatement statement) {
-        queryBank.put(query, statement);
-    }
-    
-    public static void resetStatementBank() {
-        queryBank.clear();
-    }
-    
-     public static CacheAccess<String, PreparedStatement> getStatementBank() {
-            return queryBank;
-        }
-    
     private static final String USERNAME="username";
     private static final String PASSWORD="password";
 
@@ -109,7 +97,8 @@ public class CachingUtil implements Runnable {
         try {
             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), false));
         } catch (Exception e1) {
-            logger.error(EELFLoggerDelegate.errorLogger, e1.getMessage(),AppMessages.CACHEERROR, ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+            logger.error(EELFLoggerDelegate.errorLogger, e1.getMessage(),AppMessages.CACHEERROR, 
+                ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR, e1);
         }
         ResultSet rs = MusicCore.get(pQuery);
         Iterator<Row> it = rs.iterator();
@@ -132,7 +121,8 @@ public class CachingUtil implements Runnable {
                                     + nameSpace);
                 }
             } catch (Exception e) {
-                logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.INFO, ErrorTypes.GENERALSERVICEERROR);
+                logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity
+                    .INFO, ErrorTypes.GENERALSERVICEERROR, e);
                 logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Something at AAF was changed for ns: " + nameSpace+" So not updating Cache for the namespace. ");
             }
         }
@@ -145,7 +135,8 @@ public class CachingUtil implements Runnable {
         try {
             initializeAafCache();
         } catch (MusicServiceException e) {
-            logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.INFO, ErrorTypes.GENERALSERVICEERROR);
+            logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.INFO,
+                ErrorTypes.GENERALSERVICEERROR, e);
         }
     }
 
@@ -187,7 +178,7 @@ public class CachingUtil implements Runnable {
         try {
             responseObj = triggerAAF(nameSpace, userId, password);
         }catch (Exception ex) {
-            logger.info("Exception while trigger aaf");
+            logger.info("Exception while trigger aaf", ex);
             logger.info("Exception: " + ex.getMessage());
             throw new Exception("Exception raised while triggering AAF authentication" +ex.getMessage());
         }
@@ -211,8 +202,6 @@ public class CachingUtil implements Runnable {
             throw new Exception("AAF endpoint is not set. Please specify in the properties file.");
         }
         Client client = Client.create();
-        // WebResource webResource =
-        // client.resource("https://aaftest.test.att.com:8095/proxy/authz/nss/"+nameSpace);
         WebResource webResource = client.resource(MusicUtil.getAafEndpointUrl().concat(nameSpace));
         String plainCreds = userId + ":" + password;
         byte[] plainCredsBytes = plainCreds.getBytes();
@@ -283,7 +272,8 @@ public class CachingUtil implements Runnable {
             try {
                 rs = MusicCore.get(pQuery).one();
             } catch(InvalidQueryException e) {
-                logger.error(EELFLoggerDelegate.errorLogger,"Exception admin keyspace not configured."+e.getMessage());
+                logger.error(EELFLoggerDelegate.errorLogger,"Exception admin keyspace not configured."+ e.getMessage
+                    (), e);
                 throw new MusicServiceException("Please make sure admin.keyspace_master table is configured.");
             }
             try {
@@ -291,7 +281,8 @@ public class CachingUtil implements Runnable {
                 if(isAAF != null)
                     appNameCache.put(namespace, isAAF);
             } catch (Exception e) {
-                logger.error(EELFLoggerDelegate.errorLogger,  e.getMessage(), AppMessages.QUERYERROR,ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
+                logger.error(EELFLoggerDelegate.errorLogger,  e.getMessage(), AppMessages.QUERYERROR,ErrorSeverity
+                    .ERROR, ErrorTypes.QUERYERROR, e);
             }
         }
         return isAAF;
@@ -308,7 +299,8 @@ public class CachingUtil implements Runnable {
             try {
                 uuid = rs.getUUID("uuid").toString();
             } catch (Exception e) {
-                logger.error(EELFLoggerDelegate.errorLogger,"Exception occurred during uuid retrieval from DB."+e.getMessage());
+                logger.error(EELFLoggerDelegate.errorLogger,"Exception occurred during uuid retrieval from DB."+e
+                    .getMessage(), e);
             }
         }
         return uuid;
@@ -324,7 +316,8 @@ public class CachingUtil implements Runnable {
         try {
             appName = rs.getString("application_name");
         } catch (Exception e) {
-            logger.error(EELFLoggerDelegate.errorLogger,  e.getMessage(), AppMessages.QUERYERROR, ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
+            logger.error(EELFLoggerDelegate.errorLogger,  e.getMessage(), AppMessages.QUERYERROR, ErrorSeverity
+                .ERROR, ErrorTypes.QUERYERROR, e);
         }
         return appName;
     }
@@ -376,11 +369,11 @@ public class CachingUtil implements Runnable {
             rs = MusicCore.get(queryObject).one();
         } catch (MusicServiceException e) {
             String errorMsg = "Unable to process operation. Error is "+e.getMessage();
-            logger.error(EELFLoggerDelegate.errorLogger, errorMsg);
+            logger.error(EELFLoggerDelegate.errorLogger, errorMsg, e);
             resultMap.put("Exception", errorMsg);
             return resultMap;
         } catch (InvalidQueryException e) {
-            logger.error(EELFLoggerDelegate.errorLogger,"Exception admin keyspace not configured."+e.getMessage());
+            logger.error(EELFLoggerDelegate.errorLogger,"Exception admin keyspace not configured."+e.getMessage(), e);
             resultMap.put("Exception", "Please make sure admin.keyspace_master table is configured.");
             return resultMap;
         }
@@ -399,7 +392,7 @@ public class CachingUtil implements Runnable {
     }
 
     public static Map<String, Object> authenticateAIDUser(String nameSpace, String userId, String password,
-           String keyspace) {
+            String keyspace) {
         Map<String, Object> resultMap = new HashMap<>();
         String pwd = null;
         if((musicCache.get(keyspace) != null) && (musicValidateCache.get(nameSpace) != null) 
@@ -420,14 +413,14 @@ public class CachingUtil implements Runnable {
         try {
             queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspace));
         } catch (Exception e) {
-            logger.error(EELFLoggerDelegate.errorLogger,"Adding value to query object failed: " + e.getMessage());
+            logger.error(EELFLoggerDelegate.errorLogger,"Adding value to query object failed: " + e.getMessage(), e);
         }
         Row rs = null;
         try {
             rs = MusicCore.get(queryObject).one();
         } catch (MusicServiceException e) {
             String errMsg = "Unable to process operation. Error is "+e.getMessage();
-            logger.error(EELFLoggerDelegate.errorLogger, errMsg);
+            logger.error(EELFLoggerDelegate.errorLogger, errMsg, e);
             resultMap.put("Exception", errMsg);
             return resultMap;
         }