Merge "Sonar Fix: NotifyApprovals.java"
[aaf/authz.git] / auth / auth-batch / src / main / java / org / onap / aaf / auth / batch / Batch.java
index ff60520..1c65c05 100644 (file)
@@ -81,6 +81,8 @@ public abstract class Batch {
     protected static boolean dryRun; 
     protected static String batchEnv;
 
+       private static File logdir;
+
     public static final String CASS_ENV = "CASS_ENV";
     public static final String LOG_DIR = "LOG_DIR";
     protected static final String MAX_EMAILS="MAX_EMAILS";
@@ -88,6 +90,7 @@ public abstract class Batch {
     public static final String GUI_URL="GUI_URL";
     
     protected final Organization org;
+       protected String version;
     
     protected Batch(AuthzEnv env) throws APIException, IOException, OrganizationException {
         if (batchEnv != null) {
@@ -120,6 +123,9 @@ public abstract class Batch {
         }
 
         org = OrganizationFactory.init(env);
+        if(org==null) {
+               throw new OrganizationException("Organization MUST be defined for Batch");
+        }
         org.setTestMode(dryRun);
 
         // Special names to allow behaviors beyond normal rules
@@ -138,6 +144,8 @@ public abstract class Batch {
                 }
             }
         }
+        
+        version = env.getProperty(VERSION,Config.AAF_DEFAULT_API_VERSION);
     }
 
     protected abstract void run(AuthzTrans trans);
@@ -324,16 +332,22 @@ public abstract class Batch {
         }
     }
     
-    protected static String logDir() {
-        String ld = env.getProperty(LOG_DIR);
-        if (ld==null) {
-            if (batchEnv==null) { // Deployed Batch doesn't use different ENVs, and a common logdir
-                ld = "logs/";
-            } else {
-                ld = "logs/"+batchEnv;
-            }
-        }
-        return ld;
+    protected static File logDir() {
+        if(logdir == null) {
+               String ld = env.getProperty(LOG_DIR);
+               if (ld==null) {
+                   if (batchEnv==null) { // Deployed Batch doesn't use different ENVs, and a common logdir
+                       ld = "logs/";
+                   } else {
+                       ld = "logs/"+batchEnv;
+                   }
+               }
+               logdir = new File(ld);
+               if(!logdir.exists()) {
+                       logdir.mkdirs();
+               }
+        } 
+        return logdir;
     }
     protected int count(String str, char c) {
         if (str==null || str.isEmpty()) {