6f85d1bf13011740157792a8c4112a95b0058cd9
[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 associated with you will expire on the dates shown. If "
42                                 + "allowed to expire, the ID will no longer authorized in that role on that date.<br><br>"
43                         + "It is the responsibility of the Designated Approvers to approve, but you can monitor "
44                         + "their progress by clicking the ID Link.";    
45         }
46
47         @Override
48         public boolean body(AuthzTrans trans, StringBuilder sb, int indent, Notify n, String id) {
49                 String fullname = "n/a";
50                 String kind = "Name";
51                 try {
52                         Identity identity = trans.org().getIdentity(trans, id);
53                         if(identity==null) {
54                                 trans.warn().printf("Cannot find %s in Organization",id);
55                         } else {
56                                 fullname = identity.fullName();
57                                 if(!identity.isPerson()) {
58                                         if((identity = identity.responsibleTo())!=null) {
59                                                 kind = "AppID Sponsor";
60                                                 fullname = identity.fullName();
61                                         }
62                                 }
63                         }
64                 } catch (OrganizationException e) {
65                         trans.error().log(e);
66                         fullname = "n/a";
67                 }
68                 println(sb,indent,explanation);
69                 println(sb,indent,"<br><br>");
70                 println(sb,indent,"<table>");
71                 indent+=2;
72                 println(sb,indent,"<tr>");
73                 indent+=2;
74                 println(sb,indent,"<th>"+kind+"</th>");
75                 println(sb,indent,"<th>Fully Qualified ID</th>");
76                 println(sb,indent,"<th>Role</th>");
77                 println(sb,indent,"<th>Expires</th>");
78                 indent-=2;
79                 println(sb,indent,"</tr>");
80
81                 String name = null;
82                 String fqi = null;
83                 for(List<String> row : rows.get(id)) {
84                         println(sb,indent,"<tr>");
85                         indent+=2;
86                         name = printCell(sb,indent,fullname,name);
87                         String rid = row.get(1);
88                         String fqiCell = "<a href=\"" + gui_url + "/myrequests\">" + rid + "</a>";
89                         fqi = printCell(sb,indent,fqiCell,fqi);
90                         printCell(sb,indent,row.get(2));
91                         Date expires = new Date(Long.parseLong(row.get(6)));
92                         printCell(sb,indent,Chrono.niceUTCStamp(expires));
93                         indent-=2;
94                         println(sb,indent,"</tr>");
95                 }
96                 indent-=2;
97                 println(sb,indent,"</table>");
98                 
99                 return true;
100         }
101
102         @Override
103         public String user(List<String> row) {
104                 if( (row != null) && row.size()>1) {
105                         return row.get(1);
106                 }
107                 return null;
108         }
109
110
111 }