Update distribution files to support helm charts
[music.git] / src / main / java / org / onap / music / main / CachingUtil.java
index a436683..a81887a 100755 (executable)
  */
 package org.onap.music.main;
 
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
-import javax.ws.rs.core.HttpHeaders;
 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.codehaus.jackson.map.ObjectMapper;
 import org.mindrot.jbcrypt.BCrypt;
 import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.AAFResponse;
 import org.onap.music.eelf.logging.EELFLoggerDelegate;
 import org.onap.music.eelf.logging.format.AppMessages;
 import org.onap.music.eelf.logging.format.ErrorSeverity;
 import org.onap.music.eelf.logging.format.ErrorTypes;
 import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.datastore.jsonobjects.JsonNotification;
 import org.onap.music.datastore.jsonobjects.JsonCallback;
-import com.att.eelf.configuration.EELFLogger;
 import com.datastax.driver.core.DataType;
 import com.datastax.driver.core.ResultSet;
 import com.datastax.driver.core.Row;
@@ -112,7 +105,6 @@ public class CachingUtil implements Runnable {
             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), false));
         } catch (Exception e1) {
             logger.error(EELFLoggerDelegate.errorLogger, e1.getMessage(),AppMessages.CACHEERROR, ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
-            e1.printStackTrace();
         }
         ResultSet rs = MusicCore.get(pQuery);
         Iterator<Row> it = rs.iterator();
@@ -137,7 +129,6 @@ public class CachingUtil implements Runnable {
             } catch (Exception e) {
                 logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.INFO, ErrorTypes.GENERALSERVICEERROR);
                 logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Something at AAF was changed for ns: " + nameSpace+" So not updating Cache for the namespace. ");
-                e.printStackTrace();
             }
         }
 
@@ -156,7 +147,7 @@ public class CachingUtil implements Runnable {
     public static boolean authenticateAAFUser(String nameSpace, String userId, String password,
                     String keySpace) throws Exception {
 
-        if (aafCache.get(nameSpace) != null) {
+        if (aafCache.get(nameSpace) != null && musicCache.get(keySpace)!=null) {
             if (keySpace != null && !musicCache.get(keySpace).equals(nameSpace)) {
                logger.info(EELFLoggerDelegate.applicationLogger,"Create new application for the same namespace.");
             } else if (aafCache.get(nameSpace).get(userId).equals(password)) {
@@ -190,9 +181,10 @@ public class CachingUtil implements Runnable {
         boolean responseObj = triggerAAF(nameSpace, userId, password);
         if (responseObj) {
             //if (responseObj.getNs().get(0).getAdmin().contains(userId)) {
-               //Map<String, String> map = new HashMap<>();
-                //map.put(userId, password);
-                //aafCache.put(nameSpace, map);
+               Map<String, String> map = new HashMap<>();
+                map.put(userId, password);
+                aafCache.put(nameSpace, map);
+                CachingUtil.updateMusicCache(keySpace, nameSpace);
                return true;
             //}
         }
@@ -279,7 +271,6 @@ public class CachingUtil implements Runnable {
                     appNameCache.put(namespace, isAAF);
             } catch (Exception e) {
                logger.error(EELFLoggerDelegate.errorLogger,  e.getMessage(), AppMessages.QUERYERROR,ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
-               e.printStackTrace();
             }
         }
         return isAAF;
@@ -297,7 +288,6 @@ public class CachingUtil implements Runnable {
                 uuid = rs.getUUID("uuid").toString();
             } catch (Exception e) {
                 logger.error(EELFLoggerDelegate.errorLogger,"Exception occured during uuid retrieval from DB."+e.getMessage());
-                e.printStackTrace();
             }
         }
         return uuid;
@@ -314,7 +304,6 @@ public class CachingUtil implements Runnable {
             appName = rs.getString("application_name");
         } catch (Exception e) {
                logger.error(EELFLoggerDelegate.errorLogger,  e.getMessage(), AppMessages.QUERYERROR, ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
-            e.printStackTrace();
         }
         return appName;
     }
@@ -361,7 +350,6 @@ public class CachingUtil implements Runnable {
                        rs = MusicCore.get(queryObject).one();
                } catch (MusicServiceException e) {
                        // TODO Auto-generated catch block
-                       e.printStackTrace();
                        resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
                        return resultMap;
         } catch (InvalidQueryException e) {
@@ -405,14 +393,13 @@ public class CachingUtil implements Runnable {
         try {
             queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspace));
         } catch (Exception e) {
-            e.printStackTrace();
+                logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
         }
         Row rs = null;
         try {
             rs = MusicCore.get(queryObject).one();
         } catch (MusicServiceException e) {
-            e.printStackTrace();
-            resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
+               resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
             return resultMap;
         }
         if(rs == null) {
@@ -448,7 +435,7 @@ public class CachingUtil implements Runnable {
         try {
             MusicCore.nonKeyRelatedPut(pQuery, "eventual");
         } catch (Exception e) {
-              e.printStackTrace();
+                logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR, "Error in deleteKeysFromDB");
         }
     }
 }