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;
57 private static final String FIELD_STRING = "id,created,sponsor,renewal";
60 * Load a Row of Strings (from CSV file).
62 * Be CAREFUL that the Row lists match the Fields above!!! If this changes, change
65 * 3) Alter existing Tables
67 * @throws BatchException
69 public void set(String[] row ) throws BatchException {
71 throw new BatchException("Row of MiscID_XRef is too short");
79 public void set(Row row) {
80 id = row.getString(0);
81 sponsor = row.getString(1);
82 created = row.getString(2);
83 renewal = row.getString(3);
87 public static void load(Trans trans, Session session ) {
88 load(trans, session,"SELECT " + FIELD_STRING + " FROM authz.miscid;",data);
91 public static void load(Trans trans, Session session, Map<String,MiscID> map ) {
92 load(trans, session,"SELECT " + FIELD_STRING + " FROM authz.miscid;",map);
95 public static void loadOne(Trans trans, Session session, String id ) {
96 load(trans, session,"SELECT " + FIELD_STRING + " FROM authz.miscid WHERE id ='" + id + "';", data);
99 public static void load(Trans trans, Session session, String query, Map<String,MiscID> map) {
100 trans.info().log( "query: " + query );
101 TimeTaken tt = trans.start("Read MiscID", Env.REMOTE);
105 Statement stmt = new SimpleStatement( query );
106 results = session.execute(stmt);
112 tt = trans.start("Load Map", Env.SUB);
114 for ( Row row : results.all()) {
115 MiscID miscID = new MiscID();
117 data.put(miscID.id,miscID);
124 trans.info().log("Found",count,"miscID records");
129 * @see java.lang.Object#hashCode()
132 public int hashCode() {
133 return id.hashCode();
137 * @see java.lang.Object#equals(java.lang.Object)
140 public boolean equals(Object obj) {
141 if (null!=obj && obj instanceof MiscID) {
142 return id.equals(((MiscID)obj).id);
147 public StringBuilder insertStmt() {
148 StringBuilder sb = new StringBuilder("INSERT INTO authz.miscid (");
149 sb.append(FIELD_STRING);
150 sb.append(") VALUES ('");
162 public StringBuilder updateStmt(MiscID source) {
163 StringBuilder sb = null;
164 if (id.equals(source.id)) {
165 sb = addField(sb,"sponser",sponsor,source.sponsor);
166 sb = addField(sb,"created",created,source.created);
167 sb = addField(sb,"renewal",renewal,source.renewal);
170 sb.append(" WHERE id='");
177 private StringBuilder addField(StringBuilder sb, String name, String a, String b) {
180 sb = new StringBuilder("UPDATE authz.miscid SET ");