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============================================
38 package org.onap.portalsdk.analytics.model.search;
40 import java.util.ArrayList;
42 import javax.servlet.http.HttpServletRequest;
44 import org.onap.portalsdk.analytics.error.RaptorException;
45 import org.onap.portalsdk.analytics.system.AppUtils;
46 import org.onap.portalsdk.analytics.system.DbUtils;
47 import org.onap.portalsdk.analytics.system.Globals;
48 import org.onap.portalsdk.analytics.util.AppConstants;
49 import org.onap.portalsdk.analytics.util.DataSet;
50 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
51 import com.fasterxml.jackson.databind.ObjectMapper;
54 private boolean pagination = true;
56 private int totalSize;
59 public boolean isPagination() {
63 public void setPagination(boolean pagination) {
64 this.pagination = pagination;
67 public int getPageSize() {
71 public void setPageSize(int pageSize) {
72 this.pageSize = pageSize;
75 public int getTotalSize() {
79 public void setTotalSize(int totalSize) {
80 this.totalSize = totalSize;
83 public int getPageNo() {
87 public void setPageNo(int pageNo) {
95 private MetaReport metaReport;
97 public MetaReport getMetaReport() {
101 public void setMetaReport(MetaReport metaReport) {
102 this.metaReport = metaReport;
105 private ArrayList<ArrayList<SearchResultColumn>> columns = new ArrayList<>();
106 private ArrayList<ArrayList<SearchResultRow>> rows = new ArrayList<>();
108 public ArrayList<ArrayList<SearchResultColumn>> getColumns() {
112 public void setColumns(ArrayList<ArrayList<SearchResultColumn>> columns) {
113 this.columns = columns;
116 public ArrayList<ArrayList<SearchResultRow>> getRows() {
120 public void setRows(ArrayList<ArrayList<SearchResultRow>> rows) {
127 public class ReportSearchResultJSON extends SearchResultJSON {
129 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ReportSearchResultJSON.class);
130 private static final String HTML_FORM = "forma";
131 private String jsonString = "";
132 private SearchReport searchReport;
133 // private ArrayList<ArrayList<SearchResultColumn>> columns = new
134 // ArrayList<ArrayList<SearchResultColumn>>();
135 // private ArrayList<ArrayList<SearchResultRow>> rows = new ArrayList<ArrayList<SearchResultRow>>();
137 public ReportSearchResultJSON(int pageNo) {
138 this(pageNo, Globals.getDefaultPageSize(), -1, -1);
139 } // ReportSearchResult
141 public ReportSearchResultJSON(int pageNo, int writeAccessColIndex, int ownerIndicatorColIndex) {
142 this(pageNo, Globals.getDefaultPageSize(), writeAccessColIndex, ownerIndicatorColIndex);
143 } // ReportSearchResult
145 public ReportSearchResultJSON(int pageNo, int pageSize, int writeAccessColIndex,
146 int ownerIndicatorColIndex) {
148 searchReport = new SearchReport();
149 MetaReport metaReport = new MetaReport();
150 // if(searchReport.getMetaReport()!=null)
151 searchReport.setMetaReport(metaReport);
152 metaReport.setPageNo(pageNo);
153 metaReport.setPageSize(pageSize);
154 metaReport.setPagination(true);
155 addColumn(new SearchResultColumn("no", "No", "5%", "Center"));
156 addColumn(new SearchResultColumn("rep_id", "Report ID", "5%", "Center"));
157 addColumn(new SearchResultColumn("rep_name", "Report Name", "25%", "Left"));
158 addColumn(new SearchResultColumn("descr", "Description", "30%", "Left"));
159 addColumn(new SearchResultColumn("owner", "Report Owner", "10%", "Center"));
160 addColumn(new SearchResultColumn("create_date", "Create Date", "10%", "Center"));
161 addColumn(new SearchResultColumn("copy", "Copy", "5%", "Center",
162 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
163 + ".value='report.copy';",
164 "Copy report", HTML_FORM,
165 "Are you sure you want to create a copy of this report?", AppUtils
168 "13", "12", true, false, false));
170 * addColumn(new SearchResultColumn(" Schedule ", "5%", "Center", "document."
171 * + HTML_FORM + "." + AppConstants.RI_ACTION + ".value='report.schedule_only';", "Schedule report",
172 * HTML_FORM, null, AppUtils .getImgFolderURL() + "calendar_icon.gif", "13", "12", true, false,
176 addColumn(new SearchResultColumn("edit", "Edit", "5%", "Center",
177 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
178 + ".value='report.edit';",
179 "Edit report", HTML_FORM, null, AppUtils
182 "12", "12", false, true, false));
183 addColumn(new SearchResultColumn("delete", "Delete", "5%", "Center", "document." + HTML_FORM
184 + "." + AppConstants.RI_ACTION + ".value='report.delete';", "Delete report",
185 HTML_FORM, "Are you sure you want to delete this report?", AppUtils
188 "12", "12", false, false, true));
189 addColumn(new SearchResultColumn("schedule", "Schedule", "5%", "Center", "document." + HTML_FORM
190 + "." + AppConstants.RI_ACTION + ".value='report.schedule.report.submit_wmenu';", "Schedule report",
191 HTML_FORM, null, AppUtils
193 + "calendar_icon.gif",
194 "20", "20", false, false, false, true));
195 addColumn(new SearchResultColumn("run", "Run", "5%", "Center",
196 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
197 + ".value='report.run';",
198 "Run report", HTML_FORM, null, AppUtils
202 searchReport.getColumns().add(searchResultColumns);
203 } // ReportSearchResult
205 public void parseData(DataSet ds, HttpServletRequest request, int pageNo, int pageSize, int writeAccessColIndex,
206 int ownerIndicatorColIndex) throws RaptorException {
207 // Presumes single ID field in the first column of the DataSet and row
208 // number in the first SearchResultColumn
210 pageNo = AppUtils.getRequestNvlValue(request, "r_page").length() > 0
211 ? Integer.parseInt(AppUtils.getRequestNvlValue(request, "r_page"))
213 String userID = AppUtils.getUserID(request);
214 int dataSize = ds.getRowCount();
217 if (searchReport.getMetaReport() != null) {
218 searchReport.getMetaReport().setPageNo(pageNo);
219 // searchReport.getMetaReport().setPageSize(pageSize);
220 pageSize = searchReport.getMetaReport().getPageSize();
221 searchReport.getMetaReport().setTotalSize(dataSize);
223 int startRow = (pageNo >= 0) ? (pageNo * pageSize) : 0;
224 int endRow = (pageNo >= 0) ? Math.min(startRow + pageSize, ds.getRowCount())
227 for (int r = startRow; r < endRow; r++) {
228 SearchResultRow row = new SearchResultRow();
229 searchResultRows.add(row);
231 String idValue = ds.getString(r, 0);
233 boolean bCanEdit = true;
234 if (writeAccessColIndex >= 0) {
235 String isReadOnlyValue = nvl(ds.getString(r, writeAccessColIndex), "Y");
236 bCanEdit = AppUtils.isSuperUser(request) || AppUtils.isAdminUser(request);
237 if (isReadOnlyValue != null) {
238 bCanEdit = bCanEdit || isReadOnlyValue.equals("N");
243 boolean bCanDelete = bCanEdit;
244 if (Globals.getDeleteOnlyByOwner() && ownerIndicatorColIndex >= 0) {
245 String isOwnedByUserRecord = nvl(ds.getString(r, ownerIndicatorColIndex), "N");
246 bCanDelete = AppUtils.isSuperUser(request);
247 if (isOwnedByUserRecord != null) {
248 bCanDelete = bCanDelete || isOwnedByUserRecord.equals("Y");
252 boolean bCanSchedule = ds.getString(r, getNumColumns() - 3).equals("Y");
254 row.addColumnContent(
255 new ColumnContent(getColumn(0).getColumnId(), new SearchResultField("" + (r + 1), idValue,
256 getColumn(0), true)));
257 boolean isAuthorized = true;
258 for (int c = 1; c < getNumColumns(); c++) {
259 SearchResultColumn column = getColumn(c);
262 if (column.isCopyLink())
263 isAuthorized = Globals.getCanCopyOnReadOnly() ? true : bCanEdit;
264 else if (column.isDeleteLink())
265 isAuthorized = bCanDelete;
266 else if (column.isEditLink())
267 isAuthorized = bCanEdit;
268 else if (column.isScheduleLink())
269 isAuthorized = bCanSchedule;
270 row.addColumnContent(new ColumnContent(column.getColumnId(), new SearchResultField(
271 (column.getLinkURL() == null) ? ds.getString(r, c)
274 idValue, column, isAuthorized)));
277 searchReport.getRows().add(searchResultRows);
278 ObjectMapper mapper = new ObjectMapper();
279 String jsonInString = "";
281 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(searchReport);
282 } catch (Exception ex) {
283 logger.warn("Exception in parseData", ex);
285 logger.debug(jsonInString);
286 this.jsonString = jsonInString;
289 private String nvl(String s) {
290 return (s == null) ? "" : s;
293 private String nvl(String s, String sDefault) {
294 return nvl(s).equals("") ? sDefault : s;
297 public String getJSONString() {
301 public void setJSONString(String jSONString) {
302 jsonString = jSONString;
305 } // ReportSearchResult