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.helpers;
25 import java.util.TreeMap;
27 import org.onap.aaf.auth.batch.BatchException;
28 import org.onap.aaf.misc.env.Env;
29 import org.onap.aaf.misc.env.TimeTaken;
30 import org.onap.aaf.misc.env.Trans;
32 import com.datastax.driver.core.ResultSet;
33 import com.datastax.driver.core.Row;
34 import com.datastax.driver.core.Session;
35 import com.datastax.driver.core.SimpleStatement;
36 import com.datastax.driver.core.Statement;
39 public static final TreeMap<String,MiscID> data = new TreeMap<>();
42 aad890|mj9030|20040902|20120207
44 **** Field Definitions ****
45 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)
46 SPONSOR_ATTUID - ATTUID of MiscID Sponsor (Owner)
47 CREATE_DATE - Date when MiscID was created
48 LAST_RENEWAL_DATE - Date when MiscID Sponsorship was last renewed
50 public String id,sponsor,created,renewal;
52 private static final String fieldString = "id,created,sponsor,renewal";
55 * Load a Row of Strings (from CSV file).
57 * Be CAREFUL that the Row lists match the Fields above!!! If this changes, change
60 * 3) Alter existing Tables
62 * @throws BatchException
63 * @throws IllegalAccessException
64 * @throws IllegalArgumentException
66 public void set(String row []) throws BatchException {
67 if (row.length<4) {throw new BatchException("Row of MiscID_XRef is too short");}
74 public void set(Row row) {
75 id = row.getString(0);
76 sponsor = row.getString(1);
77 created = row.getString(2);
78 renewal = row.getString(3);
82 public static void load(Trans trans, Session session ) {
83 load(trans, session,"SELECT " + fieldString + " FROM authz.miscid;",data);
86 public static void load(Trans trans, Session session, Map<String,MiscID> map ) {
87 load(trans, session,"SELECT " + fieldString + " FROM authz.miscid;",map);
90 public static void loadOne(Trans trans, Session session, String id ) {
91 load(trans, session,"SELECT " + fieldString + " FROM authz.miscid WHERE id ='" + id + "';", data);
94 public static void load(Trans trans, Session session, String query, Map<String,MiscID> map) {
95 trans.info().log( "query: " + query );
96 TimeTaken tt = trans.start("Read MiscID", Env.REMOTE);
100 Statement stmt = new SimpleStatement( query );
101 results = session.execute(stmt);
107 tt = trans.start("Load Map", Env.SUB);
109 for ( Row row : results.all()) {
110 MiscID miscID = new MiscID();
112 data.put(miscID.id,miscID);
119 trans.info().log("Found",count,"miscID records");
124 * @see java.lang.Object#hashCode()
127 public int hashCode() {
128 return id.hashCode();
132 * @see java.lang.Object#equals(java.lang.Object)
135 public boolean equals(Object obj) {
136 if (obj!=null && obj instanceof MiscID) {
137 return id.equals(((MiscID)obj).id);
142 public StringBuilder insertStmt() throws IllegalArgumentException, IllegalAccessException {
143 StringBuilder sb = new StringBuilder("INSERT INTO authz.miscid (");
144 sb.append(fieldString);
145 sb.append(") VALUES ('");
157 public StringBuilder updateStmt(MiscID source) {
158 StringBuilder sb = null;
159 if (id.equals(source.id)) {
160 sb = addField(sb,"sponser",sponsor,source.sponsor);
161 sb = addField(sb,"created",created,source.created);
162 sb = addField(sb,"renewal",renewal,source.renewal);
165 sb.append(" WHERE id='");
172 private StringBuilder addField(StringBuilder sb, String name, String a, String b) {
175 sb = new StringBuilder("UPDATE authz.miscid SET ");