2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.auth.batch.reports;
25 import java.io.IOException;
26 import java.util.Date;
27 import java.util.GregorianCalendar;
28 import java.util.Iterator;
29 import java.util.List;
31 import java.util.TreeMap;
32 import java.util.UUID;
33 import org.onap.aaf.auth.batch.Batch;
34 import org.onap.aaf.auth.env.AuthzTrans;
35 import org.onap.aaf.auth.org.OrganizationException;
36 import org.onap.aaf.cadi.util.CSV;
37 import org.onap.aaf.cadi.util.CSV.Writer;
38 import org.onap.aaf.misc.env.APIException;
39 import org.onap.aaf.misc.env.Env;
40 import org.onap.aaf.misc.env.TimeTaken;
41 import org.onap.aaf.misc.env.util.Chrono;
42 import org.onap.aaf.misc.env.util.Split;
44 import com.datastax.driver.core.ResultSet;
45 import com.datastax.driver.core.Row;
46 import com.datastax.driver.core.SimpleStatement;
47 import com.datastax.driver.core.Statement;
50 public class ApprovedRpt extends Batch {
52 private static final String APPR_RPT = "ApprovedRpt";
53 private static final String CSV = ".csv";
54 private static final String INFO = "info";
56 private Writer approvedW;
58 private static String yr_mon;
60 public ApprovedRpt(AuthzTrans trans) throws APIException, IOException, OrganizationException {
62 trans.info().log("Starting Connection Process");
64 TimeTaken tt0 = trans.start("Cassandra Initialization", Env.SUB);
66 // TimeTaken tt = trans.start("Connect to Cluster", Env.REMOTE);
68 // session = cluster.connect();
74 String sdate = Chrono.dateOnlyStamp(now);
75 File file = new File(logDir(),APPR_RPT + sdate +CSV);
76 CSV csv = new CSV(env.access(),file);
77 approvedW = csv.writer(false);
79 historyR = new CSV(env.access(),args()[1]).setDelimiter('|');
88 protected void run(AuthzTrans trans) {
90 Map<String,Boolean> checked = new TreeMap<String, Boolean>();
92 final AuthzTrans transNoAvg = trans.env().newTransNoAvg();
94 // Statement stmt = new SimpleStatement( "select dateof(id), approver, status, user, type, memo from authz.approved;" );
95 // results = session.execute(stmt);
96 // Iterator<Row> iter = results.iterator();
99 * while (iter.hasNext()) {
102 d = row.getTimestamp(0);
104 approvedW.row("aprvd",
105 Chrono.dateOnlyStamp(d),
118 GregorianCalendar gc = new GregorianCalendar();
119 gc.add(GregorianCalendar.MONTH, -2);
120 Date begin = gc.getTime();
121 approvedW.comment("date, approver, status, user, role, memo");
123 historyR.visit(row -> {
124 String s = row.get(7);
125 if(s.equals(yr_mon)) {
126 String target = row.get(5);
127 if("user_role".equals(target)) {
128 String action = row.get(1);
131 write("created",row);
134 write("approved",row);
144 } catch (Exception e) {
149 private void write(String a_or_d, List<String> row) {
150 String[] target = Split.splitTrim('|', row.get(4));
152 if(target.length>1) {
153 UUID id = UUID.fromString(row.get(0));
154 Date date = Chrono.uuidToDate(id);
157 String approver = row.get(6);
158 if("batch:JobChange".equals(approver)) {
160 memo = "existing role membership reduced to invoke reapproval";
165 if(!approver.equals(target[0])) {
167 Chrono.niceDateStamp(date),