import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.onap.aaf.misc.env.APIException;
public abstract class NotifyBody {
+ private static final String DUPL = "<td style=\"text-indent: 4em;\">''</td>";
private static final Map<String,NotifyBody> bodyMap = new HashMap<>();
protected Map<String,List<List<String>>> 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(final String type, final String name) {
+ 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<String> row) {
return name;
}
+ public String type() {
+ return type;
+ }
+
public String date() {
return date;
}
* @param row
* @return
*/
- public abstract String body(AuthzTrans trans, Notify n, String id);
+ 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.
*/
protected abstract String user(List<String> row);
+ public abstract String subject();
+
/**
* Get Notify Body based on key of
* type|name
*
*/
public static Collection<NotifyBody> getAll() {
- return bodyMap.values();
+ // Note: The same Notify Body is entered several times with different keys.
+ // Therefore, need a Set of Values, not all the Values.
+ Set<NotifyBody> set = new HashSet<>();
+ set.addAll(bodyMap.values());
+ return set;
}
/**
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Package pkg = NotifyBody.class.getPackage();
String path = pkg.getName().replace('.', '/');
-// Enumeration<URL> urls = cl.getResources(path);
-// while(urls.hasMoreElements()) {
-// URL url = urls.nextElement();
URL url = cl.getResource(path);
if(url == null) {
throw new APIException("Cannot load resources from " + path);
}
- System.out.println(url);
File dir;
try {
dir = new File(url.toURI());
}
}
}
-// }
+ }
+
+ protected void print(StringBuilder sb, int indent, Object ... objs) {
+ for(int i=0;i<indent;++i) {
+ sb.append(' ');
+ }
+ for(Object o : objs) {
+ sb.append(o.toString());
+ }
+ }
+
+ protected void println(StringBuilder sb, int indent, Object ... objs) {
+ print(sb,indent,objs);
+ sb.append('\n');
+ }
+
+ protected void printf(StringBuilder sb, int indent, String fmt, Object ... objs) {
+ print(sb,indent,String.format(fmt, objs));
+ }
+
+ 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,"<td>",current,"</td>");
+ }
+
+ public synchronized void inc() {
+ ++count;
+ }
+
+ public int count() {
+ return count;
}
}