Skip to content

Commit

Permalink
buscar anos
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-hos committed Nov 19, 2017
1 parent 2ffd2fd commit 6056ace
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 5 deletions.
26 changes: 26 additions & 0 deletions src/main/java/com/sjcdigital/temis/model/dto/Ano.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.sjcdigital.temis.model.dto;

import java.io.Serializable;

public class Ano implements Serializable {

private static final long serialVersionUID = 1L;

@Deprecated
public Ano() {}

public Ano(final Integer ano) {
this.ano = ano;
}

private Integer ano;

public Integer getAno() {
return ano;
}

public void setAno(Integer ano) {
this.ano = ano;
}

}
27 changes: 27 additions & 0 deletions src/main/java/com/sjcdigital/temis/model/dto/Anos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.sjcdigital.temis.model.dto;

import java.io.Serializable;
import java.util.List;

public class Anos implements Serializable {

private static final long serialVersionUID = 1L;

@Deprecated
public Anos() {}

public Anos(final List<Ano> anos) {
this.anos = anos;
}

private List<Ano> anos;

public List<Ano> getAnos() {
return anos;
}

public void setAnos(List<Ano> anos) {
this.anos = anos;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import javax.ejb.TransactionAttributeType;
import javax.persistence.TypedQuery;

import com.sjcdigital.temis.model.dto.Ano;
import com.sjcdigital.temis.model.dto.Anos;
import com.sjcdigital.temis.model.dto.chart.DataChart;
import com.sjcdigital.temis.model.entities.impl.Lei;
import com.sjcdigital.temis.model.repositories.Repository;
Expand Down Expand Up @@ -162,6 +164,12 @@ public List<DataChart> contaLeisPorClasse() {
return query.getResultList();
}

public Anos anos() {
TypedQuery<Ano> query = em.createQuery("SELECT DISTINCT new com.sjcdigital.temis.model.dto.Ano(lei.ano) FROM Lei lei ORDER BY lei.ano", Ano.class);
List<Ano> anos = query.getResultList();
return new Anos(anos);
}

public List<Lei> comIds(final List<Long> ids) {
TypedQuery<Lei> query = em.createQuery("SELECT lei FROM Lei lei WHERE lei.id in (:ids)", Lei.class);
query.setParameter("ids", ids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ protected void converteParaLei(final RetornoPesquisa retornoPesquisa) {

private Integer montaAno(String numeroProcesso) {

Matcher matcher = RegexUtils.getMatcher("(\\/)([0-9]{2,4})", numeroProcesso);
Matcher matcher = RegexUtils.getMatcher("(\\/)([0-9]{4})", numeroProcesso);
Integer ano = LocalDate.now().getYear();

if (matcher.find()) {
ano = matcher.group(2).length() == 2 ? new Integer("20" + matcher.group(2).trim()) : new Integer(matcher.group(2).trim());
}
ano = new Integer(matcher.group(2).trim());
}

return ano;
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/sjcdigital/temis/resources/LeiResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ public interface LeiResource {
@GET
@Path("/filtra")
Response filtraPaginado( @QueryParam("idSituacao") Long idSituacao, @QueryParam("idClasse") Long idClasse,
@QueryParam("idTipo") Long idTipo, @QueryParam("ano") Integer ano, @QueryParam("total") int total,
@QueryParam("pg") int pg );
@QueryParam("idTipo") Long idTipo, @QueryParam("ano") Integer ano,
@QueryParam("total") int total, @QueryParam("pg") int pg );

@GET
@Path("/grafico")
Response graficos();

@GET
@Path("/anos")
Response buscaAnos();

@PUT
@Path("/{id}/vota")
Response votar(@PathParam("id") Long id, @QueryParam("rating") Integer rating, @Context HttpServletRequest request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,9 @@ public Response filtraPaginado(Long idSituacao, Long idClasse, Long idTipo, Inte
return Response.ok().entity(leisFiltrada).build();
}

@Override
public Response buscaAnos() {
return Response.ok().entity(leis.anos()).build();
}

}

0 comments on commit 6056ace

Please sign in to comment.