summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/MassMail.java93
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/client/Holder.java46
-rw-r--r--cadi/client/src/test/java/org/onap/aaf/cadi/client/test/JU_Holder.java46
3 files changed, 140 insertions, 45 deletions
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/MassMail.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/MassMail.java
index 272a41ba..e84df37b 100644
--- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/MassMail.java
+++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/MassMail.java
@@ -21,17 +21,14 @@
package org.onap.aaf.auth.batch.reports;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import org.onap.aaf.auth.batch.Batch;
import org.onap.aaf.auth.batch.helpers.NS;
@@ -101,9 +98,31 @@ public class MassMail extends Batch {
}
subject = readIn(subdir, "subject");
- head = readIn(subdir, "html.head");
+ if(subject==null) {
+ throw new IOException("MassMail needs a 'subject' file in your mailing directory");
+ } else {
+ subject = subject.replace("%ENV%", batchEnv);
+ }
+ String temp = readIn(subdir, "html.head");
+ if(temp==null) {
+ File f = new File(trans.getProperty("HEADER_HTML"));
+ if(!f.exists()) {
+ throw new IOException("No 'html.head' found in mailing dir, or default HEADER_HTML property");
+ }
+ temp = readIn(f.getParentFile(),f.getName());
+ }
+ head = temp;
+
content = readIn(subdir,"html.content");
- tail = readIn(subdir,"html.tail");
+ temp = readIn(subdir,"html.tail");
+ if(temp==null) {
+ File f = new File(trans.getProperty("FOOTER_HTML"));
+ if(!f.exists()) {
+ throw new IOException("No 'html.tail' found in mailing dir, or default FOOTER_HTML property");
+ }
+ temp = readIn(f.getParentFile(),f.getName());
+ }
+ tail = temp;
trans.info().log("Starting Connection Process");
TimeTaken tt0 = trans.start("Cassandra Initialization", Env.SUB);
@@ -120,8 +139,6 @@ public class MassMail extends Batch {
NS.load(trans, session, NS.v2_0_11);
UserRole.load(trans, session, UserRole.v2_0_11);
-// now = new Date();
-// String sdate = Chrono.dateOnlyStamp(now);
} finally {
tt0.done();
}
@@ -129,19 +146,22 @@ public class MassMail extends Batch {
private String readIn(File subdir, String name) throws IOException {
File file = new File(subdir, name);
- byte[] bytes = new byte[(int) file.length()];
- FileInputStream fis = new FileInputStream(file);
- try {
- fis.read(bytes);
- return new String(bytes);
- } finally {
- fis.close();
+ if(file.exists()) {
+ byte[] bytes = new byte[(int) file.length()];
+ FileInputStream fis = new FileInputStream(file);
+ try {
+ fis.read(bytes);
+ return new String(bytes);
+ } finally {
+ fis.close();
+ }
+ } else {
+ return null;
}
}
@Override
protected void run(AuthzTrans trans) {
-// try {
trans.info().log("Create a Mass Mailing");
final AuthzTrans transNoAvg = trans.env().newTransNoAvg();
@@ -168,13 +188,15 @@ public class MassMail extends Batch {
if (bOwners) {
StringBuilder o = to;
List<UserRole> owners = UserRole.getByRole().get(ns.ndd.name + ".owner");
- if (owners.isEmpty()) {
+ if (owners==null || owners.isEmpty()) {
trans.error().log(ns.ndd.name, "has no owners!");
} else {
for (UserRole owner : owners) {
try {
Identity identity = org.getIdentity(transNoAvg, owner.user());
- if (identity.isPerson()) {
+ if(identity==null) {
+ trans.error().log(owner.user() + " is not a valid Identity in " + org.getName());
+ } else if (identity.isPerson()) {
if (o.length() > 0) {
o.append(',');
greet.append(',');
@@ -201,19 +223,24 @@ public class MassMail extends Batch {
if (bAdmins) {
StringBuilder a;
- if (bOwners) {
+ if ( bOwners && to.length()>0 ) {
a = cc;
} else {
a = to;
}
List<UserRole> admins = UserRole.getByRole().get(ns.ndd.name + ".admin");
- if (admins.isEmpty()) {
+ if (admins==null || admins.isEmpty()) {
trans.warn().log(ns.ndd.name, "has no admins!");
} else {
for (UserRole admin : admins) {
+ if(to.indexOf(admin.user())>0) {
+ continue;
+ }
try {
Identity identity = org.getIdentity(transNoAvg, admin.user());
- if (identity.isPerson()) {
+ if(identity==null) {
+ trans.error().log(admin.user() + " is not a valid Identity in " + org.getName());
+ } else if (identity.isPerson()) {
if (a.length() > 0) {
a.append(',');
}
@@ -257,37 +284,13 @@ public class MassMail extends Batch {
} finally {
ps.close();
}
+
} catch (IOException e) {
trans.error().log(e);
}
}
-// UserRole.load(transNoAvg, session, UserRole.v2_0_11, ur -> {
-// if("owner".equals(ur.rname())) {
-// try {
-// Identity identity = org.getIdentity(transNoAvg, ur.user());
-// if(identity.isPerson()) {
-// System.out.println("Emailing " + identity.email());
-// }
-// } catch (OrganizationException e) {
-// trans.error().log(e, "Error Reading Organization");
-// }
-// }
-// Organization org = trans.org();
-// Identity identity = org.getIdentity(trans, ur.row);
-//
-// if(!check(transNoAvg, checked, ur.user())) {
-// ur.row(whichWriter(transNoAvg,ur.user()),UserRole.UR);
-// }
-// } catch (OrganizationException e) {
-// trans.error().log(e, "Error Decrypting X509");
-// }
-// });
}
-
-// } catch (OrganizationException e) {
-// trans.info().log(e);
-
}
@Override
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/client/Holder.java b/cadi/client/src/main/java/org/onap/aaf/cadi/client/Holder.java
new file mode 100644
index 00000000..8744e896
--- /dev/null
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/client/Holder.java
@@ -0,0 +1,46 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+
+package org.onap.aaf.cadi.client;
+
+/**
+ * Use to set Variables outside of Anonymous classes.
+ * @author Jonathan
+ *
+ * @param <T>
+ */
+public class Holder<T> {
+ private T value;
+ public Holder(T t) {
+ value = t;
+ }
+ public T set(T t) {
+ value = t;
+ return t;
+ }
+
+ public T get() {
+ return value;
+ }
+ public String toString() {
+ return value.toString();
+ }
+}
diff --git a/cadi/client/src/test/java/org/onap/aaf/cadi/client/test/JU_Holder.java b/cadi/client/src/test/java/org/onap/aaf/cadi/client/test/JU_Holder.java
new file mode 100644
index 00000000..d8c5a598
--- /dev/null
+++ b/cadi/client/src/test/java/org/onap/aaf/cadi/client/test/JU_Holder.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * ===========================================================================
+ * * 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.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * *
+ ******************************************************************************/
+
+package org.onap.aaf.cadi.client.test;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+import org.junit.Test;
+
+import org.onap.aaf.cadi.client.Holder;
+
+public class JU_Holder {
+
+ @Test
+ public void test() {
+ String str1 = "a string";
+ String str2 = "another string";
+ Holder<String> holder = new Holder<String>(str1);
+ assertThat(holder.get(), is(str1));
+ assertThat(holder.toString(), is(str1));
+
+ holder.set(str2);
+ assertThat(holder.get(), is(str2));
+ assertThat(holder.toString(), is(str2));
+ }
+
+}