git-svn-id: https://svn.coded.pt/svn/SIPRP@937 bb69d46d-e84e-40c8-a05a-06db0d633741

lxbfYeaa
Frederico Palma 17 years ago
parent 5aa9a36334
commit 249682fd87

@ -103,7 +103,8 @@ public class SIPRPDataLoader implements CompanyDataLoader
Singleton.setInstance( SingletonConstants.LOCAL_USER, "postgres" );
Singleton.setInstance( SingletonConstants.LOCAL_PASSWORD, "Typein" );
Singleton.setInstance( SingletonConstants.LOCAL_URL_PREFIX, "jdbc:postgresql://" );
Singleton.setInstance( SingletonConstants.LOCAL_URL, "10.158.2.2:5432" );
// Singleton.setInstance( SingletonConstants.LOCAL_URL, "10.158.2.2:5432" );
Singleton.setInstance( SingletonConstants.LOCAL_URL, "localhost:5436" );
Singleton.setInstance( SingletonConstants.LOCAL_DB_NAME, "siprp_local" );
Singleton.setInstance( SingletonConstants.LOCAL_DRIVER_NAME, "org.postgresql.Driver" );
//

@ -1,35 +1,220 @@
package siprp.higiene.gestao.importacao;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Vector;
import com.evolute.utils.xml.XSLTransformer;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import siprp.planoactuacao.db.DBConstants;
import com.evolute.utils.arrays.Virtual2DArray;
import com.evolute.utils.db.DBManager;
import com.evolute.utils.db.Executer;
import com.evolute.utils.db.JDBCManager;
import com.evolute.utils.db.keyretrievers.JDBCAutoKeyRetriever;
import com.evolute.utils.sql.Assignment;
import com.evolute.utils.sql.Expression;
import com.evolute.utils.sql.Field;
import com.evolute.utils.sql.Insert;
import com.evolute.utils.sql.Select;
import com.evolute.utils.sql.Select2;
import com.evolute.utils.strings.UnicodeChecker;
public class Importador
{
private Executer EXECUTER;
public static void main( String args[] )
throws Exception
{
Importador importador = new Importador();
importador.converter();
Insert.setDefaultKeyRetriever( JDBCAutoKeyRetriever.DEFAULT );
UnicodeChecker.setUseDoubleSlash( true );
String url = "jdbc:postgresql://localhost:5436/siprp_local";
String user = "postgres";
String pwd = "Typein";
DBManager dbm = new JDBCManager( url, user, pwd, 10, 8, 8, null );
Importador importador = new Importador( dbm.getSharedExecuter() );
// importador.converter();
importador.importar();
}
public void converter()
public Importador( Executer executer )
throws Exception
{
InputStream xsl = getClass().getClassLoader().getResourceAsStream( "siprp/higiene/gestao/importacao/importacao_ods_to_xml.xsl" );
InputStream xmlContent = getClass().getClassLoader().getResourceAsStream( "siprp/higiene/gestao/importacao/content.xml" );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XSLTransformer.getXSLTransformer().transform( xmlContent, xsl, baos );
FileOutputStream fos = new FileOutputStream( "/home/fpalma/projectos2/SIPRP/SIPRPSoft/src/siprp/higiene/gestao/importacao/data.xml" );
fos.write( baos.toByteArray() );
fos.close();
System.out.println( new String( baos.toByteArray() ) );
// DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
// EXECUTER = dbm.getSharedExecuter();
EXECUTER = executer;
}
// NAO APAGAR
// public void converter()
// throws Exception
// {
// InputStream xsl = getClass().getClassLoader().getResourceAsStream( "siprp/higiene/gestao/importacao/importacao_ods_to_xml.xsl" );
// InputStream xmlContent = getClass().getClassLoader().getResourceAsStream( "siprp/higiene/gestao/importacao/content.xml" );
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// XSLTransformer.getXSLTransformer().transform( xmlContent, xsl, baos );
// FileOutputStream fos = new FileOutputStream( "/home/fpalma/projectos2/SIPRP/SIPRPSoft/src/siprp/higiene/gestao/importacao/data.xml" );
// fos.write( baos.toByteArray() );
// fos.close();
// }
public void importar()
throws Exception
{
SAXBuilder builder = new SAXBuilder();
InputStream fileFoIs = getClass().getClassLoader().getResourceAsStream( "siprp/higiene/gestao/importacao/data.xml" );
Document fileDocument = builder.build( fileFoIs );
Element root = fileDocument.getRootElement();
List<Element> entradas = root.getChildren( "entrada" );
for( Element entrada : entradas )
{
Element temaElement = entrada.getChild( "tema" );
String tema = getTexto( temaElement );
Element riscoElement = entrada.getChild( "risco" );
String risco = getTexto( riscoElement );
Element requisitoElement = entrada.getChild( "requisito" );
String requisito = getTexto( requisitoElement );
Element medidaElement = entrada.getChild( "medida" );
String medida = getTexto( medidaElement );
if( tema.length() == 0 || risco.length() == 0 )
{
continue;
}
Integer idTema = inserirTema( tema );
Integer idRisco = inserirRisco( idTema, risco );
inserirMedida( idRisco, medida, requisito );
}
}
protected String getTexto( Element elemento )
{
List<Element> linhas = elemento != null ? elemento.getChildren( "linha" ) : new Vector<Element>();
String texto = limparEspacos( linhas.size() > 0 ? linhas.get( 0 ).getText() : "" );
for( int l = 1; l < linhas.size(); l++ )
{
String linha = limparEspacos( linhas.get( 0 ).getText() );
texto += "\n" + linha;
}
return texto.trim();
}
protected String limparEspacos( String texto )
{
texto = texto.replaceAll( "\n", " " );
texto = texto.replaceAll( "\t", "" );
while( texto.indexOf( " " ) != -1 )
{
texto = texto.replaceAll( " ", " " );
}
return texto;
}
protected Integer inserirTema( String tema )
throws Exception
{
Select select =
new Select2(
new String[]{ "hs_risco_tema" },
new Integer[]{},
new Expression[]{},
new String[]{ "id" },
new Field( "description" ).isEqual( tema ),
null,
null,
null,
null );
Virtual2DArray array = EXECUTER.executeQuery( select );
Integer id = ( array.columnLength() > 0 && array.get( 0, 0 ) != null ) ? ( Integer ) array.get( 0, 0 ) : null;
if( id == null )
{
Insert insert =
new Insert( "hs_risco_tema",
new Assignment[]{
new Assignment( "description", tema )
} );
EXECUTER.executeQuery( insert );
id = inserirTema( tema );
}
return id;
}
protected Integer inserirRisco( Integer temaId, String risco )
throws Exception
{
Select select =
new Select2(
new String[]{ "hs_risco" },
new Integer[]{},
new Expression[]{},
new String[]{ "id" },
new Field( "description" ).isEqual( risco ).and(
new Field( "tema_id" ).isEqual( temaId ) ),
null,
null,
null,
null );
Virtual2DArray array = EXECUTER.executeQuery( select );
Integer id = ( array.columnLength() > 0 && array.get( 0, 0 ) != null ) ? ( Integer ) array.get( 0, 0 ) : null;
if( id == null )
{
Insert insert =
new Insert( "hs_risco",
new Assignment[]{
new Assignment( "description", risco ),
new Assignment( "tema_id", temaId )
} );
EXECUTER.executeQuery( insert );
id = inserirRisco( temaId, risco );
}
return id;
}
protected Integer inserirMedida( Integer riscoId, String medida, String requisito )
throws Exception
{
Select select =
new Select2(
new String[]{ "hs_medida", "hs_risco_medida" },
new Integer[]{ Select2.JOIN_LEFT_OUTER },
new Expression[]{
new Field( "hs_medida.id" ).isEqual( new Field( "hs_risco_medida.medida_id" ) ).and(
new Field( "hs_risco_medida.risco_id" ).isEqual( riscoId ) )
},
new String[]{ "hs_medida.id" },
new Field( "hs_medida.description" ).isEqual( medida ).and(
new Field( "hs_medida.requesitos_legais" ).isEqual( requisito ) ),
null,
null,
null,
null );
Virtual2DArray array = EXECUTER.executeQuery( select );
Integer id = array.columnLength() > 0 ? ( Integer ) array.get( 0, 0 ) : null;
if( id == null )
{
Insert insert =
new Insert( "hs_medida",
new Assignment[]{
new Assignment( new Field( "description" ), medida ),
new Assignment( new Field( "requesitos_legais" ), requisito ),
} );
EXECUTER.executeQuery( insert );
id = inserirMedida( null, medida, requisito );
insert =
new Insert( "hs_risco_medida",
new Assignment[]{
new Assignment( new Field( "medida_id" ), id ),
new Assignment( new Field( "risco_id" ), riscoId ),
} );
EXECUTER.executeQuery( insert );
}
return id;
}
}

File diff suppressed because it is too large Load Diff

@ -28,8 +28,8 @@
<xsl:template match="table:table">
<xsl:for-each select="table:table-row">
<entrada>
<xsl:if test="position() &gt; 1">
<entrada>
<xsl:for-each select="table:table-cell">
<xsl:choose>
<xsl:when test="position() = 1">
@ -54,8 +54,8 @@
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:if>
</entrada>
</xsl:if>
</xsl:for-each>
</xsl:template>

@ -16,6 +16,27 @@ import siprp.update.updates.V10_1_To_V10_2;
import siprp.update.updates.V10_2_To_V10_3;
import siprp.update.updates.V10_3_To_V10_4;
import siprp.update.updates.V10_4_To_V10_5;
import siprp.update.updates.V10_5_To_V10_6;
import siprp.update.updates.V6_1_To_V7_0;
import siprp.update.updates.V7_0_To_V7_2;
import siprp.update.updates.V7_2_To_V7_4;
import siprp.update.updates.V7_4_To_V7_5;
import siprp.update.updates.V7_5_To_V7_6;
import siprp.update.updates.V7_6_To_V7_7;
import siprp.update.updates.V7_7_To_V7_8;
import siprp.update.updates.V7_8_To_V7_9;
import siprp.update.updates.V7_9_To_V8_0;
import siprp.update.updates.V8_0_To_V8_1;
import siprp.update.updates.V8_1_To_V8_2;
import siprp.update.updates.V8_2_To_V8_3;
import siprp.update.updates.V8_3_To_V8_4;
import siprp.update.updates.V8_4_To_V8_5;
import siprp.update.updates.V8_5_To_V8_6;
import siprp.update.updates.V8_6_To_V8_7;
import siprp.update.updates.V8_7_To_V8_8;
import siprp.update.updates.V8_8_To_V8_9;
import siprp.update.updates.V8_9_To_V9_0;
import siprp.update.updates.V9_0_To_V9_1;
import siprp.update.updates.V9_1_To_V9_2;
import siprp.update.updates.V9_2_To_V9_3;
import siprp.update.updates.V9_3_To_V9_4;
@ -44,23 +65,24 @@ public class UpdateList
{
protected static final Update UPDATE_LIST[] =
new Update[]{
// new V6_1_To_V7_0(), new V7_0_To_V7_2(),
// new V7_2_To_V7_4(), new V7_4_To_V7_5(),
// new V7_5_To_V7_6(), new V7_6_To_V7_7(),
// new V7_7_To_V7_8(), new V7_8_To_V7_9(),
// new V7_9_To_V8_0(), new V8_0_To_V8_1(),
// new V8_1_To_V8_2(), new V8_2_To_V8_3(),
// new V8_3_To_V8_4(), new V8_4_To_V8_5(),
// new V8_5_To_V8_6(), new V8_6_To_V8_7(),
// new V8_7_To_V8_8(), new V8_8_To_V8_9(),
// new V8_9_To_V9_0(), new V9_0_To_V9_1(),
new V6_1_To_V7_0(), new V7_0_To_V7_2(),
new V7_2_To_V7_4(), new V7_4_To_V7_5(),
new V7_5_To_V7_6(), new V7_6_To_V7_7(),
new V7_7_To_V7_8(), new V7_8_To_V7_9(),
new V7_9_To_V8_0(), new V8_0_To_V8_1(),
new V8_1_To_V8_2(), new V8_2_To_V8_3(),
new V8_3_To_V8_4(), new V8_4_To_V8_5(),
new V8_5_To_V8_6(), new V8_6_To_V8_7(),
new V8_7_To_V8_8(), new V8_8_To_V8_9(),
new V8_9_To_V9_0(), new V9_0_To_V9_1(),
new V9_1_To_V9_2(), new V9_2_To_V9_3(),
new V9_3_To_V9_4(), new V9_4_To_V9_5(),
new V9_5_To_V9_6(), new V9_6_To_V9_7(),
new V9_7_To_V9_8(), new V9_8_To_V9_9(),
new V9_9_To_V10_0(), new V10_0_To_V10_1(),
new V10_1_To_V10_2(), new V10_2_To_V10_3(),
new V10_3_To_V10_4(), new V10_4_To_V10_5()
new V10_3_To_V10_4(), new V10_4_To_V10_5(),
new V10_5_To_V10_6()
};
protected static Executer EXECUTER;

Loading…
Cancel
Save