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;
34 import org.onap.aaf.auth.batch.Batch;
35 import org.onap.aaf.auth.env.AuthzTrans;
36 import org.onap.aaf.auth.org.OrganizationException;
37 import org.onap.aaf.cadi.routing.GreatCircle;
38 import org.onap.aaf.cadi.util.CSV;
39 import org.onap.aaf.cadi.util.CSV.Visitor;
40 import org.onap.aaf.cadi.util.CSV.Writer;
41 import org.onap.aaf.misc.env.APIException;
42 import org.onap.aaf.misc.env.Env;
43 import org.onap.aaf.misc.env.TimeTaken;
44 import org.onap.aaf.misc.env.util.Chrono;
45 import org.onap.aaf.misc.env.util.Split;
47 import com.datastax.driver.core.ResultSet;
48 import com.datastax.driver.core.Row;
49 import com.datastax.driver.core.SimpleStatement;
50 import com.datastax.driver.core.Statement;
53 public class ApprovedRpt extends Batch {
55 private static final String APPR_RPT = "ApprovedRpt";
56 private static final String CSV = ".csv";
57 private static final String INFO = "info";
59 private Writer approvedW;
61 private static String yr_mon;
63 public ApprovedRpt(AuthzTrans trans) throws APIException, IOException, OrganizationException {
65 trans.info().log("Starting Connection Process");
67 TimeTaken tt0 = trans.start("Cassandra Initialization", Env.SUB);
69 // TimeTaken tt = trans.start("Connect to Cluster", Env.REMOTE);
71 // session = cluster.connect();
77 String sdate = Chrono.dateOnlyStamp(now);
78 File file = new File(logDir(),APPR_RPT + sdate +CSV);
79 CSV csv = new CSV(env.access(),file);
80 approvedW = csv.writer(false);
82 historyR = new CSV(env.access(),args()[1]).setDelimiter('|');
91 protected void run(AuthzTrans trans) {
93 Map<String,Boolean> checked = new TreeMap<String, Boolean>();
95 final AuthzTrans transNoAvg = trans.env().newTransNoAvg();
97 // Statement stmt = new SimpleStatement( "select dateof(id), approver, status, user, type, memo from authz.approved;" );
98 // results = session.execute(stmt);
99 // Iterator<Row> iter = results.iterator();
102 * while (iter.hasNext()) {
105 d = row.getTimestamp(0);
107 approvedW.row("aprvd",
108 Chrono.dateOnlyStamp(d),
121 GregorianCalendar gc = new GregorianCalendar();
122 gc.add(GregorianCalendar.MONTH, -2);
123 Date begin = gc.getTime();
124 approvedW.comment("date, approver, status, user, role, memo");
126 historyR.visit(row -> {
127 String s = row.get(7);
128 if(s.equals(yr_mon)) {
129 String target = row.get(5);
130 if("user_role".equals(target)) {
131 String action = row.get(1);
134 write("created",row);
137 write("approved",row);
147 } catch (Exception e) {
152 private void write(String a_or_d, List<String> row) {
153 String[] target = Split.splitTrim('|', row.get(4));
155 if(target.length>1) {
156 UUID id = UUID.fromString(row.get(0));
157 Date date = Chrono.uuidToDate(id);
160 String approver = row.get(6);
161 if("batch:JobChange".equals(approver)) {
163 memo = "existing role membership reduced to invoke reapproval";
168 if(!approver.equals(target[0])) {
170 Chrono.niceDateStamp(date),