2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalsdk.analytics.model.search;
24 import javax.servlet.http.HttpServletRequest;
26 import org.openecomp.portalsdk.analytics.error.RaptorException;
27 import org.openecomp.portalsdk.analytics.system.*;
28 import org.openecomp.portalsdk.analytics.util.*;
30 import com.fasterxml.jackson.databind.ObjectMapper;
33 private boolean pagination = true;
35 private int totalSize;
37 public boolean isPagination() {
40 public void setPagination(boolean pagination) {
41 this.pagination = pagination;
43 public int getPageSize() {
46 public void setPageSize(int pageSize) {
47 this.pageSize = pageSize;
49 public int getTotalSize() {
52 public void setTotalSize(int totalSize) {
53 this.totalSize = totalSize;
55 public int getPageNo() {
58 public void setPageNo(int pageNo) {
65 private MetaReport metaReport;
66 public MetaReport getMetaReport() {
69 public void setMetaReport(MetaReport metaReport) {
70 this.metaReport = metaReport;
72 private ArrayList<ArrayList<SearchResultColumn>> columns = new ArrayList<ArrayList<SearchResultColumn>>();
73 private ArrayList<ArrayList<SearchResultRow>> rows = new ArrayList<ArrayList<SearchResultRow>>();
74 public ArrayList<ArrayList<SearchResultColumn>> getColumns() {
77 public void setColumns(ArrayList<ArrayList<SearchResultColumn>> columns) {
78 this.columns = columns;
80 public ArrayList<ArrayList<SearchResultRow>> getRows() {
83 public void setRows(ArrayList<ArrayList<SearchResultRow>> rows) {
89 public class ReportSearchResultJSON extends SearchResultJSON {
90 private static final String HTML_FORM = "forma";
91 private String JSONString= "";
92 private SearchReport searchReport;
93 //private ArrayList<ArrayList<SearchResultColumn>> columns = new ArrayList<ArrayList<SearchResultColumn>>();
94 //private ArrayList<ArrayList<SearchResultRow>> rows = new ArrayList<ArrayList<SearchResultRow>>();
97 public ReportSearchResultJSON(int pageNo) {
98 this(pageNo, Globals.getDefaultPageSize(), -1, -1);
99 } // ReportSearchResult
101 public ReportSearchResultJSON(int pageNo, int writeAccessColIndex, int ownerIndicatorColIndex) {
102 this(pageNo, Globals.getDefaultPageSize(), writeAccessColIndex, ownerIndicatorColIndex);
103 } // ReportSearchResult
105 public ReportSearchResultJSON(int pageNo, int pageSize, int writeAccessColIndex,
106 int ownerIndicatorColIndex) {
108 searchReport = new SearchReport();
109 MetaReport metaReport = new MetaReport();
110 //if(searchReport.getMetaReport()!=null)
111 searchReport.setMetaReport(metaReport);
112 metaReport.setPageNo(pageNo);
113 metaReport.setPageSize(pageSize);
114 metaReport.setPagination(true);
115 addColumn(new SearchResultColumn("no", "No", "5%", "Center"));
116 addColumn(new SearchResultColumn("rep_id", "Report ID", "5%", "Center"));
117 addColumn(new SearchResultColumn("rep_name", "Report Name", "25%", "Left"));
118 addColumn(new SearchResultColumn("descr", "Description", "30%", "Left"));
119 addColumn(new SearchResultColumn("owner", "Report Owner", "10%", "Center"));
120 addColumn(new SearchResultColumn("create_date", "Create Date", "10%", "Center"));
121 addColumn(new SearchResultColumn("copy", "Copy", "5%", "Center",
122 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
123 + ".value='report.copy';", "Copy report", HTML_FORM,
124 "Are you sure you want to create a copy of this report?", AppUtils
126 + "modify_icon.gif", "13", "12", true, false, false));
127 /*addColumn(new SearchResultColumn(" Schedule ", "5%", "Center",
128 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
129 + ".value='report.schedule_only';", "Schedule report", HTML_FORM,
132 + "calendar_icon.gif", "13", "12", true, false, false));
135 addColumn(new SearchResultColumn("edit", "Edit", "5%", "Center",
136 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
137 + ".value='report.edit';", "Edit report", HTML_FORM, null, AppUtils
139 + "pen_paper.gif", "12", "12", false, true, false));
140 addColumn(new SearchResultColumn("delete", "Delete", "5%", "Center", "document." + HTML_FORM
141 + "." + AppConstants.RI_ACTION + ".value='report.delete';", "Delete report",
142 HTML_FORM, "Are you sure you want to delete this report?", AppUtils
144 + "deleteicon.gif", "12", "12", false, false, true));
145 addColumn(new SearchResultColumn("schedule", "Schedule", "5%", "Center", "document." + HTML_FORM
146 + "." + AppConstants.RI_ACTION + ".value='report.schedule.report.submit_wmenu';", "Schedule report",
147 HTML_FORM, null, AppUtils
149 + "calendar_icon.gif", "20", "20", false, false, false, true));
150 addColumn(new SearchResultColumn("run", "Run", "5%", "Center",
151 "document." + HTML_FORM + "." + AppConstants.RI_ACTION
152 + ".value='report.run';", "Run report", HTML_FORM, null, AppUtils
154 + "test_run.gif", "12", "12"));
155 searchReport.getColumns().add(searchResultColumns);
156 } // ReportSearchResult
158 public void parseData(DataSet ds, HttpServletRequest request, int pageNo, int pageSize, int writeAccessColIndex, int ownerIndicatorColIndex) throws RaptorException {
159 // Presumes single ID field in the first column of the DataSet and row
160 // number in the first SearchResultColumn
162 pageNo = AppUtils.getRequestNvlValue(request, "r_page").length()>0?Integer.parseInt(AppUtils.getRequestNvlValue(request, "r_page")):0;
163 String userID = AppUtils.getUserID(request);
164 int dataSize = ds.getRowCount();
167 if(searchReport.getMetaReport()!=null) {
168 searchReport.getMetaReport().setPageNo(pageNo);
169 //searchReport.getMetaReport().setPageSize(pageSize);
170 pageSize = searchReport.getMetaReport().getPageSize();
171 searchReport.getMetaReport().setTotalSize(dataSize);
173 int startRow = (pageNo >= 0) ? (pageNo * pageSize) : 0;
174 int endRow = (pageNo >= 0) ? Math.min(startRow + pageSize, ds.getRowCount()) : ds
176 for (int r = startRow; r < endRow; r++) {
177 SearchResultRow row = new SearchResultRow();
178 searchResultRows.add(row);
180 String idValue = ds.getString(r, 0);
182 boolean bCanEdit = true;
183 if (writeAccessColIndex >= 0) {
184 String isReadOnlyValue = nvl(ds.getString(r, writeAccessColIndex), "Y");
185 bCanEdit = AppUtils.isSuperUser(request) || AppUtils.isAdminUser(request)
186 || isReadOnlyValue.equals("N");
189 boolean bCanDelete = bCanEdit;
190 if (Globals.getDeleteOnlyByOwner() && ownerIndicatorColIndex >= 0) {
191 String isOwnedByUserRecord = nvl(ds.getString(r, ownerIndicatorColIndex), "N");
192 bCanDelete = AppUtils.isSuperUser(request) || isOwnedByUserRecord.equals("Y");
195 boolean bCanSchedule = ds.getString(r, getNumColumns()-3).equals("Y");
197 row.addColumnContent(new ColumnContent(getColumn(0).getColumnId(), new SearchResultField("" + (r + 1), idValue,
198 getColumn(0), true)));
199 boolean isAuthorized = true;
200 for (int c = 1; c < getNumColumns(); c++) {
201 SearchResultColumn column = getColumn(c);
204 if(column.isCopyLink())
205 isAuthorized = Globals.getCanCopyOnReadOnly()? true:bCanEdit;
206 else if (column.isDeleteLink())
207 isAuthorized = bCanDelete;
208 else if (column.isEditLink())
209 isAuthorized = bCanEdit;
210 else if (column.isScheduleLink())
211 isAuthorized = bCanSchedule;
212 row.addColumnContent(new ColumnContent(column.getColumnId(), new SearchResultField(
213 (column.getLinkURL() == null) ? ds.getString(r, c) : column
214 .getLinkTitle(), idValue, column, isAuthorized
218 searchReport.getRows().add(searchResultRows);
219 ObjectMapper mapper = new ObjectMapper();
220 String jsonInString = "";
222 jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(searchReport);
223 } catch (Exception ex) {
224 ex.printStackTrace();
227 System.out.println(jsonInString);
228 this.JSONString = jsonInString;
231 private String nvl(String s) {
232 return (s == null) ? "" : s;
235 private String nvl(String s, String sDefault) {
236 return nvl(s).equals("") ? sDefault : s;
239 public String getJSONString() {
243 public void setJSONString(String jSONString) {
244 JSONString = jSONString;
248 } // ReportSearchResult