forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@1734 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
49ad4d0cf2
commit
b1673156b1
@ -0,0 +1,160 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package updates.updates;
|
||||
|
||||
import com.evolute.entity.ProviderInterface;
|
||||
import com.evolute.entity.evo.EvoDataException;
|
||||
import com.evolute.entity.evo.EvoDataObject;
|
||||
import com.evolute.module.updater.AbstractUpdate;
|
||||
import com.evolute.utils.Singleton;
|
||||
import db.DBConstants.DB;
|
||||
import db.data.siprp.outer.PlanoAreasData;
|
||||
import db.data.siprp.outer.PlanoMedidasData;
|
||||
import db.data.siprp.outer.PlanoPostosTrabalhoData;
|
||||
import db.data.siprp.outer.PlanoRiscosData;
|
||||
import db.data.siprp.outer.PlanosActuacaoData;
|
||||
import db.data.siprp_local.outer.HsRelatorioAreaData;
|
||||
import db.data.siprp_local.outer.HsRelatorioMedidaData;
|
||||
import db.data.siprp_local.outer.HsRelatorioPostoData;
|
||||
import db.data.siprp_local.outer.HsRelatorioRiscoData;
|
||||
import db.providers.EvoBaseProvider;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import utils.Utils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dneves
|
||||
*/
|
||||
public class FixPlanoImportedUnicode extends AbstractUpdate
|
||||
{
|
||||
|
||||
private ProviderInterface< EvoDataObject< ? >, EvoDataException > SIPRP = null;
|
||||
|
||||
private ProviderInterface< EvoDataObject< ? >, EvoDataException > LOCAL = null;
|
||||
|
||||
private final Integer planoID;
|
||||
|
||||
|
||||
public FixPlanoImportedUnicode( double start, double end, Integer planoID )
|
||||
{
|
||||
super( start, end, "Corrigir encoding de planos importados" );
|
||||
this.planoID = planoID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doUpdate() throws Exception
|
||||
{
|
||||
SIPRP = EvoBaseProvider.getInstance().getProvider( DB.SIPRP );
|
||||
LOCAL = EvoBaseProvider.getInstance().getProvider( DB.SIPRP_LOCAL );
|
||||
|
||||
PlanosActuacaoData planoActuacao = SIPRP.load( PlanosActuacaoData.class, planoID, PlanosActuacaoData.ID );
|
||||
System.out.println( "\nFixing planoActuacao ID : " + planoID + " = " + ( planoActuacao == null ? "null" : planoActuacao.getNome_estabelecimento() ) );
|
||||
fixAreas( planoActuacao );
|
||||
}
|
||||
|
||||
private void fixAreas( PlanosActuacaoData planoActuacao ) throws Exception
|
||||
{
|
||||
if ( planoActuacao != null )
|
||||
{
|
||||
List<PlanoAreasData> areas = planoActuacao.fromPlanoAreas_plano_id();
|
||||
for ( PlanoAreasData area : areas )
|
||||
{
|
||||
Integer hsRelatorioAreaID = area.getArea_id();
|
||||
HsRelatorioAreaData relatorioArea = LOCAL.load( HsRelatorioAreaData.class, hsRelatorioAreaID );
|
||||
if ( relatorioArea != null )
|
||||
{
|
||||
System.out.println( "\n\tAreaID : " + area.getId() + " = " + area.getDescricao() );
|
||||
System.out.println( "\tLocalAreaID : " + relatorioArea.getId() + " = " + relatorioArea.getDescription() );
|
||||
|
||||
area.setDescricao( Utils.parseToInsert( relatorioArea.getDescription() ) );
|
||||
area.save();
|
||||
}
|
||||
fixRiscos(area);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fixRiscos(PlanoAreasData area) throws Exception
|
||||
{
|
||||
List<PlanoRiscosData> riscos = area.fromPlanoRiscos_area_id();
|
||||
for (PlanoRiscosData risco : riscos)
|
||||
{
|
||||
Integer hsRelatorioRiscoID = risco.getRisco_id();
|
||||
HsRelatorioRiscoData relatorioRisco = LOCAL.load( HsRelatorioRiscoData.class, hsRelatorioRiscoID );
|
||||
if ( relatorioRisco != null )
|
||||
{
|
||||
System.out.println( "\n\t\tRiscoID : " + risco.getId() + " = " + risco.getDescricao() );
|
||||
System.out.println( "\t\tLocalRiscoID : " + relatorioRisco.getId() + " = " + relatorioRisco.getDescription() );
|
||||
|
||||
risco.setDescricao( Utils.parseToInsert( relatorioRisco.getDescription() ) );
|
||||
risco.save();
|
||||
}
|
||||
fixMedidas(risco);
|
||||
}
|
||||
}
|
||||
|
||||
private void fixMedidas(PlanoRiscosData risco) throws Exception
|
||||
{
|
||||
List<PlanoMedidasData> medidas = risco.fromPlanoMedidas_risco_id();
|
||||
for (PlanoMedidasData medida : medidas)
|
||||
{
|
||||
Integer hsRelatorioMedidaID = medida.getMedida_id();
|
||||
HsRelatorioMedidaData relatorioMedida = LOCAL.load( HsRelatorioMedidaData.class, hsRelatorioMedidaID );
|
||||
if ( relatorioMedida != null )
|
||||
{
|
||||
System.out.println( "\n\t\t\tMedidaID : " + medida.getId() + " = " + medida.getDescricao() );
|
||||
System.out.println( "\t\t\tLocalMedidaID : " + relatorioMedida.getId() + " = " + relatorioMedida.getDescription() );
|
||||
|
||||
medida.setDescricao( Utils.parseToInsert( relatorioMedida.getDescription() ) );
|
||||
medida.save();
|
||||
}
|
||||
fixPostosTrabalho(medida);
|
||||
}
|
||||
}
|
||||
|
||||
private void fixPostosTrabalho(PlanoMedidasData medida) throws Exception
|
||||
{
|
||||
List<PlanoPostosTrabalhoData> postosTrabalho = medida.fromPlanoPostosTrabalho_medida_id();
|
||||
for (PlanoPostosTrabalhoData posto : postosTrabalho)
|
||||
{
|
||||
Integer hsRelatorioPostoID = posto.getPosto_id();
|
||||
HsRelatorioPostoData relatorioPosto = LOCAL.load( HsRelatorioPostoData.class, hsRelatorioPostoID );
|
||||
if ( relatorioPosto != null )
|
||||
{
|
||||
System.out.println( "\n\t\t\t\tPostoID : " + posto.getId() + " = " + posto.getDescricao() );
|
||||
System.out.println( "\t\t\t\tLocalPostoID : " + relatorioPosto.getId() + " = " + relatorioPosto.getDescription() );
|
||||
|
||||
posto.setDescricao( Utils.parseToInsert( relatorioPosto.getDescription() ) );
|
||||
posto.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main( String ... args ) throws Exception
|
||||
{
|
||||
FixPlanoImportedUnicode update = new FixPlanoImportedUnicode( 0, 1, new Integer( 81 ) );
|
||||
|
||||
Properties props = new Properties();
|
||||
props.load( update.getClass().getClassLoader().getResourceAsStream( "app.properties" ) );
|
||||
|
||||
Set< Object > keySet = props.keySet();
|
||||
Iterator< Object > it = keySet.iterator();
|
||||
while ( it.hasNext() )
|
||||
{
|
||||
Object key = it.next();
|
||||
Object value = props.getProperty( ( String ) key );
|
||||
|
||||
Singleton.setInstance( ( String ) key, value );
|
||||
}
|
||||
|
||||
EvoBaseProvider.getInstance();
|
||||
|
||||
update.doUpdate();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package updates.updates;
|
||||
|
||||
import com.evolute.module.updater.AbstractUpdate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dneves
|
||||
*/
|
||||
public class Update3 extends AbstractUpdate
|
||||
{
|
||||
|
||||
public Update3( double start, double end )
|
||||
{
|
||||
super( start, end, "Corrigir encoding de planos importados" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doUpdate() throws Exception
|
||||
{
|
||||
// TODO : fix db unicode
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue