2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
21 package org.onap.aaf.auth.batch.reports.bodies;
24 import java.io.IOException;
25 import java.lang.reflect.Constructor;
26 import java.lang.reflect.InvocationTargetException;
27 import java.lang.reflect.Modifier;
28 import java.net.URISyntaxException;
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.HashMap;
33 import java.util.List;
36 import java.util.TreeMap;
38 import org.onap.aaf.auth.batch.reports.Notify;
39 import org.onap.aaf.auth.env.AuthzTrans;
40 import org.onap.aaf.cadi.Access;
41 import org.onap.aaf.misc.env.APIException;
43 public abstract class NotifyBody {
44 private static final Map<String,NotifyBody> bodyMap = new HashMap<>();
46 protected Map<String,List<List<String>>> rows;
47 private final String name;
48 private final String type;
50 private int escalation;
52 public NotifyBody(final String type, final String name) {
53 rows = new TreeMap<>();
60 public void store(List<String> row) {
62 if("info".equals(row.get(0))) {
67 escalation = Integer.parseInt(row.get(3));
70 } else if(type.equals(row.get(0))) {
71 String user = user(row);
73 List<List<String>> lss = rows.get(user);
75 lss = new ArrayList<>();
84 public String name() {
88 public String date() {
91 public int escalation() {
95 public Set<String> users() {
100 * ID must be set from Row for Email lookup
108 public abstract String body(AuthzTrans trans, Notify n, String id);
111 * Return "null" if user not found in row... Code will handle.
115 protected abstract String user(List<String> row);
118 * Get Notify Body based on key of
121 public static NotifyBody get(String key) {
122 return bodyMap.get(key);
126 * Return set of loaded NotifyBodies
129 public static Collection<NotifyBody> getAll() {
130 return bodyMap.values();
135 * @throws URISyntaxException
138 public static void load(Access access) throws APIException, IOException {
139 // class load available NotifyBodies
140 ClassLoader cl = Thread.currentThread().getContextClassLoader();
141 Package pkg = NotifyBody.class.getPackage();
142 String path = pkg.getName().replace('.', '/');
143 // Enumeration<URL> urls = cl.getResources(path);
144 // while(urls.hasMoreElements()) {
145 // URL url = urls.nextElement();
146 URL url = cl.getResource(path);
148 throw new APIException("Cannot load resources from " + path);
150 System.out.println(url);
153 dir = new File(url.toURI());
154 } catch (URISyntaxException e) {
155 throw new APIException(e);
158 String[] files = dir.list();
160 for(String sf : files) {
161 int dot = sf.indexOf('.');
163 String cls = pkg.getName()+'.'+sf.substring(0,dot);
165 Class<?> c = cl.loadClass(cls);
167 if(!Modifier.isAbstract(c.getModifiers())) {
168 Constructor<?> cst = c.getConstructor(Access.class);
169 NotifyBody nb = (NotifyBody)cst.newInstance(access);
171 bodyMap.put("info|"+nb.name, nb);
172 bodyMap.put(nb.type+'|'+nb.name, nb);
176 } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {