2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Modifications Copyright (C) 2019 IBM.
8 * ===========================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END====================================================
24 package org.onap.aaf.auth.batch.helpers;
27 import java.util.TreeMap;
29 import org.onap.aaf.auth.batch.BatchException;
30 import org.onap.aaf.misc.env.Env;
31 import org.onap.aaf.misc.env.TimeTaken;
32 import org.onap.aaf.misc.env.Trans;
34 import com.datastax.driver.core.ResultSet;
35 import com.datastax.driver.core.Row;
36 import com.datastax.driver.core.Session;
37 import com.datastax.driver.core.SimpleStatement;
38 import com.datastax.driver.core.Statement;
41 public static final TreeMap<String,MiscID> data = new TreeMap<>();
44 aad890|mj9030|20040902|20120207
46 **** Field Definitions ****
47 MISCID - AT&T Miscellaneous ID - Non-User ID (Types: Internal Mechanized ID, External Mechanized ID, Datagate ID, Customer ID, Vendor ID, Exchange Mail ID, CLEC ID, Specialized ID, Training ID)
48 SPONSOR_ATTUID - ATTUID of MiscID Sponsor (Owner)
49 CREATE_DATE - Date when MiscID was created
50 LAST_RENEWAL_DATE - Date when MiscID Sponsorship was last renewed
53 public String sponsor;
54 public String created;
55 public String renewal;
56 public static String SELECT_QUERY = "SELECT ";
58 private static final String FIELD_STRING = "id,created,sponsor,renewal";
61 * Load a Row of Strings (from CSV file).
63 * Be CAREFUL that the Row lists match the Fields above!!! If this changes, change
66 * 3) Alter existing Tables
68 * @throws BatchException
70 public void set(String[] row ) throws BatchException {
72 throw new BatchException("Row of MiscID_XRef is too short");
80 public void set(Row row) {
81 id = row.getString(0);
82 sponsor = row.getString(1);
83 created = row.getString(2);
84 renewal = row.getString(3);
88 public static void load(Trans trans, Session session ) {
89 load(trans, session,SELECT_QUERY + FIELD_STRING + " FROM authz.miscid;",data);
92 public static void load(Trans trans, Session session, Map<String,MiscID> map ) {
93 load(trans, session,SELECT_QUERY + FIELD_STRING + " FROM authz.miscid;",map);
96 public static void loadOne(Trans trans, Session session, String id ) {
97 load(trans, session,SELECT_QUERY + FIELD_STRING + " FROM authz.miscid WHERE id ='" + id + "';", data);
100 public static void load(Trans trans, Session session, String query, Map<String,MiscID> map) {
101 trans.info().log( "query: " + query );
102 TimeTaken tt = trans.start("Read MiscID", Env.REMOTE);
106 Statement stmt = new SimpleStatement( query );
107 results = session.execute(stmt);
113 tt = trans.start("Load Map", Env.SUB);
115 for ( Row row : results.all()) {
116 MiscID miscID = new MiscID();
118 data.put(miscID.id,miscID);
125 trans.info().log("Found",count,"miscID records");
130 * @see java.lang.Object#hashCode()
133 public int hashCode() {
134 return id.hashCode();
138 * @see java.lang.Object#equals(java.lang.Object)
141 public boolean equals(Object obj) {
142 if (null!=obj && obj instanceof MiscID) {
143 return id.equals(((MiscID)obj).id);
148 public StringBuilder insertStmt() {
149 StringBuilder sb = new StringBuilder("INSERT INTO authz.miscid (");
150 sb.append(FIELD_STRING);
151 sb.append(") VALUES ('");
163 public StringBuilder updateStmt(MiscID source) {
164 StringBuilder sb = null;
165 if (id.equals(source.id)) {
166 sb = addField(sb,"sponser",sponsor,source.sponsor);
167 sb = addField(sb,"created",created,source.created);
168 sb = addField(sb,"renewal",renewal,source.renewal);
171 sb.append(" WHERE id='");
178 private StringBuilder addField(StringBuilder sb, String name, String a, String b) {
181 sb = new StringBuilder("UPDATE authz.miscid SET ");