Example usage for org.hibernate.envers.query.criteria MatchMode EXACT

List of usage examples for org.hibernate.envers.query.criteria MatchMode EXACT

Introduction

In this page you can find the example usage for org.hibernate.envers.query.criteria MatchMode EXACT.

Prototype

MatchMode EXACT

To view the source code for org.hibernate.envers.query.criteria MatchMode EXACT.

Click Source Link

Document

Match the pattern exactly.

Usage

From source file:br.ufac.sion.service.AuditoriaService.java

public Set<AuditoriaDTO> findAllRevisions(FiltroAuditoria filtro) throws NegocioException {
    if (filtro.getDataInicio() != null && filtro.getDataFim() != null) {
        if (!filtro.getDataFim().isAfter(filtro.getDataInicio())) {
            throw new NegocioException("A data de termino deve ser maior que a data de incio!");
        }/*from   w  ww .j  av  a  2  s.c  o  m*/
    }
    Set<AuditoriaDTO> dtos = new HashSet<>();

    AuditReader reader = AuditReaderFactory.get(em);

    AuditQuery query = reader.createQuery().forRevisionsOfEntity(filtro.getClasse(), false, true);

    if (filtro.getDataInicio() != null) {
        query.add(AuditEntity.revisionProperty("timestamp")
                .gt(Timestamp.from(filtro.getDataInicio().toInstant(ZoneOffset.UTC)).getTime()));
    }
    if (filtro.getDataFim() != null) {
        query.add(AuditEntity.revisionProperty("timestamp")
                .lt(Timestamp.from(filtro.getDataFim().toInstant(ZoneOffset.UTC)).getTime()));
    }

    if (StringUtils.isNotEmpty(filtro.getLogin())) {
        query.add(AuditEntity.revisionProperty("username").ilike(filtro.getLogin(), MatchMode.EXACT));
    }

    if (filtro.getTiposRevisao().length > 0) {
        System.out.println("entra id tipo revisao");
        query.add(AuditEntity.property("REVTYPE").in(filtro.getTiposRevisao()));
    }

    List<Object[]> result = query.getResultList();

    for (Object[] o : result) {
        try {
            //                Object instancia = filtro.getClass().cast(o[0]);
            Object instancia = Class.forName(filtro.getClasse().getName()).cast(o[0]);
            //                Method metodo;
            //                metodo = instancia.getClass().getMethod("getId");
            //                Long id = (Long) metodo.invoke(instancia);

            CustomRevisionEntity revision = (CustomRevisionEntity) o[1];
            RevisionType revisionType = (RevisionType) o[2];

            Instant instant = Instant.ofEpochMilli(revision.getTimestamp());

            AuditoriaDTO dto = new AuditoriaDTO(instancia, revisionType, filtro.getEntidade(), revision);

            dtos.add(dto);
        } catch (Exception ex) {
            throw new NegocioException(ex.getMessage());
        }
    }
    return dtos;
}