X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=auth%2Fauth-batch%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fhelpers%2FNotification.java;h=abfd1ca4b5919775a6fe321807c83adc8d6bc7bb;hb=4b5a7d721d994a49057e9bfb403c7bff1b376660;hp=57ff5c61a1db0d53886e1adcb89af3d0dbdf6b0f;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/helpers/Notification.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/helpers/Notification.java index 57ff5c61..abfd1ca4 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/helpers/Notification.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/helpers/Notification.java @@ -41,169 +41,169 @@ import com.datastax.driver.core.SimpleStatement; import com.datastax.driver.core.Statement; public class Notification { - public enum TYPE { - OA("Owner Approval",1),SA("Supervisor Approval",2),CN("Credential Expiration",20); - - private String desc; - private int type; - - private TYPE(String desc,int type) { - this.desc = desc; - this.type = type; - } - - public String desc() { - return desc; - } - - public int idx() { - return type; - } + public enum TYPE { + OA("Owner Approval",1),SA("Supervisor Approval",2),CN("Credential Expiration",20); + + private String desc; + private int type; + + private TYPE(String desc,int type) { + this.desc = desc; + this.type = type; + } + + public String desc() { + return desc; + } + + public int idx() { + return type; + } - public static TYPE get(int idx) { - for(TYPE nt : TYPE.values()) { - if(idx==nt.type) { - return nt; - } - } - return null; - } - } + public static TYPE get(int idx) { + for(TYPE nt : TYPE.values()) { + if(idx==nt.type) { + return nt; + } + } + return null; + } + } public static final TreeMap> data = new TreeMap<>(); public static final Date now = new Date(); public final String user; - public final TYPE type; - public Date last; - public int checksum; - public Message msg; - private int current; - public Organization org; - public int count; - - private Notification(String user, TYPE nt, Date last, int checksum) { - this.user = user; - this.type = nt; - this.last = last; - this.checksum = checksum; - current = 0; - count = 0; - } - - public static void load(Trans trans, Session session, Creator creator ) { - trans.info().log( "query: " + creator.select() ); + public final TYPE type; + public Date last; + public int checksum; + public Message msg; + private int current; + public Organization org; + public int count; + + private Notification(String user, TYPE nt, Date last, int checksum) { + this.user = user; + this.type = nt; + this.last = last; + this.checksum = checksum; + current = 0; + count = 0; + } + + public static void load(Trans trans, Session session, Creator creator ) { + trans.info().log( "query: " + creator.select() ); TimeTaken tt = trans.start("Load Notify", Env.REMOTE); ResultSet results; - try { - Statement stmt = new SimpleStatement(creator.select()); - results = session.execute(stmt); + try { + Statement stmt = new SimpleStatement(creator.select()); + results = session.execute(stmt); } finally { - tt.done(); + tt.done(); } - int count = 0; + int count = 0; tt = trans.start("Process Notify", Env.SUB); try { - for(Row row : results.all()) { - ++count; - try { - Notification not = creator.create(row); - List ln = data.get(not.user); - if(ln==null) { - ln = new ArrayList<>(); - data.put(not.user, ln); - } - ln.add(not); - } finally { - tt.done(); - } - } + for(Row row : results.all()) { + ++count; + try { + Notification not = creator.create(row); + List ln = data.get(not.user); + if(ln==null) { + ln = new ArrayList<>(); + data.put(not.user, ln); + } + ln.add(not); + } finally { + tt.done(); + } + } } finally { - tt.done(); - trans.info().log("Found",count,"Notify Records"); + tt.done(); + trans.info().log("Found",count,"Notify Records"); } - } - - public static Notification get(String user, TYPE type) { - List ln = data.get(user); - if(ln!=null) { - for(Notification n : ln) { - if(type.equals(n.type)) { - return n; - } - } - } - return null; - } + } + + public static Notification get(String user, TYPE type) { + List ln = data.get(user); + if(ln!=null) { + for(Notification n : ln) { + if(type.equals(n.type)) { + return n; + } + } + } + return null; + } - public static Notification create(String user, TYPE type) { - return new Notification(user,type,null,0); - } - - public static Creator v2_0_18 = new Creator() { - @Override - public Notification create(Row row) { - int idx =row.getInt(1); - TYPE type = TYPE.get(idx); - if(type==null) { - return null; - } - return new Notification(row.getString(0), type, row.getTimestamp(2), row.getInt(3)); - } + public static Notification create(String user, TYPE type) { + return new Notification(user,type,null,0); + } + + public static Creator v2_0_18 = new Creator() { + @Override + public Notification create(Row row) { + int idx =row.getInt(1); + TYPE type = TYPE.get(idx); + if(type==null) { + return null; + } + return new Notification(row.getString(0), type, row.getTimestamp(2), row.getInt(3)); + } - @Override - public String select() { - return "SELECT user,type,last,checksum FROM authz.notify LIMIT 100000"; - } - }; + @Override + public String select() { + return "SELECT user,type,last,checksum FROM authz.notify LIMIT 100000"; + } + }; - - public void set(Message msg) { - this.msg = msg; - } + + public void set(Message msg) { + this.msg = msg; + } - public int checksum() { - if(msg==null) { - current=0; - } else if(current==0) { - for(String l : msg.lines) { - for(byte b : l.getBytes()) { - current+=b; - } - } - } - return current; - } - - public boolean update(AuthzTrans trans, Session session, boolean dryRun) { - checksum(); - if(last==null || current==0 || current!=checksum) { - last = now; - current = checksum(); - String update = "UPDATE authz.notify SET " + - "last = '" + Chrono.utcStamp(last) + - "', checksum=" + - current + - " WHERE user='" + - user + - "' AND type=" + - type.idx() + - ";"; - if(dryRun) { - trans.info().log("Would",update); - } else { - session.execute(update); - } - return true; - } - return false; - } + public int checksum() { + if(msg==null) { + current=0; + } else if(current==0) { + for(String l : msg.lines) { + for(byte b : l.getBytes()) { + current+=b; + } + } + } + return current; + } + + public boolean update(AuthzTrans trans, Session session, boolean dryRun) { + checksum(); + if(last==null || current==0 || current!=checksum) { + last = now; + current = checksum(); + String update = "UPDATE authz.notify SET " + + "last = '" + Chrono.utcStamp(last) + + "', checksum=" + + current + + " WHERE user='" + + user + + "' AND type=" + + type.idx() + + ";"; + if(dryRun) { + trans.info().log("Would",update); + } else { + session.execute(update); + } + return true; + } + return false; + } - public String toString() { - return "\"" + user + "\",\"" + type.name() + "\",\"" - + Chrono.dateTime(last)+ "\", " + checksum; - } + public String toString() { + return "\"" + user + "\",\"" + type.name() + "\",\"" + + Chrono.dateTime(last)+ "\", " + checksum; + } } \ No newline at end of file