2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
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 * ================================================================================
20 package org.openecomp.portalsdk.analytics.model.base;
24 import org.openecomp.portalsdk.analytics.error.RaptorException;
25 import org.openecomp.portalsdk.analytics.model.*;
26 import org.openecomp.portalsdk.analytics.model.runtime.*;
27 import org.openecomp.portalsdk.analytics.system.*;
28 import org.openecomp.portalsdk.analytics.util.*;
30 public class IdNameLookup extends IdNameSql {
31 private String dbTableName = null;
33 private String dbIdField = null;
35 private String dbNameField = null;
37 private String dbSortByField = null;
39 private String searchString = "";
41 public IdNameLookup(int pageNo, String dbTableName, String dbIdField, String dbNameField) {
42 this(dbTableName, dbIdField, dbNameField);
47 public IdNameLookup(String dbTableName, String dbIdField, String dbNameField) {
48 this(dbTableName, dbIdField, dbNameField, null, "", false);
51 /* public IdNameLookup(String dbTableName, String dbIdField, String dbNameField,
52 String dbSortByField) {
55 setDbTableName(dbTableName);
56 setDbIdField(dbIdField);
57 setDbNameField(dbNameField);
58 setDbSortByField(dbSortByField);
62 public IdNameLookup(String dbTableName, String dbIdField, String dbNameField,
63 String dbSortByField, String defaultSQL) {
66 setDbTableName(dbTableName);
67 setDbIdField(dbIdField);
68 setDbNameField(dbNameField);
69 setDbSortByField(dbSortByField);
70 setDefaultSQL(defaultSQL);
74 public IdNameLookup(String dbTableName, String dbIdField, String dbNameField,
75 String dbSortByField, boolean textField) {
77 setDbTableName(dbTableName);
78 setDbIdField(dbIdField);
79 setDbNameField(dbNameField);
80 setDbSortByField(dbSortByField);
85 public IdNameLookup(String dbTableName, String dbIdField, String dbNameField,
86 String dbSortByField, String defaultSQL, boolean textField) {
89 setDbTableName(dbTableName);
90 setDbIdField(dbIdField);
91 setDbNameField(dbNameField);
92 setDbSortByField(dbSortByField);
93 setDefaultSQL(defaultSQL);
98 public String getDbTableName() {
102 public String getDbIdField() {
106 public String getDbNameField() {
110 public String getDbSortByField() {
111 return dbSortByField;
114 public void setDbTableName(String dbTableName) {
115 this.dbTableName = dbTableName;
118 public void setDbIdField(String dbIdField) {
119 this.dbIdField = dbIdField;
122 public void setDbNameField(String dbNameField) {
123 this.dbNameField = dbNameField;
127 public void setDbSortByField(String dbSortByField) {
128 this.dbSortByField = dbSortByField;
131 private void updateParentSQL() {
132 String sql_start = "SELECT DISTINCT " + dbIdField + " id, " + dbNameField + " name";
133 String sql_end = " FROM " + dbTableName + " WHERE " + dbIdField + " IS NOT NULL";
134 if (searchString.length() > 0)
135 sql_end += " AND UPPER(" + dbNameField + ") LIKE UPPER('" + searchString + "')";
137 String sql_middle = "";
138 if (dbSortByField != null && (!dbSortByField.equals(dbNameField)) && (!dbSortByField.trim().startsWith("TO_DATE")))
140 + ((dbSortByField.indexOf(' ') > 0) ? dbSortByField.substring(0,
141 dbSortByField.indexOf(' ')) : dbSortByField) + " sort";
143 setSqlNoOrderBy(sql_start + sql_middle + sql_end);
144 // System.out.println("SQL Start " + sql_start);
145 // System.out.println("SQL Middle " + sql_middle);
146 // System.out.println("SQL End " + sql_end);
147 // System.out.println("DbSortByField " + dbSortByField);
149 setSql(sql_start + sql_middle + sql_end + " ORDER BY " + nvl(dbSortByField, "2"));
152 public boolean canUseSearchString() {
156 public String getBaseSQL() {
157 return "SELECT " + dbIdField + " FROM " + dbTableName;
160 public String getBaseWholeSQL() {
161 return "SELECT " + dbIdField + " FROM " + dbTableName;
165 public void loadData(int pageNo) throws RaptorException {
166 loadData(pageNo, "");
169 public void loadData(String pageNo) throws RaptorException {
170 loadData(pageNo, "");
174 public void loadData(String pageNo, String searchString, String dbInfo) throws RaptorException {
179 iPageNo = Integer.parseInt(pageNo);
180 } catch (NumberFormatException e) {
183 loadData(iPageNo, searchString, dbInfo);
186 private void loadData(int pageNo, String searchString, String dbInfo) throws RaptorException {
187 boolean dataAlreadyLoaded = (this.pageNo == pageNo)
188 && (this.searchString.equals(searchString));
190 if (dataAlreadyLoaded)
193 if (!this.searchString.equals(searchString)) {
198 this.pageNo = pageNo;
199 this.searchString = searchString;
201 performLoadData(searchString,dbInfo);