restore a couple of fields' access to public
[aaf/authz.git] / auth / auth-batch / src / main / java / org / onap / aaf / auth / batch / helpers / Role.java
index 6d87ded..a61619e 100644 (file)
@@ -9,9 +9,9 @@
  * 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.
@@ -28,8 +28,10 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
+import java.util.SortedMap;
 import java.util.TreeMap;
 
+import org.onap.aaf.auth.dao.cass.RoleDAO;
 import org.onap.aaf.misc.env.Env;
 import org.onap.aaf.misc.env.TimeTaken;
 import org.onap.aaf.misc.env.Trans;
@@ -41,44 +43,45 @@ import com.datastax.driver.core.SimpleStatement;
 import com.datastax.driver.core.Statement;
 
 public class Role implements Comparable<Role> {
-    public static final TreeMap<Role,Set<String>> data = new TreeMap<>();
-    public static final TreeMap<String,Role> keys = new TreeMap<>();
-    public static final TreeMap<String,Role> byName = new TreeMap<>();
+    public static final SortedMap<Role,Set<String>> data = new TreeMap<>();
+    public static final SortedMap<String,Role> keys = new TreeMap<>();
+    public static final SortedMap<String,Role> byName = new TreeMap<>();
     private static List<Role> deleteRoles = new ArrayList<>();
 
-    public final String ns;
-    public final String name;
-    public final String description;
+    public RoleDAO.Data rdd;
     private String full;
     private String encode;
-    public final Set<String> perms;
-    
+
     public Role(String full) {
-        ns = name = description = "";
+        rdd = new RoleDAO.Data();
+        rdd.ns = "";
+        rdd.name = "";
+        rdd.description = "";
+        rdd.perms = new HashSet<>();
         this.full = full;
-        perms = new HashSet<>();
     }
-    
+
     public Role(String ns, String name, String description,Set<String> perms) {
-        this.ns = ns;
-        this.name = name;
-        this.description = description;
+           rdd = new RoleDAO.Data();
+        rdd.ns = ns;
+        rdd.name = name;
+        rdd.description = description;
+        rdd.perms = perms;
         this.full = null;
         this.encode = null;
-        this.perms = perms;
     }
-    
+
     public String encode() {
         if (encode==null) {
-            encode = ns + '|' + name;
-        } 
+            encode = rdd.ns + '|' + rdd.name;
+        }
         return encode;
     }
 
     public String fullName() {
         if (full==null) {
-            full = ns + '.' + name;
-        } 
+            full = rdd.ns + '.' + rdd.name;
+        }
         return full;
     }
 
@@ -93,7 +96,7 @@ public class Role implements Comparable<Role> {
     private static void load(Trans trans, Session session, String query) {
         trans.info().log( "query: " + query );
         TimeTaken tt = trans.start("Read Roles", Env.REMOTE);
-       
+
         ResultSet results;
         try {
             Statement stmt = new SimpleStatement( query );
@@ -111,7 +114,7 @@ public class Role implements Comparable<Role> {
                     row = iter.next();
                     Role rk =new Role(row.getString(0),row.getString(1), row.getString(2),row.getSet(3,String.class));
                     keys.put(rk.encode(), rk);
-                    data.put(rk,rk.perms);
+                    data.put(rk,rk.rdd.perms);
                     byName.put(rk.fullName(), rk);
                 }
             } finally {
@@ -121,7 +124,7 @@ public class Role implements Comparable<Role> {
             trans.info().log("Found",data.size(),"roles");
         }
     }
-    
+
     public static long count(Trans trans, Session session) {
         String query = "select count(*) from authz.role LIMIT 1000000;";
         trans.info().log( "query: " + query );
@@ -164,11 +167,11 @@ public class Role implements Comparable<Role> {
     public static String fullName(String role) {
         return role.replace('|', '.');
     }
-    
+
     public static void stageRemove(Role r) {
         deleteRoles.add(r);
     }
-    
+
     public static void executeRemove() {
         for (Role p : deleteRoles) {
             keys.remove(p.encode);
@@ -177,4 +180,11 @@ public class Role implements Comparable<Role> {
         deleteRoles.clear();
     }
 
+    public static void clear() {
+        data.clear();
+        keys.clear();
+        byName.clear();
+        deleteRoles.clear();
+    }
+
 }
\ No newline at end of file