<%@page import="org.apache.axis.AxisFault"%>
<%@ taglib prefix="wp" uri="aps-core.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@ taglib prefix="es" uri="/WEB-INF/plugins/ppcommon/aps/tld/eldasoft-common-core.tld" %>


<wp:contentNegotiation mimeType="application/xhtml+xml" charset="utf-8" />

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang='it'>
<head>
	<title><wp:i18n key="MAIN_TITLE" /></title>
</head>
<body>
	<c:catch var="catchExceptionStartup">
	<es:checkCustomization var="visConsensoPrivacy" objectId="REG-IMPRESA" attribute="PRIVACY" feature="VIS" />
	</c:catch>
	<div id="startup">
		Test startup webapp = <c:choose><c:when test='${catchExceptionStartup == null}'>OK</c:when><c:otherwise>KO</c:otherwise></c:choose>
	</div>
	<c:catch var="catchExceptionPort">
	<sql:query var="portTest" dataSource="jdbc/portDataSource">select version from ppcommon_ver where plugin='ppgare'</sql:query>	
	</c:catch>
	<c:set var="portKO" value="${catchExceptionPort != null || portTest.rowCount == 0}"/>
	<div id="db-port">
		Test DB Port = <c:choose><c:when test="${portKO}">KO</c:when><c:otherwise>OK</c:otherwise></c:choose>
	</div>
	<c:catch var="catchExceptionServ">
	<sql:query var="servTest" dataSource="jdbc/portDataSource">select version from ppcommon_ver where plugin='ppgare'</sql:query>	
	</c:catch>
	<c:set var="servKO" value="${catchExceptionServ != null || servTest.rowCount == 0}"/>
	<div id="db-serv">
		Test DB Serv = <c:choose><c:when test="${servKO}">KO</c:when><c:otherwise>OK</c:otherwise></c:choose>
	</div>

	<c:if test="${!portKO}">
	<div id="version-db-port">
		Versione DB Port = <c:out value="${portTest.rows[0].version}"/>	
	</div>
	</c:if>
	<c:if test="${!servKO}">
	<div id="version-db-serv">
		Versione DB Serv = <c:out value="${servTest.rows[0].version}"/>	
	</div>
	</c:if>
	<div id="version-application">
	<%
    	String file = application.getRealPath("/") + "WEB-INF/PA_VER.TXT";
		String webappVersion = org.apache.commons.io.FileUtils.readFileToString(new java.io.File(file), "ISO-8859-1");
	%>
		Versione applicativo (PA_VER.TXT) = <%=webappVersion%>
	</div>

	<%
		String wsBEAVersion = "";
		try {
			it.maggioli.eldasoft.plugins.ppgare.aps.system.services.bandi.WSBandiEsitiAvvisiWrapper wsBEA = 
				(it.maggioli.eldasoft.plugins.ppgare.aps.system.services.bandi.WSBandiEsitiAvvisiWrapper) 
				com.agiletec.aps.util.ApsWebApplicationUtils.getBean("WSBandiEsitiAvvisi", request);
			
			if(wsBEA != null) {
				wsBEAVersion = wsBEA.getProxyWSBandiEsitiAvvisi().getVersion().getVersion(); 
			}
		} catch(Exception ex) {			
			if(ex.toString().contains("404")) {
				wsBEAVersion = "[ERROR: il servizio non risponde]"; 
			} else {
				wsBEAVersion = "[ERROR: informazione non presente]"; 
			}		
		}
	%>		
	<div id="version-application">							
		Versione servizio BandiEsitiAvvisi (WSBEA_VER.TXT) = <%=wsBEAVersion%>
	</div>
	
	<%
		String wsAppaltiVersion = ""; 
		String appaltiVersion = "";
		try {
			it.maggioli.eldasoft.plugins.ppgare.aps.system.services.bandi.WSGareAppaltoWrapper wsAppalti = 
				(it.maggioli.eldasoft.plugins.ppgare.aps.system.services.bandi.WSGareAppaltoWrapper) 
				com.agiletec.aps.util.ApsWebApplicationUtils.getBean("WSGareAppalto", request);
			
			if(wsAppalti != null) {
				wsAppaltiVersion = wsAppalti.getProxyWSGare().getVersion().getVersion(); 
			 	appaltiVersion = wsAppalti.getProxyWSGare().getAppaltiVersion().getVersion();
			}
		} catch(Exception ex) {
			if(ex.toString().contains("404")) {
				wsAppaltiVersion = "[ERROR: il servizio non risponde]"; 
			} else {
				wsAppaltiVersion = "[ERROR: informazione non presente]"; 
			}		
			appaltiVersion = wsAppaltiVersion;
		}
	%>		
	<div id="version-application">							
		Versione servizio Appalti (WSPG_VER.TXT) = <%=wsAppaltiVersion%>
	</div>
	<div id="version-application">
		Versione DB Appalti = <%=appaltiVersion%>
	</div>	
		
</body>
</html>