X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-batch%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fbatch%2Freports%2Fbodies%2FNotifyBody.java;fp=auth%2Fauth-batch%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fbatch%2Freports%2Fbodies%2FNotifyBody.java;h=ec8d1451ca20c0e9f2bf3440831cce40173b2f76;hb=3d1706fcbe7f95830ff6fd23cf679ee55c6d0595;hp=ae7daa09c431ba9d893e2bd12f0a0c99d00e06a5;hpb=321dce367d74092a0ba09930c3aa526abdbd5da8;p=aaf%2Fauthz.git
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java
index ae7daa09..ec8d1451 100644
--- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java
+++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java
@@ -46,217 +46,217 @@ import org.onap.aaf.cadi.Access;
import org.onap.aaf.misc.env.APIException;
public abstract class NotifyBody {
- private static final String DUPL = "
'' | ";
- private static final Map bodyMap = new HashMap<>();
+ private static final String DUPL = "'' | ";
+ private static final Map bodyMap = new HashMap<>();
- protected Map>> rows;
- protected final String env;
- protected final String gui_url;
-
- private final String name;
- private final String type;
- private String date;
- private int escalation;
- private int count;
-
- public NotifyBody(Access access, final String type, final String name) {
- rows = new TreeMap<>();
- this.name = name;
- this.type = type;
- date="";
- escalation = 1;
- count = 0;
- env = access.getProperty("CASS_ENV","DEVL");
- gui_url = access.getProperty("GUI_URL", "");
- }
-
- public void store(List row) {
- if(!row.isEmpty()) {
- if("info".equals(row.get(0))) {
- if(row.size()>2) {
- date = row.get(2);
- }
- if(row.size()>3) {
- escalation = Integer.parseInt(row.get(3));
- }
- return;
- } else if(type.equals(row.get(0))) {
- String user = user(row);
- if(user!=null) {
- List> lss = rows.get(user);
- if(lss == null) {
- lss = new ArrayList<>();
- rows.put(user,lss);
- }
- lss.add(row);
- }
- }
- }
- }
+ protected Map>> rows;
+ protected final String env;
+ protected final String gui_url;
+
+ private final String name;
+ private final String type;
+ private String date;
+ private int escalation;
+ private int count;
+
+ public NotifyBody(Access access, final String type, final String name) {
+ rows = new TreeMap<>();
+ this.name = name;
+ this.type = type;
+ date="";
+ escalation = 1;
+ count = 0;
+ env = access.getProperty("CASS_ENV","DEVL");
+ gui_url = access.getProperty("GUI_URL", "");
+ }
+
+ public void store(List row) {
+ if(!row.isEmpty()) {
+ if("info".equals(row.get(0))) {
+ if(row.size()>2) {
+ date = row.get(2);
+ }
+ if(row.size()>3) {
+ escalation = Integer.parseInt(row.get(3));
+ }
+ return;
+ } else if(type.equals(row.get(0))) {
+ String user = user(row);
+ if(user!=null) {
+ List> lss = rows.get(user);
+ if(lss == null) {
+ lss = new ArrayList<>();
+ rows.put(user,lss);
+ }
+ lss.add(row);
+ }
+ }
+ }
+ }
- public String name() {
- return name;
- }
-
- public String type() {
- return type;
- }
-
- public String date() {
- return date;
- }
- public int escalation() {
- return escalation;
- }
-
- public Set users() {
- return rows.keySet();
- }
-
- /**
- * ID must be set from Row for Email lookup
- *
- * @param trans
- * @param n
- * @param id
- * @param row
- * @return
- */
- public abstract boolean body(AuthzTrans trans, StringBuilder sb, int indent, Notify n, String id);
-
- /**
- * Return "null" if user not found in row... Code will handle.
- * @param row
- * @return
- */
- protected abstract String user(List row);
-
- /**
- * Provide a context-sensitive Subject, which includes ENV as well as details
- *
- * @return
- */
- public abstract String subject();
+ public String name() {
+ return name;
+ }
+
+ public String type() {
+ return type;
+ }
+
+ public String date() {
+ return date;
+ }
+ public int escalation() {
+ return escalation;
+ }
+
+ public Set users() {
+ return rows.keySet();
+ }
+
+ /**
+ * ID must be set from Row for Email lookup
+ *
+ * @param trans
+ * @param n
+ * @param id
+ * @param row
+ * @return
+ */
+ public abstract boolean body(AuthzTrans trans, StringBuilder sb, int indent, Notify n, String id);
+
+ /**
+ * Return "null" if user not found in row... Code will handle.
+ * @param row
+ * @return
+ */
+ protected abstract String user(List row);
+
+ /**
+ * Provide a context-sensitive Subject, which includes ENV as well as details
+ *
+ * @return
+ */
+ public abstract String subject();
- /**
- * Record the fact that a particular Notification was marked as "sent" by Emailer.
- *
- * @param trans
- * @param approver
- * @param ln
- */
- public abstract void record(AuthzTrans trans, StringBuilder query, String id, List notified, LastNotified ln);
-
- /**
- * Get Notify Body based on key of
- * type|name
- */
- public static NotifyBody get(String key) {
- return bodyMap.get(key);
- }
-
- /**
- * Return set of loaded NotifyBodies
- *
- */
- public static Collection getAll() {
- // Note: The same Notify Body is entered several times with different keys.
- // Therefore, need a Set of Values, not all the Values.
- Set set = new HashSet<>();
- set.addAll(bodyMap.values());
- return set;
- }
-
- /**
- * @param propAccess
- * @throws URISyntaxException
- *
- */
- public static void load(Access access) throws APIException, IOException {
- // class load available NotifyBodies
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- Package pkg = NotifyBody.class.getPackage();
- String path = pkg.getName().replace('.', '/');
- URL url = cl.getResource(path);
- List classNames = new ArrayList<>();
- String urlString = url.toString();
- if(urlString.startsWith("jar:file:")) {
- int exclam = urlString.lastIndexOf('!');
- JarFile jf = new JarFile(urlString.substring(9,exclam));
- try {
- Enumeration jfe = jf.entries();
- while(jfe.hasMoreElements()) {
- String name = jfe.nextElement().getName();
- if(name.startsWith(path) && name.endsWith(".class")) {
- classNames.add(name.substring(0,name.length()-6).replace('/', '.'));
- }
- }
- } finally {
- jf.close();
- }
- } else {
- File dir = new File(url.getFile());
- for( String f : dir.list()) {
- if(f.endsWith(".class")) {
- classNames.add(pkg.getName()+'.'+f.substring(0,f.length()-6));
- }
- }
- }
- for(String cls : classNames) {
- try {
- Class> c = cl.loadClass(cls);
- if(c!=null) {
- if(!Modifier.isAbstract(c.getModifiers())) {
- Constructor> cst = c.getConstructor(Access.class);
- NotifyBody nb = (NotifyBody)cst.newInstance(access);
- if(nb!=null) {
- bodyMap.put("info|"+nb.name, nb);
- bodyMap.put(nb.type+'|'+nb.name, nb);
- }
- }
- }
- } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- e.printStackTrace();
- }
- }
- }
+ /**
+ * Record the fact that a particular Notification was marked as "sent" by Emailer.
+ *
+ * @param trans
+ * @param approver
+ * @param ln
+ */
+ public abstract void record(AuthzTrans trans, StringBuilder query, String id, List notified, LastNotified ln);
+
+ /**
+ * Get Notify Body based on key of
+ * type|name
+ */
+ public static NotifyBody get(String key) {
+ return bodyMap.get(key);
+ }
+
+ /**
+ * Return set of loaded NotifyBodies
+ *
+ */
+ public static Collection getAll() {
+ // Note: The same Notify Body is entered several times with different keys.
+ // Therefore, need a Set of Values, not all the Values.
+ Set set = new HashSet<>();
+ set.addAll(bodyMap.values());
+ return set;
+ }
+
+ /**
+ * @param propAccess
+ * @throws URISyntaxException
+ *
+ */
+ public static void load(Access access) throws APIException, IOException {
+ // class load available NotifyBodies
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Package pkg = NotifyBody.class.getPackage();
+ String path = pkg.getName().replace('.', '/');
+ URL url = cl.getResource(path);
+ List classNames = new ArrayList<>();
+ String urlString = url.toString();
+ if(urlString.startsWith("jar:file:")) {
+ int exclam = urlString.lastIndexOf('!');
+ JarFile jf = new JarFile(urlString.substring(9,exclam));
+ try {
+ Enumeration jfe = jf.entries();
+ while(jfe.hasMoreElements()) {
+ String name = jfe.nextElement().getName();
+ if(name.startsWith(path) && name.endsWith(".class")) {
+ classNames.add(name.substring(0,name.length()-6).replace('/', '.'));
+ }
+ }
+ } finally {
+ jf.close();
+ }
+ } else {
+ File dir = new File(url.getFile());
+ for( String f : dir.list()) {
+ if(f.endsWith(".class")) {
+ classNames.add(pkg.getName()+'.'+f.substring(0,f.length()-6));
+ }
+ }
+ }
+ for(String cls : classNames) {
+ try {
+ Class> c = cl.loadClass(cls);
+ if(c!=null) {
+ if(!Modifier.isAbstract(c.getModifiers())) {
+ Constructor> cst = c.getConstructor(Access.class);
+ NotifyBody nb = (NotifyBody)cst.newInstance(access);
+ if(nb!=null) {
+ bodyMap.put("info|"+nb.name, nb);
+ bodyMap.put(nb.type+'|'+nb.name, nb);
+ }
+ }
+ }
+ } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+ }
- protected void print(StringBuilder sb, int indent, Object ... objs) {
- for(int i=0;i",current,"");
- }
-
- public synchronized void inc() {
- ++count;
- }
-
- public int count() {
- return count;
- }
+ protected String printCell(StringBuilder sb, int indent, String current, String prev) {
+ if(current.equals(prev)) {
+ println(sb,indent,DUPL);
+ } else {
+ printCell(sb,indent,current);
+ }
+ return current; // use to set prev...
+ }
+
+ protected void printCell(StringBuilder sb, int indent, String current) {
+ println(sb,indent,"",current," | ");
+ }
+
+ public synchronized void inc() {
+ ++count;
+ }
+
+ public int count() {
+ return count;
+ }
}