Batch, Remove unneeded Classes, refine, etc
[aaf/authz.git] / auth / auth-batch / src / main / java / org / onap / aaf / auth / batch / reports / bodies / NotifyCredBody.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21 package org.onap.aaf.auth.batch.reports.bodies;
22
23 import java.io.IOException;
24 import java.util.GregorianCalendar;
25 import java.util.List;
26
27 import org.onap.aaf.auth.batch.helpers.LastNotified;
28 import org.onap.aaf.auth.batch.reports.Notify;
29 import org.onap.aaf.auth.env.AuthzTrans;
30 import org.onap.aaf.cadi.Access;
31 import org.onap.aaf.misc.env.util.Chrono;
32
33 public abstract class NotifyCredBody extends NotifyBody {
34
35         private final String explanation;
36         private final String instruction;
37          
38         public NotifyCredBody(Access access, String name) throws IOException {
39                 super(access,"cred",name);
40                 
41                 // Default
42                 explanation = "The following Credentials that you are responsible for "
43                                 + "are expiring on the dates shown. <br><br>"
44                                 ;
45                                 
46         instruction = "<br><h3>Instructions for 'Password':</h3><ul>" 
47                                 + "<li><b><i>Click</i></b> on the Fully Qualified ID to ADD a new Password</li>"
48                                 + "<li><b>REMEMBER!</b> You are not finished until you <ol>"
49                                 + "<li><b>CHANGE <i>ALL</i></b> the configurations on <b><i>ALL</i></b> your processes!!</li>"
50                                 + "<li><b>BOUNCE</b> them</li></ol>"
51                                 + "<li>IF there is a WARNING, click the link for more information</li>"
52                                 + "</ul>";
53         }
54         
55         /**
56          * Default Dynamic Text.  Override is expected
57          * @return
58          */
59         protected String dynamic() {
60                 return "Failure to act before the expiration date will cause your App's Authentications to fail.";
61         }
62
63         @Override
64         public boolean body(AuthzTrans trans, StringBuilder sb, int indent, Notify n, String id) {
65                 print(sb,indent,explanation);
66                 print(sb,indent,dynamic());
67                 println(sb,indent,instruction);
68                 println(sb,indent,"<table>");
69                 indent+=2;
70                 println(sb,indent,"<tr>");
71                 indent+=2;
72                 println(sb,indent,"<th>Fully Qualified ID</th>");
73                 println(sb,indent,"<th>Unique ID</th>");
74                 println(sb,indent,"<th>Type</th>");
75                 println(sb,indent,"<th>Expires</th>");
76                 println(sb,indent,"<th>Warnings</th>");
77                 indent-=2;
78                 println(sb,indent,"</tr>");
79                 String theid, type, info, expires, warnings;
80                 GregorianCalendar gc = new GregorianCalendar();
81                 for(List<String> row : rows.get(id)) {
82                         theid=row.get(1);
83                         switch(row.get(3)) {
84                                 case "1":
85                                 case "2":
86                                         type = "Password";
87                                         break;
88                                 case "200":
89                                         type = "x509 (Certificate)";
90                                         break;
91                                 default:
92                                         type = "Unknown, see AAF GUI";
93                                         break;
94                         }
95                         theid = "<a href=\""+n.guiURL+"/creddetail?ns="+row.get(2)+"\">"+theid+"</a>";
96                         gc.setTimeInMillis(Long.parseLong(row.get(5)));
97                         expires = Chrono.niceUTCStamp(gc);
98                         info = row.get(6);
99                         //TODO get Warnings 
100                         warnings = "";
101                         
102                         println(sb,indent,"<tr>");
103                         indent+=2;
104                         printCell(sb,indent,theid);
105                         printCell(sb,indent,info);
106                         printCell(sb,indent,type);
107                         printCell(sb,indent,expires);
108                         printCell(sb,indent,warnings);
109                         indent-=2;
110                         println(sb,indent,"</tr>");
111                 }
112                 indent-=2;
113                 println(sb,indent,"</table>");
114                 
115                 return true;
116         }
117         
118         @Override
119         public void record(AuthzTrans trans, StringBuilder query, String id, List<String> notified, LastNotified ln) {
120                 for(List<String> row : rows.get(id)) {
121                         for(String n : notified) {
122                                 // Need to match LastNotified Key ... cred.id + '|' + inst.type + '|' + inst.tag;
123                                 ln.update(query, n, row.get(0), row.get(1)+'|'+row.get(3)+'|'+row.get(6));
124                         }
125                 }
126         }
127
128         @Override
129         public String user(List<String> row) {
130                 if( (row != null) && row.size()>1) {
131                         return row.get(1);
132                 }
133                 return null;
134         }
135
136
137 }