From 7f535078ef80a7b7efa3e3325bfccb994fbd00e8 Mon Sep 17 00:00:00 2001 From: "Christopher Lott (cl778h)" Date: Thu, 31 Aug 2017 15:16:38 -0400 Subject: Rename packages to org.onap in 1.4.0-SNAPSHOT 19 - remove openecomp 72 - remediate Sonar scan issues 79 - removed unwanted left menu under Report 90 - apply approved license text Issue: PORTAL-19, PORTAL-72, PORTAL-79, PORTAL-90 Change-Id: I41a0ef5fba623d2242574bd15f2d9fb8029a496c Signed-off-by: Christopher Lott (cl778h) --- .../model/search/ReportSearchResultJSON.java | 267 +++++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/search/ReportSearchResultJSON.java (limited to 'ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/search/ReportSearchResultJSON.java') diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/search/ReportSearchResultJSON.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/search/ReportSearchResultJSON.java new file mode 100644 index 00000000..2174383c --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/search/ReportSearchResultJSON.java @@ -0,0 +1,267 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.analytics.model.search; + +import java.util.*; + +import javax.servlet.http.HttpServletRequest; + +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.system.*; +import org.onap.portalsdk.analytics.util.*; + +import com.fasterxml.jackson.databind.ObjectMapper; + +class MetaReport { + private boolean pagination = true; + private int pageSize; + private int totalSize; + private int pageNo; + public boolean isPagination() { + return pagination; + } + public void setPagination(boolean pagination) { + this.pagination = pagination; + } + public int getPageSize() { + return pageSize; + } + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + public int getTotalSize() { + return totalSize; + } + public void setTotalSize(int totalSize) { + this.totalSize = totalSize; + } + public int getPageNo() { + return pageNo; + } + public void setPageNo(int pageNo) { + this.pageNo = pageNo; + } + + +} +class SearchReport { + private MetaReport metaReport; + public MetaReport getMetaReport() { + return metaReport; + } + public void setMetaReport(MetaReport metaReport) { + this.metaReport = metaReport; + } + private ArrayList> columns = new ArrayList>(); + private ArrayList> rows = new ArrayList>(); + public ArrayList> getColumns() { + return columns; + } + public void setColumns(ArrayList> columns) { + this.columns = columns; + } + public ArrayList> getRows() { + return rows; + } + public void setRows(ArrayList> rows) { + this.rows = rows; + } + +} + +public class ReportSearchResultJSON extends SearchResultJSON { + private static final String HTML_FORM = "forma"; + private String JSONString= ""; + private SearchReport searchReport; + //private ArrayList> columns = new ArrayList>(); + //private ArrayList> rows = new ArrayList>(); + + + public ReportSearchResultJSON(int pageNo) { + this(pageNo, Globals.getDefaultPageSize(), -1, -1); + } // ReportSearchResult + + public ReportSearchResultJSON(int pageNo, int writeAccessColIndex, int ownerIndicatorColIndex) { + this(pageNo, Globals.getDefaultPageSize(), writeAccessColIndex, ownerIndicatorColIndex); + } // ReportSearchResult + + public ReportSearchResultJSON(int pageNo, int pageSize, int writeAccessColIndex, + int ownerIndicatorColIndex) { + + searchReport = new SearchReport(); + MetaReport metaReport = new MetaReport(); + //if(searchReport.getMetaReport()!=null) + searchReport.setMetaReport(metaReport); + metaReport.setPageNo(pageNo); + metaReport.setPageSize(pageSize); + metaReport.setPagination(true); + addColumn(new SearchResultColumn("no", "No", "5%", "Center")); + addColumn(new SearchResultColumn("rep_id", "Report ID", "5%", "Center")); + addColumn(new SearchResultColumn("rep_name", "Report Name", "25%", "Left")); + addColumn(new SearchResultColumn("descr", "Description", "30%", "Left")); + addColumn(new SearchResultColumn("owner", "Report Owner", "10%", "Center")); + addColumn(new SearchResultColumn("create_date", "Create Date", "10%", "Center")); + addColumn(new SearchResultColumn("copy", "Copy", "5%", "Center", + "document." + HTML_FORM + "." + AppConstants.RI_ACTION + + ".value='report.copy';", "Copy report", HTML_FORM, + "Are you sure you want to create a copy of this report?", AppUtils + .getImgFolderURL() + + "modify_icon.gif", "13", "12", true, false, false)); + /*addColumn(new SearchResultColumn("  Schedule  ", "5%", "Center", + "document." + HTML_FORM + "." + AppConstants.RI_ACTION + + ".value='report.schedule_only';", "Schedule report", HTML_FORM, + null, AppUtils + .getImgFolderURL() + + "calendar_icon.gif", "13", "12", true, false, false)); + */ + + addColumn(new SearchResultColumn("edit", "Edit", "5%", "Center", + "document." + HTML_FORM + "." + AppConstants.RI_ACTION + + ".value='report.edit';", "Edit report", HTML_FORM, null, AppUtils + .getImgFolderURL() + + "pen_paper.gif", "12", "12", false, true, false)); + addColumn(new SearchResultColumn("delete", "Delete", "5%", "Center", "document." + HTML_FORM + + "." + AppConstants.RI_ACTION + ".value='report.delete';", "Delete report", + HTML_FORM, "Are you sure you want to delete this report?", AppUtils + .getImgFolderURL() + + "deleteicon.gif", "12", "12", false, false, true)); + addColumn(new SearchResultColumn("schedule", "Schedule", "5%", "Center", "document." + HTML_FORM + + "." + AppConstants.RI_ACTION + ".value='report.schedule.report.submit_wmenu';", "Schedule report", + HTML_FORM, null, AppUtils + .getImgFolderURL() + + "calendar_icon.gif", "20", "20", false, false, false, true)); + addColumn(new SearchResultColumn("run", "Run", "5%", "Center", + "document." + HTML_FORM + "." + AppConstants.RI_ACTION + + ".value='report.run';", "Run report", HTML_FORM, null, AppUtils + .getImgFolderURL() + + "test_run.gif", "12", "12")); + searchReport.getColumns().add(searchResultColumns); + } // ReportSearchResult + + public void parseData(DataSet ds, HttpServletRequest request, int pageNo, int pageSize, int writeAccessColIndex, int ownerIndicatorColIndex) throws RaptorException { + // Presumes single ID field in the first column of the DataSet and row + // number in the first SearchResultColumn + + pageNo = AppUtils.getRequestNvlValue(request, "r_page").length()>0?Integer.parseInt(AppUtils.getRequestNvlValue(request, "r_page")):0; + String userID = AppUtils.getUserID(request); + int dataSize = ds.getRowCount(); + //pageSize = 0; + + if(searchReport.getMetaReport()!=null) { + searchReport.getMetaReport().setPageNo(pageNo); + //searchReport.getMetaReport().setPageSize(pageSize); + pageSize = searchReport.getMetaReport().getPageSize(); + searchReport.getMetaReport().setTotalSize(dataSize); + } + 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.addColumnContent(new ColumnContent(getColumn(0).getColumnId(), 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.addColumnContent(new ColumnContent(column.getColumnId(), new SearchResultField( + (column.getLinkURL() == null) ? ds.getString(r, c) : column + .getLinkTitle(), idValue, column, isAuthorized + ))); + } // for + } // for + searchReport.getRows().add(searchResultRows); + ObjectMapper mapper = new ObjectMapper(); + String jsonInString = ""; + try { + jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(searchReport); + } catch (Exception ex) { + ex.printStackTrace(); + + } + System.out.println(jsonInString); + this.JSONString = jsonInString; + } // parseData + + private String nvl(String s) { + return (s == null) ? "" : s; + } + + private String nvl(String s, String sDefault) { + return nvl(s).equals("") ? sDefault : s; + } + + public String getJSONString() { + return JSONString; + } + + public void setJSONString(String jSONString) { + JSONString = jSONString; + } + + +} // ReportSearchResult + -- cgit 1.2.3-korg