Add a MassMail Batch Program
[aaf/authz.git] / auth / auth-batch / src / main / java / org / onap / aaf / auth / batch / update / Extend.java
index 9e080b6..bb09c6c 100644 (file)
@@ -8,9 +8,9 @@
  * 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
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -42,7 +42,7 @@ import org.onap.aaf.auth.env.AuthzTrans;
 import org.onap.aaf.auth.layer.Result;
 import org.onap.aaf.auth.org.OrganizationException;
 import org.onap.aaf.cadi.CadiException;
-import org.onap.aaf.cadi.client.Holder;
+import org.onap.aaf.cadi.util.Holder;
 import org.onap.aaf.cadi.util.CSV;
 import org.onap.aaf.misc.env.APIException;
 import org.onap.aaf.misc.env.Env;
@@ -56,11 +56,11 @@ public class Extend extends Batch {
     private List<File> extFiles;
     private final int extendBy;
     private int gcType;
-    
+
     public Extend(AuthzTrans trans) throws APIException, IOException, OrganizationException {
         super(trans.env());
         trans.info().log("Starting Connection Process");
-        
+
         noAvg = env.newTransNoAvg();
         noAvg.setUser(new BatchPrincipal("Extend"));
 
@@ -73,14 +73,14 @@ public class Extend extends Batch {
             } finally {
                 tt.done();
             }
-            cqlBatch = new CQLBatch(noAvg.info(),session); 
+            cqlBatch = new CQLBatch(noAvg.info(),session);
         } finally {
             tt0.done();
         }
 
         gcType = GregorianCalendar.WEEK_OF_YEAR;
         int weeks = 4;
-        
+
         Set<String> cmd = new HashSet<>();
         for(int i=0; i< args().length;++i) {
             if("-weeks".equals(args()[i])) {
@@ -91,13 +91,13 @@ public class Extend extends Batch {
                 cmd.add(args()[i]);
             }
         }
-        
+
         if(weeks<1 || weeks > 24) {
             throw new APIException("Invalid --weeks");
         }
         extendBy = weeks;
 
-        // Create Intermediate Output 
+        // Create Intermediate Output
         File logDir = logDir();
         extFiles = new ArrayList<>();
         if(cmd.isEmpty()) {
@@ -107,7 +107,7 @@ public class Extend extends Batch {
                 extFiles.add(new File(logDir, fn));
             }
         }
-        
+
         // Load Cred.  We don't follow Visitor, because we have to gather up everything into Identity Anyway
         // to find the last one.
     }
@@ -130,7 +130,7 @@ public class Extend extends Batch {
             CSV csv = new CSV(env.access(),f);
             try {
                 csv.visit(new CSV.Visitor() {
-                    final Holder<Integer> hi = new Holder<>(0); 
+                    final Holder<Integer> hi = new Holder<>(0);
 
                     @Override
                     public void visit(List<String> row) throws IOException, CadiException {
@@ -138,7 +138,8 @@ public class Extend extends Batch {
                         int i = hi.get();
                         StringBuilder sb = hsb.get();
                         if(sb==null) {
-                            hsb.set(sb=cqlBatch.begin());
+                            sb=cqlBatch.begin();
+                            hsb.set(sb);
                         }
                         switch(row.get(0)) {
                             case "info":
@@ -189,7 +190,8 @@ public class Extend extends Batch {
                         if(i%maxBatch==0 && sb!=null) {
                             cqlBatch.execute(dryRun);
                             hi.set(1);
-                            hsb.set(sb=null);
+                            sb=null;
+                            hsb.set(sb);
                         }
                     }
                 });
@@ -197,12 +199,12 @@ public class Extend extends Batch {
                 e.printStackTrace();
             }
         }
-        
+
         // Cleanup, if required.
         cqlBatch.execute(dryRun);
 
     }
-    
+
     @Override
     protected void _close(AuthzTrans trans) {
         trans.info().log("End " + this.getClass().getSimpleName() + " processing" );