Create Helm based Certificates for Clients
[aaf/authz.git] / auth / auth-batch / src / main / java / org / onap / aaf / auth / batch / helpers / Cred.java
index b58506e..f566933 100644 (file)
@@ -62,19 +62,47 @@ public class Cred  {
         public final int type;
         public final Date expires,written;
         public final Integer other;
+        public final String tag;
+        public List<Note> notes;
+
         
-        public Instance(int type, Date expires, Integer other, long written) {
+        public Instance(int type, Date expires, Integer other, long written, String tag) {
             this.type = type;
             this.expires = expires;
             this.other = other;
             this.written = new Date(written);
+            this.tag = tag;
+        }
+        
+        /**
+         * Usually returns Null...
+         * @return
+         */
+        public List<Note> notes() {
+               return notes;
+        }
+        
+        public void addNote(int level, String note) {
+               if(notes==null) {
+                       notes=new ArrayList<>();
+               } 
+               notes.add(new Note(level,note));
         }
         
         public String toString() {
-               return expires.toString() + ": " + type;
+               return expires.toString() + ": " + type + ' ' + tag;
         }
     }
     
+    public static class Note {
+       public final int level;
+       public final String note;
+       
+       public Note(int level, String note) {
+               this.level = level;
+               this.note = note;
+       }
+    }
     public Date last(final int ... types) {
         Date last = null;
         for (Instance i : instances) {
@@ -107,12 +135,11 @@ public class Cred  {
     }
 
     public static void load(Trans trans, Session session, int ... types ) {
-        load(trans, session,"select id, type, expires, other, writetime(cred) from authz.cred;",types);
-        
+        load(trans, session,"select id, type, expires, other, writetime(cred), tag from authz.cred;",types);
     }
 
     public static void loadOneNS(Trans trans, Session session, String ns,int ... types ) {
-        load(trans, session,"select id, type, expires, other, writetime(cred) from authz.cred WHERE ns='" + ns + "';");
+        load(trans, session,"select id, type, expires, other, writetime(cred), tag from authz.cred WHERE ns='" + ns + "';");
     }
 
     private static void load(Trans trans, Session session, String query, int ...types) {
@@ -138,17 +165,19 @@ public class Cred  {
                     row = iter.next();
                     int type = row.getInt(1);
                     if (types.length>0) { // filter by types, if requested
-                        boolean quit = true;
+                        boolean hastype = false;
                         for (int t : types) {
                             if (t==type) {
+                               hastype=true;
                                 break;
                             }
                         }
-                        if (quit) {
+                        if (!hastype) {
                             continue;
                         }
                     }
-                    add(row.getString(0), row.getInt(1),row.getTimestamp(2),row.getInt(3),row.getLong(4));
+                    add(row.getString(0), row.getInt(1),row.getTimestamp(2),row.getInt(3),row.getLong(4),
+                               row.getString(5));
                 }
             } finally {
                 tt.done();
@@ -163,14 +192,15 @@ public class Cred  {
                final int type,
                final Date timestamp,
                final int other,
-               final long written
+               final long written,
+               final String tag
                ) {
         Cred cred = data.get(id);
         if (cred==null) {
             cred = new Cred(id);
             data.put(id, cred);
         }
-        cred.instances.add(new Instance(type, timestamp, other, written/1000));
+        cred.instances.add(new Instance(type, timestamp, other, written/1000,tag));
         
         List<Cred> lscd = byNS.get(cred.ns);
         if (lscd==null) {
@@ -276,11 +306,17 @@ public class Cred  {
     }
     
     public void row(final CSV.Writer csvw, final Instance inst) {
-       csvw.row("cred",id,ns,Integer.toString(inst.type),Chrono.dateOnlyStamp(inst.expires),inst.expires.getTime());
+       csvw.row("cred",id,ns,Integer.toString(inst.type),Chrono.dateOnlyStamp(inst.expires),
+                       inst.expires.getTime(),inst.tag);
+    }
+
+    public void row(final CSV.Writer csvw, final Instance inst, final String reason) {
+       csvw.row("cred",id,ns,Integer.toString(inst.type),Chrono.dateOnlyStamp(inst.expires),
+                       inst.expires.getTime(),inst.tag,reason);
     }
 
 
-    public static void row(StringBuilder sb, List<String> row) {
+    public static void batchDelete(StringBuilder sb, List<String> row) {
        sb.append("DELETE from authz.cred WHERE id='");
        sb.append(row.get(1));
        sb.append("' AND type=");
@@ -291,7 +327,6 @@ public class Cred  {
        sb.append("));\n");
        }
 
-
        public String toString() {
         StringBuilder sb = new StringBuilder(id);
         sb.append('[');
@@ -329,7 +364,18 @@ public class Cred  {
 
 
        public static String histMemo(String fmt, String orgName, List<String> row) {
-               return String.format(fmt, row.get(1),orgName,row.get(4));
+               String reason;
+               if(row.size()>5) { // Reason included
+                       reason = row.get(5);
+               } else {
+                       reason = String.format(fmt, row.get(1),orgName,row.get(4));
+               }
+               return reason;
        }
 
+
+       public static void clear() {
+               data.clear();
+               byNS.clear();
+       }
 }
\ No newline at end of file