2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Modifications Copyright (C) 2018 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
68 * @throws IllegalAccessException
69 * @throws IllegalArgumentException
71 public void set(String[] row ) throws BatchException {
73 throw new BatchException("Row of MiscID_XRef is too short");
81 public void set(Row row) {
82 id = row.getString(0);
83 sponsor = row.getString(1);
84 created = row.getString(2);
85 renewal = row.getString(3);
89 public static void load(Trans trans, Session session ) {
90 load(trans, session,"SELECT " + FIELD_STRING + " FROM authz.miscid;",data);
93 public static void load(Trans trans, Session session, Map<String,MiscID> map ) {
94 load(trans, session,"SELECT " + FIELD_STRING + " FROM authz.miscid;",map);
97 public static void loadOne(Trans trans, Session session, String id ) {
98 load(trans, session,"SELECT " + FIELD_STRING + " FROM authz.miscid WHERE id ='" + id + "';", data);
101 public static void load(Trans trans, Session session, String query, Map<String,MiscID> map) {
102 trans.info().log( "query: " + query );
103 TimeTaken tt = trans.start("Read MiscID", Env.REMOTE);
107 Statement stmt = new SimpleStatement( query );
108 results = session.execute(stmt);
114 tt = trans.start("Load Map", Env.SUB);
116 for ( Row row : results.all()) {
117 MiscID miscID = new MiscID();
119 data.put(miscID.id,miscID);
126 trans.info().log("Found",count,"miscID records");
131 * @see java.lang.Object#hashCode()
134 public int hashCode() {
135 return id.hashCode();
139 * @see java.lang.Object#equals(java.lang.Object)
142 public boolean equals(Object obj) {
143 if (obj!=null && obj instanceof MiscID) {
144 return id.equals(((MiscID)obj).id);
149 public StringBuilder insertStmt() throws IllegalArgumentException, IllegalAccessException {
150 StringBuilder sb = new StringBuilder("INSERT INTO authz.miscid (");
151 sb.append(FIELD_STRING);
152 sb.append(") VALUES ('");
164 public StringBuilder updateStmt(MiscID source) {
165 StringBuilder sb = null;
166 if (id.equals(source.id)) {
167 sb = addField(sb,"sponser",sponsor,source.sponsor);
168 sb = addField(sb,"created",created,source.created);
169 sb = addField(sb,"renewal",renewal,source.renewal);
172 sb.append(" WHERE id='");
179 private StringBuilder addField(StringBuilder sb, String name, String a, String b) {
182 sb = new StringBuilder("UPDATE authz.miscid SET ");