DataMigration, other Batch
[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.reports.Notify;
28 import org.onap.aaf.auth.env.AuthzTrans;
29 import org.onap.aaf.auth.org.Organization.Identity;
30 import org.onap.aaf.auth.org.OrganizationException;
31 import org.onap.aaf.cadi.Access;
32 import org.onap.aaf.misc.env.util.Chrono;
33
34 public abstract class NotifyURBody extends NotifyBody {
35
36         private final String explanation;
37         public NotifyURBody(Access access, String name) throws IOException {
38                 super(access,"ur",name);
39                 
40                 // Default
41                 explanation = "The Roles for the IDs listed will expire on the dates shown. If "
42                                 + "allowed to expire, the ID will no longer authorized in that role.<br><br>"
43                                 + "If the ID is for a current <b><i>Application</i></b>, this <b><i>WILL</i></b> cause an outage.";
44         }
45
46         @Override
47         public boolean body(AuthzTrans trans, StringBuilder sb, int indent, Notify n, String id) {
48                 String fullname = "n/a";
49                 String kind = "Name";
50                 try {
51                         Identity identity = trans.org().getIdentity(trans, id);
52                         if(identity==null) {
53                                 trans.warn().printf("Cannot find %s in Organization",id);
54                         } else {
55                                 fullname = identity.fullName();
56                                 if(!identity.isPerson()) {
57                                         if((identity = identity.responsibleTo())!=null) {
58                                                 kind = "AppID Sponsor";
59                                                 fullname = identity.fullName();
60                                         }
61                                 }
62                         }
63                 } catch (OrganizationException e) {
64                         trans.error().log(e);
65                         fullname = "n/a";
66                 }
67                 println(sb,indent,explanation);
68                 println(sb,indent,"<br><br>");
69                 println(sb,indent,"<table>");
70                 indent+=2;
71                 println(sb,indent,"<tr>");
72                 indent+=2;
73                 println(sb,indent,"<th>"+kind+"</th>");
74                 println(sb,indent,"<th>Fully Qualified ID</th>");
75                 println(sb,indent,"<th>Role</th>");
76                 println(sb,indent,"<th>Expires</th>");
77                 indent-=2;
78                 println(sb,indent,"</tr>");
79
80                 String name = null;
81                 String fqi = null;
82                 for(List<String> row : rows.get(id)) {
83                         println(sb,indent,"<tr>");
84                         indent+=2;
85                         name = printCell(sb,indent,fullname,name);
86                         fqi = printCell(sb,indent,row.get(1),fqi);
87                         printCell(sb,indent,row.get(2)+'.'+row.get(3));
88                         Date expires = new Date(Long.parseLong(row.get(6)));
89                         printCell(sb,indent,Chrono.niceUTCStamp(expires));
90                         indent-=2;
91                         println(sb,indent,"</tr>");
92                 }
93                 indent-=2;
94                 println(sb,indent,"</table>");
95                 
96                 return true;
97         }
98
99         @Override
100         public String user(List<String> row) {
101                 if( (row != null) && row.size()>1) {
102                         return row.get(1);
103                 }
104                 return null;
105         }
106
107
108 }