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