/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package analiseacidentestrabalho; import beans.EstatisticaProcessoBean; import beans.Utilizador; import com.evolute.utils.error.ErrorLogger; import com.sun.rave.web.ui.appbase.AbstractPageBean; import com.sun.rave.web.ui.component.Button; import com.sun.rave.web.ui.component.DropDown; import com.sun.rave.web.ui.component.Hyperlink; import com.sun.rave.web.ui.component.RadioButton; import com.sun.rave.web.ui.component.RadioButtonGroup; import com.sun.rave.web.ui.component.StaticText; import com.sun.rave.web.ui.component.Table; import com.sun.rave.web.ui.component.TextField; import com.sun.rave.web.ui.model.Option; import db.EstatisticasConstants; import db.data.siprp.outer.SeccoesData; import db.providers.AnalisesDataProvider; import db.providers.EstatisticasDataProvider; import global.Global; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.faces.FacesException; import javax.faces.context.FacesContext; import javax.servlet.http.HttpServletResponse; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import utils.Utils; /** * * @author dneves */ public class EstatisticasProcesso extends AbstractPageBean { private Hyperlink lnkPlanosActuacao = new Hyperlink(); public Hyperlink getLnkPlanosActuacao() { return lnkPlanosActuacao; } public void setLnkPlanosActuacao( Hyperlink h ) { this.lnkPlanosActuacao = h; } private Hyperlink lnkAnaliseAcidentes = new Hyperlink(); public Hyperlink getLnkAnaliseAcidentes() { return lnkAnaliseAcidentes; } public void setLnkAnaliseAcidentes( Hyperlink lnkAnaliseAcidentes ) { this.lnkAnaliseAcidentes = lnkAnaliseAcidentes; } private StaticText lblUser = new StaticText(); public StaticText getLblUser() { return lblUser; } public void setLblUser( StaticText st ) { this.lblUser = st; } private StaticText txtMsg = new StaticText(); public StaticText getTxtMsg() { return txtMsg; } public void setTxtMsg( StaticText st ) { this.txtMsg = st; } private TextField textPOR = new TextField(); public TextField getTextPOR() { return textPOR; } public void setTextPOR( TextField tf ) { this.textPOR = tf; } private TextField textNome = new TextField(); public TextField getTextNome() { return textNome; } public void setTextNome( TextField tf ) { this.textNome = tf; } private TextField textAnoOcorrencia = new TextField(); public TextField getTextAnoOcorrencia() { return textAnoOcorrencia; } public void setTextAnoOcorrencia( TextField tf ) { this.textAnoOcorrencia = tf; } // private com.sun.rave.web.ui.component.Calendar calDataOcorrencia = new com.sun.rave.web.ui.component.Calendar(); // public com.sun.rave.web.ui.component.Calendar getCalDataOcorrencia() // { // return this.calDataOcorrencia; // } // public void setCalDataOcorrencia( com.sun.rave.web.ui.component.Calendar c ) // { // this.calDataOcorrencia = c; // } private Date calDataOcorrencia = null; public Date getCalDataOcorrencia() { return calDataOcorrencia; } public void setCalDataOcorrencia( Date calDataOcorrencia ) { this.calDataOcorrencia = calDataOcorrencia; } private TextField textHoraOcorrencia = new TextField(); public TextField getTextHoraOcorrencia() { return textHoraOcorrencia; } public void setTextHoraOcorrencia( TextField tf ) { this.textHoraOcorrencia = tf; } private TextField textHorasTrabalhadas = new TextField(); public TextField getTextHorasTrabalhadas() { return textHorasTrabalhadas; } public void setTextHorasTrabalhadas( TextField tf ) { this.textHorasTrabalhadas = tf; } private Table tableEstatisticas = new Table(); public Table getTableEstatisticas() { return tableEstatisticas; } public void setTableEstatisticas( Table t ) { this.tableEstatisticas = t; } private DropDown dropCausas = new DropDown(); public DropDown getDropCausas() { return dropCausas; } public void setDropCausas(DropDown dropCausas) { this.dropCausas = dropCausas; } // private TextField textDepartamento = new TextField(); // public TextField getTextDepartamento() { // return textDepartamento; // } // public void setTextDepartamento(TextField textDepartamento) { // this.textDepartamento = textDepartamento; // } private DropDown dropEstabelecimentos = new DropDown(); public DropDown getDropEstabelecimentos() { return dropEstabelecimentos; } public void setDropEstabelecimentos( DropDown dropEstabelecimentos ) { this.dropEstabelecimentos = dropEstabelecimentos; } private DropDown dropSeccoes = new DropDown(); public DropDown getDropSeccoes() { return dropSeccoes; } public void setDropSeccoes(DropDown dropSeccoes) { this.dropSeccoes = dropSeccoes; } private DropDown dropTurno = new DropDown(); public DropDown getDropTurno() { return dropTurno; } public void setDropTurno(DropDown dropTurno) { this.dropTurno = dropTurno; } private RadioButtonGroup formacaoSHST = new RadioButtonGroup(); public RadioButtonGroup getFormacaoSHST() { return formacaoSHST; } public void setFormacaoSHST( RadioButtonGroup bg ) { this.formacaoSHST = bg; } private RadioButton formacaoSHST_true = new RadioButton(); public RadioButton getFormacaoSHST_true() { return formacaoSHST_true; } public void setFormacaoSHST_true(RadioButton formacaoSHST_true) { this.formacaoSHST_true = formacaoSHST_true; } private RadioButton formacaoSHST_false = new RadioButton(); public RadioButton getFormacaoSHST_false() { return formacaoSHST_false; } public void setFormacaoSHST_false(RadioButton formacaoSHST_false) { this.formacaoSHST_false = formacaoSHST_false; } private RadioButton formacaoSHST_none = new RadioButton(); public RadioButton getFormacaoSHST_none() { return formacaoSHST_none; } public void setFormacaoSHST_none( RadioButton formacaoSHST_none ) { this.formacaoSHST_none = formacaoSHST_none; } private RadioButton participacaoSeguro_true = new RadioButton(); public RadioButton getParticipacaoSeguro_true() { return participacaoSeguro_true; } public void setParticipacaoSeguro_true(RadioButton participacaoSeguro_true) { this.participacaoSeguro_true = participacaoSeguro_true; } private RadioButton participacaoSeguro_none = new RadioButton(); public RadioButton getParticipacaoSeguro_none() { return participacaoSeguro_none; } public void setParticipacaoSeguro_none( RadioButton participacaoSeguro_none ) { this.participacaoSeguro_none = participacaoSeguro_none; } private RadioButton postoAcidentado_true = new RadioButton(); private RadioButton postoAcidentado_false = new RadioButton(); private RadioButton outrosColaboradores_true = new RadioButton(); private RadioButton outrosColaboradores_false = new RadioButton(); public RadioButton getOutrosColaboradores_false() { return outrosColaboradores_false; } public void setOutrosColaboradores_false(RadioButton outrosColaboradores_false) { this.outrosColaboradores_false = outrosColaboradores_false; } public RadioButton getOutrosColaboradores_true() { return outrosColaboradores_true; } public void setOutrosColaboradores_true(RadioButton outrosColaboradores_true) { this.outrosColaboradores_true = outrosColaboradores_true; } public RadioButton getPostoAcidentado_false() { return postoAcidentado_false; } public void setPostoAcidentado_false(RadioButton postoAcidentado_false) { this.postoAcidentado_false = postoAcidentado_false; } public RadioButton getPostoAcidentado_true() { return postoAcidentado_true; } public void setPostoAcidentado_true(RadioButton postoAcidentado_true) { this.postoAcidentado_true = postoAcidentado_true; } private Button buttonExport = new Button(); public Button getButtonExport() { return buttonExport; } public void setButtonExport(Button buttonExport) { this.buttonExport = buttonExport; } private List< EstatisticaProcessoBean > listEstatisticas = new LinkedList< EstatisticaProcessoBean >(); public List< EstatisticaProcessoBean > getListEstatisticas() { return this.listEstatisticas; } public void setListEstatisticas( List< EstatisticaProcessoBean > l ) { this.listEstatisticas = l; } private boolean canAccess() { boolean canAccess = false; canAccess = getSessionBean1().getCanAccessEstatisticas(); return canAccess; } @Override public void init() { super.init(); try { _init(); } catch ( Exception e ) { log("Page1 Initialization Failure", e); throw e instanceof FacesException ? (FacesException) e : new FacesException(e); } if ( ! canAccess() ) { try { getExternalContext().redirect( "Login.jsp" ); } catch( Exception e ) { ErrorLogger.logException( e ); } } formacaoSHST_none.setSelected( true ); participacaoSeguro_none.setSelected( true ); } protected SessionBean1 getSessionBean1() { return ( SessionBean1 ) getBean( "SessionBean1" ); } /** *

Callback method that is called after the component tree has been * restored, but before any event processing takes place. This method * will only be called on a postback request that * is processing a form submit. Customize this method to allocate * resources that will be required in your event handlers.

*/ @Override public void preprocess() { txtMsg.setText( getSessionBean1().getMsg() ); getSessionBean1().setMsg( "" ); } /** *

Callback method that is called just before rendering takes place. * This method will only be called for the page that * will actually be rendered (and not, for example, on a page that * handled a postback and then navigated to a different page). Customize * this method to allocate resources that will be required for rendering * this page.

*/ @Override public void prerender() { System.out.println( "=== ESTATISTICAS_PROCESSO ===" ); lblUser.setText( getSessionBean1().getCurrentUser().getLogin() ); Option[] turnosOptions = new Option[ 5 ]; turnosOptions[ 0 ] = new Option( "", "" ); turnosOptions[ 1 ] = new Option( "m", "Manhã" ); turnosOptions[ 2 ] = new Option( "t", "Tarde" ); turnosOptions[ 3 ] = new Option( "n", "Noite" ); turnosOptions[ 4 ] = new Option( "o", "Outro" ); dropTurno.setItems( turnosOptions ); try { EstatisticasDataProvider statsProvider = EstatisticasDataProvider.getInstance(); Option[] causas = AnalisesDataProvider.getInstance().getCausasAcidente( true ); if ( causas != null ) { dropCausas.setItems( causas ); } Option[] seccoes = statsProvider.getSeccoesList(); if ( seccoes != null ) { dropSeccoes.setItems( seccoes ); } Option[] estabelecimentos = null; if ( getSessionBean1().isLoggedIn() && getSessionBean1().getCurrentUser() != null && getSessionBean1().getCurrentUser().getTipo() != null ) { int tipo = getSessionBean1().getCurrentUser().getTipo().intValue(); if( tipo == Global.TIPO_UTILIZADOR_DIRECTOR_SIPRP || tipo == Global.TIPO_UTILIZADOR_HS || tipo == Global.TIPO_UTILIZADOR_GESTOR || tipo == Global.TIPO_UTILIZADOR_DIRECTOR_GERAL_RH || tipo == Global.TIPO_UTILIZADOR_DIRECTOR_NACIONAL_SEGURANCA ) { estabelecimentos = statsProvider.getEstabelecimentos(); } else { Integer estabelecimentoId = getSessionBean1().getCurrentUser().getEstabelecimento_id(); String estabelecimentoNome = statsProvider.getEstabelecimentoByID( estabelecimentoId ); estabelecimentos = new com.sun.rave.web.ui.model.Option[]{ new Option( estabelecimentoId, estabelecimentoNome ) }; } } if ( estabelecimentos != null ) { dropEstabelecimentos.setItems( estabelecimentos ); } } catch ( Exception e ) { ErrorLogger.logException( e ); } } /** *

Callback method that is called after rendering is completed for * this request, if init() was called (regardless of whether * or not this was the page that was actually rendered). Customize this * method to release resources acquired in the init(), * preprocess(), or prerender() methods (or * acquired during execution of an event handler).

*/ @Override public void destroy() { } /** *

Automatically managed component initialization. WARNING: * This method is automatically generated, so any user-specified code inserted * here is subject to being replaced.

*/ private void _init() { } public String lnkAnalisesAcidente_action() { Utilizador currentUser = getSessionBean1().getCurrentUser(); int userType = currentUser == null ? -1 : currentUser.getTipo() == null ? -1 : currentUser.getTipo().intValue(); switch ( userType ) { case Global.TIPO_UTILIZADOR_SEGURANCA : return "form_seguranca"; case Global.TIPO_UTILIZADOR_RH : return "form_rh"; case Global.TIPO_UTILIZADOR_HS : return "form_hs"; case Global.TIPO_UTILIZADOR_DIRECTOR_SIPRP : return "form_dir_siprp"; case Global.TIPO_UTILIZADOR_DIRECTOR_GERAL_RH : return "form_dir_ger_rh"; case Global.TIPO_UTILIZADOR_GESTOR : return "form_gestor"; } return null; } public String lnkPlanosActuacao_action() { Utilizador u = getSessionBean1().getCurrentUser(); FacesContext fc = getFacesContext().getCurrentInstance(); Global.redirectToPlanos(fc, u); return null; } public String lnkNewUser_action() { getSessionBean1().setNavFrom( "EstatisticasProcesso" ); return "gestao_utilizadores"; } public String lnkEditUser_action() { getSessionBean1().setNavFrom( "EstatisticasProcesso" ); getSessionBean1().setModoEdicaoUtilizador( "edit" ); return "user"; } public String lnkLogout_action() { Utils.doLogout( getExternalContext(), true ); return null; } private Map< String, Object > getFormFieldValues() { String por = null; if ( textPOR.getText() != null ) { por = ( ( String ) textPOR.getText() ).trim(); por = "".equals( por ) ? null : por; } String nome = null; if ( textNome.getText() != null ) { nome = ( ( String ) textNome.getText() ).trim(); nome = "".equals( nome ) ? null : nome; } String anoOcorrencia = null; if ( textAnoOcorrencia.getText() != null ) { anoOcorrencia = ( ( String ) textAnoOcorrencia.getText() ).trim(); anoOcorrencia = "".equals( anoOcorrencia ) ? null : anoOcorrencia; } Date dataOcorrencia = null; // if ( calDataOcorrencia.getValue() != null ) // { // dataOcorrencia = ( Date )calDataOcorrencia.getValue(); // } dataOcorrencia = calDataOcorrencia; String horaOcorrencia = null; if ( textHoraOcorrencia.getText() != null ) { horaOcorrencia = ( ( String ) textHoraOcorrencia.getText() ).trim(); horaOcorrencia = "".equals( horaOcorrencia ) ? null : horaOcorrencia; } String horasTrabalhadas = null; if ( textHorasTrabalhadas.getText() != null ) { horasTrabalhadas = ( ( String ) textHorasTrabalhadas.getText() ).trim(); horasTrabalhadas = "".equals( horasTrabalhadas ) ? null : horasTrabalhadas; } // String departamento = null; // if ( textDepartamento.getText() != null ) // { // departamento = ( ( String ) textDepartamento.getText() ).trim(); // departamento = "".equals( departamento ) ? null : departamento; // } Integer estabelecimentoID = null; if ( dropEstabelecimentos.getSelected() != null ) { String estabelecimento = ( String ) dropEstabelecimentos.getSelected(); if ( estabelecimento != null ) { try { estabelecimentoID = Integer.parseInt( estabelecimento ); } catch ( Exception e ) { } } } Integer seccaoID = null; if ( dropSeccoes.getSelected() != null ) { // seccaoID = ( Integer ) dropSeccoes.getSelected(); String seccao = ( String ) dropSeccoes.getSelected(); if ( seccao != null ) { try { seccaoID = Integer.parseInt( seccao ); } catch ( Exception e ) { } } } Integer causas = null; if ( dropCausas.getSelected() != null ) { String causaID = ( String ) dropCausas.getSelected(); if ( causaID != null ) { try { causas = Integer.parseInt( causaID ); } catch ( Exception e ) { } } } String turno = null; if ( dropTurno.getSelected() != null ) { turno = ( String ) dropTurno.getSelected(); turno = turno == null || "".equals( turno.trim() ) ? null : turno; } Boolean shst = null; if ( formacaoSHST_true.getSelected() != null || formacaoSHST_false.getSelected() != null || formacaoSHST_none.getSelected() != null ) { Boolean trueSelected = ( Boolean ) formacaoSHST_true.getSelected(); Boolean falseSelected = ( Boolean ) formacaoSHST_false.getSelected(); Boolean noneSelected = ( Boolean ) formacaoSHST_none.getSelected(); if ( trueSelected != null && trueSelected ) { shst = Boolean.TRUE; } if ( falseSelected != null && falseSelected ) { shst = Boolean.FALSE; } if ( noneSelected != null && noneSelected ) { shst = null; } } Boolean participadoSeguro = ( participacaoSeguro_true.getSelected() != null && (Boolean) participacaoSeguro_true.getSelected() ) ? Boolean.TRUE : null; Boolean postoAcidentado = null; if ( postoAcidentado_true.getSelected() != null || postoAcidentado_false.getSelected() != null ) { postoAcidentado = ( Boolean ) postoAcidentado_true.getSelected(); } Boolean outrosAcidentados = null; if ( outrosColaboradores_true.getSelected() != null || outrosColaboradores_false.getSelected() != null ) { outrosAcidentados = ( Boolean ) outrosColaboradores_true.getSelected(); } Map< String, Object > searchProperties = new HashMap< String, Object >(); searchProperties.put( EstatisticasConstants.KEY_POR, por ); searchProperties.put( EstatisticasConstants.KEY_NOME, nome ); searchProperties.put( EstatisticasConstants.KEY_ANO_OCORRENCIA, anoOcorrencia ); searchProperties.put( EstatisticasConstants.KEY_DATA_OCORRENCIA, dataOcorrencia ); searchProperties.put( EstatisticasConstants.KEY_HORA_OCORRENCIA, horaOcorrencia ); searchProperties.put( EstatisticasConstants.KEY_HORAS_TRABALHADAS, horasTrabalhadas ); // searchProperties.put( EstatisticasConstants.KEY_DEPARTAMENTO, departamento ); searchProperties.put( EstatisticasConstants.KEY_ESTABELECIMENTO, estabelecimentoID ); searchProperties.put( EstatisticasConstants.KEY_SECCAO, seccaoID ); searchProperties.put( EstatisticasConstants.KEY_CAUSAS_ACIDENTE, causas ); searchProperties.put( EstatisticasConstants.KEY_TURNO_TRABALHO, turno ); searchProperties.put( EstatisticasConstants.KEY_FORMACAO_SHST, shst ); searchProperties.put( EstatisticasConstants.KEY_PARTICIPADO_SEGURO, participadoSeguro ); searchProperties.put( EstatisticasConstants.KEY_POSTO_ACIDENTADO, postoAcidentado ); searchProperties.put( EstatisticasConstants.KEY_OUTROS_ACIDENTADOS, outrosAcidentados ); return searchProperties; } private void getEstatisticas() { Map< String, Object > searchProperties = getFormFieldValues(); listEstatisticas = new LinkedList< EstatisticaProcessoBean >(); try { EstatisticasDataProvider edp = EstatisticasDataProvider.getInstance(); listEstatisticas = edp.getEstatisticas( searchProperties ); } catch ( Exception e ) { ErrorLogger.logException( e ); } setListEstatisticas( listEstatisticas ); } public String buttonEstatistica_action() { getEstatisticas(); buttonExport.setRendered( true ); return null; } public String buttonExport_action() { System.out.println( "=== EXPORT TO EXCEL ===" ); getEstatisticas(); System.out.println( "-> " + getListEstatisticas().size() ); HSSFWorkbook book = new HSSFWorkbook(); Map< String, HSSFCellStyle > styles = createStyles( book ); HSSFSheet sheet = book.createSheet( "Estatisticas" ); int row = writeFilters( sheet, 0 ); HSSFRow headerRow = getRow( sheet, row ); HSSFCell columnEstado = getCell( headerRow, 0 ); columnEstado.setCellValue( "Estado" ); columnEstado.setCellStyle( styles.get( EstatisticasConstants.KEY_STYLE_COLUMN_HEADER ) ); HSSFCell columnFase = getCell( headerRow, 1 ); columnFase.setCellValue( "Fase" ); columnFase.setCellStyle( styles.get( EstatisticasConstants.KEY_STYLE_COLUMN_HEADER ) ); HSSFCell columnCount = getCell( headerRow, 2 ); columnCount.setCellValue( "Contagem" ); columnCount.setCellStyle( styles.get( EstatisticasConstants.KEY_STYLE_COLUMN_HEADER ) ); row++; for ( EstatisticaProcessoBean line : getListEstatisticas() ) { HSSFRow lineRow = getRow( sheet, row ); HSSFCell columnEstadoValue = getCell( lineRow, 0 ); columnEstadoValue.setCellValue( line.getEstado() ); columnEstadoValue.setCellStyle( styles.get( EstatisticasConstants.KEY_STYLE_COLUMN_NORMAL ) ); HSSFCell columnFaseValue = getCell( lineRow, 1 ); columnFaseValue.setCellValue( line.getFase() ); columnFaseValue.setCellStyle( styles.get( EstatisticasConstants.KEY_STYLE_COLUMN_NORMAL ) ); HSSFCell columnCountValue = getCell( lineRow, 2 ); columnCountValue.setCellValue( line.getCount() ); columnCountValue.setCellStyle( styles.get( EstatisticasConstants.KEY_STYLE_COLUMN_NORMAL ) ); row++; } sheet.autoSizeColumn( 0, true ); sheet.autoSizeColumn( 1, true ); sheet.autoSizeColumn( 2, true ); try { saveWorkbook( book ); } catch ( Exception ex ) { ErrorLogger.logException( ex ); getSessionBean1().setMsg( "Erro a gerar o ficheiro." ); } return null; } private Map< String, HSSFCellStyle > createStyles( HSSFWorkbook book ) { Map< String, HSSFCellStyle > styles = new HashMap< String, HSSFCellStyle >(); HSSFCellStyle style; HSSFFont headerFont = book.createFont(); headerFont.setFontHeightInPoints( ( short ) 12 ); headerFont.setBoldweight( HSSFFont.BOLDWEIGHT_BOLD ); HSSFFont normalFont = book.createFont(); headerFont.setFontHeightInPoints( ( short ) 12 ); style = book.createCellStyle(); // style.setAlignment( HSSFCellStyle.ALIGN_CENTER ); style.setVerticalAlignment( HSSFCellStyle.VERTICAL_CENTER ); style.setFont( headerFont ); styles.put( EstatisticasConstants.KEY_STYLE_COLUMN_HEADER, style ); style = book.createCellStyle(); style.setVerticalAlignment( HSSFCellStyle.VERTICAL_CENTER ); style.setFont( normalFont ); styles.put( EstatisticasConstants.KEY_STYLE_COLUMN_NORMAL, style ); return styles; } private HSSFRow getRow( HSSFSheet sheet, int rowNumber ) { HSSFRow row = sheet.getRow( rowNumber ); if ( row == null ) { row = sheet.createRow( rowNumber ); } return row; } private HSSFCell getCell( HSSFRow row, int cellNumber ) { HSSFCell cell = row.getCell( cellNumber ); if ( cell == null ) { cell = row.createCell( cellNumber ); } return cell; } private int writeFilters( HSSFSheet sheet, int row ) { Map< String, Object > searchProperties = getFormFieldValues(); String por = ( String ) searchProperties.get( EstatisticasConstants.KEY_POR ); String nome = ( String ) searchProperties.get( EstatisticasConstants.KEY_NOME ); String anoOcorrencia = ( String ) searchProperties.get( EstatisticasConstants.KEY_ANO_OCORRENCIA ); Date dataOcorrencia = ( Date ) searchProperties.get( EstatisticasConstants.KEY_DATA_OCORRENCIA ); String horaOcorrencia = ( String ) searchProperties.get( EstatisticasConstants.KEY_HORA_OCORRENCIA ); String horasTrabalhadas = ( String ) searchProperties.get( EstatisticasConstants.KEY_HORAS_TRABALHADAS ); // String departamento = ( String ) searchProperties.get( EstatisticasConstants.KEY_DEPARTAMENTO ); Integer estabelecimentoID = ( Integer ) searchProperties.get( EstatisticasConstants.KEY_ESTABELECIMENTO ); Integer seccaoID = ( Integer ) searchProperties.get( EstatisticasConstants.KEY_SECCAO ); String estabelecimento = null; try { estabelecimento = EstatisticasDataProvider.getInstance().getEstabelecimentoByID( estabelecimentoID ); } catch ( Exception e ) { ErrorLogger.logException( e ); } String seccao = null; try { SeccoesData seccaoData = EstatisticasDataProvider.getInstance().loadSeccaoByID( seccaoID ); seccao = seccaoData == null ? null : seccaoData.getDescricao(); } catch ( Exception e ) { ErrorLogger.logException( e ); } Integer causas = ( Integer ) searchProperties.get( EstatisticasConstants.KEY_CAUSAS_ACIDENTE ); String turno = ( String ) searchProperties.get( EstatisticasConstants.KEY_TURNO_TRABALHO ); Boolean formacao_shst = ( Boolean ) searchProperties.get( EstatisticasConstants.KEY_FORMACAO_SHST ); Boolean participado_seguro = ( Boolean ) searchProperties.get( EstatisticasConstants.KEY_PARTICIPADO_SEGURO ); Boolean postoAcidentado = ( Boolean ) searchProperties.get( EstatisticasConstants.KEY_POSTO_ACIDENTADO ); Boolean outrosAcidentados = ( Boolean ) searchProperties.get( EstatisticasConstants.KEY_OUTROS_ACIDENTADOS ); String keyName = null; HSSFRow currentRow = null; HSSFCell columnLabel = null; HSSFCell columnValue = null; keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); columnValue.setCellValue( por ); row++; keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); columnValue.setCellValue( nome ); row++; keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); columnValue.setCellValue( anoOcorrencia ); row++; final SimpleDateFormat D_F = new SimpleDateFormat( "yyyy-MM-dd" ); keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); columnValue.setCellValue( dataOcorrencia == null ? "" : D_F.format( dataOcorrencia ) ); row++; keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); columnValue.setCellValue( horaOcorrencia ); row++; keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); columnValue.setCellValue( horasTrabalhadas ); row++; // keyName = EstatisticasConstants.KEY_NAMES[ row ]; // currentRow = getRow( sheet, row ); // columnLabel = getCell( currentRow, 0 ); // columnLabel.setCellValue( keyName ); // columnValue = getCell( currentRow, 1 ); // columnValue.setCellValue( departamento ); // row++; keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); columnValue.setCellValue( estabelecimento ); row++; keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); columnValue.setCellValue( seccao ); row++; String causa = ""; if ( causas != null ) { try { EstatisticasDataProvider statsProvider = EstatisticasDataProvider.getInstance(); causa = statsProvider.getCausaByID( causas ); } catch ( Exception e ) { ErrorLogger.logException( e ); } } keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); columnValue.setCellValue( causa ); row++; String turnoDesc = ""; if ( turno != null ) { if ( "m".equals( turno ) ) { turnoDesc = "Manhã"; } else if ( "t".equals( turno ) ) { turnoDesc = "Tarde"; } else if ( "n".equals( turno ) ) { turnoDesc = "Noite"; } } keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); columnValue.setCellValue( turnoDesc ); row++; keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); String fshst = ""; if ( formacao_shst != null ) { fshst = formacao_shst ? "Sim" : "Não"; } columnValue.setCellValue( fshst ); row++; keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); String fparticiapdo = ""; if ( participado_seguro != null ) { fparticiapdo = participado_seguro ? "Sim" : "Não"; } columnValue.setCellValue( fparticiapdo ); row++; row++; return row++; } private void saveWorkbook( HSSFWorkbook book ) throws Exception { byte[] bytes = book.getBytes(); System.out.println( "BOOK LEN : " + bytes.length ); FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = ( HttpServletResponse ) context.getExternalContext().getResponse(); response.setHeader( "Expires", "0" ); response.setHeader( "Cache-Control", "must-revalidate, post-check=0, pre-check=0" ); response.setHeader( "Pragma", "public" ); response.setContentType( "application/vnd.ms-excel" ); response.addHeader( "Content-disposition", "attachment;filename=\"EstatisticasProcesso.xls\"" ); response.setContentLength( bytes.length ); response.getOutputStream().write( bytes ); response.getOutputStream().flush(); response.getOutputStream().close(); context.responseComplete(); System.out.println( "SHOW workbook DONE" ); } }