Providers convertidos para usarem select e select2.

Update às bibliotecas.

git-svn-id: https://svn.coded.pt/svn/SIPRP@2025 bb69d46d-e84e-40c8-a05a-06db0d633741
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
Carlos Roque 11 years ago
parent 23c6ae8daa
commit 983f2a5512

@ -3,76 +3,15 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/activation.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/appbase.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/ashwood-2.0.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/avalon-framework-4.2.0.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/batik-all-1.7.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/commons-beanutils-1.8.3.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/commons-codec-1.3.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/commons-collections-3.1.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/commons-digester-1.8.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/commons-el-1.0.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/commons-fileupload-1.2.1.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/commons-io-1.4.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/commons-lang-2.4.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/commons-validator-1.3.1.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/cursos.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/dataprovider.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/dom4j-1.6.1.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/errorhandler.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/evologger.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/evolute.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/fop.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/jai_imageio.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/jdbcappender.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/jdom.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/jsf-api.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/jsf-extensions-common-0.1.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/jsf-extensions-dynamic-faces-0.1.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/jsf-impl.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/jsfcl.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/json-2.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/jstl.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/mail.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/org.springframework.beans-3.0.0.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/org.springframework.context-3.0.0.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/org.springframework.core-3.0.0.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/richfaces-api-3.3.3.Final.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/richfaces-impl-3.3.3.Final.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/richfaces-ui-3.3.3.Final.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/serializer-2.7.0.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/shst.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/spring-ws-core-1.5.9.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/spring-ws-core-tiger-1.5.9.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/spring-ws-support-1.5.9.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/spring-xml-1.5.9.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/sqlx.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/standard.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/tomahawk-1.1.10.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/truelicense.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/webui-jsf-suntheme.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/webui-jsf.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/xalan-2.7.0.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/xercesImpl-2.7.1.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/xml-apis-1.3.04.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/xml-apis-ext-1.3.04.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/xmlgraphics-commons-1.3.1.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/xmlParserAPIs-2.0.2.jar"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0">
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0 - Java 7">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 6 (MacOS X Default)">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="web/WEB-INF/lib/commons-logging-1.1.1.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/commons-collections4-4.0.jar"/>
<classpathentry kind="lib" path="web/WEB-INF/lib/postgresql-9.2-1002.jdbc4.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="Apache Tomcat v6.0"/>
<runtime name="Apache Tomcat v7.0 - Java 7"/>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.6"/>
<installed facet="jst.web" version="2.5"/>

@ -7,7 +7,7 @@
<depend srcdir="${app.src.dir}" destdir="${app.build.dir}" cache="${app.dependencies.chache.dir}">
<include name="**/*.java" />
</depend>
<javac srcdir="${app.src.dir}" destdir="${app.build.dir}" classpathref="app.build.classpath" debug="on" deprecation="on" fork="true" memoryMaximumSize="512M" />
<javac srcdir="${app.src.dir}" destdir="${app.build.dir}" classpathref="app.build.classpath" debug="on" deprecation="on" fork="true" memoryMaximumSize="512M" includeantruntime="false" />
<antcall target="create-app-properties-file"/>
<antcall target="app-post-build"/>
</target>

@ -75,6 +75,9 @@
<fileset dir="${app.build.dir}">
<include name="**/*" />
</fileset>
<manifest>
<attribute name="Permissions" value="all-permissions" />
</manifest>
</jar>
<copy todir="${app.deploy.dist.lib.dir}">
<fileset dir="${app.lib.dir}">

@ -245,7 +245,8 @@
<for list="${deploy.jars}" param="jar" delimiter=":">
<sequential>
<exec dir="deploy/lib" command="jarsigner" outputproperty="@{jar}.verify">
<echo message="A verificar se @{jar} esta assinado"/>
<exec dir="deploy" command="jarsigner" outputproperty="@{jar}.verify">
<arg line="-verify"/>
<arg line="@{jar}"/>
</exec>
@ -272,8 +273,10 @@
<echo message="Repacking..."/>
<for list="${unsigned.jars}" param="jar" delimiter=" ">
<sequential>
<echo message="Repacking @{jar}"/>
<apply executable="pack200" parallel="false" failonerror="false">
<arg value="--repack"/>
<arg value="-J-Xmx1g"/>
<arg value="--repack"/>
<arg value="--segment-limit=-1"/>
<fileset file="@{jar}" />
</apply>
@ -286,7 +289,7 @@
<echo message="Signing..."/>
<for list="${unsigned.jars}" param="jar" delimiter=" ">
<sequential>
<signjar destDir="signed" alias="id evolute, consultoria informática do comodo ca limited" storetype="pkcs12" keystore="ant/evolute.keystore" storepass="Typein" >
<signjar destDir="signed/lib" alias="id evolute, consultoria informática do comodo ca limited" storetype="pkcs12" keystore="ant/evolute.keystore" storepass="Typein" >
<path>
<fileset file="@{jar}" />
</path>
@ -294,16 +297,17 @@
</sequential>
</for>
<echo message="A assinar ${app.name}.jar"/>
<signjar destDir="signed" alias="id evolute, consultoria informática do comodo ca limited" storetype="pkcs12" keystore="ant/evolute.keystore" storepass="Typein" >
<path>
<fileset dir="deploy" includes="${app.name}.jar" />
<fileset dir="deploy" includes="*.jar" />
</path>
</signjar>
<property name="deploy.jars.copy" value=""/>
<for list="${deploy.jars}" param="jar" delimiter=":">
<sequential>
<var name="deploy.jars.copy" value="${deploy.jars.copy} @{jar}"/>
<var name="deploy.jars.copy" value="${deploy.jars.copy} '@{jar}'"/>
</sequential>
</for>
@ -321,6 +325,7 @@
<for list="${unsigned.jars}" param="jar" delimiter=" ">
<sequential>
<apply executable="pack200" parallel="false" dest="signed/packed/lib" failonerror="false">
<arg value="-J-Xmx1g"/>
<arg value="--segment-limit=-1"/>
<targetfile/>
<srcfile/>
@ -353,6 +358,8 @@
<echo message="Pack jars = ${pack.jars.copy}"/>
<echo message="Argumentos = ${basedir} ${deploy.jars.copy} ${pack.jars.copy} inicial"/>
<java fork="true" failonerror="yes" classname="com.evolute.xml.BuildXML" classpathref="lib.tools.classpath">
<arg line="${basedir} ${deploy.jars.copy} ${pack.jars.copy} inicial"/>
</java>
@ -362,8 +369,9 @@
<then>
<echo message="isto é um teste"/>
<echo message="other jars = ${other.jars}"/>
<echo message="deploy.jars = ${deploy.jars}"/>
<scp todir="${deploy.user}@${app.deploy.server}:/home/software/public_html/versoes_teste/${app.appName}" password="${deploy.password}" sftp="true" trust="true" >
<fileset dir="${basedir}/signed" includes="${deploy.jars}"/>
<fileset dir="${basedir}/signed" includes="**/*.jar"/>
</scp>
</then>
<else>
@ -432,9 +440,11 @@
<property name="deploy.jars.copy" value=""/>
<for list="${deploy.jars}" param="jar" delimiter=":">
<sequential>
<var name="deploy.jars.copy" value="${deploy.jars.copy} @{jar}"/>
<var name="deploy.jars.copy" value="${deploy.jars.copy} '@{jar}'"/>
</sequential>
</for>
<echo message="Basedir: ${basedir}"/>
<echo message="deploy jars copy: ${deploy.jars.copy}"/>
<java fork="true" failonerror="yes" classname="com.evolute.xml.BuildXML" classpathref="lib.tools.classpath">
<arg line="${basedir} ${deploy.jars.copy} novo"/>
</java>
@ -539,12 +549,20 @@
<echo message="Signed jars = ${signed.jars}"/>
</target>
<target name="repack-jars" depends="check-if-is-signed">
<apply executable="pack200" parallel="false" failonerror="false">
<arg value="--repack"/>
<arg value="--segment-limit=-1"/>
<fileset dir="deploy" includes="${unsigned.jars}" />
</apply>
<target name="repack-jars" depends="check-if-is-signed">
<if>
<not>
<equals arg1="${unsigned.jars}" arg2=""/>
</not>
<then>
<apply executable="pack200" parallel="false" failonerror="false">
<arg value="-J-Xmx1g"/>
<arg value="--repack"/>
<arg value="--segment-limit=-1"/>
<fileset dir="deploy" includes="${unsigned.jars}" />
</apply>
</then>
</if>
</target>
<target name="sign-jars-2" depends="repack-jars">
@ -552,9 +570,22 @@
<mkdir dir="signed/lib"/>
<mkdir dir="signed/packed/lib"/>
<echo message="Unsigned jars: ${unsigned.jars}"/>
<for list="${unsigned.jars}" param="jar" delimiter=" ">
<sequential>
<echo message="Signing jar @{jar}"/>
<signjar destDir="signed" alias="id evolute, consultoria informática do comodo ca limited" storetype="pkcs12" keystore="ant/evolute.keystore" storepass="Typein" >
<path>
<fileset dir="deploy" includes="@{jar}"/>
</path>
</signjar>
</sequential>
</for>
<signjar destDir="signed" alias="id evolute, consultoria informática do comodo ca limited" storetype="pkcs12" keystore="ant/evolute.keystore" storepass="Typein" >
<path>
<fileset dir="deploy" includes="${unsigned.jars}" />
<fileset dir="deploy" includes="*.jar"/>
</path>
</signjar>
@ -632,6 +663,7 @@
<echo message="Packing jars..."/>
<echo message="toDeploy.packed.copy = ${toDeploy.packed.copy}"/>
<apply executable="pack200" parallel="false" dest="signed/packed" failonerror="false">
<arg value="-J-Xmx1g"/>
<arg value="--modification-time=latest"/>
<arg value="--deflate-hint=true"/>
<arg value="--segment-limit=-1"/>
@ -648,7 +680,7 @@
<property name="deploy.jars.copy" value=""/>
<for list="${deploy.jars}" param="jar" delimiter=":">
<sequential>
<var name="deploy.jars.copy" value="${deploy.jars.copy} @{jar}"/>
<var name="deploy.jars.copy" value="${deploy.jars.copy} '@{jar}'"/>
</sequential>
</for>
@ -658,7 +690,7 @@
<property name="pack.jars.copy" value=""/>
<for list="${pack.jars}" param="jar" delimiter=":">
<sequential>
<var name="pack.jars.copy" value="${pack.jars.copy} @{jar}"/>
<var name="pack.jars.copy" value="${pack.jars.copy} '@{jar}'"/>
</sequential>
</for>
@ -681,9 +713,9 @@
</java>
</then>
<else>
<sshexec verbose="false" failonerror="true" trust="yes" host="${app.deploy.server}" username="${deploy.user}" command='find /home/software/public_html/${app.name} -name "*.jar*" -exec md5sum {} +' password="${deploy.password}" output="jarsAtServer.txt" outputproperty="trash" />
<sshexec verbose="false" failonerror="true" trust="yes" host="${app.deploy.server}" username="${deploy.user}" command='find "/home/software/public_html/${app.name}" -name "*.jar*" -exec md5sum {} +' password="${deploy.password}" output="jarsAtServer.txt" outputproperty="trash" />
<java fork="true" failonerror="yes" classname="com.evolute.xml.ServerJarsXml" classpathref="lib.tools.classpath">
<arg line="${app.appName}"/>
<arg line="'${app.appName}'"/>
</java>
</else>
</if>
@ -714,7 +746,7 @@
<isset property="@{jar}-exists-on-server"/>
</not>
<then>
<var name="toDeploy.jars" value="${toDeploy.jars} ${new.project.signed-jar-files.name(@{jar}-path)}@{jar}"/>
<var name="toDeploy.jars" value="${toDeploy.jars};${new.project.signed-jar-files.name(@{jar}-path)}@{jar}"/>
</then>
</if>
</sequential>
@ -722,9 +754,27 @@
<echo message="toDeploy.jars = ${toDeploy.jars}"/>
</target>
<target name="send-jars-to-server-2" depends="compare-client-and-server-jars">
<target name="send-main-jar">
<if>
<isset property="TESTDEPLOY"/>
<then>
<echo message="scp @{jar} ${deploy.user}@${app.deploy.server}:/home/software/public_html/versoes_teste/${app.appName}"/>
<scp todir="${deploy.user}@${app.deploy.server}:/home/software/public_html/versoes_teste/${app.appName}" password="${deploy.password}" sftp="true" trust="true" >
<fileset dir="${basedir}/signed" includes="*.jar"/>
</scp>
</then>
<else>
<echo message="scp @{jar} ${deploy.user}@${app.deploy.server}:/home/software/public_html/${app.appName}"/>
<scp todir="${deploy.user}@${app.deploy.server}:/home/software/public_html/${app.appName}" password="${deploy.password}" sftp="true" trust="true" >
<fileset dir="${basedir}/signed" includes="*.jar"/>
</scp>
</else>
</if>
</target>
<target name="send-jars-to-server-2" depends="compare-client-and-server-jars, send-main-jar">
<echo message="Jars to deploy: ${toDeploy.jars}"/>
<for list="${toDeploy.jars}" param="jar" delimiter=" ">
<for list="${toDeploy.jars}" param="jar" delimiter=";">
<sequential>
<if>
<and>

@ -17,7 +17,7 @@
<property name="docs.dir" value="${app.dir}/docs" />
<property name="docs.api.dir" value="${docs.dir}/api" />
<property name="app.src.dir" value="${app.dir}/src" />
<property name="app.lib.dir" value="${app.dir}/web/WEB-INF/lib" />
<property name="app.lib.dir" value="${app.dir}/lib" />
<property name="deploy.project.relative.lib.dir" value="lib" />
<property name="app.dist.dir" value="${app.dir}/dist" />
<property name="app.dist.lib.dir" value="${app.dist.dir}/lib" />
@ -36,7 +36,6 @@
<path id="app.build.classpath">
<pathelement location="${app.build.dir}" />
<path refid="app.jar.classpath" />
<path refid="lib.tools.classpath" />
</path>
<path id="lib.docs.classpath">

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="evo-web-build-common" basedir="../../">
<import file="evo-web-compile-common.xml" />
<target name="web-build" description="Compiles all application classes" depends="web-prepare,web-pre-build">
<mkdir dir="${web.build.dir}" />
<depend srcdir="${web.src.dir}" destdir="${web.build.dir}" cache="${web.dependencies.chache.dir}">
<include name="**/*.java" />
</depend>
<javac srcdir="${web.src.dir}" destdir="${web.build.dir}" classpathref="web.build.classpath" debug="on" deprecation="on" fork="true" memoryMaximumSize="512M" />
<antcall target="create-web-properties-file"/>
<antcall target="web-post-build"/>
</target>
<target name="create-web-properties-file">
<propertyfile file="${web.build.dir}/PlanosActuacao.properties">
<entry key="timestamp" type="date" value="now"/>
<entry key="user" value="${user.name}"/>
</propertyfile>
</target>
</project>

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="evo-web-compile-common" basedir="../../">
<import file="evo-web-load-properties.xml" />
<!-- BUILD -->
<target name="web-post-build" />
<target name="web-pre-build" />
<target name="web-build" />
<target name="cifrar" depends="web-properties-exists" if="web.properties.exists" >
<echo message="Encrypting web.properties" />
<typedef classpathref="lib.tools.classpath" resource="net/jtools/classloadertask/antlib.xml">
<classpath>
<path refid="lib.tools.classpath"/>
</classpath>
</typedef>
<classloader loader="project">
<classpath>
<fileset dir="${lib.tools.dir}" includes="*.jar"/>
</classpath>
</classloader>
<taskdef name="cifrar-props" classpathref="lib.tools.classpath" classname="com.evolute.ant.PropsEncryptorTask" onerror="fail" />
<cifrar-props filepath="${properties.dir}${file.separator}app.properties" destpath="${web.build.dir}${file.separator}app.properties"/>
</target>
<target name="web-properties-exists">
<available file="${properties.dir}${file.separator}app.properties" property="web.properties.exists"/>
</target>
<target name="web-prepare" depends="load-properties">
<echo message="Dealing with package-info.java files (ant compilation problem workaround)" />
<delete failonerror="false">
<fileset dir="${web.build.dir}" includes="**/package-info.java"/>
</delete>
<echo message="Copying non-java files to build directory" />
<copy failonerror="false" overwrite="true" verbose="true" todir="${web.build.dir}" file="${web.version.file}"/>
<copy verbose="true" failonerror="true" overwrite="true" todir="${web.build.dir}">
<fileset dir="${web.src.dir}">
<exclude name="**/*.java" />
<exclude name="*.java" />
</fileset>
<fileset dir="${properties.dir}">
<exclude name="app.properties" />
<include name="**/*" />
</fileset>
</copy>
<antcall target="cifrar"/>
</target>
<target name="web-clean" description="Removes all generated files" depends="load-static-properties">
<delete verbose="true" failonerror="false">
<fileset dir="${web.build.dir}">
<include name="**/*" />
</fileset>
</delete>
<delete dir="${web.build.dir}" verbose="true" failonerror="true" />
<delete dir="${web.dist.dir}" verbose="true" failonerror="true" />
<delete dir="${web.deploy.dist.dir}" verbose="true" failonerror="true" />
</target>
<!-- JAR -->
<target name="web-create-jar" description="Make application Jar" depends="web-clean, web-build" >
<pathconvert property="jar.classpath.converted" refid="web.jar.classpath" pathsep=" ">
<map from="${web.dir}/" to="" />
<map from="${basedir}/" to="" />
</pathconvert>
<mkdir dir="${web.dist.dir}" />
<jar destfile="${web.dist.dir}${file.separator}PlanosActuacao.jar">
<fileset dir="${web.build.dir}">
<include name="**/*" />
</fileset>
</jar>
<copy todir="${web.dist.lib.dir}">
<fileset dir="${web.lib.dir}">
<include name="**/*" />
</fileset>
</copy>
</target>
</project>

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="evo-web-load-properties" basedir="../../">
<property name="properties.base.dir" value="${basedir}/properties" />
<property name="lib.tools.dir" value="${basedir}/lib.tools" />
<path id="lib.tools.classpath">
<fileset dir="${lib.tools.dir}" />
</path>
<target name="load-static-properties" >
<property name="web.dir" value="${basedir}" />
<property name="evolute.dir" value="${basedir}/../evolute" />
<property name="evolute.lib.dir" value="${evolute.dir}/lib" />
<property name="evolute.lib.tools.dir" value="${evolute.dir}/lib.tools" />
<property name="evolute.ant.dir" value="${evolute.dir}/ant" />
<property name="evolute.jar.name" value="evolute.jar" />
<property name="docs.dir" value="${web.dir}/docs" />
<property name="docs.api.dir" value="${docs.dir}/api" />
<property name="web.src.dir" value="${web.dir}/src" />
<property name="web.lib.dir" value="${web.dir}/lib" />
<property name="deploy.project.relative.lib.dir" value="lib" />
<property name="web.dist.dir" value="${web.dir}/dist" />
<property name="web.dist.lib.dir" value="${web.dist.dir}/lib" />
<property name="web.deploy.dist.dir" value="${web.dir}/deploy" />
<property name="web.deploy.dist.lib.dir" value="${web.deploy.dist.dir}/lib" />
<property name="web.build.dir" value="${web.dir}/build" />
<property name="web.dependencies.chache.dir" value="${web.dir}/dependenciesCache" />
<property name="codegen.project.ant" value="${basedir}/../codegen/build.xml"/>
<property name="codegen.properties.file" value="${basedir}/properties/codegen.xml"/>
<property name="leaf.project.ant" value="${basedir}/../LEAF/build.xml"/>
<path id="web.jar.classpath">
<fileset dir="${web.lib.dir}" />
<fileset dir="${basedir}/web/WEB-INF/lib" />
<fileset file="${basedir}/lib.tools/servlet-api.jar" />
<fileset file="${basedir}/lib.tools/jsp-api.jar" />
<fileset file="${basedir}/lib.tools/el-api.jar" />
</path>
<path id="web.build.classpath">
<pathelement location="${web.build.dir}" />
<path refid="web.jar.classpath" />
</path>
<path id="lib.docs.classpath">
<path refid="lib.tools.classpath" />
<path refid="web.jar.classpath" />
</path>
<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="lib.tools.classpath" />
</target>
<target name="load-properties-file" >
<property name="properties.dir" value="${properties.base.dir}" />
<property file="${properties.dir}/app.properties" />
<property file="${properties.dir}/project.properties" />
<antcall target="load-static-properties"/>
</target>
<target name="load-properties" depends="load-static-properties,load-properties-file">
<property name="web.name" value="${web.appName}" />
<property name="web.jar.name" value="${web.name}.jar" />
<property name="jnlp.dir" value="${web.dir}/jnlp" />
<property name="jnlp.extensions.dir" value="${jnlp.dir}/extensions" />
<property name="web.java.version" value="${java.version}" />
<property name="web.deploy.server" value="www.evolute.pt" />
<property name="web.deploy.path" value="/home/software/src_${web.name}" />
<property name="web.deploy.jnlp.path" value="${web.deploy.path}/jnlp" />
<property name="web.deploy.production.script" value="/home/software/auto_deploy.sh ${web.name}" />
<property name="web.deploy.test.script" value="/home/software/auto_test_deploy.sh ${web.name}" />
<property name="deploy.prepare.script" value="/home/software/auto_prepare_deploy.sh ${web.name}" />
<property name="web.deploy.docs.server" value="${web.deploy.server}" />
<property name="web.deploy.docs.path" value="/home/software/public_html/docs/${web.name}" />
<property name="web.docs.prepare.script" value="/home/software/auto_prepare_docs_upload.sh" />
<property name="web.version.file" value="${properties.base.dir}/version.properties" />
<property name="web.version.comment" value="${web.name} versioning file" />
<property name="web.run.args" value="" />
<property name="jvm.run.args" value="-XX:-UseGCOverheadLimit" />
<property name="web.ws.wsdl.url" value="${web.ws.wsdl.url.protocol}://${web.ws.wsdl.url.host}:${web.ws.wsdl.url.port}${web.ws.wsdl.url.path}" />
<property name="web.max.mem" value="512M" />
<property name="leaf.main" value="com.evolute.leaf.Main" />
<property name="deployer.main" value="com.evolute.deploy.Main" />
</target>
</project>

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="evo-web-build" basedir="../" default="build-war">
<import file="common/evo-web-build-common.xml" />
<target name="build-war" depends="web-clean,web-create-jar">
<war destfile="${web.dist.dir}/${ant.project.name}.war" webxml="${basedir}/web/WEB-INF/web.xml">
<fileset dir="${basedir}/web">
<include name="**/*.*" />
<exclude name="WEB-INF/web.xml" />
</fileset>
<lib file="${web.dist.dir}/${ant.project.name}.jar"/>
</war>
</target>
</project>

Binary file not shown.

@ -22,7 +22,49 @@ public class Area implements Serializable, Comparable< Area >
private Integer ordem;
private List<Risco> riscos;
public Integer getId() {
public Area withId( final Integer id )
{
this.id = id;
return this;
}
public Area withArea_id( final Integer area_id )
{
this.area_id = area_id;
return this;
}
public Area withPlano_id( final Integer plano_id )
{
this.plano_id = plano_id;
return this;
}
public Area withDescricao( final String descricao )
{
this.descricao = descricao;
return this;
}
public Area withIs_principal( final Boolean is_principal )
{
this.is_principal = is_principal;
return this;
}
public Area withOrdem( final Integer ordem )
{
this.ordem = ordem;
return this;
}
public Area withRiscos( final List< Risco > riscos )
{
this.riscos = riscos;
return this;
}
public Integer getId() {
return id;
}

@ -8,13 +8,8 @@ package db.providers;
import com.evolute.entity.ProviderInterface;
import com.evolute.entity.evo.EvoDataException;
import com.evolute.entity.evo.EvoDataObject;
import com.evolute.utils.db.DBException;
import com.evolute.utils.db.Executer;
import com.evolute.utils.error.ErrorLogger;
import db.DBConstants;
import java.sql.ResultSet;
import java.sql.Statement;
public abstract class GenericDataProvider
{
@ -52,71 +47,4 @@ public abstract class GenericDataProvider
{
return localProvider;
}
// public void checkConnection()
// {
// Db db = Db.getInstance();
// if ( db.getConnection() == null )
// {
// try
// {
// db.connect();
// }
// catch ( Exception ex )
// {
// ErrorLogger.logException( ex );
// }
// }
// }
protected Integer getMaxTableId(String table)
{
Statement st = createStatement();
String id = table + ".id";
String sql = "SELECT max(" + id + ")+1 AS MAXID FROM " + table;
try
{
ResultSet rs = st.executeQuery(sql);
rs.first();
Integer newId = new Integer(rs.getInt("MAXID"));
if(newId.intValue() == 0)
{
newId = new Integer(1);
}
return newId;
}
catch(Exception ex)
{
return new Integer(1);
}
}
protected Statement createStatement()
{
try
{
// Db db = Db.getInstance();
// return db.createStatement();
return EvoBaseProvider.getInstance().createStatement();
}
catch ( DBException ex )
{
ErrorLogger.logException( ex );
}
return null;
}
protected Statement createLocalStatement()
{
try
{
return EvoBaseProvider.getInstance().createLocalStatement();
}
catch ( DBException ex )
{
ErrorLogger.logException( ex );
}
return null;
}
}

@ -17,7 +17,6 @@ import com.evolute.utils.sql.Select2;
import com.evolute.utils.sql.Update;
import com.evolute.utils.sql.expression.Par;
import com.evolute.utils.strings.StringPlainer;
import db.data.siprp.outer.EstabelecimentosData;
import db.data.siprp.outer.EstadoMedidasData;
import db.data.siprp.outer.PlanoAreasData;
import db.data.siprp.outer.PlanoMedidasData;
@ -33,7 +32,6 @@ import db.entidades.PlanoActuacao;
import db.entidades.PostoTrabalho;
import db.entidades.Risco;
import db.entidades.Utilizador;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -51,8 +49,6 @@ public class PlanosDataProvider extends GenericDataProvider
protected static final String UNCONTROLLED = "Incontrolado";
protected static final String CONTROLLED = "Controlado";
protected static final String INDETERMINATE = "Indeterminado";
protected static final String NAO_VALORAVEL = "N\u00E3o Valor\u00E1vel";
protected static final String NAO_VALORAVEL_SHORT = "N/V";
protected static final String MUITO_ALTO = "Muito Alto";
protected static final String ALTO = "Alto";
protected static final String MEDIO = "M\u00e9dio";
@ -92,19 +88,19 @@ public class PlanosDataProvider extends GenericDataProvider
{
p.setObservacoes_dns( "" );
}
if ( p.getUser_dir_loja() != null && p.getUser_dir_loja().intValue() == 0 )
if ( p.getUser_dir_loja() != null && p.getUser_dir_loja() == 0 )
{
p.setUser_dir_loja( null );
}
if ( p.getUser_dns() != null && p.getUser_dns().intValue() == 0 )
if ( p.getUser_dns() != null && p.getUser_dns() == 0 )
{
p.setUser_dns( null );
}
if ( p.getUser_hs() != null && p.getUser_hs().intValue() == 0 )
if ( p.getUser_hs() != null && p.getUser_hs() == 0 )
{
p.setUser_hs( null );
}
if ( p.getUser_seg() != null && p.getUser_seg().intValue() == 0 )
if ( p.getUser_seg() != null && p.getUser_seg() == 0 )
{
p.setUser_seg( null );
}
@ -122,7 +118,7 @@ public class PlanosDataProvider extends GenericDataProvider
new Assignment( new Field( "obs_correcao" ), p.getObs_correcao() ),
new Assignment( new Field( "correcao" ), p.getCorrecao() ),
new Assignment( new Field( "fase_antes_correcao" ), p.getFase_antes_correcao() ),
new Assignment( new Field( "concluido_por_desactivacao" ), ( p.getConcluidoPorDesactivacao() == null ? new Boolean( false ) : p.getConcluidoPorDesactivacao() ) ),
new Assignment( new Field( "concluido_por_desactivacao" ), ( p.getConcluidoPorDesactivacao() == null ? Boolean.FALSE : p.getConcluidoPorDesactivacao() ) ),
new Assignment( new Field( "data_desactivacao" ), p.getDataDesactivacao() ),
new Assignment( new Field( "data_validacao_dir_loja" ), p.getData_validacao_dir_loja() ),
new Assignment( new Field( "user_dir_loja" ), p.getUser_dir_loja() ),
@ -193,7 +189,7 @@ public class PlanosDataProvider extends GenericDataProvider
for ( Medida m : medidas )
{
Integer emID = null;
if ( m.getValidarMedidaId() != null && m.getValidarMedidaId().intValue() != 0 )
if ( m.getValidarMedidaId() != null && m.getValidarMedidaId() != 0 )
{
emID = m.getValidarMedidaId();
}
@ -210,38 +206,7 @@ public class PlanosDataProvider extends GenericDataProvider
}
}
// private String getExpression( String nome, String estabelecimento, String dataVisita )
// {
// String tables = "planos_actuacao";
// String whereExpression = "planos_actuacao.deleted_date IS NULL ";
//
// if ( nome != null )
// {
// nome = StringPlainer.convertString( nome.trim() );
// nome = nome.replaceAll( " ", "%" );
// whereExpression += "AND ( " +
// "plain_utf8( planos_actuacao.tecnico_hs_nome ) LIKE '%" + nome + "%' " +
// "OR plain_utf8( planos_actuacao.tecnico_superior_hs_nome ) LIKE '%" + nome + "%' " +
// ") ";
// }
// if ( estabelecimento != null )
// {
// estabelecimento = StringPlainer.convertString( estabelecimento.trim() );
// estabelecimento = estabelecimento.replaceAll( " ", "%" );
// whereExpression += "AND plain_utf8( planos_actuacao.nome_estabelecimento ) LIKE '%" + estabelecimento + "%' ";
// }
// if ( dataVisita != null )
// {
// whereExpression += "AND planos_actuacao.data_visita = '" + dataVisita + "' ";
// }
//
// return "SELECT * FROM " + tables + " WHERE " + whereExpression;
// }
private enum SECTION { ACTIVOS, SEGUIMENTO, CONCLUIDOS; };
private enum SECTION { ACTIVOS, SEGUIMENTO, CONCLUIDOS }
private Select2 getExpression( SECTION section, Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano )
{
@ -263,7 +228,7 @@ public class PlanosDataProvider extends GenericDataProvider
{
where = where.and( faseExpression );
}
if( ano != null && ano.intValue() > 0 && dataVisita == null )
if( ano != null && ano > 0 && dataVisita == null )
{
where = where.and( new Field( "EXTRACT( year FROM " + PlanosActuacaoData.DATA_VISITA_FULL + " )" ).isEqual( ano) );
}
@ -361,11 +326,6 @@ public class PlanosDataProvider extends GenericDataProvider
Virtual2DArray array = getExecuter().executeQuery( query );
return getFullPlanos( array );
// String sql = getExpression( nome, estabelecimento, dataVisita );
// sql += " AND " + getFaseActivos( u );
// Statement st = createStatement();
// ResultSet rs = st.executeQuery( query );
// return getFullPlanos( rs );
}
public List< PlanoActuacao > searchPlanosSeguimento( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano )
@ -378,12 +338,6 @@ public class PlanosDataProvider extends GenericDataProvider
Virtual2DArray array = getExecuter().executeQuery( query );
return getFullPlanos( array );
// String sql = getExpression( nome, estabelecimento, dataVisita );
// sql += " AND " + getFaseSeguimento( u );
// Statement st = createStatement();
// ResultSet rs = st.executeQuery( sql );
// return getFullPlanos( rs );
}
public List< PlanoActuacao > searchPlanosConcluidos( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano )
@ -396,12 +350,6 @@ public class PlanosDataProvider extends GenericDataProvider
Virtual2DArray array = getExecuter().executeQuery( query );
return getFullPlanos( array );
// String sql = getExpression( nome, estabelecimento, dataVisita );
// sql += " AND " + getFaseConcluidos( u );
// Statement st = createStatement();
// ResultSet rs = st.executeQuery( sql );
// return getFullPlanos( rs );
}
@ -409,135 +357,62 @@ public class PlanosDataProvider extends GenericDataProvider
private Expression getFaseActivos( Utilizador u )
{
Expression result = null;
int userType = u.getTipo().intValue();
int userType = u.getTipo();
switch ( userType )
{
case Global.TECNICO_HS :
result = new Par(
new Field( "fase" ).isEqual( new Integer( 1 ) )
.or( new Field( "fase" ).isEqual( new Integer( 5 ) ) )
new Field( "fase" ).isEqual( 1 )
.or( new Field( "fase" ).isEqual( 5 ) )
);
break;
case Global.RESPONSAVEL_SEGURANCA :
result = new Field( "fase" ).isEqual( new Integer( 2 ) );
result = new Field( "fase" ).isEqual( 2 );
break;
case Global.DIRECTOR_LOJA :
result = new Field( "fase" ).isEqual( new Integer( 3 ) );
result = new Field( "fase" ).isEqual( 3 );
break;
case Global.DIRECTOR_NACIONAL_SEGURANCA :
result = new Field( "fase" ).isEqual( new Integer( 4 ) );
result = new Field( "fase" ).isEqual( 4 );
break;
}
if ( userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS && userType != Global.DIRECTOR_NACIONAL_SEGURANCA )
{
Expression expr = new Field( "estabelecimento_id" ).isEqual( new Integer( u.getEstabelecimento_id() ) );
Expression expr = new Field( "estabelecimento_id" ).isEqual( u.getEstabelecimento_id() );
result = result == null ? expr : result.and( expr );
}
return result;
}
// private String getFaseActivos( Utilizador u )
// {
// String sql = "";
// int userType = u.getTipo().intValue();
// switch ( userType )
// {
// case Global.TECNICO_HS:
// sql += " AND (fase = 1 OR fase = 5)";
// break;
//
// case Global.RESPONSAVEL_SEGURANCA:
// sql += " AND fase = 2";
// break;
//
// case Global.DIRECTOR_LOJA:
// sql += " AND fase = 3";
// break;
//
// case Global.DIRECTOR_NACIONAL_SEGURANCA:
// sql += " AND fase = 4";
// break;
// }
// if ( userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS && userType != Global.DIRECTOR_NACIONAL_SEGURANCA )
// {
// sql += " AND estabelecimento_id = " + u.getEstabelecimento_id();
// }
//
// return sql;
// }
// private String getFaseSeguimento( Utilizador u )
// {
// int userType = u.getTipo();
// String sql = "";
// switch( userType )
// {
// case Global.TECNICO_HS:
// sql = " AND (fase <> 1 AND fase <> 5 AND fase <> 6) ";
// break;
// case Global.RESPONSAVEL_SEGURANCA:
// sql = " AND (fase <> 2 AND fase <> 6) ";
// break;
// case Global.DIRECTOR_LOJA:
// sql = " AND (fase <> 3 AND fase <> 6) ";
// break;
// case Global.DIRECTOR_NACIONAL_SEGURANCA:
// sql = " AND (fase <> 4 AND fase <> 6) ";
// break;
// case Global.DIRECTOR_SIPRP:
// case Global.RH:
// case Global.DIRECTOR_GERAL_RH:
// case Global.GESTOR:
// sql = " AND (fase > 1 AND fase < 6) ";
// break;
// default:
// break;
// }
//
// if ( userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS
// && userType != Global.DIRECTOR_NACIONAL_SEGURANCA && userType != Global.DIRECTOR_GERAL_RH
// && userType != Global.GESTOR )
// {
// sql += " AND estabelecimento_id = " + u.getEstabelecimento_id();
// }
// if ( userType == Global.GESTOR )
// {
// if ( u.getEstabelecimento_gestor().intValue() > 0 )
// {
// sql += " AND estabelecimento_id = " + u.getEstabelecimento_gestor();
// }
// }
// return sql;
// }
private Expression getFaseSeguimento( Utilizador u )
{
Expression result = null;
int userType = u.getTipo().intValue();
int userType = u.getTipo();
switch ( userType )
{
case Global.TECNICO_HS :
result = new Par(
new Field( "fase" ).isDifferent( new Integer( 1 ) )
.and( new Field( "fase" ).isDifferent( new Integer( 5 ) ) )
.and( new Field( "fase" ).isDifferent( new Integer( 6 ) ) )
new Field( "fase" ).isDifferent( 1 )
.and( new Field( "fase" ).isDifferent( 5 ) )
.and( new Field( "fase" ).isDifferent( 6 ) )
);
break;
case Global.RESPONSAVEL_SEGURANCA :
result = new Par(
new Field( "fase" ).isDifferent( new Integer( 2 ) )
.and( new Field( "fase" ).isDifferent( new Integer( 6 ) ) )
new Field( "fase" ).isDifferent( 2 )
.and( new Field( "fase" ).isDifferent( 6 ) )
);
break;
case Global.DIRECTOR_LOJA :
result = new Par(
new Field( "fase" ).isDifferent( new Integer( 3 ) )
.and( new Field( "fase" ).isDifferent( new Integer( 6 ) ) )
new Field( "fase" ).isDifferent( 3 )
.and( new Field( "fase" ).isDifferent( 6 ) )
);
break;
case Global.DIRECTOR_NACIONAL_SEGURANCA :
result = new Par(
new Field( "fase" ).isDifferent( new Integer( 4 ) )
.and( new Field( "fase" ).isDifferent( new Integer( 6 ) ) )
new Field( "fase" ).isDifferent( 4 )
.and( new Field( "fase" ).isDifferent( 6 ) )
);
break;
case Global.DIRECTOR_SIPRP :
@ -545,8 +420,8 @@ public class PlanosDataProvider extends GenericDataProvider
case Global.DIRECTOR_GERAL_RH :
case Global.GESTOR :
result = new Par(
new Field( "fase" ).isGreater( new Integer( 1 ) )
.and( new Field( "fase" ).isLess( new Integer( 6 ) ) )
new Field( "fase" ).isGreater( 1 )
.and( new Field( "fase" ).isLess( 6 ) )
);
break;
}
@ -560,32 +435,19 @@ public class PlanosDataProvider extends GenericDataProvider
}
if ( userType == Global.GESTOR )
{
if ( u.getEstabelecimento_gestor().intValue() > 0 )
if ( u.getEstabelecimento_gestor() > 0 )
{
Expression expr = new Field( "estabelecimento_id" ).isEqual( u.getEstabelecimento_gestor() );
result = result == null ? expr : result.and( expr );
result = result.and( expr );
}
}
return result;
}
// private String getFaseConcluidos( Utilizador u )
// {
// int userType = u.getTipo().intValue();
// String sql = " AND fase = 6 ";
//
// if ( userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS
// && userType != Global.DIRECTOR_NACIONAL_SEGURANCA && userType != Global.DIRECTOR_GERAL_RH )
// {
// sql += " AND estabelecimento_id = " + u.getEstabelecimento_id();
// }
//
// return sql;
// }
private Expression getFaseConcluidos( Utilizador u )
{
Expression result = new Field( "fase" ).isEqual( new Integer( 6 ) );
int userType = u.getTipo().intValue();
Expression result = new Field( "fase" ).isEqual( 6 );
int userType = u.getTipo();
if ( userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS
&& userType != Global.DIRECTOR_NACIONAL_SEGURANCA && userType != Global.DIRECTOR_GERAL_RH
&& userType != Global.GESTOR )
@ -595,14 +457,12 @@ public class PlanosDataProvider extends GenericDataProvider
return result;
}
private List< PlanoActuacao > getFullPlanos( Virtual2DArray array )
{
List< PlanoActuacao > result = new LinkedList< PlanoActuacao >();
if ( array != null )
{
for ( int i = 0; i < array.columnLength(); i++ )
for ( int i = 0; i < array.rowCount(); i++ )
{
Integer estabelecimentoID = array.get( i, 0 );
Integer fase = array.get( i, 1 );
@ -611,7 +471,6 @@ public class PlanosDataProvider extends GenericDataProvider
Boolean validacaoDirectorLoja = array.get( i, 4 );
Boolean validacaoDNS = array.get( i, 5 );
Boolean validacaoHS = array.get( i, 6 );
String parecerDNS = array.get( i, 7 );
String observacaoCorreccao = array.get( i, 8 );
Date dataValidacaoDirectorLoja = array.get( i, 9 );
Integer userDirectorLoja = array.get( i, 10 );
@ -623,16 +482,10 @@ public class PlanosDataProvider extends GenericDataProvider
String correccao = array.get( i, 16 );
String observacoesDL = array.get( i, 17 );
String observacoesDNS = array.get( i, 18 );
String verificacaoSIPRP = array.get( i, 19 );
Date dataControlo = array.get( i, 20 );
Date dataEmailControlo = array.get( i, 21 );
Integer empresaID = array.get( i, 22 );
String nomeEmpresa = array.get( i, 23 );
Integer tecnicoHSID = array.get( i, 24 );
String tecnicoHSNome = array.get( i, 25 );
Integer id = array.get( i, 26 );
Date dataRelatorio = array.get( i, 27 );
Timestamp deletedStamp = array.get( i, 28 );
Boolean concluidoPorDesactivacao = array.get( i, 29 );
Integer tecnicoSuperiorHSID = array.get( i, 30 );
String tecnicoSuperiorHSNome = array.get( i, 31 );
@ -678,68 +531,13 @@ public class PlanosDataProvider extends GenericDataProvider
pa.setHs_relatorio_id( hsRelatorioID );
pa.setTem_patrimoniais( temPatrimoniais );
// pa.setData_controlo( dataControlo );
// pa.setData_email_controlo( dataEmailControlo );
// pa.setEmpresa_id( empresaID );
// pa.setData_relatorio( dataRelatorio );
result.add( pa );
}
}
return result;
}
// private List< PlanoActuacao > getFullPlanos( ResultSet rs ) throws Exception
// {
// List< PlanoActuacao > list = new LinkedList< PlanoActuacao >();
// if ( rs.isBeforeFirst() )
// {
// rs.first();
// do
// {
// PlanoActuacao pa = new PlanoActuacao();
// pa.setId( new Integer( rs.getInt("id") ) );
// pa.setEstabelecimento_id( new Integer( rs.getInt( "estabelecimento_id" ) ) );
// pa.setNome_estabelecimento( Utils.unicodeToHTML( rs.getString( "nome_estabelecimento" ) ) );
// pa.setNome_empresa( Utils.unicodeToHTML( rs.getString( "nome_empresa" ) ) );
// pa.setFase( new Integer( rs.getInt( "fase" ) ) );
// java.sql.Date sqlDate = rs.getDate( "data_visita" );
// pa.setData_visita( new java.util.Date( sqlDate.getTime() ) );
// pa.setValidacao_director_loja( new Boolean( rs.getBoolean( "validacao_director_loja" ) ) );
// pa.setValidacao_dns( new Boolean( rs.getBoolean("validacao_dns") ) );
// pa.setValidacao_hs( new Boolean( rs.getBoolean("validacao_hs") ) );
// pa.setObservacoes_dl( Utils.unicodeToHTML( rs.getString("observacoes_dl") ) );
// pa.setObservacoes_dns( Utils.unicodeToHTML( rs.getString("observacoes_dns") ) );
// pa.setObs_correcao( Utils.unicodeToHTML( rs.getString("obs_correcao") ) );
// pa.setAreas( getAreasByPlano( pa ) );
// pa.setTotal_riscos( getTotalRiscosByPlano( pa.getId() ) );
// pa.setCorrecao( Utils.unicodeToHTML( rs.getString( "correcao") ) );
// pa.setFase_antes_correcao( new Integer( rs.getInt( "fase_antes_correcao" ) ) );
// pa.setData_validacao_dir_loja( rs.getDate( "data_validacao_dir_loja" ) );
// pa.setUser_dir_loja( new Integer( rs.getInt( "user_dir_loja" ) ) );
// pa.setData_validacao_dns( rs.getDate( "data_validacao_dns" ) );
// pa.setUser_dns( new Integer( rs.getInt( "user_dns" ) ) );
// pa.setData_validacao_hs( rs.getDate( "data_validacao_hs" ) );
// pa.setUser_hs( new Integer( rs.getInt( "user_hs" ) ) );
// pa.setTecnico_hs_id( new Integer( rs.getInt( "tecnico_hs_id" ) ) );
// pa.setTecnico_hs_nome( Utils.unicodeToHTML( rs.getString("tecnico_hs_nome") ) );
// pa.setConcluidoPorDesactivacao( new Boolean( rs.getBoolean( "concluido_por_desactivacao" ) ) );
// pa.setDataDesactivacao( rs.getDate( "data_desactivacao" ) );
// pa.setTecnico_superior_hs_id( new Integer( rs.getInt( "tecnico_superior_hs_id" ) ) );
// pa.setTecnico_superior_hs_nome( Utils.unicodeToHTML( rs.getString( "tecnico_superior_hs_nome" ) ) );
// pa.setData_disponibilizacao( rs.getDate( "data_disponibilizacao" ) );
// pa.setData_validacao_seg( rs.getDate( "data_validacao_seg" ) );
// pa.setUser_seg( rs.getInt( "user_seg" ) );
// pa.setHs_relatorio_id( rs.getInt( "hs_relatorio_id" ) );
//
// list.add( pa );
// }
// while ( rs.next() );
// }
// return list;
// }
private List< Area > getAreasByPlanoID( final Integer planoID )
private List< Area > getAreasByPlanoID( final Integer planoID )
{
List< Area > list = new LinkedList< Area >();
try
@ -751,9 +549,9 @@ public class PlanosDataProvider extends GenericDataProvider
new String[] { PlanoAreasData.DESCRICAO_FULL }
);
Virtual2DArray array = getExecuter().executeQuery( query );
if ( array != null && array.columnLength() > 0 )
if ( array != null && array.rowCount() > 0 )
{
for ( int i = 0; i < array.columnLength(); i++ )
for ( int i = 0; i < array.rowCount(); i++ )
{
Integer areaID = array.get( i, 0 );
Integer pID = array.get( i, 1 );
@ -782,10 +580,6 @@ public class PlanosDataProvider extends GenericDataProvider
/**
* FIXME : ORDER BY patrimonial em ultimo !
*
* @param a
* @return
* @throws Exception
*/
private List< Risco > getRiscosByArea( Area a ) throws Exception
{
@ -805,9 +599,9 @@ public class PlanosDataProvider extends GenericDataProvider
query.disableOrderFieldsVerification();
Virtual2DArray array = getExecuter().executeQuery( query );
if ( array != null && array.columnLength() > 0 )
if ( array != null && array.rowCount() > 0 )
{
for ( int i = 0; i < array.columnLength(); i++ )
for ( int i = 0; i < array.rowCount(); i++ )
{
Integer riscoID = array.get( i, 0 );
Integer areaID = array.get( i, 1 );
@ -924,7 +718,7 @@ public class PlanosDataProvider extends GenericDataProvider
Virtual2DArray array = getExecuter().executeQuery( query );
if ( array != null )
{
for ( int i = 0; i < array.columnLength(); i++ )
for ( int i = 0; i < array.rowCount(); i++ )
{
Integer planoMedidaID = array.get( i, 0 );
String descricao = array.get( i, 1 );
@ -956,7 +750,7 @@ public class PlanosDataProvider extends GenericDataProvider
Virtual2DArray array = getExecuter().executeQuery( query );
if ( array != null )
{
for ( int i = 0; i < array.columnLength(); i++ )
for ( int i = 0; i < array.rowCount(); i++ )
{
Integer planoPostoTrabalhoID = array.get( i, 0 );
Integer medidaID = array.get( i, 1 );
@ -999,7 +793,7 @@ public class PlanosDataProvider extends GenericDataProvider
null
);
Virtual2DArray array = getExecuter().executeQuery( query );
if ( array != null && array.columnLength() > 0 )
if ( array != null && array.rowCount() > 0 )
{
Long countL = array.get( 0, 0 );
count = countL == null ? 0 : countL.intValue();
@ -1027,12 +821,10 @@ public class PlanosDataProvider extends GenericDataProvider
Virtual2DArray array = getExecuter().executeQuery( query );
if ( array != null )
{
for ( int i = 0; i < array.columnLength(); i++ )
for ( int i = 0; i < array.rowCount(); i++ )
{
Integer estadoID = array.get( i, 0 );
String descricao = array.get( i, 1 );
Integer ordem = array.get( i, 2 );
String activo = array.get( i, 3 );
EstadoMedida estado = new EstadoMedida();
estado.setId( estadoID );
@ -1043,11 +835,6 @@ public class PlanosDataProvider extends GenericDataProvider
return list;
}
// public HsRelatorioRiscoValorQualitativoData loadValorQualitativoByID( Integer valorID ) throws Exception
// {
// return getLocalProvider().load( HsRelatorioRiscoValorQualitativoData.class, valorID, HsRelatorioRiscoValorQualitativoData.ID );
// }
public void loadValoresQualitativos() throws Exception
{
VALORES_QUALITATIVOS_BY_ID.clear();
@ -1065,7 +852,6 @@ public class PlanosDataProvider extends GenericDataProvider
public PlanoValoresQualitativosData loadValorQualitativoByID( Integer valorID ) throws Exception
{
// return getProvider().load( PlanoValoresQualitativosData.class, valorID, PlanoValoresQualitativosData.ID );
if( !VALORES_QUALITATIVOS_BY_ID.containsKey( valorID) )
{
loadValoresQualitativos();
@ -1092,7 +878,7 @@ public class PlanosDataProvider extends GenericDataProvider
null, null, null );
query.disableOrderFieldsVerification();
Virtual2DArray array = getExecuter().executeQuery( query );
for ( int i = 0; i < array.columnLength(); i++ )
for ( int i = 0; i < array.rowCount(); i++ )
{
Integer ano = array.get( i, 0 );
result.add( ano );
@ -1129,7 +915,7 @@ public class PlanosDataProvider extends GenericDataProvider
int total = 0;
String last = null;
int totalEstado = 0;
for( int n = 0; n < array.columnLength(); n++ )
for( int n = 0; n < array.rowCount(); n++ )
{
String estado = array.get( n, 0 );
if( last == null ? estado != null : !last.equals( estado ) )
@ -1219,7 +1005,7 @@ public class PlanosDataProvider extends GenericDataProvider
int total = 0;
String last = null;
int totalEstado = 0;
for( int n = 0; n < array.columnLength(); n++ )
for( int n = 0; n < array.rowCount(); n++ )
{
String estado = array.get( n, 0 );
if( last == null ? estado != null : !last.equals( estado ) )
@ -1250,13 +1036,12 @@ public class PlanosDataProvider extends GenericDataProvider
return linhas;
}
// public List<EstabelecimentosData> getEstabelecimentosForEstatistica( Utilizador u )
public List<Mappable> getEstabelecimentosForEstatistica( Utilizador u )
throws Exception
{
Expression exp = new Field( db.data.siprp_local.outer.EstabelecimentosData.EMPRESA_ID_FULL ).isEqual( 32 ).and(
new Field( db.data.siprp_local.outer.EstabelecimentosData.INACTIVO_FULL ).isDifferent( "y" ) );
int userType = u.getTipo().intValue();
int userType = u.getTipo();
if ( userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS
&& userType != Global.DIRECTOR_NACIONAL_SEGURANCA && userType != Global.DIRECTOR_GERAL_RH
&& userType != Global.GESTOR )
@ -1275,22 +1060,10 @@ public class PlanosDataProvider extends GenericDataProvider
null);
Virtual2DArray array = getLocalExecuter().executeQuery( select );
List<Mappable> estabelecimentos = new ArrayList<Mappable>();
for( int n = 0; n < array.columnLength(); n++ )
for( int n = 0; n < array.rowCount(); n++ )
{
estabelecimentos.add( new MappableObject( ( Integer ) array.get( n, 0), ( String ) array.get( n, 1 ) ) );
estabelecimentos.add( new MappableObject( ( Integer ) array.get( n, 0), array.get( n, 1 ) ) );
}
return estabelecimentos;
// int userType = u.getTipo().intValue();
// if ( userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS
// && userType != Global.DIRECTOR_NACIONAL_SEGURANCA && userType != Global.DIRECTOR_GERAL_RH
// && userType != Global.GESTOR )
// {
// return getProvider().listLoad( EstabelecimentosData.class, new Object[]{ u.getEstabelecimento_id() },
// new String[]{ EstabelecimentosData.ID_FULL }, new String[]{ EstabelecimentosData.NOME_FULL } );
// }
// else
// {
// return getProvider().listLoad( EstabelecimentosData.class, EstabelecimentosData.NOME_FULL);
// }
}
}

@ -5,8 +5,20 @@
package db.providers;
import com.evolute.utils.arrays.Virtual2DArray;
import com.evolute.utils.error.ErrorLogger;
import com.evolute.utils.sql.Expression;
import com.evolute.utils.sql.Field;
import com.evolute.utils.sql.Select;
import com.evolute.utils.sql.Select2;
import db.data.siprp_local.outer.EmpresasData;
import db.data.siprp_local.outer.HsRelatorioAreaData;
import db.data.siprp_local.outer.HsRelatorioData;
import db.data.siprp_local.outer.HsRelatorioMedidaData;
import db.data.siprp_local.outer.HsRelatorioPostoData;
import db.data.siprp_local.outer.HsRelatorioPostoMedidaData;
import db.data.siprp_local.outer.HsRelatorioPostoRiscoData;
import db.data.siprp_local.outer.HsRelatorioRiscoData;
import db.data.siprp_local.outer.ImageData;
import db.entidades.Area;
import db.entidades.Medida;
@ -14,8 +26,8 @@ import db.entidades.PlanoActuacao;
import db.entidades.PostoTrabalho;
import db.entidades.Risco;
import db.entidades.Valor;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.MessageFormat;
import java.util.LinkedList;
import java.util.List;
import utils.Utils;
@ -26,14 +38,11 @@ import utils.Utils;
*/
public class RelatoriosDataProvider extends GenericDataProvider
{
// private DbLocal dblocal = DbLocal.getInstance();
private static RelatoriosDataProvider INSTANCE = null;
private RelatoriosDataProvider() throws Exception
{
super();
// dblocal.connect();
}
public static synchronized RelatoriosDataProvider getInstance() throws Exception
@ -45,9 +54,12 @@ public class RelatoriosDataProvider extends GenericDataProvider
return INSTANCE;
}
@SuppressWarnings( "UnusedDeclaration" )
public PlanoActuacao getFullPlano(PlanoActuacao plano, Integer relatorioId)
{
//TODO: Check method (file) usage
try
{
plano = getAreasByPlano(plano, relatorioId);
@ -56,302 +68,266 @@ public class RelatoriosDataProvider extends GenericDataProvider
{
ErrorLogger.logException( ex );
}
return plano;
}
private PlanoActuacao getAreasByPlano( PlanoActuacao plano, Integer relatorioID ) throws Exception
{
Statement st = createLocalStatement();
String sql = "select distinct area_id, hs_relatorio_area.description as descricao from hs_relatorio_posto ";
sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id ";
sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id ";
sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id ";
sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id ";
sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id ";
sql += "where hs_relatorio.id = " + relatorioID + " ";
sql += "order by area_id ";
System.out.println("AREAS BY PLANO SQL : " + sql);
ResultSet rs = st.executeQuery(sql);
Select select = new Select2(
new String[] { HsRelatorioPostoData.TABLENAME, HsRelatorioPostoMedidaData.TABLENAME,
HsRelatorioMedidaData.TABLENAME, HsRelatorioRiscoData.TABLENAME,
HsRelatorioData.TABLENAME, HsRelatorioAreaData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
new Expression[]{
new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) ),
new Field( HsRelatorioMedidaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.MEDIDA_ID_FULL ) ),
new Field( HsRelatorioRiscoData.ID_FULL ).isEqual( new Field( HsRelatorioMedidaData.RISCO_ID_FULL ) ),
new Field( HsRelatorioData.ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.RELATORIO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID_FULL ) )
},
new String[]{ "distinct " + HsRelatorioPostoData.AREA_ID_FULL, HsRelatorioAreaData.DESCRIPTION_FULL },
new Field( HsRelatorioData.ID_FULL ).isEqual( relatorioID ),
new String[]{ HsRelatorioPostoData.AREA_ID_FULL }, null, null, null
);
Virtual2DArray res = getLocalExecuter().executeQuery( select );
List< Area > areas = new LinkedList< Area >();
if ( rs.isBeforeFirst() )
{
rs.first();
do
for( int i = 0; i < res.rowCount(); i++ )
{
Integer rId = res.get( i, 0 );
String rDescription = res.get( i, 1 );
List< Risco > rRiscos = null;
if(existemMedidasByArea(rId))
{
Area a = new Area();
a.setId(new Integer( rs.getInt("area_id") ));
a.setArea_id(a.getId());
if(existemMedidasByArea(a.getId()))
Area a = new Area().withArea_id( rId ).withId( rId );
rDescription = Utils.unicodeToHTML( rDescription );
try
{
a.setDescricao(Utils.unicodeToHTML(rs.getString("descricao")));
try
{
a.setRiscos(getRiscosByArea(a));
}
catch(Exception ex)
{
System.out.println("ERRO RISCOS BY AREA !!!!");
ErrorLogger.logException( ex );
a.setRiscos(null);
}
areas.add(a);
rRiscos = getRiscosByArea( a );
}
catch( Exception ex )
{
System.out.println( "ERRO RISCOS BY AREA !!!!" );
ErrorLogger.logException( ex );
}
areas.add( a.withDescricao( rDescription ).withRiscos( rRiscos ) );
}
}
if( !areas.isEmpty() )
{
plano.setAreas( areas );
}
}while(rs.next());
plano.setAreas(areas);
}
return plano;
}
private List<Risco> getRiscosByArea(Area a) throws Exception
{
// Statement st = dblocal.createStatement();
Statement st = createLocalStatement();
String sql = "select distinct hs_relatorio_risco.id, hs_relatorio_risco.description as descricao from hs_relatorio_posto ";
sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id ";
sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id ";
sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id ";
sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id ";
sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id ";
sql += "where area_id = " + a.getId() + " ";
sql += "order by hs_relatorio_risco.id ";
System.out.println("RISCOS BY AREA SQL : " + sql);
ResultSet rs = st.executeQuery(sql);
Select select = new Select2(
new String[] { HsRelatorioPostoData.TABLENAME, HsRelatorioPostoMedidaData.TABLENAME,
HsRelatorioMedidaData.TABLENAME, HsRelatorioRiscoData.TABLENAME,
HsRelatorioData.TABLENAME, HsRelatorioAreaData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
new Expression[]{
new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) ),
new Field( HsRelatorioMedidaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.MEDIDA_ID_FULL ) ),
new Field( HsRelatorioRiscoData.ID_FULL ).isEqual( new Field( HsRelatorioMedidaData.RISCO_ID_FULL ) ),
new Field( HsRelatorioData.ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.RELATORIO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID_FULL ) )
},
new String[]{ "distinct " + HsRelatorioRiscoData.ID_FULL, HsRelatorioRiscoData.DESCRIPTION_FULL },
new Field( HsRelatorioPostoData.AREA_ID ).isEqual( a.getId() ),
new String[]{ HsRelatorioRiscoData.ID_FULL }, null, null, null
);
Virtual2DArray res = getLocalExecuter().executeQuery( select );
List< Risco > riscos = new LinkedList< Risco >();
if(rs.isBeforeFirst())
{
rs.first();
do
{
Risco r = new Risco();
r.setId(new Integer( rs.getInt("id") ));
if(existemMedidasByRisco(r.getId()))
{
r.setDescricao(Utils.unicodeToHTML(rs.getString("descricao")));
r.setValores(getValoresByRisco(r, a));
//Integer valor = getValorByRisco(r, a);
//r.setValorQuantitativo(valor);
r.setRisco_id(new Integer( rs.getInt("id") ));
r.setMedidas(getMedidasByRisco( r, a));
riscos.add(r);
}
}while(rs.next());
}
for( int i = 0; i < res.rowCount(); i++ )
{
Integer rId = res.get( i, 0 );
String rDescricao = res.get( i, 1 );
if(existemMedidasByRisco(rId))
{
Risco r = new Risco();
r.setDescricao( Utils.unicodeToHTML( rDescricao ) );
r.setValores( getValoresByRisco( r, a ) );
r.setRisco_id( rId );
r.setMedidas( getMedidasByRisco( r, a ) );
riscos.add( r );
}
}
return riscos;
}
private List<Valor> getValoresByRisco(Risco r, Area a) throws Exception
//private Integer getValorByRisco(Risco r, Area a) throws Exception
{
// Statement st = dblocal.createStatement();
Statement st = createLocalStatement();
String sql = "select valor from ";
sql += "(select distinct hs_relatorio_posto_risco.risco_id, ";
sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null ";
sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade ";
sql += "else hs_relatorio_posto_risco.valor_qualitativo_id ";
sql += "end as valor ";
sql += "from hs_relatorio_posto ";
sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id ";
sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id ";
sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id ";
sql += "inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) ";
sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id ";
sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id ";
sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + ") subquery ";
sql += "order by subquery.valor";
System.out.println("VALORES BY RISCO : " + sql);
ResultSet rs = st.executeQuery(sql);
Select innerSelect = new Select2(
new String[] { HsRelatorioPostoData.TABLENAME, HsRelatorioPostoMedidaData.TABLENAME,
HsRelatorioMedidaData.TABLENAME, HsRelatorioRiscoData.TABLENAME, HsRelatorioPostoRiscoData.TABLENAME,
HsRelatorioData.TABLENAME, HsRelatorioAreaData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER,
Select2.JOIN_INNER, Select2.JOIN_INNER },
new Expression[]{
new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) ),
new Field( HsRelatorioMedidaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.MEDIDA_ID_FULL ) ),
new Field( HsRelatorioRiscoData.ID_FULL ).isEqual( new Field( HsRelatorioMedidaData.RISCO_ID_FULL ) ),
new Field( HsRelatorioPostoRiscoData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) )
.and( new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.ID_FULL ) ) ),
new Field( HsRelatorioData.ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.RELATORIO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID_FULL ) )
},
new String[]{ "DISTINCT " + HsRelatorioPostoRiscoData.RISCO_ID_FULL,
"CASE WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null )
.and( new Field( HsRelatorioPostoRiscoData.PROBABILIDADE_FULL ).isEqual( null ) )
.and( new Field( HsRelatorioPostoRiscoData.SEVERIDADE_FULL ).isEqual( null ) ).toString() +
" THEN null WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null ) +
" THEN " + HsRelatorioPostoRiscoData.PROBABILIDADE_FULL + "*" + HsRelatorioPostoRiscoData.SEVERIDADE_FULL +
" ELSE " + HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL +
" END AS valor " },
new Field( HsRelatorioPostoRiscoData.RISCO_ID ).isEqual( r.getId() ).and( new Field( HsRelatorioPostoData.AREA_ID_FULL ).isEqual( a.getId() ) ),
new String[]{ HsRelatorioRiscoData.ID_FULL }, null, null, null
);
Select select = new Select( MessageFormat.format( "SELECT valor FROM ( {0} ) subquery ORDER BY subquery.valor ", innerSelect.toString() ) );
System.out.println("VALORES BY RISCO : " + select.toString());
Virtual2DArray res = getLocalExecuter().executeQuery( select );
List< Valor > valores = new LinkedList< Valor >();
Integer valor = null;
if(rs.isBeforeFirst())
{
rs.first();
do
{
Valor v = new Valor();
Object oValor = rs.getObject("valor");
if(oValor == null)
{
v.setValorQuantitativo(null);
//r.setValorQuantitativo(null);
valor = null;
}
else
{
v.setValorQuantitativo((Integer) oValor);
//r.setValorQuantitativo((Integer) oValor);
valor = (Integer) oValor;
}
// System.out.println("RISCO : " + r.getId().toString() + "VALOR : " + oValor.toString());
//int valor = rs.getInt("valor");
//v.setValorQuantitativo(new Integer(valor));
//v.setMedidas(getMedidasByValor(v, r, a));
valores.add(v);
}while(rs.next());
}
for( int i = 0; i < res.rowCount(); i++ )
{
Valor v = new Valor();
Object oValor = res.get( i, 0 );
if(oValor == null)
{
v.setValorQuantitativo(null);
}
else
{
v.setValorQuantitativo((Integer) oValor);
}
valores.add(v);
}
return valores;
//return valor;
}
// private List<Medida> getMedidasByValor(Valor v, Risco r, Area a) throws Exception
// {
// Statement st = dblocal.createStatement();
// String sql = "select distinct medida_id, valor, descricao from ";
// sql += "( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, ";
// sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null ";
// sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade ";
// sql += "else hs_relatorio_posto_risco.valor_qualitativo_id ";
// sql += "end as valor ";
// sql += "from hs_relatorio_posto ";
// sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id ";
// sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id ";
// sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id ";
// sql += "inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) ";
// sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id ";
// sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id ";
// sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + " and hs_relatorio_posto_medida.is_plano_actuacao = true" + ") subquery ";
// //sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + ") subquery ";
// //sql += "where valor = " + v.getValorQuantitativo() + " ";
// sql += "order by subquery.medida_id, valor";
// System.out.println("MEDIDAS BY VALOR SQL : " + sql);
// ResultSet rs = st.executeQuery(sql);
// List<Medida> medidas = new ArrayList();
// if(rs.isBeforeFirst())
// {
// rs.first();
// do
// {
// Medida m = new Medida();
// //int valor = rs.getInt("valor");
// //m.setValorQuantitativo(new Integer(valor));
// m.setId(new Integer( rs.getInt("medida_id") ));
// m.setDescricao(Utils.unicodeToHTML(rs.getString("descricao")));
// m.setPostos(getPostosByMedidaAndValor(m, v, a));
// medidas.add(m);
// }while(rs.next());
// }
// return medidas;
// }
private List<Medida> getMedidasByRisco(Risco r, Area a) throws Exception
{
// Statement st = dblocal.createStatement();
Statement st = createLocalStatement();
String sql = "select distinct medida_id, valor, descricao from ";
sql += "( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, ";
sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null ";
sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade ";
sql += "else hs_relatorio_posto_risco.valor_qualitativo_id ";
sql += "end as valor ";
sql += "from hs_relatorio_posto ";
sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id ";
sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id ";
sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id ";
sql += "inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) ";
sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id ";
sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id ";
sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + " and hs_relatorio_posto_medida.is_plano_actuacao = true" + ") subquery ";
//sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + ") subquery ";
//sql += "where valor = " + v.getValorQuantitativo() + " ";
sql += "order by subquery.medida_id, valor";
System.out.println("MEDIDAS BY RISCO SQL : " + sql);
ResultSet rs = st.executeQuery(sql);
List< Medida > medidas = new LinkedList< Medida >();
if ( rs.isBeforeFirst() )
{
rs.first();
do
{
Medida m = new Medida();
//int valor = rs.getInt("valor");
//m.setValorQuantitativo(new Integer(valor));
m.setId(new Integer( rs.getInt("medida_id") ));
m.setMedida_id(m.getId());
m.setDescricao(Utils.unicodeToHTML(rs.getString("descricao")));
//m.setPostos(getPostosByMedidaAndValor(m, v, a));
m.setPostos(getPostosByMedida(r, m, a));
medidas.add(m);
}while(rs.next());
}
return medidas;
Select innerSelect = new Select2(
new String[] { HsRelatorioPostoData.TABLENAME, HsRelatorioPostoMedidaData.TABLENAME,
HsRelatorioMedidaData.TABLENAME, HsRelatorioRiscoData.TABLENAME, HsRelatorioPostoRiscoData.TABLENAME,
HsRelatorioData.TABLENAME, HsRelatorioAreaData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER,
Select2.JOIN_INNER, Select2.JOIN_INNER },
new Expression[]{
new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) ),
new Field( HsRelatorioMedidaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.MEDIDA_ID_FULL ) ),
new Field( HsRelatorioRiscoData.ID_FULL ).isEqual( new Field( HsRelatorioMedidaData.RISCO_ID_FULL ) ),
new Field( HsRelatorioPostoRiscoData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) )
.and( new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.ID_FULL ) ) ),
new Field( HsRelatorioData.ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.RELATORIO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID_FULL ) )
},
new String[]{ "DISTINCT " + HsRelatorioPostoMedidaData.MEDIDA_ID_FULL,
HsRelatorioPostoRiscoData.RISCO_ID_FULL,
HsRelatorioMedidaData.DESCRIPTION_FULL,
"CASE WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null )
.and( new Field( HsRelatorioPostoRiscoData.PROBABILIDADE_FULL ).isEqual( null ) )
.and( new Field( HsRelatorioPostoRiscoData.SEVERIDADE_FULL ).isEqual( null ) ).toString() +
" THEN null WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null ) +
" THEN " + HsRelatorioPostoRiscoData.PROBABILIDADE_FULL + "*" + HsRelatorioPostoRiscoData.SEVERIDADE_FULL +
" ELSE " + HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL +
" END AS valor " },
new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( r.getId() )
.and( new Field( HsRelatorioPostoData.AREA_ID_FULL ).isEqual( a.getId() ) )
.and( new Field( HsRelatorioPostoMedidaData.IS_PLANO_ACTUACAO_FULL ).isEqual( Boolean.TRUE ) ),
new String[]{ HsRelatorioRiscoData.ID_FULL }, null, null, null
);
Select select = new Select( MessageFormat.format( "SELECT distinct medida_id, valor, descricao FROM ( {0} ) subquery ORDER BY subquery.medida_id, valor ", innerSelect.toString() ) );
System.out.println( "MEDIDAS BY RISCO SQL : " + select.toString() );
Virtual2DArray res = getLocalExecuter( ).executeQuery( select );
List< Medida > medidas = new LinkedList< Medida >( );
for( int i = 0; i < res.rowCount( ); i++ )
{
Medida m = new Medida( );
m.setId( (Integer) res.get( i, 0 ) );
m.setMedida_id( m.getId( ) );
m.setDescricao( Utils.unicodeToHTML( ( String ) res.get(i, 1) ) );
m.setPostos( getPostosByMedida( r, m, a ) );
medidas.add( m );
}
return medidas;
}
// private List<PostoTrabalho> getPostosByMedidaAndValor(Medida m, Valor v, Area a) throws Exception
// {
// Statement st = dblocal.createStatement();
// String sql = "select subquery.posto_id, valor, descricao from ";
// sql += "(select hs_relatorio_posto_medida.posto_id, hs_relatorio_posto.description as descricao, ";
// sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null ";
// sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade ";
// sql += "else hs_relatorio_posto_risco.valor_qualitativo_id ";
// sql += "end as valor ";
// sql += "from hs_relatorio_posto_medida ";
// sql += "inner join hs_relatorio_posto_risco on hs_relatorio_posto_risco.posto_id = hs_relatorio_posto_medida.posto_id ";
// sql += "inner join hs_relatorio_posto on hs_relatorio_posto.id = hs_relatorio_posto_medida.posto_id ";
// sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id ";
// sql += "where medida_id = " + m.getId() + " and area_id = " + a.getId() + ") subquery ";
// //sql += "where valor = " + v.getValorQuantitativo();
// System.out.println("POSTOS BY MEDIDA SQL : " + sql);
// ResultSet rs = st.executeQuery(sql);
// List<PostoTrabalho> postos = new ArrayList();
// if(rs.isBeforeFirst())
// {
// rs.first();
// do
// {
// PostoTrabalho p = new PostoTrabalho();
// p.setId(new Integer( rs.getInt("posto_id") ));
// p.setDescricao(Utils.unicodeToHTML(rs.getString("descricao")));
// postos.add(p);
// }while(rs.next());
// }
// return postos;
// }
private List<PostoTrabalho> getPostosByMedida(Risco r, Medida m, Area a) throws Exception
{
// Statement st = dblocal.createStatement();
Statement st = createLocalStatement();
String sql = "select subquery.posto_id, valor, descricao from ";
sql += "(select hs_relatorio_posto_medida.posto_id, hs_relatorio_posto.description as descricao, ";
sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null ";
sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade ";
sql += "else hs_relatorio_posto_risco.valor_qualitativo_id ";
sql += "end as valor ";
sql += "from hs_relatorio_posto_medida ";
sql += "inner join hs_relatorio_posto_risco on hs_relatorio_posto_risco.posto_id = hs_relatorio_posto_medida.posto_id ";
sql += "inner join hs_relatorio_posto on hs_relatorio_posto.id = hs_relatorio_posto_medida.posto_id ";
sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id ";
sql += "where medida_id = " + m.getId() + " and area_id = " + a.getId() + " and risco_id = " + r.getId() + ") subquery ";
//sql += "where valor = " + v.getValorQuantitativo();
System.out.println("POSTOS BY MEDIDA SQL : " + sql);
ResultSet rs = st.executeQuery(sql);
Select innerSelect = new Select2(
new String[] { HsRelatorioPostoMedidaData.TABLENAME, HsRelatorioPostoRiscoData.TABLENAME,
HsRelatorioPostoData.TABLENAME, HsRelatorioAreaData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
new Expression[]{
new Field( HsRelatorioPostoRiscoData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ) ),
new Field( HsRelatorioPostoData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID ) )
},
new String[]{ HsRelatorioPostoMedidaData.POSTO_ID_FULL,
HsRelatorioPostoData.DESCRIPTION_FULL,
"CASE WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null )
.and( new Field( HsRelatorioPostoRiscoData.PROBABILIDADE_FULL ).isEqual( null ) )
.and( new Field( HsRelatorioPostoRiscoData.SEVERIDADE_FULL ).isEqual( null ) ).toString() +
" THEN null WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null ) +
" THEN " + HsRelatorioPostoRiscoData.PROBABILIDADE_FULL + "*" + HsRelatorioPostoRiscoData.SEVERIDADE_FULL +
" ELSE " + HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL +
" END AS valor " },
new Field( HsRelatorioPostoRiscoData.RISCO_ID ).isEqual( r.getId() )
.and( new Field( HsRelatorioPostoData.AREA_ID ).isEqual( a.getId() ) )
.and( new Field( HsRelatorioPostoMedidaData.MEDIDA_ID ).isEqual( m.getId() ) ),
new String[]{ HsRelatorioRiscoData.ID_FULL }, null, null, null
);
Select select = new Select( MessageFormat.format( "SELECT subquery.posto_id, valor, descricao FROM ( {0} ) subquery ", innerSelect.toString() ) );
System.out.println("POSTOS BY MEDIDA SQL : " + select.toString());
Virtual2DArray res = getLocalExecuter( ).executeQuery( select );
List< PostoTrabalho > postos = new LinkedList< PostoTrabalho >();
if(rs.isBeforeFirst())
{
rs.first();
do
{
PostoTrabalho p = new PostoTrabalho();
p.setId(new Integer( rs.getInt("posto_id") ));
p.setPosto_id(p.getId());
p.setDescricao(Utils.unicodeToHTML(rs.getString("descricao")));
postos.add(p);
}while(rs.next());
}
for( int i = 0; i < res.rowCount( ); i++ )
{
PostoTrabalho p = new PostoTrabalho();
p.setId( (Integer) res.get( i, 0 ) );
p.setPosto_id( p.getId() );
p.setDescricao( Utils.unicodeToHTML( (String) res.get( i, 1 ) ) );
postos.add( p );
}
return postos;
}
@ -359,113 +335,107 @@ public class RelatoriosDataProvider extends GenericDataProvider
private boolean existemMedidasByArea(Integer area_id) throws Exception
{
// Statement st = dblocal.createStatement();
Statement st = createLocalStatement();
String sql = "select distinct medida_id, valor, descricao ";
sql += "from ( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, ";
sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null ";
sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade else hs_relatorio_posto_risco.valor_qualitativo_id end as valor from hs_relatorio_posto ";
sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id ";
sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id ";
sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id ";
sql += "inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) ";
sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id ";
sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id ";
sql += "where area_id = " + area_id + " and hs_relatorio_posto_medida.is_plano_actuacao = true) subquery order by subquery.medida_id, valor";
System.out.println("EXISTEM MEDIDAS BY AREA SQL : " + sql);
ResultSet rs = st.executeQuery(sql);
if(rs.isBeforeFirst())
{
return true;
}
else
{
return false;
}
Select innerSelect = new Select2(
new String[] { HsRelatorioPostoData.TABLENAME, HsRelatorioPostoMedidaData.TABLENAME,
HsRelatorioMedidaData.TABLENAME, HsRelatorioRiscoData.TABLENAME, HsRelatorioPostoRiscoData.TABLENAME,
HsRelatorioData.TABLENAME, HsRelatorioAreaData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER,
Select2.JOIN_INNER, Select2.JOIN_INNER },
new Expression[]{
new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) ),
new Field( HsRelatorioMedidaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.MEDIDA_ID_FULL ) ),
new Field( HsRelatorioRiscoData.ID_FULL ).isEqual( new Field( HsRelatorioMedidaData.RISCO_ID_FULL ) ),
new Field( HsRelatorioPostoRiscoData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) )
.and( new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.ID_FULL ) ) ),
new Field( HsRelatorioData.ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.RELATORIO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID_FULL ) )
},
new String[]{ "DISTINCT " + HsRelatorioPostoMedidaData.MEDIDA_ID_FULL,
HsRelatorioPostoRiscoData.RISCO_ID_FULL,
HsRelatorioMedidaData.DESCRIPTION_FULL,
"CASE WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null )
.and( new Field( HsRelatorioPostoRiscoData.PROBABILIDADE_FULL ).isEqual( null ) )
.and( new Field( HsRelatorioPostoRiscoData.SEVERIDADE_FULL ).isEqual( null ) ).toString() +
" THEN null WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null ) +
" THEN " + HsRelatorioPostoRiscoData.PROBABILIDADE_FULL + "*" + HsRelatorioPostoRiscoData.SEVERIDADE_FULL +
" ELSE " + HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL +
" END AS valor " },
new Field( HsRelatorioPostoData.AREA_ID_FULL ).isEqual( area_id )
.and( new Field( HsRelatorioPostoMedidaData.IS_PLANO_ACTUACAO_FULL ).isEqual( Boolean.TRUE ) ),
new String[]{ HsRelatorioRiscoData.ID_FULL }, null, null, null
);
Select select = new Select( MessageFormat.format( "SELECT distinct medida_id, valor, descricao FROM ( {0} ) subquery ORDER BY subquery.medida_id, valor ", innerSelect.toString() ) );
System.out.println("EXISTEM MEDIDAS BY AREA SQL : " + select.toString());
Virtual2DArray res = getLocalExecuter( ).executeQuery( select );
return res.rowCount() > 0;
}
private boolean existemMedidasByRisco(Integer risco_id) throws Exception
{
// Statement st = dblocal.createStatement();
Statement st = createLocalStatement();
String sql = "select distinct medida_id ";
sql += "from ( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, ";
sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null ";
sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade else hs_relatorio_posto_risco.valor_qualitativo_id end as valor from hs_relatorio_posto ";
sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id ";
sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id ";
sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id ";
sql += "inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) ";
sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id ";
sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id ";
sql += "where hs_relatorio_posto_risco.risco_id = " + risco_id + " and hs_relatorio_posto_medida.is_plano_actuacao = true) subquery order by medida_id";
System.out.println("EXISTEM MEDIDAS BY RISCO SQL : " + sql);
ResultSet rs = st.executeQuery(sql);
if(rs.isBeforeFirst())
{
return true;
}
else
{
return false;
}
Select innerSelect = new Select2(
new String[] { HsRelatorioPostoData.TABLENAME, HsRelatorioPostoMedidaData.TABLENAME,
HsRelatorioMedidaData.TABLENAME, HsRelatorioRiscoData.TABLENAME, HsRelatorioPostoRiscoData.TABLENAME,
HsRelatorioData.TABLENAME, HsRelatorioAreaData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER,
Select2.JOIN_INNER, Select2.JOIN_INNER },
new Expression[]{
new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) ),
new Field( HsRelatorioMedidaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.MEDIDA_ID_FULL ) ),
new Field( HsRelatorioRiscoData.ID_FULL ).isEqual( new Field( HsRelatorioMedidaData.RISCO_ID_FULL ) ),
new Field( HsRelatorioPostoRiscoData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) )
.and( new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.ID_FULL ) ) ),
new Field( HsRelatorioData.ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.RELATORIO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID_FULL ) )
},
new String[]{ "DISTINCT " + HsRelatorioPostoMedidaData.MEDIDA_ID_FULL,
HsRelatorioPostoRiscoData.RISCO_ID_FULL,
HsRelatorioMedidaData.DESCRIPTION_FULL,
"CASE WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null )
.and( new Field( HsRelatorioPostoRiscoData.PROBABILIDADE_FULL ).isEqual( null ) )
.and( new Field( HsRelatorioPostoRiscoData.SEVERIDADE_FULL ).isEqual( null ) ).toString() +
" THEN null WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null ) +
" THEN " + HsRelatorioPostoRiscoData.PROBABILIDADE_FULL + "*" + HsRelatorioPostoRiscoData.SEVERIDADE_FULL +
" ELSE " + HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL +
" END AS valor " },
new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( risco_id )
.and( new Field( HsRelatorioPostoMedidaData.IS_PLANO_ACTUACAO_FULL ).isEqual( Boolean.TRUE ) ),
new String[]{ HsRelatorioRiscoData.ID_FULL }, null, null, null
);
Select select = new Select( MessageFormat.format( "SELECT distinct medida_id FROM ( {0} ) subquery ORDER BY medida_id ", innerSelect.toString() ) );
System.out.println("EXISTEM MEDIDAS BY RISCO SQL : " + select.toString());
Virtual2DArray res = getLocalExecuter( ).executeQuery( select );
return res.rowCount() > 0;
}
public String getEmpresaNome(Integer empresa_id) throws Exception
{
String nome = "";
EmpresasData empresaData = getLocalProvider().load( EmpresasData.class, empresa_id, EmpresasData.ID );
if ( empresaData != null )
{
nome = Utils.unicodeToHTML( empresaData.getDesignacao_social() );
}
return nome;
// Statement st = createLocalStatement();
//
// String sql ="SELECT designacao_social FROM empresas WHERE id = " + empresa_id;
// ResultSet rslocal = st.executeQuery(sql);
// rslocal.first();
// String nome = Utils.unicodeToHTML(rslocal.getString("designacao_social"));
// return nome;
}
public byte[] getLogoByEmpresa( Integer empresaId )
throws Exception
{
byte[] logo = null;
EmpresasData empresaData = getLocalProvider().load( EmpresasData.class, empresaId, EmpresasData.ID );
EmpresasData empresaData = getLocalProvider().load( EmpresasData.class, empresaId, EmpresasData.ID, null );
if ( empresaData != null )
{
Integer logoID = empresaData.getEmpresa_logo_id();
logo = getLogo( logoID );
}
return logo;
// Statement st = createLocalStatement();
//
// String sql = "select empresa_logo_id from empresas where id = " + empresaId;
// ResultSet rslocal = st.executeQuery(sql);
// if ( rslocal.isBeforeFirst() )
// {
// rslocal.first();
// Integer logoId = new Integer( rslocal.getInt("empresa_logo_id") );
// byte[] logo = getLogo( logoId );
// return logo;
// }
//
// return null;
}
public byte[] getLogo( Integer logoID ) throws Exception
{
byte[] logo = null;
ImageData imageData = getLocalProvider().load( ImageData.class, logoID, ImageData.ID );
ImageData imageData = getLocalProvider().load( ImageData.class, logoID, ImageData.ID, null );
if ( imageData != null )
{
logo = imageData.getImage_data();
@ -473,16 +443,4 @@ public class RelatoriosDataProvider extends GenericDataProvider
System.out.println( "\nRelatoriosDataProvider . getLogo( " + logoID + " ) : " + ( logo == null ? "null" : "size = " + logo.length ) );
return logo;
}
// public byte[] getLogo(Integer logoId) throws Exception
// {
// Statement st = createLocalStatement();
//
// String sql = "select image_data from image where id = " + logoId;
// ResultSet rslocal = st.executeQuery(sql);
// rslocal.first();
// byte[] logo = rslocal.getBytes("image_data");
// System.out.println("LOGO SIZE : " + logo.length);
// return logo;
// }
}
}

@ -6,14 +6,15 @@
package db.providers;
import com.evolute.utils.arrays.Virtual2DArray;
import com.evolute.utils.db.DBException;
import com.evolute.utils.sql.Expression;
import com.evolute.utils.sql.Field;
import com.evolute.utils.sql.Select;
import com.evolute.utils.sql.Select2;
import db.data.siprp.outer.EmpresasData;
import db.data.siprp.outer.UtilizadoresData;
import db.entidades.Utilizador;
import utils.Global;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
@ -57,7 +58,7 @@ public class UtilizadoresDataProvider extends GenericDataProvider
null, null, null
);
Virtual2DArray result = getExecuter().executeQuery( query );
if ( result != null && result.columnLength() > 0 )
if ( result != null && result.rowCount( ) > 0 )
{
Integer userID = result.get( 0, 0 );
user = getUtilizador( userID );
@ -100,43 +101,12 @@ public class UtilizadoresDataProvider extends GenericDataProvider
}
return user;
}
// public Utilizador getUtilizador( Integer id ) throws Exception
// {
// Utilizador u = null;
// Statement st = createStatement();
// String sql = "SELECT * FROM utilizadores WHERE id = " + id;
// ResultSet rs = st.executeQuery( sql );
// if ( rs.first() )
// {
// u = new Utilizador();
// u.setId(new Integer(rs.getInt("id")));
// u.setLogin(rs.getString("login"));
// u.setPassword(rs.getString("password"));
// u.setData_password(rs.getDate("data_password"));
// u.setEmail(rs.getString("email"));
// u.setEmpresa_id(new Integer(rs.getInt("empresa_id")));
// u.setEstabelecimento_id(new Integer(rs.getInt("estabelecimento_id")));
// u.setAdministrador(rs.getString("administrador"));
// u.setTipo(new Integer(rs.getInt("tipo")));
// u.setNumero_cedula(rs.getString("numero_cedula"));
// u.setCap(rs.getString("cap"));
// u.setNome(rs.getString("nome"));
// u.setMedico_id(new Integer(rs.getInt("medico_id")));
// u.setFuncionario_hst_id(new Integer(rs.getInt("funcionario_hst_id")));
// u.setActivo(rs.getString("activo"));
// u.setResponsavel_loja(rs.getString("responsavel_loja"));
// u.setGestor_geral(rs.getString("gestor_geral"));
// u.setApagado(rs.getString("apagado"));
// }
// return u;
// }
public List< Utilizador > getUtilizadoresListByTipo( Integer tipo, String responsavel_loja, Integer estabelecimento_id )
throws Exception
{
List< Utilizador > list = new LinkedList< Utilizador >();
int type = tipo.intValue();
int type = tipo;
Expression where = new Field( UtilizadoresData.ACTIVO_FULL ).isEqual( "y" );
where = where.and( new Field( UtilizadoresData.APAGADO_FULL ).isEqual( "n" ) );
@ -164,52 +134,6 @@ public class UtilizadoresDataProvider extends GenericDataProvider
}
}
// String sql = "";
// String estabelecimento_constraint = "";
// if ( type == Global.DIRECTOR_LOJA || type == Global.RESPONSAVEL_SEGURANCA || type == Global.DIRECTOR_NACIONAL_SEGURANCA )
// {
// estabelecimento_constraint = " AND estabelecimento_id = " + estabelecimento_id;
// }
// if ( type == Global.RESPONSAVEL_SEGURANCA && responsavel_loja.matches( "y" ) )
// {
// sql = "SELECT * FROM utilizadores WHERE activo = 'y' AND apagado = 'n' AND tipo = " + tipo + estabelecimento_constraint + " AND responsavel_loja = 'y'";
// }
// else if ( type == Global.DIRECTOR_LOJA || type == Global.TECNICO_HS || type == Global.DIRECTOR_NACIONAL_SEGURANCA )
// {
// sql = "SELECT * FROM utilizadores WHERE activo = 'y' AND apagado = 'n' AND tipo = " + tipo + estabelecimento_constraint;
// }
//
// System.out.println( "UTILIZADORES LIST BY TIPO SQL : " + sql );
// Statement st = createStatement();
// ResultSet rs = st.executeQuery( sql );
// if ( rs.isBeforeFirst() )
// {
// rs.first();
// do
// {
// Utilizador u = new Utilizador();
// u.setId( new Integer( rs.getInt( "id" ) ) );
// u.setLogin( rs.getString( "login" ) );
// u.setPassword( rs.getString( "password" ) );
// u.setData_password( rs.getDate( "data_password" ) );
// u.setEmail( rs.getString( "email" ) );
// u.setEmpresa_id( new Integer( rs.getInt( "empresa_id" ) ) );
// u.setEstabelecimento_id( new Integer( rs.getInt( "estabelecimento_id" ) ) );
// u.setAdministrador( rs.getString( "administrador" ) );
// u.setTipo( new Integer( rs.getInt( "tipo" ) ) );
// u.setNumero_cedula( rs.getString( "numero_cedula" ) );
// u.setCap( rs.getString( "cap" ) );
// u.setNome( rs.getString( "nome" ) );
// u.setMedico_id( new Integer( rs.getInt( "medico_id" ) ) );
// u.setFuncionario_hst_id( new Integer( rs.getInt( "funcionario_hst_id" ) ) );
// u.setActivo( rs.getString( "activo" ) );
// u.setResponsavel_loja( rs.getString( "responsavel_loja" ) );
// list.add( u );
// }
// while ( rs.next() );
// }
return list;
}
@ -227,36 +151,17 @@ public class UtilizadoresDataProvider extends GenericDataProvider
}
return list;
}
// public ArrayList getUtilizadoresList() throws Exception
// {
// ArrayList list = new ArrayList();
// Statement st = createStatement();
// String sql = "select * from utilizadores where activo = 'y' and apagado = 'n'";
//
// ResultSet rs = st.executeQuery(sql);
// rs.first();
// do
// {
// Utilizador u = new Utilizador();
// u.setId(new Integer(rs.getInt("id")));
// u.setLogin(rs.getString("login"));
// u.setPassword(rs.getString("password"));
// u.setData_password(rs.getDate("data_password"));
// u.setEmail(rs.getString("email"));
// u.setEmpresa_id(new Integer(rs.getInt("empresa_id")));
// u.setEstabelecimento_id(new Integer(rs.getInt("estabelecimento_id")));
// u.setAdministrador(rs.getString("administrador"));
// u.setTipo(new Integer(rs.getInt("tipo")));
// u.setNumero_cedula(rs.getString("numero_cedula"));
// u.setCap(rs.getString("cap"));
// u.setNome(rs.getString("nome"));
// u.setMedico_id(new Integer(rs.getInt("medico_id")));
// u.setFuncionario_hst_id(new Integer(rs.getInt("funcionario_hst_id")));
// u.setActivo(rs.getString("activo"));
// u.setResponsavel_loja(rs.getString("responsavel_loja"));
// list.add(u);
// }while(rs.next());
// return list;
// }
public Boolean isSiprp( Utilizador utilizador ) throws DBException
{
Select select = new Select2( EmpresasData.TABLENAME, new Field( EmpresasData.DESIGNACAO_SOCIAL_FULL ).isILike( "siprp%" )
.and( new Field( EmpresasData.ID_FULL ).isEqual( utilizador.getEmpresa_id() ) ), "1" );
Select outer = new Select( "select exists( " + select.toString() + " )" );
Virtual2DArray array = getExecuter().executeQuery( outer );
return array.rowCount() > 0 ? ( Boolean ) array.get( 0, 1 ) : Boolean.FALSE;
}
}

@ -1,5 +1,14 @@
package importer;
import com.evolute.utils.sql.Select;
import db.data.siprp_local.outer.HsRelatorioAreaData;
import db.data.siprp_local.outer.HsRelatorioData;
import db.data.siprp_local.outer.HsRelatorioMedidaData;
import db.data.siprp_local.outer.HsRelatorioPostoData;
import db.data.siprp_local.outer.HsRelatorioPostoMedidaData;
import db.data.siprp_local.outer.HsRelatorioPostoRiscoData;
import db.data.siprp_local.outer.HsRelatorioRiscoData;
import db.data.siprp_local.outer.HsRelatorioRiscoValorQualitativoData;
import db.providers.*;
import com.evolute.utils.arrays.Virtual2DArray;
import com.evolute.utils.error.ErrorLogger;
@ -21,11 +30,11 @@ import db.entidades.PostoTrabalho;
import db.entidades.Risco;
import db.entidades.Valor;
import db.entidades.ValorQualitativo;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.MessageFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import utils.Utils;
@ -64,7 +73,7 @@ public class PlanosActuacaoImporterProvider extends GenericDataProvider
new String[] { PlanosActuacaoData.DATA_VISITA_FULL },
new String[] {} );
Virtual2DArray array = getExecuter().executeQuery( query );
for ( int i = 0; i < array.columnLength(); i++ )
for ( int i = 0; i < array.rowCount(); i++ )
{
Date date = array.get( i, 0 );
System.out.println( "\n\t\t\tData-Visita Plano : " + date );
@ -84,7 +93,7 @@ public class PlanosActuacaoImporterProvider extends GenericDataProvider
new String[] {}
);
Virtual2DArray array = getExecuter().executeQuery( query );
for ( int i = 0; i < array.columnLength(); i++ )
for ( int i = 0; i < array.rowCount(); i++ )
{
Integer estabelecimentoID = array.get( i, 0 );
result.add( estabelecimentoID );
@ -109,325 +118,332 @@ public class PlanosActuacaoImporterProvider extends GenericDataProvider
private PlanoActuacao getAreasByPlano( PlanoActuacao plano, Integer relatorioID ) throws Exception
{
String sql = "select hs_relatorio_posto.area_id as area, hs_relatorio_area.description as descricao, hs_relatorio_area.ordem as ordem, bool_or( coalesce( hs_relatorio_posto.is_principal, false ) ) as is_principal "
+ " from hs_relatorio_posto "
+ " inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "
+ " inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "
+ " inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "
+ " inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "
+ " inner join hs_relatorio_area on hs_relatorio_area.id = hs_relatorio_posto.area_id "
+ " where hs_relatorio.id = " + relatorioID + " and hs_relatorio_posto_medida.is_plano_actuacao "
+ " and hs_relatorio_posto.deleted_date is null and hs_relatorio_area.deleted_date is null "
+ " group by area, descricao, ordem"
+ " order by area ";
Select select = new Select2(
new String[] { HsRelatorioPostoData.TABLENAME, HsRelatorioPostoMedidaData.TABLENAME,
HsRelatorioMedidaData.TABLENAME, HsRelatorioRiscoData.TABLENAME,
HsRelatorioData.TABLENAME, HsRelatorioAreaData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
new Expression[]{
new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) ),
new Field( HsRelatorioMedidaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.MEDIDA_ID_FULL ) ),
new Field( HsRelatorioRiscoData.ID_FULL ).isEqual( new Field( HsRelatorioMedidaData.RISCO_ID_FULL ) ),
new Field( HsRelatorioData.ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.RELATORIO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID_FULL ) )
},
new String[]{ HsRelatorioPostoData.AREA_ID_FULL, HsRelatorioAreaData.DESCRIPTION_FULL, HsRelatorioAreaData.ORDEM_FULL,
"bool_or(coalesce(" + HsRelatorioPostoData.IS_PRINCIPAL_FULL + ", false))"
},
new Field( HsRelatorioData.ID_FULL ).isEqual( relatorioID )
.and( new Field( HsRelatorioPostoMedidaData.IS_PLANO_ACTUACAO_FULL ).isEqual( Boolean.TRUE ) )
.and( new Field( HsRelatorioPostoData.DELETED_DATE_FULL ).isEqual( null ) )
.and( new Field( HsRelatorioAreaData.DELETED_DATE_FULL ).isEqual( null ) ),
new String[]{ HsRelatorioPostoData.AREA_ID_FULL },
new String[]{ HsRelatorioPostoData.AREA_ID_FULL, HsRelatorioAreaData.DESCRIPTION_FULL, HsRelatorioAreaData.ORDEM_FULL },
null, null
);
System.out.println( "\n\t\t\t\t\t\tprovider . getAreasByPlano( " + plano.getId() + ", " + relatorioID + " ) : " );
System.out.println( "\n\t\t\t\t\t\t\t\tSQL : " + sql );
System.out.println( "\n\t\t\t\t\t\t\t\tSQL : " + select.toString() );
Virtual2DArray res = getLocalExecuter().executeQuery( select );
Statement st = createLocalStatement();
ResultSet rs = st.executeQuery( sql );
List< Area > areas = new LinkedList< Area >();
if ( rs.isBeforeFirst() )
{
rs.first();
do
{
Area a = new Area();
a.setId( new Integer( rs.getInt( "area" ) ) );
a.setArea_id( a.getId() );
a.setIs_principal( new Boolean( rs.getBoolean( "is_principal" ) ) );
Integer ordem = ( Integer ) rs.getObject( "ordem" );
if( ordem != null )
{
a.setOrdem( ordem );
}
if ( existemMedidasByArea( a.getId() ) )
{
a.setDescricao( Utils.unicodeToHTML( rs.getString( "descricao") ) );
try
{
a.setRiscos( getRiscosByArea( a ) );
}
catch ( Exception ex )
{
System.out.println( "\nERRO RISCOS BY AREA !!!!" );
ErrorLogger.logException( ex );
a.setRiscos( null );
}
if( a.getRiscos().size() > 0 )
{
areas.add( a );
}
}
}
while ( rs.next() );
plano.setAreas( areas );
}
for( int i = 0; i < res.rowCount(); i++ )
{
Integer rId = res.get( i, 0 );
String rDescription = res.get( i, 1 );
Integer rOrdem = res.get( i, 2 );
Boolean rIsPrincipal = res.get( i, 3 );
Area a = new Area().withId( rId ).withArea_id( rId ).withIs_principal( rIsPrincipal );
if( rOrdem != null )
{
a.setOrdem( rOrdem );
}
if ( existemMedidasByArea( rId ) )
{
a.setDescricao( Utils.unicodeToHTML( rDescription ) );
try
{
a.setRiscos( getRiscosByArea( a ) );
}
catch ( Exception ex )
{
System.out.println( "\nERRO RISCOS BY AREA !!!!" );
ErrorLogger.logException( ex );
a.setRiscos( null );
}
if( a.getRiscos().size() > 0 )
{
areas.add( a );
}
}
}
plano.setAreas( areas );
return plano;
}
private List< Risco > getRiscosByArea( Area a ) throws Exception
{
String sql = "select distinct hs_relatorio_risco.id, hs_relatorio_risco.description as descricao, hs_relatorio_risco.is_patrimonial as is_patrimonial "
+ " from hs_relatorio_posto "
+ " inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "
+ " inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "
+ " inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "
+ " inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "
+ " inner join hs_relatorio_area on hs_relatorio_area.id = area_id "
+ " where area_id = " + a.getId() + " and hs_relatorio_posto_medida.is_plano_actuacao and hs_relatorio_posto.deleted_date is null "
+ " order by hs_relatorio_risco.id ";
Select select = new Select2(
new String[] { HsRelatorioPostoData.TABLENAME, HsRelatorioPostoMedidaData.TABLENAME,
HsRelatorioMedidaData.TABLENAME, HsRelatorioRiscoData.TABLENAME,
HsRelatorioData.TABLENAME, HsRelatorioAreaData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
new Expression[]{
new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) ),
new Field( HsRelatorioMedidaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.MEDIDA_ID_FULL ) ),
new Field( HsRelatorioRiscoData.ID_FULL ).isEqual( new Field( HsRelatorioMedidaData.RISCO_ID_FULL ) ),
new Field( HsRelatorioData.ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.RELATORIO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID_FULL ) )
},
new String[]{ "DISTINCT " + HsRelatorioRiscoData.ID_FULL, HsRelatorioRiscoData.DESCRIPTION_FULL,
HsRelatorioRiscoData.IS_PATRIMONIAL_FULL },
new Field( HsRelatorioPostoData.AREA_ID_FULL ).isEqual( a.getId() )
.and( new Field( HsRelatorioPostoMedidaData.IS_PLANO_ACTUACAO_FULL ).isEqual( Boolean.TRUE ) )
.and( new Field( HsRelatorioPostoData.DELETED_DATE_FULL ).isEqual( null ) ),
new String[]{ HsRelatorioRiscoData.ID_FULL }, null, null, null
);
System.out.println( "\t\t\t\t\t\t\tprovider . getRiscosByArea( " + a.getId() + " ) : " );
System.out.println( "\t\t\t\t\t\t\t\t\tSQL : " + sql );
System.out.println( "\t\t\t\t\t\t\t\t\tSQL : " + select.toString() );
Virtual2DArray res = getLocalExecuter().executeQuery( select );
Statement st = createLocalStatement();
ResultSet rs = st.executeQuery( sql );
List< Risco > riscos = new LinkedList< Risco >();
if ( rs.isBeforeFirst() )
{
rs.first();
do
{
Risco r = new Risco();
r.setId( new Integer( rs.getInt( "id" ) ) );
if ( existemMedidasByRisco( r.getId() ) )
{
r.setDescricao( Utils.unicodeToHTML( rs.getString( "descricao" ) ) );
r.setIsPatrimonial( rs.getBoolean( "is_patrimonial" ) );
r.setValores( getValoresByRisco( r, a ) );
r.setRisco_id( new Integer( rs.getInt( "id" ) ) );
r.setMedidas( getMedidasByRisco( r, a ) );
if( r.getMedidas().size() > 0 )
{
riscos.add( r );
}
}
}
while ( rs.next() );
}
return riscos;
for( int i = 0; i < res.rowCount(); i++ )
{
Integer rId = res.get( i, 0 );
String rDescription = res.get( i, 1 );
Boolean rIsPatrimonial = res.get( i , 2 );
Risco r = new Risco();
r.setId( rId );
if ( existemMedidasByRisco( rId ) )
{
r.setDescricao( Utils.unicodeToHTML( rDescription ) );
r.setIsPatrimonial( rIsPatrimonial );
r.setValores( getValoresByRisco( r, a ) );
r.setRisco_id( rId );
r.setMedidas( getMedidasByRisco( r, a ) );
if( r.getMedidas().size() > 0 )
{
riscos.add( r );
}
}
}
return riscos;
}
private List< Valor > getValoresByRisco( Risco r, Area a ) throws Exception
{
String sql = "select subquery.valor, subquery.valor_qualitativo_id from "
+ " (select distinct hs_relatorio_posto_risco.risco_id, hs_relatorio_posto_risco.valor_qualitativo_id, hs_relatorio_risco_valor_qualitativo.description, "
+ " case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "
+ " when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade "
+ " else null "
+ " end as valor "
+ " from hs_relatorio_posto "
+ " inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "
+ " inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "
+ " inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "
+ " inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) "
+ " inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "
+ " inner join hs_relatorio_area on hs_relatorio_area.id = area_id "
+ " left outer join hs_relatorio_risco_valor_qualitativo on ( hs_relatorio_risco_valor_qualitativo.id = hs_relatorio_posto_risco.valor_qualitativo_id ) "
+ " where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + " and hs_relatorio_posto.deleted_date is null) subquery "
+ " order by subquery.valor";
Select innerSelect = new Select2(
new String[] { HsRelatorioPostoData.TABLENAME, HsRelatorioPostoMedidaData.TABLENAME,
HsRelatorioMedidaData.TABLENAME, HsRelatorioRiscoData.TABLENAME, HsRelatorioPostoRiscoData.TABLENAME,
HsRelatorioData.TABLENAME, HsRelatorioAreaData.TABLENAME, HsRelatorioRiscoValorQualitativoData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER,
Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_LEFT_OUTER },
new Expression[]{
new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) ),
new Field( HsRelatorioMedidaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.MEDIDA_ID_FULL ) ),
new Field( HsRelatorioRiscoData.ID_FULL ).isEqual( new Field( HsRelatorioMedidaData.RISCO_ID_FULL ) ),
new Field( HsRelatorioPostoRiscoData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) )
.and( new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.ID_FULL ) ) ),
new Field( HsRelatorioData.ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.RELATORIO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID_FULL ) ),
new Field( HsRelatorioRiscoValorQualitativoData.ID_FULL ).isEqual( new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ) )
},
new String[]{ "DISTINCT " + HsRelatorioPostoRiscoData.RISCO_ID_FULL,
HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL,
HsRelatorioRiscoValorQualitativoData.DESCRIPTION_FULL,
"CASE WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null )
.and( new Field( HsRelatorioPostoRiscoData.PROBABILIDADE_FULL ).isEqual( null ) )
.and( new Field( HsRelatorioPostoRiscoData.SEVERIDADE_FULL ).isEqual( null ) ).toString() +
" THEN null WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null ) +
" THEN " + HsRelatorioPostoRiscoData.PROBABILIDADE_FULL + "*" + HsRelatorioPostoRiscoData.SEVERIDADE_FULL +
" ELSE null END AS valor " },
new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( r.getId() )
.and( new Field( HsRelatorioPostoData.AREA_ID_FULL ).isEqual( a.getId() ) )
.and( new Field( HsRelatorioPostoData.DELETED_DATE_FULL ).isEqual( null ) ),
new String[]{ HsRelatorioRiscoData.ID_FULL }, null, null, null
);
Select select = new Select( MessageFormat.format( "SELECT subquery.valor, subquery.valor_qualitativo_id FROM ( {0} ) subquery ORDER BY subquery.valor ", innerSelect.toString() ) );
System.out.println( "\t\t\t\t\t\t\t\tprovider . getValoresByRisco( " + r.getId() + ", " + a.getId() + " ) : " );
System.out.println( "\t\t\t\t\t\t\t\t\t\tSQL : " + sql );
System.out.println( "\t\t\t\t\t\t\t\t\t\tSQL : " + select.toString() );
Virtual2DArray res = getLocalExecuter().executeQuery( select );
Statement st = createLocalStatement();
ResultSet rs = st.executeQuery( sql );
List< Valor > valores = new LinkedList< Valor >();
if ( rs.isBeforeFirst() )
{
rs.first();
do
{
Object oValor = rs.getObject( "valor" );
Object valorQualitativoID = rs.getObject( "valor_qualitativo_id" );
Valor v = new Valor();
v.setValorQuantitativo( oValor == null ? null : ( Integer ) oValor );
v.setValorQualitativoID( valorQualitativoID == null ? null : ( Integer ) valorQualitativoID );
valores.add( v );
}
while ( rs.next() );
}
return valores;
}
// private List<Medida> getMedidasByValor(Valor v, Risco r, Area a) throws Exception
// {
// Statement st = dblocal.createStatement();
// String sql = "select distinct medida_id, valor, descricao from ";
// sql += "( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, ";
// sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null ";
// sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade ";
// sql += "else hs_relatorio_posto_risco.valor_qualitativo_id ";
// sql += "end as valor ";
// sql += "from hs_relatorio_posto ";
// sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id ";
// sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id ";
// sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id ";
// sql += "inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) ";
// sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id ";
// sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id ";
// sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + " and hs_relatorio_posto_medida.is_plano_actuacao = true" + ") subquery ";
// //sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + ") subquery ";
// //sql += "where valor = " + v.getValorQuantitativo() + " ";
// sql += "order by subquery.medida_id, valor";
// System.out.println("MEDIDAS BY VALOR SQL : " + sql);
// ResultSet rs = st.executeQuery(sql);
// List<Medida> medidas = new ArrayList();
// if(rs.isBeforeFirst())
// {
// rs.first();
// do
// {
// Medida m = new Medida();
// //int valor = rs.getInt("valor");
// //m.setValorQuantitativo(new Integer(valor));
// m.setId(new Integer( rs.getInt("medida_id") ));
// m.setDescricao(Utils.unicodeToHTML(rs.getString("descricao")));
// m.setPostos(getPostosByMedidaAndValor(m, v, a));
// medidas.add(m);
// }while(rs.next());
// }
// return medidas;
// }
for( int i = 0; i < res.rowCount(); i++ )
{
Integer oValor = res.get( i, 0 );
Integer valorQualitativoID = res.get( i, 1 );
Valor v = new Valor();
v.setValorQuantitativo( oValor == null ? null : oValor );
v.setValorQualitativoID( valorQualitativoID == null ? null : valorQualitativoID );
valores.add( v );
}
return valores;
}
private List<Medida> getMedidasByRisco( Risco r, Area a ) throws Exception
{
String sql = "select distinct medida_id, valor, descricao from "
+ " ( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, "
+ " case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "
+ " when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade "
+ " else hs_relatorio_posto_risco.valor_qualitativo_id "
+ " end as valor "
+ " from hs_relatorio_posto "
+ " inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "
+ " inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "
+ " inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "
+ " inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) "
+ " inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "
+ " inner join hs_relatorio_area on hs_relatorio_area.id = area_id "
+ " where hs_relatorio_medida.description is not null and length( hs_relatorio_medida.description ) > 0 "
+ " and hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + " and hs_relatorio_posto_medida.is_plano_actuacao "
+ " and hs_relatorio_posto.deleted_date is null and hs_relatorio_medida.deleted_date is null ) subquery "
//+ " where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + ") subquery "
//+ " where valor = " + v.getValorQuantitativo() + " "
+ " order by subquery.medida_id, valor";
Select innerSelect = new Select2(
new String[] { HsRelatorioPostoData.TABLENAME, HsRelatorioPostoMedidaData.TABLENAME,
HsRelatorioMedidaData.TABLENAME, HsRelatorioRiscoData.TABLENAME, HsRelatorioPostoRiscoData.TABLENAME,
HsRelatorioData.TABLENAME, HsRelatorioAreaData.TABLENAME, HsRelatorioRiscoValorQualitativoData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER,
Select2.JOIN_INNER, Select2.JOIN_INNER },
new Expression[]{
new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) ),
new Field( HsRelatorioMedidaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.MEDIDA_ID_FULL ) ),
new Field( HsRelatorioRiscoData.ID_FULL ).isEqual( new Field( HsRelatorioMedidaData.RISCO_ID_FULL ) ),
new Field( HsRelatorioPostoRiscoData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) )
.and( new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.ID_FULL ) ) ),
new Field( HsRelatorioData.ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.RELATORIO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID_FULL ) )
},
new String[]{ "DISTINCT " + HsRelatorioPostoMedidaData.MEDIDA_ID_FULL,
HsRelatorioPostoRiscoData.RISCO_ID_FULL,
HsRelatorioMedidaData.DESCRIPTION_FULL,
"CASE WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null )
.and( new Field( HsRelatorioPostoRiscoData.PROBABILIDADE_FULL ).isEqual( null ) )
.and( new Field( HsRelatorioPostoRiscoData.SEVERIDADE_FULL ).isEqual( null ) ).toString() +
" THEN null WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null ) +
" THEN " + HsRelatorioPostoRiscoData.PROBABILIDADE_FULL + "*" + HsRelatorioPostoRiscoData.SEVERIDADE_FULL +
" ELSE " + HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL +
" END AS valor " },
new Field( HsRelatorioMedidaData.DESCRIPTION_FULL ).isDifferent( null )
.and( new Field( "length( " + HsRelatorioMedidaData.DESCRIPTION_FULL + " )" ).isGreater( 0 ) )
.and( new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( r.getId() ) )
.and( new Field( HsRelatorioPostoData.AREA_ID_FULL ).isEqual( a.getId() ) )
.and( new Field( HsRelatorioPostoMedidaData.IS_PLANO_ACTUACAO_FULL ).isEqual( Boolean.TRUE ) )
.and( new Field( HsRelatorioPostoData.DELETED_DATE_FULL ).isEqual( null ) )
.and( new Field( HsRelatorioMedidaData.DELETED_DATE_FULL ).isEqual( null ) ),
new String[]{ HsRelatorioRiscoData.ID_FULL }, null, null, null
);
Select select = new Select( MessageFormat.format( "SELECT DISTINCT medida_id, valor, descricao FROM ( {0} ) subquery ORDER BY subquery.medida_id, valor ", innerSelect.toString() ) );
System.out.println( "\t\t\t\t\t\t\t\t\tprovider . getMedidasByRisco( " + r.getId() + ", " + a.getId() + " ) : " );
System.out.println( "\t\t\t\t\t\t\t\t\t\t\tSQL : " + sql );
System.out.println( "\t\t\t\t\t\t\t\t\t\t\tSQL : " + select.toString() );
Virtual2DArray res = getLocalExecuter( ).executeQuery( select );
Statement st = createLocalStatement();
ResultSet rs = st.executeQuery( sql );
List< Medida > medidas = new LinkedList< Medida >();
if ( rs.isBeforeFirst() )
{
rs.first();
do
{
Medida m = new Medida();
m.setId( new Integer( rs.getInt("medida_id") ) );
m.setMedida_id( m.getId() );
String descricao = rs.getString( "descricao" );
if( descricao != null && descricao.trim().length() > 8)
{
m.setDescricao( Utils.unicodeToHTML( descricao ) );
//m.setPostos(getPostosByMedidaAndValor(m, v, a));
m.setPostos( getPostosByMedida( r, m, a ) );
medidas.add( m );
}
}
while ( rs.next() );
}
return medidas;
}
// private List<PostoTrabalho> getPostosByMedidaAndValor(Medida m, Valor v, Area a) throws Exception
// {
// Statement st = dblocal.createStatement();
// String sql = "select subquery.posto_id, valor, descricao from ";
// sql += "(select hs_relatorio_posto_medida.posto_id, hs_relatorio_posto.description as descricao, ";
// sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null ";
// sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade ";
// sql += "else hs_relatorio_posto_risco.valor_qualitativo_id ";
// sql += "end as valor ";
// sql += "from hs_relatorio_posto_medida ";
// sql += "inner join hs_relatorio_posto_risco on hs_relatorio_posto_risco.posto_id = hs_relatorio_posto_medida.posto_id ";
// sql += "inner join hs_relatorio_posto on hs_relatorio_posto.id = hs_relatorio_posto_medida.posto_id ";
// sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id ";
// sql += "where medida_id = " + m.getId() + " and area_id = " + a.getId() + ") subquery ";
// //sql += "where valor = " + v.getValorQuantitativo();
// System.out.println("POSTOS BY MEDIDA SQL : " + sql);
// ResultSet rs = st.executeQuery(sql);
// List<PostoTrabalho> postos = new ArrayList();
// if(rs.isBeforeFirst())
// {
// rs.first();
// do
// {
// PostoTrabalho p = new PostoTrabalho();
// p.setId(new Integer( rs.getInt("posto_id") ));
// p.setDescricao(Utils.unicodeToHTML(rs.getString("descricao")));
// postos.add(p);
// }while(rs.next());
// }
// return postos;
// }
for( int i = 0; i < res.rowCount(); i++ )
{
Integer rId = res.get( i, 0 );
String rDescricao = res.get( i, 2 );
Medida m = new Medida();
m.setId( rId );
m.setMedida_id( rId );
if( rDescricao != null && rDescricao.trim().length() > 8)
{
m.setDescricao( Utils.unicodeToHTML( rDescricao ) );
m.setPostos( getPostosByMedida( r, m, a ) );
medidas.add( m );
}
}
return medidas;
}
private List<PostoTrabalho> getPostosByMedida(Risco r, Medida m, Area a) throws Exception
{
String sql = "select subquery.posto_id, valor, descricao, is_principal from ";
sql += "(select hs_relatorio_posto_medida.posto_id, hs_relatorio_posto.description as descricao, ";
sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null ";
sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade ";
sql += "else hs_relatorio_posto_risco.valor_qualitativo_id ";
sql += "end as valor, coalesce( hs_relatorio_posto.is_principal, false ) as is_principal ";
sql += "from hs_relatorio_posto_medida ";
sql += "inner join hs_relatorio_posto_risco on hs_relatorio_posto_risco.posto_id = hs_relatorio_posto_medida.posto_id ";
sql += "inner join hs_relatorio_posto on hs_relatorio_posto.id = hs_relatorio_posto_medida.posto_id ";
sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id ";
sql += "where medida_id = " + m.getId() + " and area_id = " + a.getId() + " and risco_id = " + r.getId() + ") subquery ";
//sql += "where valor = " + v.getValorQuantitativo();
System.out.println("POSTOS BY MEDIDA SQL : " + sql);
Statement st = createLocalStatement();
ResultSet rs = st.executeQuery( sql );
Select innerSelect = new Select2(
new String[] { HsRelatorioPostoMedidaData.TABLENAME, HsRelatorioPostoRiscoData.TABLENAME,
HsRelatorioPostoData.TABLENAME, HsRelatorioAreaData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
new Expression[]{
new Field( HsRelatorioPostoRiscoData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ) ),
new Field( HsRelatorioPostoData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID_FULL ) )
},
new String[]{ HsRelatorioPostoMedidaData.POSTO_ID_FULL,
HsRelatorioPostoData.DESCRIPTION_FULL,
"CASE WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null )
.and( new Field( HsRelatorioPostoRiscoData.PROBABILIDADE_FULL ).isEqual( null ) )
.and( new Field( HsRelatorioPostoRiscoData.SEVERIDADE_FULL ).isEqual( null ) ).toString() +
" THEN null WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null ) +
" THEN " + HsRelatorioPostoRiscoData.PROBABILIDADE_FULL + "*" + HsRelatorioPostoRiscoData.SEVERIDADE_FULL +
" ELSE " + HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL +
" END AS valor ",
"coalesce( " + HsRelatorioPostoData.IS_PRINCIPAL_FULL + ", false )" },
new Field( HsRelatorioPostoMedidaData.MEDIDA_ID ).isEqual( m.getId() )
.and( new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( r.getId() ) )
.and( new Field( HsRelatorioPostoData.AREA_ID_FULL ).isEqual( a.getId() ) ),
new String[]{ HsRelatorioRiscoData.ID_FULL }, null, null, null
);
Select select = new Select( MessageFormat.format( "SELECT subquery.posto_id, valor, descricao, is_principal FROM ( {0} ) subquery ", innerSelect.toString() ) );
System.out.println("POSTOS BY MEDIDA SQL : " + select.toString() );
Virtual2DArray res = getLocalExecuter( ).executeQuery( select );
List< PostoTrabalho > postos = new LinkedList< PostoTrabalho >();
if ( rs.isBeforeFirst() )
{
rs.first();
do
{
PostoTrabalho p = new PostoTrabalho();
p.setId( new Integer( rs.getInt("posto_id") ) );
p.setPosto_id( p.getId() );
p.setDescricao( Utils.unicodeToHTML( rs.getString( "descricao" ) ) );
p.setIs_principal( new Boolean( rs.getBoolean( "is_principal" ) ) );
postos.add( p );
}
while ( rs.next() );
}
return postos;
for( int i = 0; i < res.rowCount(); i++ )
{
Integer rPostoId = res.get( i, 0 );
String rDescricao = res.get( i, 2 );
Boolean rIsPrincipal = res.get( i, 3 );
PostoTrabalho p = new PostoTrabalho();
p.setId( rPostoId );
p.setPosto_id( rPostoId );
p.setDescricao( Utils.unicodeToHTML( rDescricao ) );
p.setIs_principal( rIsPrincipal );
postos.add( p );
}
return postos;
}
public List<ValorQualitativo> getValoresQualitativos()
throws Exception
{
String sql = "select id, description from hs_relatorio_risco_valor_qualitativo;";
System.out.println("VALORES QUALITATIVOS SQL : " + sql);
Statement st = createLocalStatement();
ResultSet rs = st.executeQuery( sql );
List< ValorQualitativo > valores = new LinkedList< ValorQualitativo >();
if ( rs.isBeforeFirst() )
{
rs.first();
do
{
ValorQualitativo v = new ValorQualitativo();
v.setId( new Integer( rs.getInt("id") ) );
v.setDescricao( Utils.unicodeToHTML( rs.getString( "description" ) ) );
valores.add( v );
}
while ( rs.next() );
}
return valores;
Select select = new Select2( HsRelatorioRiscoValorQualitativoData.TABLENAME, null, HsRelatorioRiscoValorQualitativoData.ID_FULL, HsRelatorioRiscoValorQualitativoData.DESCRIPTION_FULL );
System.out.println("VALORES QUALITATIVOS SQL : " + select.toString());
Virtual2DArray res = getLocalExecuter( ).executeQuery( select );
List< ValorQualitativo > valores = new LinkedList< ValorQualitativo >();
for( int i = 0; i < res.rowCount(); i++ )
{
Integer rId = res.get( i, 0 );
String rDescricao = res.get( i, 1 );
ValorQualitativo v = new ValorQualitativo();
v.setId( rId );
v.setDescricao( Utils.unicodeToHTML( rDescricao ) );
valores.add( v );
}
return valores;
}
public List<PlanoValoresQualitativosData> getValoresQualitativosOnline() throws Exception
@ -437,52 +453,95 @@ public class PlanosActuacaoImporterProvider extends GenericDataProvider
private boolean existemMedidasByArea( Integer areaID ) throws Exception
{
String sql = "select distinct medida_id, valor, descricao "
+ " from ( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, "
+ " case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "
+ " when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade else hs_relatorio_posto_risco.valor_qualitativo_id end as valor from hs_relatorio_posto "
+ " inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "
+ " inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "
+ " inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "
+ " inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) "
+ " inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "
+ " inner join hs_relatorio_area on hs_relatorio_area.id = area_id "
+ " where area_id = " + areaID + " and hs_relatorio_posto_medida.is_plano_actuacao = true) subquery "
+ " order by subquery.medida_id, valor";
Select innerSelect = new Select2(
new String[] { HsRelatorioPostoData.TABLENAME, HsRelatorioPostoMedidaData.TABLENAME,
HsRelatorioMedidaData.TABLENAME, HsRelatorioRiscoData.TABLENAME, HsRelatorioPostoRiscoData.TABLENAME,
HsRelatorioData.TABLENAME, HsRelatorioAreaData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER,
Select2.JOIN_INNER, Select2.JOIN_INNER },
new Expression[]{
new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) ),
new Field( HsRelatorioMedidaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.MEDIDA_ID_FULL ) ),
new Field( HsRelatorioRiscoData.ID_FULL ).isEqual( new Field( HsRelatorioMedidaData.RISCO_ID_FULL ) ),
new Field( HsRelatorioPostoRiscoData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) )
.and( new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.ID_FULL ) ) ),
new Field( HsRelatorioData.ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.RELATORIO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID_FULL ) )
},
new String[]{ "DISTINCT " + HsRelatorioPostoMedidaData.MEDIDA_ID_FULL,
HsRelatorioPostoRiscoData.RISCO_ID_FULL,
HsRelatorioMedidaData.DESCRIPTION_FULL,
"CASE WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null )
.and( new Field( HsRelatorioPostoRiscoData.PROBABILIDADE_FULL ).isEqual( null ) )
.and( new Field( HsRelatorioPostoRiscoData.SEVERIDADE_FULL ).isEqual( null ) ).toString() +
" THEN null WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null ) +
" THEN " + HsRelatorioPostoRiscoData.PROBABILIDADE_FULL + "*" + HsRelatorioPostoRiscoData.SEVERIDADE_FULL +
" ELSE " + HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL +
" END AS valor " },
new Field( HsRelatorioPostoData.AREA_ID_FULL ).isEqual( areaID )
.and( new Field( HsRelatorioPostoMedidaData.IS_PLANO_ACTUACAO_FULL ).isEqual( Boolean.TRUE ) ),
new String[]{ HsRelatorioRiscoData.ID_FULL }, null, null, null
);
Select select = new Select( MessageFormat.format( "SELECT distinct medida_id, valor, descricao FROM ( {0} ) subquery ORDER BY subquery.medida_id, valor ", innerSelect.toString() ) );
System.out.println( "\t\t\t\t\t\t\t\t\tprovider . existemMedidasByArea( " + areaID + " ) : " );
System.out.println( "\t\t\t\t\t\t\t\t\t\t\tSQL : " + sql );
System.out.println( "\t\t\t\t\t\t\t\t\t\t\tSQL : " + select.toString() );
Virtual2DArray res = getLocalExecuter( ).executeQuery( select );
Statement st = createLocalStatement();
ResultSet rs = st.executeQuery( sql );
return rs.isBeforeFirst();
return res.rowCount() > 0;
}
private boolean existemMedidasByRisco(Integer risco_id) throws Exception
{
String sql = "select distinct medida_id "
+ " from ( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, "
+ " case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "
+ " when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade else hs_relatorio_posto_risco.valor_qualitativo_id end as valor from hs_relatorio_posto "
+ " inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "
+ " inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "
+ " inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "
+ " inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) "
+ " inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "
+ " inner join hs_relatorio_area on hs_relatorio_area.id = area_id "
+ " where hs_relatorio_posto_risco.risco_id = " + risco_id + " and hs_relatorio_posto_medida.is_plano_actuacao = true) subquery "
+ " order by medida_id";
System.out.println("EXISTEM MEDIDAS BY RISCO SQL : " + sql);
Statement st = createLocalStatement();
ResultSet rs = st.executeQuery( sql );
return rs.isBeforeFirst();
Select innerSelect = new Select2(
new String[] { HsRelatorioPostoData.TABLENAME, HsRelatorioPostoMedidaData.TABLENAME,
HsRelatorioMedidaData.TABLENAME, HsRelatorioRiscoData.TABLENAME, HsRelatorioPostoRiscoData.TABLENAME,
HsRelatorioData.TABLENAME, HsRelatorioAreaData.TABLENAME },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER,
Select2.JOIN_INNER, Select2.JOIN_INNER },
new Expression[]{
new Field( HsRelatorioPostoMedidaData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) ),
new Field( HsRelatorioMedidaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoMedidaData.MEDIDA_ID_FULL ) ),
new Field( HsRelatorioRiscoData.ID_FULL ).isEqual( new Field( HsRelatorioMedidaData.RISCO_ID_FULL ) ),
new Field( HsRelatorioPostoRiscoData.POSTO_ID_FULL ).isEqual( new Field( HsRelatorioPostoData.ID_FULL ) )
.and( new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.ID_FULL ) ) ),
new Field( HsRelatorioData.ID_FULL ).isEqual( new Field( HsRelatorioRiscoData.RELATORIO_ID_FULL ) ),
new Field( HsRelatorioAreaData.ID_FULL ).isEqual( new Field( HsRelatorioPostoData.AREA_ID_FULL ) )
},
new String[]{ "DISTINCT " + HsRelatorioPostoMedidaData.MEDIDA_ID_FULL,
HsRelatorioPostoRiscoData.RISCO_ID_FULL,
HsRelatorioMedidaData.DESCRIPTION_FULL,
"CASE WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null )
.and( new Field( HsRelatorioPostoRiscoData.PROBABILIDADE_FULL ).isEqual( null ) )
.and( new Field( HsRelatorioPostoRiscoData.SEVERIDADE_FULL ).isEqual( null ) ).toString() +
" THEN null WHEN " +
new Field( HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL ).isEqual( null ) +
" THEN " + HsRelatorioPostoRiscoData.PROBABILIDADE_FULL + "*" + HsRelatorioPostoRiscoData.SEVERIDADE_FULL +
" ELSE " + HsRelatorioPostoRiscoData.VALOR_QUALITATIVO_ID_FULL +
" END AS valor " },
new Field( HsRelatorioPostoRiscoData.RISCO_ID_FULL ).isEqual( risco_id )
.and( new Field( HsRelatorioPostoMedidaData.IS_PLANO_ACTUACAO_FULL ).isEqual( Boolean.TRUE ) ),
new String[]{ HsRelatorioRiscoData.ID_FULL }, null, null, null
);
Select select = new Select( MessageFormat.format( "SELECT distinct medida_id FROM ( {0} ) subquery ORDER BY medida_id ", innerSelect.toString() ) );
System.out.println("EXISTEM MEDIDAS BY RISCO SQL : " + select.toString());
Virtual2DArray res = getLocalExecuter( ).executeQuery( select );
return res.rowCount() > 0;
}
public Integer createPlano( PlanoActuacao p ) throws Exception
{
Integer newPlanoID = null;
Integer newPlanoID;
Date todayDate = new Date();
boolean concluidoPorDesactivacao = p.getConcluidoPorDesactivacao() == null ? Boolean.FALSE : p.getConcluidoPorDesactivacao();
@ -535,7 +594,6 @@ public class PlanosActuacaoImporterProvider extends GenericDataProvider
planoData.setTecnico_superior_hs_nome( p.getTecnico_superior_hs_nome() );
planoData.setData_desactivacao( dataDesactivacao );
// planoData.setData_disponibilizacao( p.getData_disponibilizacao() );
planoData.setData_validacao_seg( null );
planoData.setUser_seg( null );
@ -552,7 +610,7 @@ public class PlanosActuacaoImporterProvider extends GenericDataProvider
public Integer createArea( Area a ) throws Exception
{
Integer newAreaID = null;
Integer newAreaID;
PlanoAreasData areaData = new PlanoAreasData();
areaData.setArea_id( a.getArea_id() );
@ -571,7 +629,7 @@ public class PlanosActuacaoImporterProvider extends GenericDataProvider
public Integer createRisco( Risco r ) throws Exception
{
Integer newRiscoID = null;
Integer newRiscoID;
PlanoRiscosData riscoData = new PlanoRiscosData();
riscoData.setDescricao( Utils.parseToInsert( r.getDescricao() ) );
@ -593,7 +651,7 @@ public class PlanosActuacaoImporterProvider extends GenericDataProvider
public Integer createMedida( Medida m ) throws Exception
{
Integer newMedidaID = null;
Integer newMedidaID;
PlanoMedidasData medidaData = new PlanoMedidasData();
medidaData.setMedida_id( m.getMedida_id() );
@ -650,20 +708,18 @@ public class PlanosActuacaoImporterProvider extends GenericDataProvider
valor.save();
}
//====================
public String getEmpresaNome( Integer empresaID ) throws Exception
{
String nome = null;
EmpresasData empresaData = getLocalProvider().load( EmpresasData.class, empresaID, EmpresasData.ID );
EmpresasData empresaData = getLocalProvider().load( EmpresasData.class, empresaID, EmpresasData.ID, null );
if ( empresaData != null )
{
nome = Utils.unicodeToHTML( empresaData.getDesignacao_social() );
}
else
{
ErrorLogger.logException( new Exception( "CreatePlanosDataProvider . getEmpresaNome( " + empresaID + " ) : is Null !" +
"\n\tempresaData = " + (empresaData == null ? "null" : "not null") + ", nome = " + nome ) );
ErrorLogger.logException( new Exception( "CreatePlanosDataProvider . getEmpresaNome( " + empresaID + " ) : is Null !" + "\n\tempresaData = " + ( "null" ) + ", nome = " + nome ) );
}
return nome;
}

Loading…
Cancel
Save