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.search;
24 import javax.servlet.http.HttpServletRequest;
26 import org.openecomp.portalsdk.analytics.error.RaptorException;
27 import org.openecomp.portalsdk.analytics.system.*;
28 import org.openecomp.portalsdk.analytics.util.*;
30 public class SearchResult{
31 private int pageNo = -1;
33 private int pageSize = 50;
35 private int dataSize = -1;
37 private int writeAccessColIndex = -1;
39 private int ownerIndicatorColIndex = -1;
41 private String csvPageFileName = null;
45 private String csvAllRowsFileName = null;
47 private String excelAllRowsFileName = null;
49 public ArrayList searchResultColumns = new ArrayList();
51 public ArrayList searchResultRows = new ArrayList();
53 public SearchResult(int pageNo) {
54 this(pageNo, Globals.getDefaultPageSize());
57 public SearchResult(int pageNo, int pageSize) {
58 this(pageNo, pageSize, -1, -1);
61 public SearchResult(int pageNo, int pageSize, int writeAccessColIndex,
62 int ownerIndicatorColIndex) {
66 this.pageSize = pageSize;
68 this.writeAccessColIndex = writeAccessColIndex;
69 this.ownerIndicatorColIndex = ownerIndicatorColIndex;
72 public int getPageNo() {
76 public int getPageSize() {
80 public int getDataSize() {
84 public String getCsvPageFileName() {
85 return csvPageFileName;
88 public String getCsvAllRowsFileName() {
89 return csvAllRowsFileName;
92 public String getExcelAllRowsFileName() {
93 return excelAllRowsFileName;
96 private void setDataSize(int dataSize) {
97 this.dataSize = dataSize;
100 public void setCsvPageFileName(String csvPageFileName) {
101 this.csvPageFileName = csvPageFileName;
106 public void setCsvAllRowsFileName(String csvAllRowsFileName) {
107 this.csvAllRowsFileName = csvAllRowsFileName;
112 public void addColumn(SearchResultColumn column) {
113 searchResultColumns.add(column);
116 public SearchResultColumn getColumn(int index) {
117 return (SearchResultColumn) searchResultColumns.get(index);
120 public int getNumColumns() {
121 return searchResultColumns.size();
124 public int getNumRows() {
125 return searchResultRows.size();
128 public SearchResultRow getRow(int index) {
129 return (SearchResultRow) searchResultRows.get(index);
132 public void parseData(DataSet ds, HttpServletRequest request) throws RaptorException {
133 // Presumes single ID field in the first column of the DataSet and row
134 // number in the first SearchResultColumn
135 String userID = AppUtils.getUserID(request);
136 setDataSize(ds.getRowCount());
138 int startRow = (pageNo >= 0) ? (pageNo * pageSize) : 0;
139 int endRow = (pageNo >= 0) ? Math.min(startRow + pageSize, ds.getRowCount()) : ds
141 for (int r = startRow; r < endRow; r++) {
142 SearchResultRow row = new SearchResultRow();
143 searchResultRows.add(row);
145 String idValue = ds.getString(r, 0);
147 boolean bCanEdit = true;
148 if (writeAccessColIndex >= 0) {
149 String isReadOnlyValue = nvl(ds.getString(r, writeAccessColIndex), "Y");
150 bCanEdit = AppUtils.isSuperUser(request) || AppUtils.isAdminUser(request)
151 || isReadOnlyValue.equals("N");
154 boolean bCanDelete = bCanEdit;
155 if (Globals.getDeleteOnlyByOwner() && ownerIndicatorColIndex >= 0) {
156 String isOwnedByUserRecord = nvl(ds.getString(r, ownerIndicatorColIndex), "N");
157 bCanDelete = AppUtils.isSuperUser(request) || isOwnedByUserRecord.equals("Y");
160 boolean bCanSchedule = ds.getString(r, getNumColumns()-3).equals("Y");
162 row.addSearchResultField(new SearchResultField("" + (r + 1), idValue,
163 getColumn(0), true));
164 boolean isAuthorized = true;
165 for (int c = 1; c < getNumColumns(); c++) {
166 SearchResultColumn column = getColumn(c);
169 if(column.isCopyLink())
170 isAuthorized = Globals.getCanCopyOnReadOnly()? true:bCanEdit;
171 else if (column.isDeleteLink())
172 isAuthorized = bCanDelete;
173 else if (column.isEditLink())
174 isAuthorized = bCanEdit;
175 else if (column.isScheduleLink())
176 isAuthorized = bCanSchedule;
178 row.addSearchResultField(new SearchResultField(
179 (column.getLinkURL() == null) ? ds.getString(r, c) : column
180 .getLinkTitle(), idValue, column, isAuthorized
186 public void truncateToPage(int pageNo) {
187 if (this.pageNo >= 0 || pageNo < 0)
190 this.pageNo = pageNo;
192 int startRow = pageNo * pageSize;
193 int endRow = Math.min(startRow + pageSize, dataSize);
195 for (int r = getNumRows() - 1; r >= endRow; r--)
196 searchResultRows.remove(r);
198 for (int r = startRow - 1; r >= 0; r--)
199 searchResultRows.remove(r);
202 /** *********************************************************************** */
204 private String nvl(String s) {
205 return (s == null) ? "" : s;
208 private String nvl(String s, String sDefault) {
209 return nvl(s).equals("") ? sDefault : s;