Batch, Remove unneeded Classes, refine, etc
[aaf/authz.git] / auth / auth-batch / src / main / java / org / onap / aaf / auth / batch / reports / bodies / NotifyURBody.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.Date;
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.auth.org.Organization.Identity;
31 import org.onap.aaf.auth.org.OrganizationException;
32 import org.onap.aaf.cadi.Access;
33 import org.onap.aaf.misc.env.util.Chrono;
34
35 public abstract class NotifyURBody extends NotifyBody {
36
37         private final String explanation;
38         public NotifyURBody(Access access, String name) throws IOException {
39                 super(access,"ur",name);
40                 
41                 // Default
42                 explanation = "The Roles for the IDs associated with you will expire on the dates shown. "
43                                 + "If the role membership is allowed to expire, "
44                                 + "the ID will no longer have the permissions associated with that role.<br><br>"
45                         + "It is the responsibility of the Designated Approvers to approve, but you can monitor "
46                         + "their progress by clicking the ID Link.";    
47         }
48
49         @Override
50         public boolean body(AuthzTrans trans, StringBuilder sb, int indent, Notify n, String id) {
51                 String fullname = "n/a";
52                 String kind = "Name";
53                 try {
54                         Identity identity = trans.org().getIdentity(trans, id);
55                         if(identity==null) {
56                                 trans.warn().printf("Cannot find %s in Organization",id);
57                         } else {
58                                 fullname = identity.fullName();
59                                 if(!identity.isPerson()) {
60                                         if((identity = identity.responsibleTo())!=null) {
61                                                 kind = "AppID Sponsor";
62                                                 fullname = identity.fullName();
63                                         }
64                                 }
65                         }
66                 } catch (OrganizationException e) {
67                         trans.error().log(e);
68                         fullname = "n/a";
69                 }
70                 println(sb,indent,explanation);
71                 println(sb,indent,"<br><br>");
72                 println(sb,indent,"<table>");
73                 indent+=2;
74                 println(sb,indent,"<tr>");
75                 indent+=2;
76                 println(sb,indent,"<th>"+kind+"</th>");
77                 println(sb,indent,"<th>Fully Qualified ID</th>");
78                 println(sb,indent,"<th>Role</th>");
79                 println(sb,indent,"<th>Expires</th>");
80                 indent-=2;
81                 println(sb,indent,"</tr>");
82
83                 String name = null;
84                 String fqi = null;
85                 for(List<String> row : rows.get(id)) {
86                         println(sb,indent,"<tr>");
87                         indent+=2;
88                         name = printCell(sb,indent,fullname,name);
89                         String rid = row.get(1);
90                         String fqiCell = "<a href=\"" + gui_url + "/myrequests\">" + rid + "</a>";
91                         fqi = printCell(sb,indent,fqiCell,fqi);
92                         printCell(sb,indent,row.get(2));
93                         Date expires = new Date(Long.parseLong(row.get(6)));
94                         printCell(sb,indent,Chrono.niceUTCStamp(expires));
95                         indent-=2;
96                         println(sb,indent,"</tr>");
97                 }
98                 indent-=2;
99                 println(sb,indent,"</table>");
100                 
101                 return true;
102         }
103         
104         
105         @Override
106         public void record(AuthzTrans trans, StringBuilder query, String id, List<String> notified, LastNotified ln) {
107                 for(List<String> row : rows.get(id)) {
108                         for(String n : notified) {
109                                 // Need to match LastNotified Key ... ur.user() + '|'+ur.role();
110                                 ln.update(query, n, row.get(0), row.get(1)+'|'+row.get(2));
111                         }
112                 }
113         }
114
115         @Override
116         public String user(List<String> row) {
117                 if( (row != null) && row.size()>1) {
118                         return row.get(1);
119                 }
120                 return null;
121         }
122
123
124 }