Ejemplo n.º 1
0
  @GET
  @RolesAllowed({"Supervisor"})
  @Produces(MediaType.APPLICATION_JSON)
  public Response getTipoRelatorio() throws JSONException {
    JSONArray resposta = new JSONArray();

    for (TipoRelatorioEnum tipoRelatorioEnum : TipoRelatorioEnum.values()) {
      JSONObject obj = new JSONObject();
      obj.put("rotulo", tipoRelatorioEnum.getRotulo());
      obj.put("nome", tipoRelatorioEnum.toString());
      resposta.put(obj);
    }

    try {
      return Response.status(Response.Status.OK)
          .entity(resposta)
          .type(MediaType.APPLICATION_JSON)
          .build();
    } catch (Exception ex) {
      LOGGER.error(ex);
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
  }
Ejemplo n.º 2
0
  @GET
  @Path("{tipo}")
  @RolesAllowed({"Supervisor"})
  @Produces("application/pdf;charset=utf-8")
  public Response geraRelatorio(@PathParam("tipo") String tipoRelatorio) {
    TipoRelatorioEnum tipoRelatorioEnum = TipoRelatorioEnum.valueOf(tipoRelatorio);

    Connection con = (Connection) context.getProperties().get("conexao");
    Usuario usuario = (Usuario) context.getProperties().get("usuario");

    Map<String, Object> parametros = new HashMap<>();
    parametros.put("usuario", usuario.getNome());

    JasperReport relatorio;
    JasperReport subReport;
    InputStream is;

    try {
      switch (tipoRelatorioEnum) {
        case A:
          is =
              getClass()
                  .getClassLoader()
                  .getResourceAsStream("relatorios/atendimento_detalhe.jrxml");
          subReport = JasperCompileManager.compileReport(is);
          parametros.put("subreport", subReport);

          is =
              getClass()
                  .getClassLoader()
                  .getResourceAsStream("relatorios/chamados_atendimento_por_analista.jrxml");
          relatorio = JasperCompileManager.compileReport(is);
          break;

        case S:
          is =
              getClass()
                  .getClassLoader()
                  .getResourceAsStream("relatorios/chamados_por_situacao.jrxml");
          relatorio = JasperCompileManager.compileReport(is);
          break;

        case E:
          is =
              getClass().getClassLoader().getResourceAsStream("relatorios/encerrado_detalhe.jrxml");
          subReport = JasperCompileManager.compileReport(is);
          parametros.put("subreport", subReport);

          is =
              getClass()
                  .getClassLoader()
                  .getResourceAsStream("relatorios/chamados_encerrado_por_analista.jrxml");
          relatorio = JasperCompileManager.compileReport(is);
          //                    is =
          // getClass().getClassLoader().getResourceAsStream("relatorios/chamados_encerrado_por_analista.jasper");
          //                    relatorio = (JasperReport) JRLoader.loadObject(is);
          break;

        default:
          throw new AssertionError(tipoRelatorioEnum.name());
      }

      JasperPrint jasperPrint = JasperFillManager.fillReport(relatorio, parametros, con);

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      JasperExportManager.exportReportToPdfStream(jasperPrint, baos);

      return Response.status(Response.Status.OK)
          .entity(baos.toByteArray())
          .type("application/pdf")
          .build();
    } catch (Exception ex) {
      LOGGER.error(ex);
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    } finally {
      DBUtil.fecha(con);
    }
  }