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 <%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %>
21 <%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %>
22 <%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %>
23 <%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %>
24 <%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %>
25 <%@ page import="java.util.Vector" %>
26 <%@ page import="java.util.List" %>
27 <%@ page import="org.openecomp.portalsdk.analytics.model.DataCache" %>
28 <%@ page import="java.util.Iterator" %>
29 <%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataSourceType" %>
30 <%@ page import="org.openecomp.portalsdk.analytics.model.definition.DBColumnInfo" %>
31 <%@ page import="org.openecomp.portalsdk.analytics.model.definition.TableSource" %>
32 <%@ page import="org.openecomp.portalsdk.analytics.model.base.IdNameValue" %>
33 <%@ page import="org.openecomp.portalsdk.analytics.xmlobj.SemaphoreType" %>
34 <%@ page import="org.openecomp.portalsdk.analytics.xmlobj.FormFieldType" %>
35 <%@ page import="org.openecomp.portalsdk.analytics.model.definition.TableJoin" %>
36 <%@ page import="org.openecomp.portalsdk.analytics.error.UserDefinedException"%>
39 ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION);
40 WizardSequence ws = rdef.getWizardSequence();
41 String curSubStep = ws.getCurrentSubStep();
42 boolean isEdit = curSubStep.equals(AppConstants.WSS_EDIT);
43 DataSourceType currTable = null;
45 currTable = rdef.getTableById(AppUtils.getRequestNvlValue(request, AppConstants.RI_DETAIL_ID));
46 Vector reportTableSources = (isEdit)?DataCache.getReportTableSources((String) session.getAttribute("remoteDB")):DataCache.getReportTableSources(AppUtils.getUserRoles(request),((String) session.getAttribute("remoteDB")), AppUtils.getUserID(request), request);
47 if(reportTableSources.size()<=0) {
48 request.setAttribute(AppConstants.RI_EXCEPTION, new Exception("Please add table name to the raptor table for generating report"));
49 throw new UserDefinedException("Please add table name to the raptor table for generating report");
51 Vector reportTableJoins = (isEdit)?DataCache.getReportTableJoins():DataCache.getReportTableJoins(AppUtils.getUserRoles(request)); %>
54 <script language="JavaScript">
56 var tablesExist = false;
57 <% if(rdef.getDataSourceList().getDataSource().size()>0) { %>
60 function setJoinTableName(tableId) {
62 for(var i=1; i<document.forma.joinTableName.options.length; i++)
63 if(tableId==document.forma.joinTableName.options[i].value)
66 document.forma.joinTableName.selectedIndex = selIndex;
70 function tableNameChange() {
71 var newTableName = "";
72 newTableName = document.forma.tableName.options[document.forma.tableName.selectedIndex].value;
74 document.forma.displayName.value=document.forma.tableName.options[document.forma.tableName.selectedIndex].text;
76 // Setting the PK values
79 <% for(int i=0; i<reportTableSources.size(); i++) {
80 TableSource tableSource = (TableSource) reportTableSources.get(i); %>
81 else if(newTableName=="<%= tableSource.getTableName() %>")
82 document.forma.tablePK.value = "<%= tableSource.getPkFields() %>";
85 <% if(rdef.getDataSourceList().getDataSource().size()>0) {
86 for(Iterator iter=rdef.getDataSourceList().getDataSource().iterator(); iter.hasNext(); ) {
87 DataSourceType dst = (DataSourceType) iter.next();
89 for(int i=0; i<reportTableJoins.size(); i++) {
90 TableJoin tableJoin = (TableJoin) reportTableJoins.get(i);
91 if(dst.getTableName().equals(tableJoin.getSrcTableName())) { %>
92 if(newTableName=="<%= tableJoin.getDestTableName() %>")
93 setJoinTableName("<%= dst.getTableId() %>");
95 <% } else if(dst.getTableName().equals(tableJoin.getDestTableName())) { %>
96 if(newTableName=="<%= tableJoin.getSrcTableName() %>")
97 setJoinTableName("<%= dst.getTableId() %>");
102 setJoinTableName("");
104 listJoinExpr(document.forma.tableName.options[document.forma.tableName.selectedIndex].value,
105 document.forma.joinTableName.options[document.forma.joinTableName.selectedIndex].value);
113 <script language="JavaScript">
115 //load table join info to an array of objects
116 function table_join(src_table, dest_table, join_expr) {
117 this.src_table = src_table;
118 this.dest_table = dest_table;
119 this.join_expr = join_expr;
122 var table_joins = new Array();
124 <% for(int i=0; i<reportTableJoins.size(); i++) {
125 TableJoin tableJoin = (TableJoin) reportTableJoins.get(i); %>
126 table_joins[table_joins.length] =
127 new table_join("<%=tableJoin.getSrcTableName()%>","<%=tableJoin.getDestTableName()%>","<%=tableJoin.getJoinExpr()%>");
130 function table_id_name_mapping(table_id, table_name) {
131 this.table_id = table_id;
132 this.table_name = table_name;
135 var table_id_name_mappings = new Array();
137 <% for(Iterator iter=rdef.getDataSourceList().getDataSource().iterator(); iter.hasNext(); ) {
138 DataSourceType dst = (DataSourceType) iter.next(); %>
139 table_id_name_mappings["<%= dst.getTableId()%>"] = "<%= dst.getTableName()%>";
140 table_id_name_mappings["<%= dst.getTableName()%>"] = "<%= dst.getTableId()%>";
143 function listJoinExpr(tableName, joinTableId) {
145 removeAllOptions(document.forma.joinExpr);
146 var isJoinExprFound = false;
149 addOption(document.forma.joinExpr, "" ,"No Change");
152 for ( var i=0; i<table_joins.length; i++) {
153 if( (table_joins[i].src_table==tableName && table_joins[i].dest_table==table_id_name_mappings[joinTableId])
155 (table_joins[i].dest_table==tableName && table_joins[i].src_table==table_id_name_mappings[joinTableId])
158 addOption(document.forma.joinExpr, table_joins[i].join_expr ,table_joins[i].join_expr );
159 isJoinExprFound = true;
165 removeAllOptions(document.forma.joinExpr);
166 addOption(document.forma.joinExpr, "" ,"No Join Condition Defined");
170 function removeAllOptions(selectbox)
173 for(i=selectbox.options.length-1;i>=0;i--)
179 function addOption(selectbox, value, text )
181 var optn = document.createElement("OPTION");
185 selectbox.options.add(optn);
190 <table width="100%" class="tableBorder" border="0" cellspacing="1" cellpadding="3" align=center>
192 <td class=rbg1 colspan=2 valign="Middle"><b class=rtableheader>Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %> - <%= curSubStep %></b></td>
195 <td align="right" width="25%" class=rbg2 height="30" style="background-image:url(<%= AppUtils.getImgFolderURL() %>required.gif); background-position:top right; background-repeat:no-repeat;"><font class=rtabletext>Table Name </font></td>
196 <td align="left" width="50%" class=rbg3><font class=rtabletext>
199 for(int i=0; i<reportTableSources.size(); i++) {
200 TableSource tableSource = (TableSource) reportTableSources.get(i);
201 if(currTable.getTableName().equals(tableSource.getTableName())) {
202 tName = tableSource.getDisplayName();
206 <%= nvl(tName, currTable.getTableName()) %>
207 <input type="hidden" name="tableName" value="<%=currTable.getTableName()%>">
209 <select name="tableName" class="rtabletext" onChange="tableNameChange()">
210 <% for(int i=0; i<reportTableSources.size(); i++) {
211 TableSource tableSource = (TableSource) reportTableSources.get(i); %>
212 <option value="<%= tableSource.getTableName() %>"<%= (i==0)?" selected":"" %>><%= tableSource.getDisplayName() %>
216 <input type="hidden" name="tablePK" value="<%= ((TableSource) reportTableSources.get(0)).getPkFields() %>">
220 <td align="right" width="25%" class=rbg2 height="30"><font class=rtabletext>Display Name </font></td>
221 <td align="left" width="50%" class=rbg3><font class=rtabletext>
222 <input type="text" class="rtabletext" size="30" maxlength="30" name="displayName" value="<%= isEdit?currTable.getDisplayName():((TableSource) reportTableSources.get(0)).getDisplayName() %>"></font></td>
224 <% if(rdef.getDataSourceList().getDataSource().size()>(isEdit?1:0)) {
225 String outerJoinType = (isEdit?rdef.getOuterJoinType(currTable):""); %>
227 <td align="right" width="25%" class=rbg2 height="30"><font class=rtabletext>Join To Table </font></td>
228 <td align="left" width="50%" class=rbg3><font class=rtabletext>
230 <% if(currTable.getRefTableId()==null){%>
231 --- Table Not Joined ---
233 <%=rdef.getTableById(currTable.getRefTableId()).getDisplayName() %>
234 </br>on : <%=currTable.getRefDefinition() %>
236 <input type="hidden" name="joinTableName" value="<%=currTable.getRefTableId()%>">
239 <select name="joinTableName" onChange="listJoinExpr();">
240 <option value="" selected>--- Tables Not Joined ---
241 <% for(Iterator iter=rdef.getDataSourceList().getDataSource().iterator(); iter.hasNext(); ) {
242 DataSourceType dst = (DataSourceType) iter.next(); %>
243 <option value="<%= dst.getTableId() %>"><%= dst.getDisplayName() %>
251 <td align="right" width="25%" class=rbg2 height="30"><font class=rtabletext>All availabe Join Options </font></td>
252 <td align="left" width="50%" class=rbg3><font class=rtabletext>
253 <select name="joinExpr">
254 <option value="" selected>No Join Condition</option>
259 <script language="JavaScript">
260 listJoinExpr("<%=currTable.getTableName()%>","<%=currTable.getRefTableId()%>");
265 <td align="right" width="25%" class=rbg2 height="30"><font class=rtabletext>Join Type </font></td>
266 <td align="left" width="50%" class=rbg3><font class=rtabletext>
267 <select name="outerJoin">
268 <option value=""<%= (outerJoinType.length()==0)?" selected":"" %>>Include only records present in both tables
269 <option value="<%= AppConstants.OJ_CURRENT %>"<%= outerJoinType.equals(AppConstants.OJ_CURRENT)?" selected":"" %>>Include join table records without match in this table
270 <option value="<%= AppConstants.OJ_JOINED %>"<%= outerJoinType.equals(AppConstants.OJ_JOINED)?" selected":"" %>>Include records from this table without match in the join table
278 <script language="JavaScript">
280 function checkNotJoined() {
281 <% if(rdef.getDataSourceList().getDataSource().size()>(isEdit?1:0)) { %>
282 if(document.forma.outerJoin.selectedIndex==0) {
284 var selTable = "<%= currTable.getTableName() %>";
285 var selDisplayName = "<%= currTable.getDisplayName() %>";
287 var selTable = document.forma.tableName.options[document.forma.tableName.selectedIndex].value;
288 var selDisplayName = document.forma.tableName.options[document.forma.tableName.selectedIndex].text;
292 <% for(int i=0; i<reportTableSources.size(); i++) {
293 TableSource tableSource = (TableSource) reportTableSources.get(i);
294 if(tableSource.getIsLargeData().equals("Y")) { %>
295 ||selTable=="<%= tableSource.getTableName() %>"
300 alert("Table "+selDisplayName+" contains large amount of data\nand cannot be added unless it is joined to another table.\nPlease select a Join To Table from the list.");
301 document.forma.outerJoin.focus();
307 else { // if(document.forma.outerJoin.selectedIndex>0)
308 var selTable = document.forma.tableName.options[document.forma.tableName.selectedIndex].value;
309 var selJoinTblId = document.forma.outerJoin.options[document.forma.outerJoin.selectedIndex].value;
310 var selJoinTable = "";
311 <% for(Iterator iter=rdef.getDataSourceList().getDataSource().iterator(); iter.hasNext(); ) {
312 DataSourceType dst = (DataSourceType) iter.next(); %>
313 if(selJoinTblId=="<%= dst.getTableId() %>")
314 selJoinTable = "<%= dst.getTableName() %>";
316 for(Iterator iter=reportTableJoins.iterator(); iter.hasNext(); ) {
317 TableJoin tableJoin = (TableJoin) iter.next(); %>
318 if((selTable=="<%= tableJoin.getSrcTableName() %>"&&selJoinTable=="<%= tableJoin.getDestTableName() %>")||
319 (selTable=="<%= tableJoin.getDestTableName() %>"&&selJoinTable=="<%= tableJoin.getSrcTableName() %>"))
323 alert("Table "+document.forma.tableName.options[document.forma.tableName.selectedIndex].text+
324 " cannot be joined to table "+document.forma.outerJoin.options[document.forma.outerJoin.selectedIndex].text+
325 ".\nPlease select a different join.");
334 function dataValidate() {
335 if(document.forma.displayName.value=="")
337 document.forma.displayName.value = "<%= currTable.getDisplayName() %>";
339 document.forma.displayName.value = document.forma.tableName.options[selectedIndex].text;
343 <% for(Iterator iter=rdef.getDataSourceList().getDataSource().iterator(); iter.hasNext(); ) {
344 DataSourceType dst = (DataSourceType) iter.next();
346 if(! (isEdit&&dst.getTableId().equals(currTable.getTableId()))) { %>
347 ||document.forma.displayName.value=="<%= dst.getDisplayName() %>"
351 alert("Table with display name "+document.forma.displayName.value+" already exists.\nPlease select another name.");
352 document.forma.displayName.focus();
353 document.forma.displayName.select();
358 if(! checkNotJoined())
367 private String nvl(String s) { return (s==null)?"":s; }
368 private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; }