Improve Batches
[aaf/authz.git] / auth / auth-batch / src / main / java / org / onap / aaf / auth / batch / reports / bodies / NotifyPendingApprBody.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.util.List;
24
25 import org.onap.aaf.auth.batch.reports.Notify;
26 import org.onap.aaf.auth.env.AuthzTrans;
27 import org.onap.aaf.cadi.Access;
28
29 public class NotifyPendingApprBody extends NotifyBody {
30
31         public NotifyPendingApprBody(Access access) {
32                 super(access,"appr","PendingApproval");
33         }
34
35         @Override
36         public boolean body(AuthzTrans trans, StringBuilder sb, int indent, Notify n, String id) {
37                 boolean rv = false;
38                 for(List<String> row : rows.get(id)) {
39                         String qty = row.get(2);
40                         if("1".equals(qty)) {
41                                 printf(sb,indent,"You have an Approval in the AAF %s Environment awaiting your decision.\n",row.get(3));
42                         } else {
43                                 printf(sb,indent,"You have %s Approvals in the AAF %s Environment awaiting your decision.\n",qty,row.get(3));
44                         }
45                         printf(sb,indent,"<br><br><b>ACTION:</b> <i>Click on</i> <a href=\"%s/approve\">AAF Approval Page</a>",n.guiURL);
46                         rv = true;
47                         break; // only one
48                 }
49                 
50                 return rv;
51         }
52
53         @Override
54         public String user(List<String> row) {
55                 if( (row != null) && row.size()>1) {
56                         return row.get(1);
57                 }
58                 return null;
59         }
60
61         @Override
62         public String subject() {
63                 return String.format("AAF Pending Approval Notification (ENV: %s)",env);
64         }
65
66         /* (non-Javadoc)
67          * @see org.onap.aaf.auth.batch.reports.bodies.NotifyBody#store(java.util.List)
68          */
69         @Override
70         public void store(List<String> row) {
71                 // Notify Pending is setup for 1 Notification at a time
72                 super.rows.clear();
73                 super.store(row);
74         }
75
76 }