2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 IBM.
7 * ===========================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END====================================================
23 package org.onap.aaf.auth.batch.reports;
26 import java.io.IOException;
27 import java.util.Date;
28 import java.util.GregorianCalendar;
29 import java.util.List;
30 import java.util.UUID;
32 import org.onap.aaf.auth.batch.Batch;
33 import org.onap.aaf.auth.env.AuthzTrans;
34 import org.onap.aaf.auth.org.OrganizationException;
35 import org.onap.aaf.cadi.util.CSV;
36 import org.onap.aaf.cadi.util.CSV.Writer;
37 import org.onap.aaf.misc.env.APIException;
38 import org.onap.aaf.misc.env.Env;
39 import org.onap.aaf.misc.env.TimeTaken;
40 import org.onap.aaf.misc.env.util.Chrono;
41 import org.onap.aaf.misc.env.util.Split;
44 public class ApprovedRpt extends Batch {
46 private static final String APPR_RPT = "ApprovedRpt";
47 private static final String CSV = ".csv";
49 private Writer approvedW;
51 private static String yearMon;
53 public ApprovedRpt(AuthzTrans trans) throws APIException, IOException, OrganizationException {
55 trans.info().log("Starting Connection Process");
57 TimeTaken tt0 = trans.start("Cassandra Initialization", Env.SUB);
60 String sdate = Chrono.dateOnlyStamp(now);
61 File file = new File(logDir(),APPR_RPT + sdate +CSV);
62 CSV csv = new CSV(env.access(),file);
63 approvedW = csv.writer(false);
65 historyR = new CSV(env.access(),args()[1]).setDelimiter('|');
74 protected void run(AuthzTrans trans) {
76 GregorianCalendar gc = new GregorianCalendar();
77 gc.add(GregorianCalendar.MONTH, -2);
78 approvedW.comment("date, approver, status, user, role, memo");
79 historyR.visit(row -> {
80 String s = row.get(7);
81 if(s.equals(yearMon)) {
82 String target = row.get(5);
83 if("user_role".equals(target)) {
84 String action = row.get(1);
90 write("approved",row);
100 } catch (Exception e) {
105 private void write(String a_or_d, List<String> row) {
106 String[] target = Split.splitTrim('|', row.get(4));
108 if(target.length>1) {
109 UUID id = UUID.fromString(row.get(0));
110 Date date = Chrono.uuidToDate(id);
113 String approver = row.get(6);
114 if("batch:JobChange".equals(approver)) {
116 memo = "existing role membership reduced to invoke reapproval";
121 if(!approver.equals(target[0])) {
123 Chrono.niceDateStamp(date),