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;
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.Globals;
47 import org.onap.portalsdk.analytics.util.AppConstants;
48 import org.onap.portalsdk.analytics.util.DataSet;
50 import com.fasterxml.jackson.databind.ObjectMapper;
53 private boolean pagination = true;
55 private int totalSize;
57 public boolean isPagination() {
60 public void setPagination(boolean pagination) {
61 this.pagination = pagination;
63 public int getPageSize() {
66 public void setPageSize(int pageSize) {
67 this.pageSize = pageSize;
69 public int getTotalSize() {
72 public void setTotalSize(int totalSize) {
73 this.totalSize = totalSize;
75 public int getPageNo() {
78 public void setPageNo(int pageNo) {
85 private MetaReport metaReport;
86 public MetaReport getMetaReport() {
89 public void setMetaReport(MetaReport metaReport) {
90 this.metaReport = metaReport;
92 private ArrayList<ArrayList<SearchResultColumn>> columns = new ArrayList<ArrayList<SearchResultColumn>>();
93 private ArrayList<ArrayList<SearchResultRow>> rows = new ArrayList<ArrayList<SearchResultRow>>();
94 public ArrayList<ArrayList<SearchResultColumn>> getColumns() {
97 public void setColumns(ArrayList<ArrayList<SearchResultColumn>> columns) {
98 this.columns = columns;
100 public ArrayList<ArrayList<SearchResultRow>> getRows() {
103 public void setRows(ArrayList<ArrayList<SearchResultRow>> rows) {
109 public class ReportSearchResultJSON extends SearchResultJSON {
110 private static final String HTML_FORM = "forma";
111 private String JSONString= "";
112 private SearchReport searchReport;
113 //private ArrayList<ArrayList<SearchResultColumn>> columns = new ArrayList<ArrayList<SearchResultColumn>>();
114 //private ArrayList<ArrayList<SearchResultRow>> rows = new ArrayList<ArrayList<SearchResultRow>>();
117 public ReportSearchResultJSON(int pageNo) {
118 this(pageNo, Globals.getDefaultPageSize(), -1, -1);
119 } // ReportSearchResult
121 public ReportSearchResultJSON(int pageNo, int writeAccessColIndex, int ownerIndicatorColIndex) {
122 this(pageNo, Globals.getDefaultPageSize(), writeAccessColIndex, ownerIndicatorColIndex);
123 } // ReportSearchResult
125 public ReportSearchResultJSON(int pageNo, int pageSize, int writeAccessColIndex,
126 int ownerIndicatorColIndex) {
128 searchReport = new SearchReport();
129 MetaReport metaReport = new MetaReport();
130 //if(searchReport.getMetaReport()!=null)
131 searchReport.setMetaReport(metaReport);
132 metaReport.setPageNo(pageNo);
133 metaReport.setPageSize(pageSize);
134 metaReport.setPagination(true);
135 addColumn(new SearchResultColumn("no", "No", "5%", "Center"));
136 addColumn(new SearchResultColumn("rep_id", "Report ID", "5%", "Center"));
137 addColumn(new SearchResultColumn("rep_name", "Report Name", "25%", "Left"));
138 addColumn(new SearchResultColumn("descr", "Description", "30%", "Left"));
139 addColumn(new SearchResultColumn("owner", "Report Owner", "10%", "Center"));
140 addColumn(new SearchResultColumn("create_date", "Create Date", "10%", "Center"));
141 addColumn(new SearchResultColumn("copy", "Copy", "5%", "Center",
142 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
143 + ".value='report.copy';", "Copy report", HTML_FORM,
144 "Are you sure you want to create a copy of this report?", AppUtils
146 + "modify_icon.gif", "13", "12", true, false, false));
147 /*addColumn(new SearchResultColumn(" Schedule ", "5%", "Center",
148 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
149 + ".value='report.schedule_only';", "Schedule report", HTML_FORM,
152 + "calendar_icon.gif", "13", "12", true, false, false));
155 addColumn(new SearchResultColumn("edit", "Edit", "5%", "Center",
156 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
157 + ".value='report.edit';", "Edit report", HTML_FORM, null, AppUtils
159 + "pen_paper.gif", "12", "12", false, true, false));
160 addColumn(new SearchResultColumn("delete", "Delete", "5%", "Center", "document." + HTML_FORM
161 + "." + AppConstants.RI_ACTION + ".value='report.delete';", "Delete report",
162 HTML_FORM, "Are you sure you want to delete this report?", AppUtils
164 + "deleteicon.gif", "12", "12", false, false, true));
165 addColumn(new SearchResultColumn("schedule", "Schedule", "5%", "Center", "document." + HTML_FORM
166 + "." + AppConstants.RI_ACTION + ".value='report.schedule.report.submit_wmenu';", "Schedule report",
167 HTML_FORM, null, AppUtils
169 + "calendar_icon.gif", "20", "20", false, false, false, true));
170 addColumn(new SearchResultColumn("run", "Run", "5%", "Center",
171 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
172 + ".value='report.run';", "Run report", HTML_FORM, null, AppUtils
174 + "test_run.gif", "12", "12"));
175 searchReport.getColumns().add(searchResultColumns);
176 } // ReportSearchResult
178 public void parseData(DataSet ds, HttpServletRequest request, int pageNo, int pageSize, int writeAccessColIndex, int ownerIndicatorColIndex) throws RaptorException {
179 // Presumes single ID field in the first column of the DataSet and row
180 // number in the first SearchResultColumn
182 pageNo = AppUtils.getRequestNvlValue(request, "r_page").length()>0?Integer.parseInt(AppUtils.getRequestNvlValue(request, "r_page")):0;
183 String userID = AppUtils.getUserID(request);
184 int dataSize = ds.getRowCount();
187 if(searchReport.getMetaReport()!=null) {
188 searchReport.getMetaReport().setPageNo(pageNo);
189 //searchReport.getMetaReport().setPageSize(pageSize);
190 pageSize = searchReport.getMetaReport().getPageSize();
191 searchReport.getMetaReport().setTotalSize(dataSize);
193 int startRow = (pageNo >= 0) ? (pageNo * pageSize) : 0;
194 int endRow = (pageNo >= 0) ? Math.min(startRow + pageSize, ds.getRowCount()) : ds
196 for (int r = startRow; r < endRow; r++) {
197 SearchResultRow row = new SearchResultRow();
198 searchResultRows.add(row);
200 String idValue = ds.getString(r, 0);
202 boolean bCanEdit = true;
203 if (writeAccessColIndex >= 0) {
204 String isReadOnlyValue = nvl(ds.getString(r, writeAccessColIndex), "Y");
205 bCanEdit = AppUtils.isSuperUser(request) || AppUtils.isAdminUser(request)
206 || isReadOnlyValue.equals("N");
209 boolean bCanDelete = bCanEdit;
210 if (Globals.getDeleteOnlyByOwner() && ownerIndicatorColIndex >= 0) {
211 String isOwnedByUserRecord = nvl(ds.getString(r, ownerIndicatorColIndex), "N");
212 bCanDelete = AppUtils.isSuperUser(request) || isOwnedByUserRecord.equals("Y");
215 boolean bCanSchedule = ds.getString(r, getNumColumns()-3).equals("Y");
217 row.addColumnContent(new ColumnContent(getColumn(0).getColumnId(), new SearchResultField("" + (r + 1), idValue,
218 getColumn(0), true)));
219 boolean isAuthorized = true;
220 for (int c = 1; c < getNumColumns(); c++) {
221 SearchResultColumn column = getColumn(c);
224 if(column.isCopyLink())
225 isAuthorized = Globals.getCanCopyOnReadOnly()? true:bCanEdit;
226 else if (column.isDeleteLink())
227 isAuthorized = bCanDelete;
228 else if (column.isEditLink())
229 isAuthorized = bCanEdit;
230 else if (column.isScheduleLink())
231 isAuthorized = bCanSchedule;
232 row.addColumnContent(new ColumnContent(column.getColumnId(), new SearchResultField(
233 (column.getLinkURL() == null) ? ds.getString(r, c) : column
234 .getLinkTitle(), idValue, column, isAuthorized
238 searchReport.getRows().add(searchResultRows);
239 ObjectMapper mapper = new ObjectMapper();
240 String jsonInString = "";
242 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(searchReport);
243 } catch (Exception ex) {
244 ex.printStackTrace();
247 System.out.println(jsonInString);
248 this.JSONString = jsonInString;
251 private String nvl(String s) {
252 return (s == null) ? "" : s;
255 private String nvl(String s, String sDefault) {
256 return nvl(s).equals("") ? sDefault : s;
259 public String getJSONString() {
263 public void setJSONString(String jSONString) {
264 JSONString = jSONString;
268 } // ReportSearchResult