Adding code coverage reduce duplicate lines
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / onap / policy / utils / UserUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.policy.utils;
21
22 import java.util.ArrayList;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Set;
26
27 import org.onap.policy.controller.PolicyController;
28 import org.onap.policy.model.Roles;
29
30 public final class UserUtils {
31         
32         private UserUtils () {
33                 // Empty Constructor
34         }
35         
36         public static class Pair<T, U> {
37                 public final T t;
38                 public final U u;
39                 
40                 public Pair (T t, U u) {
41                         this.t = t;
42                         this.u = u;
43                 }
44         }
45         
46         public static Pair<Set<String>, List<String>> checkRoleAndScope(List<Object> userRoles) {
47                 Set<String> scopes;
48                 List<String> roles;
49                 //Check if the Role and Scope Size are Null get the values from db. 
50 //              List<Object> userRoles = ;
51                 roles = new ArrayList<>();
52                 scopes = new HashSet<>();
53                 for(Object role: userRoles){
54                         Roles userRole = (Roles) role;
55                         roles.add(userRole.getRole());
56                         if(userRole.getScope() != null){
57                                 if(userRole.getScope().contains(",")){
58                                         String[] multipleScopes = userRole.getScope().split(",");
59                                         for(int i =0; i < multipleScopes.length; i++){
60                                                 scopes.add(multipleScopes[i]);
61                                         }
62                                 }else{
63                                         scopes.add(userRole.getScope());
64                                 }               
65                         }
66                 }
67                 return new Pair<>(scopes, roles);
68         }
69
70 }