private String generateAvailSLATime( DocumentHTML document, HttpServletRequest request, AcordoNivelServicoDTO acordoNivelServicoDTO, Integer idAcordoNivelServico, UsuarioDTO usuarioDto) throws IOException, ParseException { SlaAvaliacaoDTO slaAvaliacaoDto = (SlaAvaliacaoDTO) document.getBean(); ControleGenerateSLAPorAcordoNivelServico controleGenerateSLAPorAcordoNivelServico = new ControleGenerateSLAPorAcordoNivelServico(); ControleGenerateSLAPorAcordoNivelServicoEmAndamento controleGenerateSLAPorAcordoNivelServicoEmAndamento = new ControleGenerateSLAPorAcordoNivelServicoEmAndamento(); List lst = controleGenerateSLAPorAcordoNivelServico.execute( idAcordoNivelServico, slaAvaliacaoDto.getDataInicio(), slaAvaliacaoDto.getDataFim()); double qtdeDentroPrazo = 0; double qtdeForaPrazo = 0; if (lst != null && lst.size() > 0) { for (Iterator itSLA = lst.iterator(); itSLA.hasNext(); ) { Object[] objs = (Object[]) itSLA.next(); if (((String) objs[0]).indexOf("Fora") > -1 || ((String) objs[0]).indexOf("Out") > -1) { qtdeForaPrazo = (Double) objs[2]; } else { qtdeDentroPrazo = (Double) objs[2]; } } } double qtdeDentroPrazoPerc = (qtdeDentroPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100; double qtdeForaPrazoPerc = (qtdeForaPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100; final DefaultValueDataset dataset = new DefaultValueDataset(new Double(qtdeDentroPrazoPerc)); // create the chart... final ThermometerPlot plot = new ThermometerPlot(dataset); final JFreeChart chart = new JFreeChart( UtilI18N.internacionaliza(request, "sla.avaliacao.avaliacaogeral"), // chart title JFreeChart.DEFAULT_TITLE_FONT, plot, // plot false); // include legend plot.setSubrangeInfo(ThermometerPlot.NORMAL, 90.000001, 100); plot.setSubrangeInfo(ThermometerPlot.WARNING, 80.000001, 90); plot.setSubrangeInfo(ThermometerPlot.CRITICAL, 0, 80); plot.setThermometerStroke(new BasicStroke(2.0f)); plot.setThermometerPaint(Color.lightGray); String nomeImgAval = CITCorporeUtil.caminho_real_app + "/tempFiles/" + usuarioDto.getIdUsuario() + "/avalSLA_" + acordoNivelServicoDTO.getIdAcordoNivelServico() + ".png"; String nomeImgAvalRel = br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS") + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO") + "/tempFiles/" + usuarioDto.getIdUsuario() + "/avalSLA_" + acordoNivelServicoDTO.getIdAcordoNivelServico() + ".png"; File arquivo = new File(nomeImgAval); if (arquivo.exists()) { arquivo.delete(); } else { String nomeDir = CITCorporeUtil.caminho_real_app + "/tempFiles/" + usuarioDto.getIdUsuario() + "/"; File dirTemp = new File(nomeDir); dirTemp.mkdirs(); arquivo.createNewFile(); } ChartUtilities.saveChartAsPNG(arquivo, chart, 500, 200); List lst2 = controleGenerateSLAPorAcordoNivelServicoEmAndamento.execute(idAcordoNivelServico); qtdeDentroPrazo = 0; qtdeForaPrazo = 0; if (lst2 != null && lst2.size() > 0) { for (Iterator itSLA = lst2.iterator(); itSLA.hasNext(); ) { Object[] objs = (Object[]) itSLA.next(); if (((String) objs[0]).indexOf("Fora") > -1 || ((String) objs[0]).indexOf("Out") > -1) { qtdeForaPrazo = (Double) objs[2]; } else { qtdeDentroPrazo = (Double) objs[2]; } } } qtdeDentroPrazoPerc = (qtdeDentroPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100; qtdeForaPrazoPerc = (qtdeForaPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100; DefaultPieDataset datasetPie = new DefaultPieDataset(); datasetPie.setValue( UtilI18N.internacionaliza(request, "sla.avaliacao.noprazo") + " (" + UtilFormatacao.formatDouble(qtdeDentroPrazo, 0) + ")", new Double(qtdeDentroPrazoPerc)); datasetPie.setValue( UtilI18N.internacionaliza(request, "sla.avaliacao.foraprazo") + " (" + UtilFormatacao.formatDouble(qtdeForaPrazo, 0) + ")", new Double(qtdeForaPrazoPerc)); JFreeChart chartX = ChartFactory.createPieChart( UtilI18N.internacionaliza(request, "sla.avaliacao.emandamento"), // chart title datasetPie, // data true, // include legend true, false); PiePlot plotPie = (PiePlot) chartX.getPlot(); plotPie.setLabelFont(new Font("SansSerif", Font.PLAIN, 6)); plotPie.setNoDataMessage(UtilI18N.internacionaliza(request, "sla.avaliacao.naohadados")); plotPie.setCircular(true); plotPie.setLabelGap(0); String nomeImgAval2 = CITCorporeUtil.caminho_real_app + "/tempFiles/" + usuarioDto.getIdUsuario() + "/avalSLA2_" + idAcordoNivelServico + ".png"; String nomeImgAvalRel2 = br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS") + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO") + "/tempFiles/" + usuarioDto.getIdUsuario() + "/avalSLA2_" + idAcordoNivelServico + ".png"; File arquivo2 = new File(nomeImgAval2); if (arquivo2.exists()) { arquivo2.delete(); } ChartUtilities.saveChartAsPNG(arquivo2, chartX, 200, 200); String table = ""; table += "<tr>"; table += "<td style='border:1px solid black; vertical-align:middle;'>"; // table += // UtilHTML.encodeHTML(UtilStrings.retiraApostrofe(acordoNivelServicoDTO.getTituloSLA())); table += "<br>" + geraTabelaMeses( acordoNivelServicoDTO.getTituloSLA(), idAcordoNivelServico, request, usuarioDto); table += "</td>"; table += "<td style='border:1px solid black; vertical-align:middle;'>"; if (acordoNivelServicoDTO.getTipo() != null && acordoNivelServicoDTO.getTipo().equalsIgnoreCase("T")) { table += "<img src='" + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS") + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO") + "/imagens/relogio.png' border='0' title='" + UtilI18N.internacionaliza(request, "sla.avaliacao.tempo") + "'/>"; table += UtilI18N.internacionaliza(request, "sla.avaliacao.tempo"); } else if (acordoNivelServicoDTO.getTipo() != null && acordoNivelServicoDTO.getTipo().equalsIgnoreCase("D")) { table += "<img src='" + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS") + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO") + "/imagens/disponibilidade.png' border='0' title='" + UtilI18N.internacionaliza(request, "sla.avaliacao.disponibilidade") + "'/>"; table += UtilI18N.internacionaliza(request, "sla.avaliacao.disponibilidade"); } else if (acordoNivelServicoDTO.getTipo() != null && acordoNivelServicoDTO.getTipo().equalsIgnoreCase("V")) { table += "<img src='" + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS") + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO") + "/imagens/outrasfontes.png' border='0' title='" + UtilI18N.internacionaliza(request, "sla.avaliacao.outrasfontes") + "'/>"; table += UtilI18N.internacionaliza(request, "sla.avaliacao.outrasfontes"); } table += "</td>"; table += "<td style='border:1px solid black; vertical-align:middle;'>"; if (acordoNivelServicoDTO.getDataFim() != null && acordoNivelServicoDTO.getDataFim().before(UtilDatas.getDataAtual())) { table += "<img src='" + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS") + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO") + "/imagens/bolavermelha.png' border='0' title='" + UtilI18N.internacionaliza(request, "sla.avaliacao.inativo") + "'/>"; table += UtilI18N.internacionaliza(request, "sla.avaliacao.inativo"); } else { table += "<img src='" + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS") + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO") + "/imagens/bolaverde.png' border='0' title='" + UtilI18N.internacionaliza(request, "sla.avaliacao.ativo") + "'/>"; table += UtilI18N.internacionaliza(request, "sla.avaliacao.ativo"); } table += "</td>"; table += "<td style='border:1px solid black'>"; table += "<img src='" + nomeImgAvalRel + "' border='0'/>"; table += "</td>"; table += "<td style='border:1px solid black'>"; table += "<img src='" + nomeImgAvalRel2 + "' border='0'/>"; table += "</td>"; table += "</tr>"; return table; }
public void avalia( DocumentHTML document, HttpServletRequest request, HttpServletResponse response) throws Exception { UsuarioDTO usuarioDto = WebUtil.getUsuario(request); if (usuarioDto == null) { document.alert(UtilI18N.internacionaliza(request, "citcorpore.comum.sessaoExpirada")); document.executeScript( "window.location = '" + Constantes.getValue("SERVER_ADDRESS") + request.getContextPath() + "'"); return; } AcordoNivelServicoService acordoNivelServicoService = (AcordoNivelServicoService) ServiceLocator.getInstance().getService(AcordoNivelServicoService.class, null); RequisitoSLAService requisitoSLAService = (RequisitoSLAService) ServiceLocator.getInstance().getService(RequisitoSLAService.class, null); Collection colAcordos = acordoNivelServicoService.findAcordosSemVinculacaoDireta(); Collection colReqs = requisitoSLAService.list(); ControleGenerateSLAPorRequisitoSLA controleGenerateSLAPorRequisitoSLA = new ControleGenerateSLAPorRequisitoSLA(); ControleGenerateSLAPorRequisitoSLAEmAndamento controleGenerateSLAPorRequisitoSLAEmAndamento = new ControleGenerateSLAPorRequisitoSLAEmAndamento(); String table = "<table border='1'>"; if (colAcordos != null && colAcordos.size() > 0) { table += "<tr>"; table += "<td>"; table += "<b>" + UtilI18N.internacionaliza(request, "sla.avaliacao.acordo") + "</b>"; table += "</td>"; table += "</tr>"; table += "<tr>"; table += "<td>"; table += " "; table += "</td>"; table += "</tr>"; for (Iterator it = colAcordos.iterator(); it.hasNext(); ) { AcordoNivelServicoDTO acordoNivelServicoDTO = (AcordoNivelServicoDTO) it.next(); table += "<tr>"; table += "<td colspan='5' style='background-color:gray'>"; table += UtilI18N.internacionaliza(request, "citcorpore.comum.acordo") + ": <b>" + acordoNivelServicoDTO.getTituloSLA() + "</b>"; table += "</td>"; table += "</tr>"; if (acordoNivelServicoDTO.getTipo().equalsIgnoreCase("T")) { table += generateSLATime( document, request, acordoNivelServicoDTO, acordoNivelServicoDTO.getIdAcordoNivelServico(), usuarioDto); table += generateAvailSLATime( document, request, acordoNivelServicoDTO, acordoNivelServicoDTO.getIdAcordoNivelServico(), usuarioDto); } else if (acordoNivelServicoDTO.getTipo().equalsIgnoreCase("D")) { table += generateAvailSLAAvailability( document, request, response, acordoNivelServicoDTO, acordoNivelServicoDTO.getIdAcordoNivelServico(), usuarioDto); } } } if (colReqs != null && colReqs.size() > 0) { table += "<tr>"; table += "<td>"; table += " "; table += "</td>"; table += "</tr>"; table += "<tr>"; table += "<td>"; table += "<b>" + UtilI18N.internacionaliza(request, "sla.avaliacao.requisito") + "</b>"; table += "</td>"; table += "</tr>"; for (Iterator it = colReqs.iterator(); it.hasNext(); ) { RequisitoSLADTO requisitoSLADTO = (RequisitoSLADTO) it.next(); List lst = controleGenerateSLAPorRequisitoSLA.execute(requisitoSLADTO.getIdRequisitoSLA()); double qtdeDentroPrazo = 0; double qtdeForaPrazo = 0; if (lst != null && lst.size() > 0) { for (Iterator itSLA = lst.iterator(); itSLA.hasNext(); ) { Object[] objs = (Object[]) itSLA.next(); if (((String) objs[0]).indexOf("Fora") > -1 || ((String) objs[0]).indexOf("Out") > -1) { qtdeForaPrazo = (Double) objs[2]; } else { qtdeDentroPrazo = (Double) objs[2]; } } } double qtdeDentroPrazoPerc = (qtdeDentroPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100; double qtdeForaPrazoPerc = (qtdeForaPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100; final DefaultValueDataset dataset = new DefaultValueDataset(new Double(qtdeDentroPrazoPerc)); // create the chart... final ThermometerPlot plot = new ThermometerPlot(dataset); final JFreeChart chart = new JFreeChart( UtilI18N.internacionaliza(request, "sla.avaliacao.avaliacaogeral"), // chart title JFreeChart.DEFAULT_TITLE_FONT, plot, // plot false); // include legend plot.setSubrangeInfo(ThermometerPlot.NORMAL, 90.000001, 100); plot.setSubrangeInfo(ThermometerPlot.WARNING, 80.000001, 90); plot.setSubrangeInfo(ThermometerPlot.CRITICAL, 0, 80); plot.setThermometerStroke(new BasicStroke(2.0f)); plot.setThermometerPaint(Color.lightGray); String nomeImgAval = CITCorporeUtil.caminho_real_app + "/tempFiles/" + usuarioDto.getIdUsuario() + "/avalREQSLA_" + requisitoSLADTO.getIdRequisitoSLA() + ".png"; String nomeImgAvalRel = br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS") + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO") + "/tempFiles/" + usuarioDto.getIdUsuario() + "/avalREQSLA_" + requisitoSLADTO.getIdRequisitoSLA() + ".png"; File arquivo = new File(nomeImgAval); if (arquivo.exists()) { arquivo.delete(); } else { String nomeDir = CITCorporeUtil.caminho_real_app + "/tempFiles/" + usuarioDto.getIdUsuario() + "/"; File dirTemp = new File(nomeDir); dirTemp.mkdirs(); arquivo.createNewFile(); } ChartUtilities.saveChartAsPNG(arquivo, chart, 500, 200); List lst2 = controleGenerateSLAPorRequisitoSLAEmAndamento.execute( requisitoSLADTO.getIdRequisitoSLA()); qtdeDentroPrazo = 0; qtdeForaPrazo = 0; if (lst2 != null && lst2.size() > 0) { for (Iterator itSLA = lst2.iterator(); itSLA.hasNext(); ) { Object[] objs = (Object[]) itSLA.next(); if (((String) objs[0]).indexOf("Fora") > -1 || ((String) objs[0]).indexOf("Out") > -1) { qtdeForaPrazo = (Double) objs[2]; } else { qtdeDentroPrazo = (Double) objs[2]; } } } qtdeDentroPrazoPerc = (qtdeDentroPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100; qtdeForaPrazoPerc = (qtdeForaPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100; DefaultPieDataset datasetPie = new DefaultPieDataset(); datasetPie.setValue( UtilI18N.internacionaliza(request, "sla.avaliacao.noprazo") + " (" + UtilFormatacao.formatDouble(qtdeDentroPrazo, 0) + ")", new Double(qtdeDentroPrazoPerc)); datasetPie.setValue( UtilI18N.internacionaliza(request, "sla.avaliacao.foraprazo") + " (" + UtilFormatacao.formatDouble(qtdeForaPrazo, 0) + ")", new Double(qtdeForaPrazoPerc)); JFreeChart chartX = ChartFactory.createPieChart( UtilI18N.internacionaliza(request, "sla.avaliacao.emandamento"), // chart title datasetPie, // data true, // include legend false, false); PiePlot plotPie = (PiePlot) chartX.getPlot(); plotPie.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plotPie.setNoDataMessage(UtilI18N.internacionaliza(request, "sla.avaliacao.naohadados")); plotPie.setCircular(false); plotPie.setLabelGap(0.02); String nomeImgAval2 = CITCorporeUtil.caminho_real_app + "/tempFiles/" + usuarioDto.getIdUsuario() + "/avalREQSLA2_" + requisitoSLADTO.getIdRequisitoSLA() + ".png"; String nomeImgAvalRel2 = br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS") + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO") + "/tempFiles/" + usuarioDto.getIdUsuario() + "/avalREQSLA2_" + requisitoSLADTO.getIdRequisitoSLA() + ".png"; File arquivo2 = new File(nomeImgAval2); if (arquivo2.exists()) { arquivo2.delete(); } ChartUtilities.saveChartAsPNG(arquivo2, chartX, 200, 200); table += "<tr>"; table += "<td style='border:1px solid black; vertical-align:middle;'>"; table += UtilHTML.encodeHTML(UtilStrings.retiraApostrofe(requisitoSLADTO.getAssunto())); table += "</td>"; table += "<td style='border:1px solid black; vertical-align:middle;'>"; if (requisitoSLADTO.getSituacao() != null && requisitoSLADTO.getSituacao().equalsIgnoreCase("A")) { table += "<img src='" + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS") + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO") + "/imagens/bolaverde.png' border='0' title='" + UtilI18N.internacionaliza(request, "requisitosla.ativo") + "'/>"; table += UtilI18N.internacionaliza(request, "requisitosla.ativo"); } else if (requisitoSLADTO.getSituacao() != null && requisitoSLADTO.getSituacao().equalsIgnoreCase("P")) { table += "<img src='" + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS") + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO") + "/imagens/bolavermelha.png' border='0' title='" + UtilI18N.internacionaliza(request, "requisitosla.planejamento") + "'/>"; table += UtilI18N.internacionaliza(request, "requisitosla.planejamento"); } else if (requisitoSLADTO.getSituacao() != null && requisitoSLADTO.getSituacao().equalsIgnoreCase("R")) { table += "<img src='" + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS") + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO") + "/imagens/bolavermelha.png' border='0' title='" + UtilI18N.internacionaliza(request, "requisitosla.emrevisao") + "'/>"; table += UtilI18N.internacionaliza(request, "requisitosla.emrevisao"); } else { table += "<img src='" + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS") + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO") + "/imagens/bolavermelha.png' border='0' title='" + UtilI18N.internacionaliza(request, "requisitosla.inativo") + "'/>"; table += UtilI18N.internacionaliza(request, "requisitosla.inativo"); } table += "</td>"; table += "<td style='border:1px solid black'>"; table += "<img src='" + nomeImgAvalRel + "' border='0'/>"; table += "</td>"; table += "<td style='border:1px solid black'>"; table += "<img src='" + nomeImgAvalRel2 + "' border='0'/>"; table += "</td>"; table += "</tr>"; } } table += "</table>"; document.getElementById("divInfo").setInnerHTML(table); }
protected JFreeChart createThermometerChart() throws JRException { JRThermometerPlot jrPlot = (JRThermometerPlot) getPlot(); // Create the plot that will hold the thermometer. ThermometerPlot chartPlot = new ThermometerPlot((ValueDataset) getDataset()); // Build a chart around this plot JFreeChart jfreeChart = new JFreeChart(chartPlot); // Set the generic options configureChart(jfreeChart, getPlot()); jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); jfreeChart.setBorderVisible(false); Range range = convertRange(jrPlot.getDataRange()); if (range != null) { // Set the boundary of the thermomoter chartPlot.setLowerBound(range.getLowerBound()); chartPlot.setUpperBound(range.getUpperBound()); } chartPlot.setGap(0); // Units can only be Fahrenheit, Celsius or none, so turn off for now. chartPlot.setUnits(ThermometerPlot.UNITS_NONE); // Set the color of the mercury. Only used when the value is outside of // any defined ranges. List seriesPaints = (List) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SERIES_COLORS); Paint paint = jrPlot.getMercuryColor(); if (paint != null) { chartPlot.setUseSubrangePaint(false); } else { // it has no effect, but is kept for backward compatibility reasons paint = (Paint) seriesPaints.get(0); } chartPlot.setMercuryPaint(paint); chartPlot.setThermometerPaint(THERMOMETER_COLOR); chartPlot.setThermometerStroke(new BasicStroke(2f)); chartPlot.setOutlineVisible(false); chartPlot.setValueFont(chartPlot.getValueFont().deriveFont(Font.BOLD)); // Set the formatting of the value display JRValueDisplay display = jrPlot.getValueDisplay(); if (display != null) { if (display.getColor() != null) { chartPlot.setValuePaint(display.getColor()); } if (display.getMask() != null) { chartPlot.setValueFormat(new DecimalFormat(display.getMask())); } if (display.getFont() != null) { // // chartPlot.setValueFont(JRFontUtil.getAwtFont(display.getFont()).deriveFont(Font.BOLD)); } } // Set the location of where the value is displayed // Set the location of where the value is displayed ValueLocationEnum valueLocation = jrPlot.getValueLocationValue(); switch (valueLocation) { case NONE: chartPlot.setValueLocation(ThermometerPlot.NONE); break; case LEFT: chartPlot.setValueLocation(ThermometerPlot.LEFT); break; case RIGHT: chartPlot.setValueLocation(ThermometerPlot.RIGHT); break; case BULB: default: chartPlot.setValueLocation(ThermometerPlot.BULB); break; } // Define the three ranges range = convertRange(jrPlot.getLowRange()); if (range != null) { chartPlot.setSubrangeInfo(2, range.getLowerBound(), range.getUpperBound()); } range = convertRange(jrPlot.getMediumRange()); if (range != null) { chartPlot.setSubrangeInfo(1, range.getLowerBound(), range.getUpperBound()); } range = convertRange(jrPlot.getHighRange()); if (range != null) { chartPlot.setSubrangeInfo(0, range.getLowerBound(), range.getUpperBound()); } return jfreeChart; }