* ===========================================================================
* 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.
* You may obtain a copy of the License at
import com.datastax.driver.core.Statement;
public class Approval implements CacheChange.Data {
- public static final String ADD_USER_TO_ROLE = "Add User [";
+ public static final String ADD_USER_TO_ROLE = "Add User [";
public static final String RE_APPROVAL_IN_ROLE = "Extend access of User [";
public static final String RE_VALIDATE_ADMIN = "Revalidate as Admin of AAF Namespace [";
public static final String RE_VALIDATE_OWNER = "Revalidate as Owner of AAF Namespace [";
public static TreeMap<String,List<Approval>> byUser = new TreeMap<>();
public static TreeMap<UUID,List<Approval>> byTicket = new TreeMap<>();
public static List<Approval> list = new LinkedList<>();
- private final static CacheChange<Approval> cache = new CacheChange<>();
+ private static final CacheChange<Approval> cache = new CacheChange<>();
public final ApprovalDAO.Data add;
private String role;
+
+ public static Creator<Approval> v2_0_17 = new Creator<Approval>() {
+ @Override
+ public Approval create(Row row) {
+ return new Approval(row.getUUID(0), row.getUUID(1), row.getString(2),
+ row.getString(3),row.getString(4),row.getString(5),row.getString(6),row.getString(7),
+ row.getLong(8)/1000);
+ }
+
+ @Override
+ public String select() {
+ return "select id,ticket,approver,user,memo,operation,status,type,WRITETIME(status) from authz.approval";
+ }
+ };
+
+ public static Visitor<Approval> FullLoad = new Visitor<Approval>() {
+ @Override
+ public void visit(Approval app) {
+ List<Approval> ln;
+ list.add(app);
+
+ String person = app.getApprover();
+ if (person!=null) {
+ ln = byApprover.get(person);
+ if (ln==null) {
+ ln = new ArrayList<>();
+ byApprover.put(app.getApprover(), ln);
+ }
+ ln.add(app);
+ }
+
+ person = app.getUser();
+ if (person!=null) {
+ ln = byUser.get(person);
+ if (ln==null) {
+ ln = new ArrayList<>();
+ byUser.put(app.getUser(), ln);
+ }
+ ln.add(app);
+ }
+ UUID ticket = app.getTicket();
+ if (ticket!=null) {
+ ln = byTicket.get(ticket);
+ if (ln==null) {
+ ln = new ArrayList<>();
+ byTicket.put(app.getTicket(), ln);
+ }
+ ln.add(app);
+ }
+ }
+ };
public Approval(UUID id, UUID ticket, String approver,// Date last_notified,
String user, String memo, String operation, String status, String type, long updated) {
add.id = id;
add.ticket = ticket;
add.approver = approver;
-// add.last_notified = last_notified;
add.user = user;
add.memo = memo;
add.operation = operation;
} else if (memo.startsWith(RE_VALIDATE_OWNER)) {
return role + ".owner";
} else {
- first = memo.indexOf('[',second);
- if(first>=0) {
- second = memo.indexOf(']', ++first);
- if(second>=0) {
- if(memo.startsWith(RE_APPROVAL_IN_ROLE) ||
- memo.startsWith(ADD_USER_TO_ROLE)) {
- return memo.substring(first, second);
- }
- }
- }
+ first = memo.indexOf('[',second);
+ if(first>=0) {
+ second = memo.indexOf(']', ++first);
+ if(second>=0 && (memo.startsWith(RE_APPROVAL_IN_ROLE) ||
+ memo.startsWith(ADD_USER_TO_ROLE))) {
+ return memo.substring(first, second);
+ }
+ }
}
}
}
}
public static int load(Trans trans, Session session, Creator<Approval> creator, Visitor<Approval> visitor) {
- int count = 0;
- try {
- count+=call(trans,session,creator.query(null), creator, visitor);
+ int count = 0;
+ try {
+ count+=call(trans,session,creator.query(null), creator, visitor);
} finally {
trans.info().log("Found",count,"Approval Records");
}
- return count;
+ return count;
}
- public static int load(Trans trans, Session session, Creator<Approval> creator ) {
- int count = 0;
- try {
- count+=call(trans,session,creator.query(null), creator, FullLoad);
+ public static int load(Trans trans, Session session, Creator<Approval> creator ) {
+ int count = 0;
+ try {
+ count+=call(trans,session,creator.query(null), creator, FullLoad);
} finally {
trans.info().log("Found",count,"Approval Records");
}
- return count;
+ return count;
}
public static int loadUsers(Trans trans, Session session, Set<String> users, Visitor<Approval> visitor) {
- int total = 0;
- for(String user : users) {
- total+=call(trans,session,String.format("%s WHERE user='%s';",v2_0_17.select(), user),v2_0_17,visitor);
- }
- return total;
+ int total = 0;
+ for(String user : users) {
+ total+=call(trans,session,String.format("%s WHERE user='%s';",v2_0_17.select(), user),v2_0_17,visitor);
+ }
+ return total;
}
public static void row(CSV.RowSetter crs, Approval app) {
- crs.row("approval",app.add.id,app.add.ticket,app.add.user,app.role,app.add.memo);
- }
+ crs.row("approval",app.add.id,app.add.ticket,app.add.user,app.role,app.add.memo);
+ }
- private static int call(Trans trans, Session session, String query, Creator<Approval> creator, Visitor<Approval> visitor) {
- TimeTaken tt = trans.start("DB Query", Trans.REMOTE);
+ private static int call(Trans trans, Session session, String query, Creator<Approval> creator, Visitor<Approval> visitor) {
+ TimeTaken tt = trans.start("DB Query", Trans.REMOTE);
ResultSet results;
try {
Statement stmt = new SimpleStatement( query );
results = session.execute(stmt);
int count = 0;
for (Row row : results.all()) {
- ++count;
- visitor.visit(creator.create(row));
+ ++count;
+ visitor.visit(creator.create(row));
}
return count;
} finally {
}
public static void clear() {
- byApprover.clear();
- byUser.clear();
- byTicket.clear();
- list.clear();
- cache.resetLocalData();
+ byApprover.clear();
+ byUser.clear();
+ byTicket.clear();
+ list.clear();
+ cache.resetLocalData();
}
- public static Creator<Approval> v2_0_17 = new Creator<Approval>() {
- @Override
- public Approval create(Row row) {
- return new Approval(row.getUUID(0), row.getUUID(1), row.getString(2),
- row.getString(3),row.getString(4),row.getString(5),row.getString(6),row.getString(7),
- row.getLong(8)/1000);
- }
-
- @Override
- public String select() {
- return "select id,ticket,approver,user,memo,operation,status,type,WRITETIME(status) from authz.approval";
- }
- };
-
- public static Visitor<Approval> FullLoad = new Visitor<Approval>() {
- @Override
- public void visit(Approval app) {
- List<Approval> ln;
- list.add(app);
-
- String person = app.getApprover();
- if (person!=null) {
- ln = byApprover.get(person);
- if (ln==null) {
- ln = new ArrayList<>();
- byApprover.put(app.getApprover(), ln);
- }
- ln.add(app);
- }
-
- person = app.getUser();
- if (person!=null) {
- ln = byUser.get(person);
- if (ln==null) {
- ln = new ArrayList<>();
- byUser.put(app.getUser(), ln);
- }
- ln.add(app);
- }
- UUID ticket = app.getTicket();
- if (ticket!=null) {
- ln = byTicket.get(ticket);
- if (ln==null) {
- ln = new ArrayList<>();
- byTicket.put(app.getTicket(), ln);
- }
- ln.add(app);
- }
- }
- };
-
/**
* @return the status
*/
return cache.contains(a);
}
- public static void deleteByIDBatch(StringBuilder sb, String id) {
- sb.append("DELETE from authz.approval where id=");
- sb.append(id);
- sb.append(";\n");
- }
+ public static void deleteByIDBatch(StringBuilder sb, String id) {
+ sb.append("DELETE from authz.approval where id=");
+ sb.append(id);
+ sb.append(";\n");
+ }
}