+
+ //
+ // Do Pending Approval Notifies. We do this separately, because we are consolidating
+ // all the new entries, etc.
+ //
+ List<CSV> csvList = new ArrayList<>();
+ for(String s : new String[] {"Approvals","ApprovalsNew"}) {
+ File f = new File(logDir(),String.format(fmt, s));
+ if(f.exists()) {
+ csvList.add(new CSV(access,f));
+ }
+ }
+
+ Map<String,Pending> mpending = new TreeMap<>();
+ Holder<Integer> count = new Holder<>(0);
+ for(CSV approveCSV : csvList) {
+ TimeTaken tt = trans.start("Load Analyzed Reminders",Trans.SUB,approveCSV.name());
+ try {
+ approveCSV.visit(row -> {
+ switch(row.get(0)) {
+// case "info":
+// break;
+ case Pending.REMIND:
+ try {
+ String user = row.get(1);
+ Pending p = new Pending(row);
+ Pending mp = mpending.get(user);
+ if(mp==null) {
+ mpending.put(user, p);
+ } else {
+ mp.inc(p); // FYI, unlikely
+ }
+ count.set(count.get()+1);
+ } catch (ParseException e) {
+ trans.error().log(e);
+ }
+ break;
+ }
+ });
+ } catch (IOException | CadiException e) {
+ trans.error().log(e);
+ } finally {
+ tt.done();
+ }
+ }
+ trans.info().printf("Read %d Reminder Rows", count.get());
+
+ NotifyPendingApprBody npab = new NotifyPendingApprBody(access);
+
+ GregorianCalendar gc = new GregorianCalendar();
+ gc.add(GregorianCalendar.DAY_OF_MONTH, 7); // Get from INFO?
+ Date oneWeek = gc.getTime();
+ CSV.Saver rs = new CSV.Saver();
+
+ TimeTaken tt = trans.start("Obtain Last Notifications for Approvers", Trans.SUB);
+ try {
+ lastN.add(mpending.keySet());
+ } finally {
+ tt.done();
+ }
+
+ Pending p;
+
+ tt = trans.start("Notify for Pending", Trans.SUB);
+ List<String> idList = new ArrayList<String>();
+ String id;
+ try {
+ for(Entry<String, Pending> es : mpending.entrySet()) {
+ id = es.getKey();
+ idList.clear();
+ idList.add(id);
+ p = es.getValue();
+ boolean nap = p.newApprovals();
+ if(!nap) {
+ Date dateLastNotified = lastN.lastNotified(id,"pending","");
+ if(dateLastNotified==null || dateLastNotified.after(oneWeek) ) {
+ nap=true;
+ }
+ }
+ if(nap) {
+ rs.row("appr", id,p.qty(),batchEnv);
+ npab.store(rs.asList());
+ if(notify(noAvg, npab)>0) {
+ // Update
+ cbl.preLoop();
+// lastN.update(cbl.inc(),key,"pending","");
+ npab.record(trans,cbl.inc(), id, idList, lastN);
+ npab.inc();
+ }
+ }
+ }
+ } finally {
+ cbl.flush();
+ tt.done();
+ trans.info().printf("Notified %d persons of Pending Approvals", npab.count());
+ }