Add UT to ToscaParserImpl
[vid.git] / vid-app-common / src / main / java / org / onap / vid / services / RoleGenaratorServiceImpl.java
index 500f5ac..815c85d 100644 (file)
@@ -2,15 +2,15 @@
  * ============LICENSE_START=======================================================
  * VID
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2018 Nokia. All rights reserved.
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 - 2019 Nokia. All rights reserved.
  * ================================================================================
  * 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
- *
+ * 
  * 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.
@@ -23,16 +23,11 @@ package org.onap.vid.services;
 
 import io.joshworks.restclient.http.HttpResponse;
 import jline.internal.Log;
-import org.onap.vid.aai.AaiClientInterface;
-import org.onap.vid.aai.AaiOverTLSClientInterface;
-import org.onap.vid.aai.AaiResponse;
-import org.onap.vid.aai.ServiceSubscription;
-import org.onap.vid.aai.Services;
+import org.onap.vid.aai.*;
 import org.onap.vid.model.ModelConstants;
 import org.onap.vid.model.Subscriber;
 import org.onap.vid.model.SubscriberList;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
 import java.util.HashMap;
@@ -46,17 +41,17 @@ public class RoleGenaratorServiceImpl implements RoleGeneratorService {
     AaiClientInterface client;
 
     @Autowired
-    @Qualifier("aaiClientForCodehausMapping")
     AaiOverTLSClientInterface aaiOverTLSClient;
 
     public static final String DB_NAME =  "vid_portal";
     public static final String TBL_NAME = "fn_role";
     public static final String TEMP_DELIMITER ="***";
     public static final String OLD_DELIMITER = "_";
+       public static final String CrLf = ";\r\n";
 
     @Override
     public String generateRoleScript(Boolean firstRun) {
-        String query =  "USE " + DB_NAME + ";\r\n" +
+        String query =  "USE " + DB_NAME + CrLf +
                 "SET SQL_SAFE_UPDATES = 0;\r\n";
         try {
             HttpResponse<SubscriberList> allSubscribers = aaiOverTLSClient.getAllSubscribers();
@@ -67,16 +62,17 @@ public class RoleGenaratorServiceImpl implements RoleGeneratorService {
 
         }
         catch (Exception e) {
-            Log.error("There was an error in updating roles "+e.getMessage());
+            Log.error("There was an error in updating roles ", e);
         }
         return query;
     }
 
     private String addAvailableRolesCombination(Boolean firstRun, SubscriberList subscribers) {
-        String query, availableRoles="";
-        HashMap<String,String> servicesNames = new HashMap<String,String>();
+        String query;
+        String availableRoles="";
+        HashMap<String,String> servicesNames = new HashMap<>();
         for (Subscriber subscriber: subscribers.customer) {
-            AaiResponse<Services> subscriberResponse = client.getSubscriberData(subscriber.globalCustomerId);
+            AaiResponse<Services> subscriberResponse = client.getSubscriberData(subscriber.globalCustomerId, true);
             for(ServiceSubscription service: subscriberResponse.getT().serviceSubscriptions.serviceSubscription) {
                 servicesNames.put(service.serviceType,"");
                 String roleName = "'" + subscriber.subscriberName + ModelConstants.ROLE_DELIMITER + service.serviceType + "'";
@@ -105,7 +101,7 @@ public class RoleGenaratorServiceImpl implements RoleGeneratorService {
             query = query + "('" + subscriber.globalCustomerId + "','" + subscriberName + "') ,";
         }
         if(query.length() > 0)
-            query = query.substring(0, query.length()-1) + ";\r\n";
+            query = query.substring(0, query.length()-1) + CrLf;
         return query;
     }
 
@@ -117,7 +113,7 @@ public class RoleGenaratorServiceImpl implements RoleGeneratorService {
             }
         });
         if(query[0].length() > 0)
-            query[0] = query[0].substring(0, query[0].length()-1) + ";\r\n";
+            query[0] = query[0].substring(0, query[0].length()-1) + CrLf;
         return query[0];
     }
 
@@ -146,20 +142,19 @@ public class RoleGenaratorServiceImpl implements RoleGeneratorService {
     }
 
     private String insertAvailableRolesToFnRole(){
-        String query="INSERT INTO fn_role (ROLE_NAME, ACTIVE_YN, PRIORITY)\r\n" +
+         return "INSERT INTO fn_role (ROLE_NAME, ACTIVE_YN, PRIORITY)\r\n" +
                 "SELECT RNAME, 'Y', 5\r\n" +
                 "FROM available_roles\r\n" +
                 "WHERE NOT EXISTS (SELECT ROLE_NAME\r\n" +
                 "FROM fn_role \r\n" +
                 "where RNAME = ROLE_NAME);\r\n";
-        return query;
     }
 
 
 
     private String createTemporaryTableAvailableRoles(String availableRoles) {
         String query = "CREATE TEMPORARY TABLE IF NOT EXISTS available_roles(rname VARCHAR(255));\r\n";
-        query += "INSERT INTO available_roles VALUES "+availableRoles+";\r\n";
+        query += "INSERT INTO available_roles VALUES "+availableRoles+CrLf;
                 return query;
     }
 
@@ -191,6 +186,6 @@ public class RoleGenaratorServiceImpl implements RoleGeneratorService {
     }
 
     private String dropTemporaryTable(String table) {
-        return "DROP TEMPORARY TABLE IF EXISTS " + table + ";\r\n";
+        return "DROP TEMPORARY TABLE IF EXISTS " + table + CrLf;
     }
 }