2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalsdk.analytics.model.search;
42 import javax.servlet.http.HttpServletRequest;
44 import org.onap.portalsdk.analytics.error.RaptorException;
45 import org.onap.portalsdk.analytics.system.*;
46 import org.onap.portalsdk.analytics.util.*;
48 import com.fasterxml.jackson.databind.ObjectMapper;
51 private boolean pagination = true;
53 private int totalSize;
55 public boolean isPagination() {
58 public void setPagination(boolean pagination) {
59 this.pagination = pagination;
61 public int getPageSize() {
64 public void setPageSize(int pageSize) {
65 this.pageSize = pageSize;
67 public int getTotalSize() {
70 public void setTotalSize(int totalSize) {
71 this.totalSize = totalSize;
73 public int getPageNo() {
76 public void setPageNo(int pageNo) {
83 private MetaReport metaReport;
84 public MetaReport getMetaReport() {
87 public void setMetaReport(MetaReport metaReport) {
88 this.metaReport = metaReport;
90 private ArrayList<ArrayList<SearchResultColumn>> columns = new ArrayList<ArrayList<SearchResultColumn>>();
91 private ArrayList<ArrayList<SearchResultRow>> rows = new ArrayList<ArrayList<SearchResultRow>>();
92 public ArrayList<ArrayList<SearchResultColumn>> getColumns() {
95 public void setColumns(ArrayList<ArrayList<SearchResultColumn>> columns) {
96 this.columns = columns;
98 public ArrayList<ArrayList<SearchResultRow>> getRows() {
101 public void setRows(ArrayList<ArrayList<SearchResultRow>> rows) {
107 public class ReportSearchResultJSON extends SearchResultJSON {
108 private static final String HTML_FORM = "forma";
109 private String JSONString= "";
110 private SearchReport searchReport;
111 //private ArrayList<ArrayList<SearchResultColumn>> columns = new ArrayList<ArrayList<SearchResultColumn>>();
112 //private ArrayList<ArrayList<SearchResultRow>> rows = new ArrayList<ArrayList<SearchResultRow>>();
115 public ReportSearchResultJSON(int pageNo) {
116 this(pageNo, Globals.getDefaultPageSize(), -1, -1);
117 } // ReportSearchResult
119 public ReportSearchResultJSON(int pageNo, int writeAccessColIndex, int ownerIndicatorColIndex) {
120 this(pageNo, Globals.getDefaultPageSize(), writeAccessColIndex, ownerIndicatorColIndex);
121 } // ReportSearchResult
123 public ReportSearchResultJSON(int pageNo, int pageSize, int writeAccessColIndex,
124 int ownerIndicatorColIndex) {
126 searchReport = new SearchReport();
127 MetaReport metaReport = new MetaReport();
128 //if(searchReport.getMetaReport()!=null)
129 searchReport.setMetaReport(metaReport);
130 metaReport.setPageNo(pageNo);
131 metaReport.setPageSize(pageSize);
132 metaReport.setPagination(true);
133 addColumn(new SearchResultColumn("no", "No", "5%", "Center"));
134 addColumn(new SearchResultColumn("rep_id", "Report ID", "5%", "Center"));
135 addColumn(new SearchResultColumn("rep_name", "Report Name", "25%", "Left"));
136 addColumn(new SearchResultColumn("descr", "Description", "30%", "Left"));
137 addColumn(new SearchResultColumn("owner", "Report Owner", "10%", "Center"));
138 addColumn(new SearchResultColumn("create_date", "Create Date", "10%", "Center"));
139 addColumn(new SearchResultColumn("copy", "Copy", "5%", "Center",
140 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
141 + ".value='report.copy';", "Copy report", HTML_FORM,
142 "Are you sure you want to create a copy of this report?", AppUtils
144 + "modify_icon.gif", "13", "12", true, false, false));
145 /*addColumn(new SearchResultColumn(" Schedule ", "5%", "Center",
146 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
147 + ".value='report.schedule_only';", "Schedule report", HTML_FORM,
150 + "calendar_icon.gif", "13", "12", true, false, false));
153 addColumn(new SearchResultColumn("edit", "Edit", "5%", "Center",
154 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
155 + ".value='report.edit';", "Edit report", HTML_FORM, null, AppUtils
157 + "pen_paper.gif", "12", "12", false, true, false));
158 addColumn(new SearchResultColumn("delete", "Delete", "5%", "Center", "document." + HTML_FORM
159 + "." + AppConstants.RI_ACTION + ".value='report.delete';", "Delete report",
160 HTML_FORM, "Are you sure you want to delete this report?", AppUtils
162 + "deleteicon.gif", "12", "12", false, false, true));
163 addColumn(new SearchResultColumn("schedule", "Schedule", "5%", "Center", "document." + HTML_FORM
164 + "." + AppConstants.RI_ACTION + ".value='report.schedule.report.submit_wmenu';", "Schedule report",
165 HTML_FORM, null, AppUtils
167 + "calendar_icon.gif", "20", "20", false, false, false, true));
168 addColumn(new SearchResultColumn("run", "Run", "5%", "Center",
169 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
170 + ".value='report.run';", "Run report", HTML_FORM, null, AppUtils
172 + "test_run.gif", "12", "12"));
173 searchReport.getColumns().add(searchResultColumns);
174 } // ReportSearchResult
176 public void parseData(DataSet ds, HttpServletRequest request, int pageNo, int pageSize, int writeAccessColIndex, int ownerIndicatorColIndex) throws RaptorException {
177 // Presumes single ID field in the first column of the DataSet and row
178 // number in the first SearchResultColumn
180 pageNo = AppUtils.getRequestNvlValue(request, "r_page").length()>0?Integer.parseInt(AppUtils.getRequestNvlValue(request, "r_page")):0;
181 String userID = AppUtils.getUserID(request);
182 int dataSize = ds.getRowCount();
185 if(searchReport.getMetaReport()!=null) {
186 searchReport.getMetaReport().setPageNo(pageNo);
187 //searchReport.getMetaReport().setPageSize(pageSize);
188 pageSize = searchReport.getMetaReport().getPageSize();
189 searchReport.getMetaReport().setTotalSize(dataSize);
191 int startRow = (pageNo >= 0) ? (pageNo * pageSize) : 0;
192 int endRow = (pageNo >= 0) ? Math.min(startRow + pageSize, ds.getRowCount()) : ds
194 for (int r = startRow; r < endRow; r++) {
195 SearchResultRow row = new SearchResultRow();
196 searchResultRows.add(row);
198 String idValue = ds.getString(r, 0);
200 boolean bCanEdit = true;
201 if (writeAccessColIndex >= 0) {
202 String isReadOnlyValue = nvl(ds.getString(r, writeAccessColIndex), "Y");
203 bCanEdit = AppUtils.isSuperUser(request) || AppUtils.isAdminUser(request)
204 || isReadOnlyValue.equals("N");
207 boolean bCanDelete = bCanEdit;
208 if (Globals.getDeleteOnlyByOwner() && ownerIndicatorColIndex >= 0) {
209 String isOwnedByUserRecord = nvl(ds.getString(r, ownerIndicatorColIndex), "N");
210 bCanDelete = AppUtils.isSuperUser(request) || isOwnedByUserRecord.equals("Y");
213 boolean bCanSchedule = ds.getString(r, getNumColumns()-3).equals("Y");
215 row.addColumnContent(new ColumnContent(getColumn(0).getColumnId(), new SearchResultField("" + (r + 1), idValue,
216 getColumn(0), true)));
217 boolean isAuthorized = true;
218 for (int c = 1; c < getNumColumns(); c++) {
219 SearchResultColumn column = getColumn(c);
222 if(column.isCopyLink())
223 isAuthorized = Globals.getCanCopyOnReadOnly()? true:bCanEdit;
224 else if (column.isDeleteLink())
225 isAuthorized = bCanDelete;
226 else if (column.isEditLink())
227 isAuthorized = bCanEdit;
228 else if (column.isScheduleLink())
229 isAuthorized = bCanSchedule;
230 row.addColumnContent(new ColumnContent(column.getColumnId(), new SearchResultField(
231 (column.getLinkURL() == null) ? ds.getString(r, c) : column
232 .getLinkTitle(), idValue, column, isAuthorized
236 searchReport.getRows().add(searchResultRows);
237 ObjectMapper mapper = new ObjectMapper();
238 String jsonInString = "";
240 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(searchReport);
241 } catch (Exception ex) {
242 ex.printStackTrace();
245 System.out.println(jsonInString);
246 this.JSONString = jsonInString;
249 private String nvl(String s) {
250 return (s == null) ? "" : s;
253 private String nvl(String s, String sDefault) {
254 return nvl(s).equals("") ? sDefault : s;
257 public String getJSONString() {
261 public void setJSONString(String jSONString) {
262 JSONString = jSONString;
266 } // ReportSearchResult