<%@page import="org.apache.axis.transport.http.AdminServlet"%> <%!private static final String cvsId = "$Id: ws_admin_listdatasources.jsp,v 1.0 2016/07/25 11:12:00 thu Exp $";%> <%@ page language="java" contentType="text/html; charset=UTF-8"%> <%@ page import="com.hof.util.*, java.util.*, java.text.*"%> <%@ page import="com.hof.web.form.*"%> <%@ page import="com.hof.mi.web.service.*"%> <% /* List DataSources Using Java generated stubs rather that using the Yellowfin webservices API.. */ String baseuri = request.getRequestURI(); int index = baseuri.lastIndexOf('/'); if (index >= 0) baseuri = baseuri.substring(0, index); String self = request.getServletPath(); self = self.substring(self.lastIndexOf('/') + 1); self = baseuri + "/" + self; AdministrationServiceResponse rs = null; AdministrationServiceRequest rsr = new AdministrationServiceRequest(); AdministrationServiceService ts = new AdministrationServiceServiceLocator("localhost", 8080, "/services/AdministrationService", false); AdministrationServiceSoapBindingStub rssbs = (AdministrationServiceSoapBindingStub) ts .getAdministrationService(); rsr.setLoginId("admin@yellowfin.com.au"); rsr.setPassword("test"); rsr.setOrgId(new Integer(1)); rsr.setFunction("LISTDATASOURCES"); rs = rssbs.remoteAdministrationCall(rsr); String tmp = (String) request.getParameter("sourceId"); String cmd = (String) request.getParameter("cmd"); String errorMsg = ""; String successMsg = ""; StringBuilder listDataSources = new StringBuilder(); AdministrationDataSource selectedDs = null; AdministrationDataSource[] dataSources = null; Integer selectedId = null; if (tmp != null && !tmp.isEmpty()) { try { selectedId = Integer.valueOf(tmp.trim()); } catch (Exception ex) { //ignore } } if ("SUCCESS".equals(rs.getStatusCode())) { dataSources = rs.getDatasources(); successMsg = "DATASOURCE LISTING DONE."; } else { errorMsg = "Failed to list available data sources. Code: " + rs.getErrorCode(); } if ("SAVEDATASOURCE".equals(cmd)) { String name = (String)request.getParameter("sourceName"); String desc = (String)request.getParameter("sourceDesc"); String connectionType = (String)request.getParameter("connectionType"); String sourceOptions = (String)request.getParameter("dataSourceOptions"); AdministrationDataSource adm = new AdministrationDataSource(); try { adm.setSourceId(selectedId); adm.setSourceName(name); adm.setSourceDescription(desc); adm.setConnectionType(connectionType); adm.setConnectionTypeCode("GENERICUSER"); adm.setAccessLevelCode((String)request.getParameter("accessLevelCode")); adm.setConnectionDriver((String)request.getParameter("connectionDriver")); adm.setConnectionPath((String)request.getParameter("connectionPath")); adm.setConnectionString((String)request.getParameter("connectionString")); adm.setConnectionTypeCode((String)request.getParameter("connectionTypeCode")); adm.setMaxmimumConnections(Integer.valueOf(request.getParameter("maxConnections"))); adm.setMinimumConnections(Integer.valueOf(request.getParameter("minConnections"))); adm.setMaxRows(Integer.valueOf(request.getParameter("maxRows"))); adm.setRefreshTime(Integer.valueOf(request.getParameter("refreshTime"))); adm.setConnectionTimeout(Integer.valueOf(request.getParameter("timeOut"))); adm.setSourceType((String)request.getParameter("sourceType")); adm.setLogFile((String)request.getParameter("logFile")); adm.setUserName((String)request.getParameter("userName")); adm.setTimezone((String)request.getParameter("timeZone")); adm.setUserPassword((String)request.getParameter("password")); if (sourceOptions != null && !sourceOptions.isEmpty()) { String[] kvs = sourceOptions.split(";"); List admSourceOptions = new ArrayList(); for (String kv : kvs) { String[] p = kv.split("#"); AdministrationDataSourceOption opt = new AdministrationDataSourceOption(); if (p.length > 1) { opt.setOptionKey(p[0]); opt.setOptionValue(p[1]); } else if (p.length > 0){ opt.setOptionKey(p[0]); opt.setOptionValue(null); } admSourceOptions.add(opt); } AdministrationDataSourceOption[] options = new AdministrationDataSourceOption[admSourceOptions.size()]; adm.setSourceOptions(admSourceOptions.toArray(options)); } rsr.setFunction("SAVEDATASOURCE"); rsr.setDatasource(adm); rs = rssbs.remoteAdministrationCall(rsr); boolean isNewDataSource = (selectedId == null); if ("SUCCESS".equals(rs.getStatusCode())) { selectedDs = rs.getLoadedDataSource(); selectedId = selectedDs.getSourceId(); // reload list rsr.setFunction("LISTDATASOURCES"); rs = rssbs.remoteAdministrationCall(rsr); if ("SUCCESS".equals(rs.getStatusCode())) { dataSources = rs.getDatasources(); } else { errorMsg = "Failed to load data source list. Code: " + rs.getErrorCode(); } // load full details for newly created data source rsr.setSourceId(selectedId); rsr.setFunction("LOADDATASOURCE"); rs = rssbs.remoteAdministrationCall(rsr); if ("SUCCESS".equals(rs.getStatusCode())) { selectedDs = rs.getLoadedDataSource(); if (isNewDataSource) successMsg = "DATASOURCE HAS BEEN CREATED. NEW DATASOURCE ID:" + selectedId; else successMsg = "DATASOURCE HAS BEEN SAVED."; } else { selectedDs = null; errorMsg = "Failed to load data source details. Code: " + rs.getErrorCode(); } } else { selectedDs = null; errorMsg = "Failed to load data source details. Code: " + rs.getErrorCode(); } } catch (Exception ex) { selectedDs = null; errorMsg = "Failed to save data source details. Error: " + ex.getMessage(); } } if ("LINKDATASOURCE".equals(cmd)) { try { Integer primarySourceId = null; Integer clientSourceId = null; String param1 = (String) request.getParameter("primarySourceId"); String param2 = (String) request.getParameter("clientSourceId"); if (param1 != null && !param1.isEmpty()) primarySourceId = Integer.valueOf(param1); if (param2 != null && !param2.isEmpty()) clientSourceId = Integer.valueOf(param2); rsr.setFunction("LINKDATASOURCE"); rsr.setSourceId(primarySourceId); AdministrationDataSourceClientLink link = new AdministrationDataSourceClientLink(); link.setSourceId(clientSourceId); rsr.setSourceClientLink(link); rs = rssbs.remoteAdministrationCall(rsr); if ("SUCCESS".equals(rs.getStatusCode())) { selectedDs = rs.getLoadedDataSource(); selectedId = selectedDs.getSourceId(); successMsg = "CLIENT DATASOURCE HAS BEEN LINKED TO PRIMARY."; } else { selectedDs = null; errorMsg = "Failed to link primary source with client source. Code: " + rs.getErrorCode(); } } catch (Exception ex) { selectedDs = null; errorMsg = "Failed to link primary source with client source. Error: " + ex.getMessage(); } } if ("LOADDATASOURCE".equals(cmd) && selectedId != null) { rsr.setSourceId(selectedId); rsr.setFunction("LOADDATASOURCE"); rs = rssbs.remoteAdministrationCall(rsr); if ("SUCCESS".equals(rs.getStatusCode())) { selectedDs = rs.getLoadedDataSource(); successMsg = "DATASOURCE DETAILS HAS BEEN LOADED."; } else { selectedDs = null; errorMsg = "Failed to load data source details. Code: " + rs.getErrorCode(); } } if (dataSources != null) { for (int i = 0; i < dataSources.length; i++) { AdministrationDataSource dataSource = dataSources[i]; listDataSources.append("
").append((i + 1)).append(") ").append(dataSource.getSourceId()) .append(" - ").append(dataSource.getSourceName()).append("
") .append(dataSource.getSourceDescription()).append("

Source Type:  ") .append(dataSource.getSourceType()).append("
Connection Type:  ") .append(dataSource.getConnectionType()).append("
Driver:  ") .append(dataSource.getConnectionDriver()).append("
Maximum Connection:  ") .append(dataSource.getMaxmimumConnections()).append("
") .append(dataSource.getConnectionDriver()).append("
Access Level Code:  ") .append(dataSource.getAccessLevelCode()).append("
"); } } %> <%! public String printString(Object str) { if (str != null) return str.toString(); return ""; } %>


<%=successMsg%>

<%=errorMsg%>

1. Data Source Listing

<%=listDataSources.toString()%>

2. Load & Edit Data Source


Load data source details
Please pick the data source ID from the datasource list, enter it into the input below and hit "load" button


">

Data Source details
<% if (selectedDs != null) { %>
" readonly="readonly" style="background-color: grey;"/>

































Options

<% AdministrationDataSourceOption[] options = selectedDs.getSourceOptions(); if (options != null) { int idx = 0; for (AdministrationDataSourceOption opt : options) { %>

<% idx ++; } } %>
Linked Client Source:
<% AdministrationDataSourceClientLink[] linkedClientSources = selectedDs.getClientSources(); if (linkedClientSources != null) { for (AdministrationDataSourceClientLink ls : linkedClientSources) { %> Client Org ID:   <%=ls.getClientOrgId().toString()%>
Internal Ref:   <%=ls.getClientOrgRef()%>
Source ID:   <%=ls.getSourceId().toString()%>

<% } } } %>




3. Link Client Source to Primary Source

Primary Source Id

Client Source Id