summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/search/SearchResult.java
diff options
context:
space:
mode:
authorParshad Patel <pars.patel@samsung.com>2019-10-02 11:25:24 +0900
committerParshad Patel <pars.patel@samsung.com>2019-10-02 11:25:31 +0900
commitd98d4c9f564428ee9edd398675b27226645d7ef5 (patch)
tree6b9d671ac65402a46eade8ce2612e4e5cfe443fb /ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/search/SearchResult.java
parent5cee34b123b218eff6cb488bb122f07b5056c140 (diff)
Fix NPE issue in epsdk-analytics
Fix A "NullPointerException" could be thrown Either log or rethrow this exception Define a constant instead of duplicating this literal Replace the type specification in this constructor call with the diamond operator ("<>") Issue-ID: PORTAL-562 Change-Id: I51a8bb0feec5b63f82b19097d62a4977a020fdfe Signed-off-by: Parshad Patel <pars.patel@samsung.com>
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/search/SearchResult.java')
-rw-r--r--ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/search/SearchResult.java309
1 files changed, 155 insertions, 154 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/search/SearchResult.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/search/SearchResult.java
index 056ab5b9..5b44681c 100644
--- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/search/SearchResult.java
+++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/search/SearchResult.java
@@ -33,7 +33,7 @@
*
* ============LICENSE_END============================================
*
- *
+ *
*/
package org.onap.portalsdk.analytics.model.search;
@@ -46,186 +46,187 @@ import org.onap.portalsdk.analytics.system.AppUtils;
import org.onap.portalsdk.analytics.system.Globals;
import org.onap.portalsdk.analytics.util.DataSet;
-public class SearchResult{
- private int pageNo = -1;
-
- private int pageSize = 50;
-
- private int dataSize = -1;
+public class SearchResult {
+ private int pageNo = -1;
- private int writeAccessColIndex = -1;
+ private int pageSize = 50;
- private int ownerIndicatorColIndex = -1;
+ private int dataSize = -1;
- private String csvPageFileName = null;
-
+ private int writeAccessColIndex = -1;
+ private int ownerIndicatorColIndex = -1;
- private String csvAllRowsFileName = null;
-
- private String excelAllRowsFileName = null;
+ private String csvPageFileName = null;
- public ArrayList searchResultColumns = new ArrayList();
-
- public ArrayList searchResultRows = new ArrayList();
+ private String csvAllRowsFileName = null;
- public SearchResult(int pageNo) {
- this(pageNo, Globals.getDefaultPageSize());
- } // SearchResult
+ private String excelAllRowsFileName = null;
- public SearchResult(int pageNo, int pageSize) {
- this(pageNo, pageSize, -1, -1);
- } // SearchResult
+ public ArrayList searchResultColumns = new ArrayList();
- public SearchResult(int pageNo, int pageSize, int writeAccessColIndex,
- int ownerIndicatorColIndex) {
- super();
+ public ArrayList searchResultRows = new ArrayList();
- this.pageNo = pageNo;
- this.pageSize = pageSize;
+ public SearchResult(int pageNo) {
+ this(pageNo, Globals.getDefaultPageSize());
+ } // SearchResult
- this.writeAccessColIndex = writeAccessColIndex;
- this.ownerIndicatorColIndex = ownerIndicatorColIndex;
- } // SearchResult
+ public SearchResult(int pageNo, int pageSize) {
+ this(pageNo, pageSize, -1, -1);
+ } // SearchResult
- public int getPageNo() {
- return pageNo;
- }
+ public SearchResult(int pageNo, int pageSize, int writeAccessColIndex,
+ int ownerIndicatorColIndex) {
+ super();
- public int getPageSize() {
- return pageSize;
- }
+ this.pageNo = pageNo;
+ this.pageSize = pageSize;
- public int getDataSize() {
- return dataSize;
- }
+ this.writeAccessColIndex = writeAccessColIndex;
+ this.ownerIndicatorColIndex = ownerIndicatorColIndex;
+ } // SearchResult
- public String getCsvPageFileName() {
- return csvPageFileName;
- }
+ public int getPageNo() {
+ return pageNo;
+ }
- public String getCsvAllRowsFileName() {
- return csvAllRowsFileName;
- }
+ public int getPageSize() {
+ return pageSize;
+ }
- public String getExcelAllRowsFileName() {
- return excelAllRowsFileName;
- }
-
- private void setDataSize(int dataSize) {
- this.dataSize = dataSize;
- }
+ public int getDataSize() {
+ return dataSize;
+ }
- public void setCsvPageFileName(String csvPageFileName) {
- this.csvPageFileName = csvPageFileName;
- }
+ public String getCsvPageFileName() {
+ return csvPageFileName;
+ }
+
+ public String getCsvAllRowsFileName() {
+ return csvAllRowsFileName;
+ }
+
+ public String getExcelAllRowsFileName() {
+ return excelAllRowsFileName;
+ }
+ private void setDataSize(int dataSize) {
+ this.dataSize = dataSize;
+ }
-
- public void setCsvAllRowsFileName(String csvAllRowsFileName) {
- this.csvAllRowsFileName = csvAllRowsFileName;
- }
+ public void setCsvPageFileName(String csvPageFileName) {
+ this.csvPageFileName = csvPageFileName;
+ }
+ public void setCsvAllRowsFileName(String csvAllRowsFileName) {
+ this.csvAllRowsFileName = csvAllRowsFileName;
+ }
+ public void addColumn(SearchResultColumn column) {
+ searchResultColumns.add(column);
+ } // addColumn
- public void addColumn(SearchResultColumn column) {
- searchResultColumns.add(column);
- } // addColumn
+ public SearchResultColumn getColumn(int index) {
+ return (SearchResultColumn) searchResultColumns.get(index);
+ } // getColumn
- public SearchResultColumn getColumn(int index) {
- return (SearchResultColumn) searchResultColumns.get(index);
- } // getColumn
+ public int getNumColumns() {
+ return searchResultColumns.size();
+ } // getNumColumns
- public int getNumColumns() {
- return searchResultColumns.size();
- } // getNumColumns
+ public int getNumRows() {
+ return searchResultRows.size();
+ } // getNumRows
- public int getNumRows() {
- return searchResultRows.size();
- } // getNumRows
+ public SearchResultRow getRow(int index) {
+ return (SearchResultRow) searchResultRows.get(index);
+ } // getRow
- public SearchResultRow getRow(int index) {
- return (SearchResultRow) searchResultRows.get(index);
- } // getRow
+ public void parseData(DataSet ds, HttpServletRequest request) throws RaptorException {
+ // Presumes single ID field in the first column of the DataSet and row
+ // number in the first SearchResultColumn
+ String userID = AppUtils.getUserID(request);
+ setDataSize(ds.getRowCount());
- public void parseData(DataSet ds, HttpServletRequest request) throws RaptorException {
- // Presumes single ID field in the first column of the DataSet and row
- // number in the first SearchResultColumn
- String userID = AppUtils.getUserID(request);
- setDataSize(ds.getRowCount());
-
- int startRow = (pageNo >= 0) ? (pageNo * pageSize) : 0;
- int endRow = (pageNo >= 0) ? Math.min(startRow + pageSize, ds.getRowCount()) : ds
- .getRowCount();
- for (int r = startRow; r < endRow; r++) {
- SearchResultRow row = new SearchResultRow();
- searchResultRows.add(row);
-
- String idValue = ds.getString(r, 0);
-
- boolean bCanEdit = true;
- if (writeAccessColIndex >= 0) {
- String isReadOnlyValue = nvl(ds.getString(r, writeAccessColIndex), "Y");
- bCanEdit = AppUtils.isSuperUser(request) || AppUtils.isAdminUser(request)
- || isReadOnlyValue.equals("N");
- }
-
- boolean bCanDelete = bCanEdit;
- if (Globals.getDeleteOnlyByOwner() && ownerIndicatorColIndex >= 0) {
- String isOwnedByUserRecord = nvl(ds.getString(r, ownerIndicatorColIndex), "N");
- bCanDelete = AppUtils.isSuperUser(request) || isOwnedByUserRecord.equals("Y");
- }
-
- boolean bCanSchedule = ds.getString(r, getNumColumns()-3).equals("Y");
-
- row.addSearchResultField(new SearchResultField("" + (r + 1), idValue,
- getColumn(0), true));
- boolean isAuthorized = true;
- for (int c = 1; c < getNumColumns(); c++) {
- SearchResultColumn column = getColumn(c);
- isAuthorized = true;
-
- if(column.isCopyLink())
- isAuthorized = Globals.getCanCopyOnReadOnly()? true:bCanEdit;
- else if (column.isDeleteLink())
- isAuthorized = bCanDelete;
- else if (column.isEditLink())
- isAuthorized = bCanEdit;
- else if (column.isScheduleLink())
- isAuthorized = bCanSchedule;
-
- row.addSearchResultField(new SearchResultField(
- (column.getLinkURL() == null) ? ds.getString(r, c) : column
- .getLinkTitle(), idValue, column, isAuthorized
- ));
- } // for
- } // for
- } // parseData
-
- public void truncateToPage(int pageNo) {
- if (this.pageNo >= 0 || pageNo < 0)
- return;
-
- this.pageNo = pageNo;
-
- int startRow = pageNo * pageSize;
- int endRow = Math.min(startRow + pageSize, dataSize);
-
- for (int r = getNumRows() - 1; r >= endRow; r--)
- searchResultRows.remove(r);
-
- for (int r = startRow - 1; r >= 0; r--)
- searchResultRows.remove(r);
- } // truncateToPage
-
- /** *********************************************************************** */
-
- private String nvl(String s) {
- return (s == null) ? "" : s;
- }
-
- private String nvl(String s, String sDefault) {
- return nvl(s).equals("") ? sDefault : s;
- }
+ int startRow = (pageNo >= 0) ? (pageNo * pageSize) : 0;
+ int endRow = (pageNo >= 0) ? Math.min(startRow + pageSize, ds.getRowCount())
+ : ds
+ .getRowCount();
+ for (int r = startRow; r < endRow; r++) {
+ SearchResultRow row = new SearchResultRow();
+ searchResultRows.add(row);
+
+ String idValue = ds.getString(r, 0);
+
+ boolean bCanEdit = true;
+ if (writeAccessColIndex >= 0) {
+ String isReadOnlyValue = nvl(ds.getString(r, writeAccessColIndex), "Y");
+ bCanEdit = AppUtils.isSuperUser(request) || AppUtils.isAdminUser(request);
+ if (isReadOnlyValue != null) {
+ bCanEdit = bCanEdit || isReadOnlyValue.equals("N");
+ }
+ }
+
+ boolean bCanDelete = bCanEdit;
+ if (Globals.getDeleteOnlyByOwner() && ownerIndicatorColIndex >= 0) {
+ String isOwnedByUserRecord = nvl(ds.getString(r, ownerIndicatorColIndex), "N");
+ bCanDelete = AppUtils.isSuperUser(request);
+ if (isOwnedByUserRecord != null) {
+ bCanDelete = bCanDelete || isOwnedByUserRecord.equals("Y");
+ }
+ }
+
+ boolean bCanSchedule = ds.getString(r, getNumColumns() - 3).equals("Y");
+
+ row.addSearchResultField(new SearchResultField("" + (r + 1), idValue,
+ getColumn(0), true));
+ boolean isAuthorized = true;
+ for (int c = 1; c < getNumColumns(); c++) {
+ SearchResultColumn column = getColumn(c);
+ isAuthorized = true;
+
+ if (column.isCopyLink())
+ isAuthorized = Globals.getCanCopyOnReadOnly() ? true : bCanEdit;
+ else if (column.isDeleteLink())
+ isAuthorized = bCanDelete;
+ else if (column.isEditLink())
+ isAuthorized = bCanEdit;
+ else if (column.isScheduleLink())
+ isAuthorized = bCanSchedule;
+
+ row.addSearchResultField(new SearchResultField(
+ (column.getLinkURL() == null) ? ds.getString(r, c)
+ : column
+ .getLinkTitle(),
+ idValue, column, isAuthorized));
+ } // for
+ } // for
+ } // parseData
+
+ public void truncateToPage(int pageNo) {
+ if (this.pageNo >= 0 || pageNo < 0)
+ return;
+
+ this.pageNo = pageNo;
+
+ int startRow = pageNo * pageSize;
+ int endRow = Math.min(startRow + pageSize, dataSize);
+
+ for (int r = getNumRows() - 1; r >= endRow; r--)
+ searchResultRows.remove(r);
+
+ for (int r = startRow - 1; r >= 0; r--)
+ searchResultRows.remove(r);
+ } // truncateToPage
+
+ /** *********************************************************************** */
+
+ private String nvl(String s) {
+ return (s == null) ? "" : s;
+ }
+
+ private String nvl(String s, String sDefault) {
+ return nvl(s).equals("") ? sDefault : s;
+ }
} // SearchResult