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