Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / WEB-INF / fusion / raptor / wizard_tables_edit.jsp
1 <%--
2   ================================================================================
3   eCOMP Portal SDK
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
10   
11        http://www.apache.org/licenses/LICENSE-2.0
12   
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   ================================================================================
19   --%>
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"%>
37
38 <%      
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;
44         if(isEdit)
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");
50         }
51         Vector reportTableJoins   = (isEdit)?DataCache.getReportTableJoins():DataCache.getReportTableJoins(AppUtils.getUserRoles(request)); %>
52
53 <% if(! isEdit) { %>
54 <script language="JavaScript">
55 <!--
56         var tablesExist = false;
57         <% if(rdef.getDataSourceList().getDataSource().size()>0) { %>
58                 tablesExist = true;
59         
60         function setJoinTableName(tableId) {
61                 var selIndex = 0;
62                 for(var i=1; i<document.forma.joinTableName.options.length; i++)
63                         if(tableId==document.forma.joinTableName.options[i].value)
64                                 selIndex = i;
65          
66                 document.forma.joinTableName.selectedIndex = selIndex;
67         }   // setJoinTableName
68         <% } %>
69         
70         function tableNameChange() {
71                 var newTableName = "";
72                 newTableName = document.forma.tableName.options[document.forma.tableName.selectedIndex].value;
73                 
74                 document.forma.displayName.value=document.forma.tableName.options[document.forma.tableName.selectedIndex].text;
75                 
76                 // Setting the PK values
77                 if(false) {}
78
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() %>";
83         <%      } %>
84                 
85         <% if(rdef.getDataSourceList().getDataSource().size()>0) {
86                         for(Iterator iter=rdef.getDataSourceList().getDataSource().iterator(); iter.hasNext(); ) { 
87                                 DataSourceType dst = (DataSourceType) iter.next();
88         
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() %>");
94                 else 
95         <%              } else if(dst.getTableName().equals(tableJoin.getDestTableName())) { %>
96                 if(newTableName=="<%= tableJoin.getSrcTableName() %>")
97                         setJoinTableName("<%= dst.getTableId() %>");
98                 else 
99         <%                      }   // if
100                                 }       // for
101                         } %>
102                         setJoinTableName("");
103         <% } %>
104                 listJoinExpr(document.forma.tableName.options[document.forma.tableName.selectedIndex].value,
105                              document.forma.joinTableName.options[document.forma.joinTableName.selectedIndex].value);
106         }   // tableNameChange
107         
108
109 //-->
110 </script >
111 <% } %>
112
113 <script language="JavaScript">
114 <!--
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;
120         }
121         
122         var table_joins = new Array();
123         
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()%>");
128         <% } %>
129         
130         function table_id_name_mapping(table_id, table_name) {
131                 this.table_id = table_id;
132                 this.table_name = table_name;
133         }
134         
135         var table_id_name_mappings = new Array();
136
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()%>"; 
141         <% }    %>
142
143         function listJoinExpr(tableName, joinTableId) {
144
145                 removeAllOptions(document.forma.joinExpr);
146                 var isJoinExprFound = false;
147                 
148                 <%if(isEdit) {%>
149                         addOption(document.forma.joinExpr, "" ,"No Change");
150                 <%}%>
151                 
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])
154                      ||
155                             (table_joins[i].dest_table==tableName && table_joins[i].src_table==table_id_name_mappings[joinTableId])
156                                 )
157                         {
158                                 addOption(document.forma.joinExpr, table_joins[i].join_expr ,table_joins[i].join_expr );
159                                 isJoinExprFound = true;
160                         }
161                 }
162                 
163                 if(!isJoinExprFound)
164                 {               
165                         removeAllOptions(document.forma.joinExpr);
166                         addOption(document.forma.joinExpr, "" ,"No Join Condition Defined");
167                 }
168         }
169         
170         function removeAllOptions(selectbox)
171         {
172                 var i;
173                 for(i=selectbox.options.length-1;i>=0;i--)
174                 {
175                         selectbox.remove(i);
176                 }
177         }
178         
179         function addOption(selectbox, value, text )
180         {
181                 var optn = document.createElement("OPTION");
182                 optn.text = text;
183                 optn.value = value;
184         
185                 selectbox.options.add(optn);
186         }
187 -->     
188 </script>
189
190 <table width="100%" class="tableBorder" border="0" cellspacing="1" cellpadding="3" align=center>
191         <tr>
192                 <td class=rbg1 colspan=2 valign="Middle"><b class=rtableheader>Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %> - <%= curSubStep %></b></td>
193         </tr>
194         <tr>
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>
197                 <% if(isEdit) { 
198                                 String tName = null;
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();
203                                                 break;
204                                         }       // if
205                                 } %>
206                                 <%= nvl(tName, currTable.getTableName()) %>
207                                 <input type="hidden" name="tableName" value="<%=currTable.getTableName()%>">
208                 <% } else { %>
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() %>
213                                 <%      } %>
214                         </select>
215                 <% } %>
216                         <input type="hidden" name="tablePK" value="<%= ((TableSource) reportTableSources.get(0)).getPkFields() %>">
217                 </font></td>
218         </tr> 
219         <tr>
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>
223         </tr>
224 <% if(rdef.getDataSourceList().getDataSource().size()>(isEdit?1:0)) { 
225                 String outerJoinType = (isEdit?rdef.getOuterJoinType(currTable):""); %>
226         <tr>
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>
229                 <% if(isEdit) { %>
230                         <% if(currTable.getRefTableId()==null){%>
231                                         --- Table Not Joined ---
232                         <%} else { %>
233                                         <%=rdef.getTableById(currTable.getRefTableId()).getDisplayName() %>
234                                         </br>on :&nbsp;<%=currTable.getRefDefinition() %>
235                         <%} %>
236                         <input type="hidden" name="joinTableName" value="<%=currTable.getRefTableId()%>">
237                         
238                 <% } else { %>
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() %>
244                                 <% } %>
245                         </select>
246                 <% } %>
247                 </font></td>
248         </tr> 
249         
250         <tr>
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>
255                         </select>
256                 </font></td>
257         </tr>
258         <% if(isEdit) { %>
259         <script language="JavaScript">
260                 listJoinExpr("<%=currTable.getTableName()%>","<%=currTable.getRefTableId()%>");
261         </script>
262         <%} %>
263         
264         <tr>
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
271                         </select>
272                 </font></td>
273         </tr> 
274 <% } %>
275 </table>
276 <br>
277
278 <script language="JavaScript">
279 <!--
280 function checkNotJoined() {
281 <% if(rdef.getDataSourceList().getDataSource().size()>(isEdit?1:0)) { %>
282         if(document.forma.outerJoin.selectedIndex==0) {
283         <% if(isEdit) { %>
284                 var selTable       = "<%= currTable.getTableName() %>";
285                 var selDisplayName = "<%= currTable.getDisplayName() %>";
286         <% } else { %>
287                 var selTable       = document.forma.tableName.options[document.forma.tableName.selectedIndex].value;
288                 var selDisplayName = document.forma.tableName.options[document.forma.tableName.selectedIndex].text;
289         <% } %>
290                 
291                 if(false
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() %>"
296         <%              }       // if
297                 }       // for 
298         %>
299                         ) {
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();
302                         
303                         return false;
304                 }       // if
305         }
306 <%      if(! isEdit) { %>
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() %>";
315         <%      }       // for
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() %>"))
320                         return true;
321         <%      } %>
322                 
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.");
326                 return false;
327         }       // if
328 <%      }       // if(! isEdit)
329    } %>
330         
331         return true;
332 }       // checkNotJoined
333         
334 function dataValidate() {
335         if(document.forma.displayName.value=="")
336         <% if(isEdit) { %>
337                 document.forma.displayName.value = "<%= currTable.getDisplayName() %>";
338         <% } else { %>
339                 document.forma.displayName.value = document.forma.tableName.options[selectedIndex].text;
340         <% } %>
341         
342         if(false
343         <% for(Iterator iter=rdef.getDataSourceList().getDataSource().iterator(); iter.hasNext(); ) {
344                 DataSourceType dst = (DataSourceType) iter.next();
345                         
346                         if(! (isEdit&&dst.getTableId().equals(currTable.getTableId()))) { %>
347                                 ||document.forma.displayName.value=="<%= dst.getDisplayName() %>"
348         <%      }
349                 } %>
350            ) {
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();
354                 
355                         return false;
356                 }
357         
358         if(! checkNotJoined())
359                 return false;
360         
361         return true;
362 }   // dataValidate
363 //-->
364 </script>
365
366 <%!
367         private String nvl(String s)                  { return (s==null)?"":s; }
368         private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } 
369 %>