X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aaf%2Fauthz.git;a=blobdiff_plain;f=auth%2Fauth-batch%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fbatch%2Fhelpers%2FCred.java;h=6f23c51563b1c845c90e3dfec05479159fe494db;hp=8db2b47a336a7f9b929c2134c0ed75f073dbf016;hb=988fd491d52a9074fe75ebe86e024c6889a46cc3;hpb=4c709df6500a95057a92ec3ea5c739738764388d diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java index 8db2b47a..6f23c515 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java @@ -3,6 +3,7 @@ * org.onap.aaf * =========================================================================== * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 IBM. * =========================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +22,7 @@ package org.onap.aaf.auth.batch.helpers; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; @@ -79,29 +81,29 @@ public class Cred { * @return */ public List notes() { - return notes; + return notes; } public void addNote(int level, String note) { - if(notes==null) { - notes=new ArrayList<>(); - } - notes.add(new Note(level,note)); + if(notes==null) { + notes=new ArrayList<>(); + } + notes.add(new Note(level,note)); } public String toString() { - return expires.toString() + ": " + type + ' ' + tag; + 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 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; @@ -136,11 +138,10 @@ public class Cred { public static void load(Trans trans, Session session, int ... 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), tag from authz.cred WHERE ns='" + ns + "';"); + load(trans, session,"select id, type, expires, other, writetime(cred), tag from authz.cred WHERE ns='" + ns + "';", types); } private static void load(Trans trans, Session session, String query, int ...types) { @@ -169,7 +170,7 @@ public class Cred { boolean hastype = false; for (int t : types) { if (t==type) { - hastype=true; + hastype=true; break; } } @@ -178,7 +179,7 @@ public class Cred { } } add(row.getString(0), row.getInt(1),row.getTimestamp(2),row.getInt(3),row.getLong(4), - row.getString(5)); + row.getString(5)); } } finally { tt.done(); @@ -189,13 +190,13 @@ public class Cred { } public static void add( - final String id, - final int type, - final Date timestamp, - final int other, - final long written, - final String tag - ) { + final String id, + final int type, + final Date timestamp, + final int other, + final long written, + final String tag + ) { Cred cred = data.get(id); if (cred==null) { cred = new Cred(id); @@ -203,9 +204,10 @@ public class Cred { } cred.instances.add(new Instance(type, timestamp, other, written/1000,tag)); - List lscd = byNS.get(cred.ns); + List lscd = byNS.get(cred.ns); if (lscd==null) { - byNS.put(cred.ns, (lscd=new ArrayList<>())); + lscd=new ArrayList<>(); + byNS.put(cred.ns,lscd); } boolean found = false; for (Cred c : lscd) { @@ -217,10 +219,10 @@ public class Cred { if (!found) { lscd.add(cred); } - } + } - /** + /** * Count entries in Cred data. * Note, as opposed to other methods, need to load the whole cred table for the Types. * @param numbuckets @@ -271,11 +273,9 @@ public class Cred { public void inc(int type, Date start, Date expires) { for (int i=0;i row) { - sb.append("DELETE from authz.cred WHERE id='"); - sb.append(row.get(1)); - sb.append("' AND type="); - sb.append(Integer.parseInt(row.get(3))); - // Note: We have to work with long, because Expires is part of Key... can't easily do date. - sb.append(" AND expires=dateof(maxtimeuuid("); - sb.append(row.get(5)); - sb.append("));\n"); - } + Long l = Long.parseLong(row.get(5)); + String date = sdf.format(new Date(l)); + sb.append("DELETE from authz.cred WHERE id='"); + sb.append(row.get(1)); + sb.append("' AND type="); + sb.append(Integer.parseInt(row.get(3))); + // Note: We have to work with long, because Expires is part of Key... can't easily do date. + sb.append(" AND expires='"); + sb.append(date); + sb.append("';\n"); +// sb.append(" AND expires=dateof(maxtimeuuid("); +// sb.append(row.get(5)); +// sb.append("));\n"); + + } - public String toString() { + public String toString() { StringBuilder sb = new StringBuilder(id); sb.append('['); for (Instance i : instances) { @@ -359,18 +365,24 @@ public class Cred { } - public static String histSubject(List row) { - return row.get(1); - } + public static String histSubject(List row) { + return row.get(1); + } - public static String histMemo(String fmt, String orgName, List row) { - 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 String histMemo(String fmt, String orgName, List row) { + 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