- Future.load(noAvg, session, Future.withConstruct, fut -> {
- List<Approval> appls = Approval.byTicket.get(fut.id());
- if(!futureRange.inRange(fut.expires())) {
- deleteCW.comment("Future %s expired", fut.id());
- Future.row(deleteCW,fut);
- if(appls!=null) {
- for(Approval a : appls) {
- Approval.row(deleteCW, a);
+ Approval.load(trans, session, Approval.v2_0_17);
+
+ ////////////////////
+ final Map<UUID,Ticket> goodTickets = new TreeMap<>();
+ tt = trans.start("Analyze Expired Futures",Trans.SUB);
+ try {
+ Future.load(noAvg, session, Future.withConstruct, fut -> {
+ List<Approval> appls = Approval.byTicket.get(fut.id());
+ if(!futureRange.inRange(fut.expires())) {
+ deleteCW.comment("Future %s expired", fut.id());
+ Future.row(deleteCW,fut);
+ if(appls!=null) {
+ for(Approval a : appls) {
+ Approval.row(deleteCW, a);
+ }
+ }
+ } else if(appls==null) { // Orphaned Future (no Approvals)
+ deleteCW.comment("Future is Orphaned");
+ Future.row(deleteCW,fut);
+ } else {
+ goodTickets.put(fut.fdd.id, new Ticket(fut));
+ }
+ });
+ } finally {
+ tt.done();
+ }
+
+ Set<String> approvers = new TreeSet<>();
+ tt = trans.start("Connect Approvals with Futures",Trans.SUB);
+ try {
+ for(Approval appr : Approval.list) {
+ Ticket ticket=null;
+ UUID ticketID = appr.getTicket();
+ if(ticketID!=null) {
+ ticket = goodTickets.get(appr.getTicket());
+ }
+ if(ticket == null) { // Orphaned Approvals, no Futures
+ deleteCW.comment("Approval is Orphaned");
+ Approval.row(deleteCW, appr);
+ } else {
+ // for users and approvers still valid
+ String user = appr.getUser();
+
+ if(org.isRevoked(trans, appr.getApprover())) {
+ deleteCW.comment("Approver ID is revoked");
+ Approval.row(deleteCW, appr);
+ } else if(user!=null && !user.isEmpty() && org.isRevoked(trans, user)) {
+ deleteCW.comment("USER ID is revoked");
+ Approval.row(deleteCW, appr);
+ } else {
+ ticket.approvals.add(appr); // add to found Ticket
+ approvers.add(appr.getApprover());