create RoleValidatorFactory component.
[vid.git] / vid-app-common / src / main / java / org / onap / vid / roles / RoleProvider.java
index e792139..d9f2fde 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,9 +23,17 @@ package org.onap.vid.roles;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import io.joshworks.restclient.http.HttpResponse;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import javax.servlet.http.HttpServletRequest;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 import org.onap.portalsdk.core.web.support.UserUtils;
+import org.onap.vid.aai.AaiResponse;
 import org.onap.vid.aai.exceptions.RoleParsingException;
 import org.onap.vid.model.ModelConstants;
 import org.onap.vid.model.Subscriber;
@@ -34,11 +42,6 @@ import org.onap.vid.services.AaiService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import javax.servlet.http.HttpServletRequest;
-import java.util.*;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
 
 /**
  * Created by Oren on 7/1/17.
@@ -55,16 +58,20 @@ public class RoleProvider {
 
     private Function<HttpServletRequest, Integer> getUserIdFunction;
     private Function<HttpServletRequest, Map> getRolesFunction;
+    private final RoleValidatorFactory roleValidatorFactory;
 
     @Autowired
-    public RoleProvider(AaiService aaiService) {
+    public RoleProvider(AaiService aaiService, RoleValidatorFactory roleValidatorFactory) {
         this.aaiService=aaiService;
+        this.roleValidatorFactory = roleValidatorFactory;
         getUserIdFunction = UserUtils::getUserId;
         getRolesFunction = UserUtils::getRoles;
     }
 
-    RoleProvider(AaiService aaiService, Function<HttpServletRequest, Integer> getUserIdFunction, Function<HttpServletRequest, Map> getRolesFunction) {
+    RoleProvider(AaiService aaiService, RoleValidatorFactory roleValidatorFactory,
+        Function<HttpServletRequest, Integer> getUserIdFunction, Function<HttpServletRequest, Map> getRolesFunction) {
         this.aaiService = aaiService;
+        this.roleValidatorFactory = roleValidatorFactory;
         this.getRolesFunction = getRolesFunction;
         this.getUserIdFunction = getUserIdFunction;
     }
@@ -120,8 +127,8 @@ public class RoleProvider {
 
     private String replaceSubscriberNameToGlobalCustomerID(String subscriberName, String logPrefix) {
         // SubscriberList should be cached by cacheProvider so by calling getFullSubscriberList() method we just gat it from cache
-        HttpResponse<SubscriberList> subscribersResponse = aaiService.getFullSubscriberList();
-        SubscriberList subscribers = subscribersResponse.getBody();
+        AaiResponse<SubscriberList> subscribersResponse = aaiService.getFullSubscriberList();
+        SubscriberList subscribers = subscribersResponse.getT();
 
         try {
             LOG.debug(EELFLoggerDelegate.debugLogger, logPrefix + "subscribers list size is  " + subscribers.customer.size() + " with the values " + om.writeValueAsString(subscribers.customer));
@@ -159,7 +166,7 @@ public class RoleProvider {
     }
 
     public RoleValidator getUserRolesValidator(HttpServletRequest request) {
-        return new RoleValidator(getUserRoles(request));
+        return roleValidatorFactory.by(getUserRoles(request));
     }
 }