You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SIPRP/trunk/SIPRPSoft/src/siprp/cursos/provider/CursosTemplatesProvider.java

168 lines
7.0 KiB

package siprp.cursos.provider;
import static com.evolute.utils.strings.UnicodeLatin1Map.atilde;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import javax.swing.JOptionPane;
import com.evolute.genericpeople.AutorizacaoProviderInterface;
import com.evolute.genericpeople.DefaultTemplateProvider;
import com.evolute.genericpeople.PessoaInterface;
import com.evolute.genericpeople.TemplateConstants;
import com.evolute.module.cursos.CursosDataProvider;
import com.evolute.module.cursos.CursosLogic;
import com.evolute.module.cursos.data.CurCursosData;
import com.evolute.module.cursos.data.CurFormandosData;
import com.evolute.swing.frame.EvoFrame;
import com.evolute.utils.Singleton;
import com.evolute.utils.error.ErrorLogger;
import com.evolute.utils.tables.ColumnizedObjectArray;
import com.evolute.utils.xml.SimpleXMLElement;
public class CursosTemplatesProvider extends DefaultTemplateProvider
{
private CursosDataProvider cursosProvider = CursosDataProvider.getProvider();
public CursosTemplatesProvider()
{
setTemplate( TemplateConstants.SUMARIOS, "com/evolute/module/cursos/templates/sumarios.xsl" );
setTemplate( TemplateConstants.LISTA_PRESENCAS, "com/evolute/module/cursos/templates/lista_presencas.xsl" );
setTemplate( TemplateConstants.TOPICOS_FILE, "com/evolute/module/cursos/templates/topicos.xsl" );
setTemplate( TemplateConstants.CERTIFICADO_FORMANDO, "siprp/cursos/templates/certificado_formando.xsl" );
setTemplate( TemplateConstants.CERTIFICADO_FORMADOR, "siprp/cursos/templates/certificado_formador.xsl" );
setTemplate( TemplateConstants.INSCRICAO_ACEITE, "com/evolute/module/cursos/templates/inscricao_aceite.xsl" );
setTemplate( TemplateConstants.INSCRICAO_ACEITE_POPH, "com/evolute/module/cursos/templates/inscricao_aceite_POPH.xsl" );
setTemplate( TemplateConstants.INSCRICAO_REJEITADA, "com/evolute/module/cursos/templates/inscricao_rejeitada.xsl" );
setTemplate( TemplateConstants.CONFIRMAR_INSCRICAO, "com/evolute/module/cursos/templates/confirmar_inscricao.xsl" );
}
@Override
public SimpleXMLElement getXMLForImpressaoFormador( boolean visualizar, CurCursosData curso, EvoFrame parent, List< ColumnizedObjectArray > formadores )
throws Exception
{
return super.getXMLForImpressaoFormador( visualizar, curso, parent, formadores );
}
@Override
public SimpleXMLElement getXMLForImpressaoFormando( boolean visualizar, CurCursosData curso, EvoFrame parent, List< ColumnizedObjectArray > formandos )
throws Exception
{
SimpleXMLElement xml = null;
if( formandos != null && !formandos.isEmpty() )
{
CurFormandosData formando = cursosProvider.getFormandoByID( formandos.get( 0 ).getID() );
PessoaInterface pessoa = cursosProvider.getPessoaFromFormando( formando );
Integer numero = super.getNumeroCertificado( formando.getId(), curso.getId() );
if( numero == null )
{
return null;
}
String numCertificado = numero.toString();
Calendar cal = Calendar.getInstance();
String year = "" + cal.get( Calendar.YEAR );
year = year.substring( 2, year.length() );
numCertificado += "/" + year;
String nomePessoa = super.getNomePessoa( pessoa );
if( nomePessoa == null )
{
JOptionPane.showMessageDialog( parent, "O nome do formando tem de estar preenchido!", "Erro", JOptionPane.ERROR_MESSAGE, null );
return null;
}
String sexo = pessoa.getSexo();
if( sexo == null )
{
JOptionPane.showMessageDialog( parent, "O formador tem de ter o campo sexo preenchido", "Erro", JOptionPane.ERROR_MESSAGE, null);
return null;
}
String profissao = super.getProfissao( pessoa );
if( profissao == null )
{
JOptionPane.showMessageDialog( parent, "A profiss" + atilde + "o do formando tem de estar preenchida!", "Erro", JOptionPane.ERROR_MESSAGE, null );
return null;
}
String naturalidade = super.getNaturalDe( pessoa );
if( naturalidade == null )
{
JOptionPane.showMessageDialog( parent, "A naturalidade do formando tem de estar preenchida!", "Erro", JOptionPane.ERROR_MESSAGE, null );
return null;
}
String dataNascimento = super.getDataNascimento( pessoa );
if( dataNascimento == null )
{
JOptionPane.showMessageDialog( parent, "A data de nascimento do formando tem de estar preenchida", "Erro", JOptionPane.ERROR_MESSAGE, null);
return null;
}
String nacionalidade = super.getNacionalidade( pessoa );
if( nacionalidade == null )
{
JOptionPane.showMessageDialog( parent, "A nacionalidade do formando tem de estar preenchida", "Erro", JOptionPane.ERROR_MESSAGE, null);
return null;
}
String bi_numero = pessoa.getBINumero() == null || "".equals( pessoa.getBINumero().trim() ) ? "" : "portadora do Bilhete de Identidade nº " + pessoa.getBINumero() + ", ";
String bi_emissao = pessoa.getBIArquivo() == null || "".equals( pessoa.getBIArquivo().trim() ) ? "" : " emitido em " + pessoa.getBIArquivo() + ", ";
String bi_data_emissao = pessoa.getBIData() == null ? "" : "em " + DefaultTemplateProvider.D_F.format( pessoa.getBIData() ) + ", ";
xml = new SimpleXMLElement( CERTIFICADO_FORMANDO_XML_NAME );
xml.addElement( new SimpleXMLElement( "numero_certificado", numCertificado ) );
xml.addElement( new SimpleXMLElement( "signature_filename1", visualizar ? "": AutorizacaoProviderInterface.ASSINATURA1_FILENAME ) );
xml.addElement( new SimpleXMLElement( "nome_pessoa", nomePessoa ) );
xml.addElement( new SimpleXMLElement( "profissao", profissao ) );
xml.addElement( new SimpleXMLElement( "naturalidade", naturalidade ) );
xml.addElement( new SimpleXMLElement( "data_nascimento", dataNascimento ) );
xml.addElement( new SimpleXMLElement( "nacionalidade", nacionalidade ) );
xml.addElement( new SimpleXMLElement( "sexo", sexo ) );
xml.addElement( new SimpleXMLElement( "bi_numero", bi_numero ) );
xml.addElement( new SimpleXMLElement( "bi_emissao", bi_emissao ) );
xml.addElement( new SimpleXMLElement( "bi_data_emissao", bi_data_emissao ) );
//TODO : -certificado
xml.addElement( new SimpleXMLElement( "nome_formadora", "TODO - nome formadora" ) );
xml.addElement( new SimpleXMLElement( "nome_formadora_e_responsavel", "TODO - nome formadora e responsavel" ) );
xml.addElement( new SimpleXMLElement( "nr_livro_registo", "TODO - NUMERO" ) );
xml.addElement( new SimpleXMLElement( "numero_certificado", numCertificado ) );
try
{
if( CursosLogic.getInstance().fillDadosCurso( parent, xml, curso, null ) )
{
Date today = (Date) Singleton.getInstance( Singleton.TODAY );
SimpleXMLElement dataCorrenteElement = new SimpleXMLElement( "data_corrente", new SimpleDateFormat( "dd' de 'MMMM' de 'yyyy", new Locale( "pt", "PT" ) ).format( today ) );
xml.addElement( dataCorrenteElement );
System.out.println( xml );
}
else
{
xml = null;
}
}
catch( Exception ex )
{
ErrorLogger.logException( ex );
}
}
else
{
xml = super.generateXMLTesteFormando( parent, curso );
}
return xml;
}
}