Example usage for org.hibernate.envers DefaultRevisionEntity getId

List of usage examples for org.hibernate.envers DefaultRevisionEntity getId

Introduction

In this page you can find the example usage for org.hibernate.envers DefaultRevisionEntity getId.

Prototype

public int getId() 

Source Link

Usage

From source file:TestConsole.java

License:Open Source License

private void printPersonHistory(StringBuilder sb, int personId) {
    AuditReader reader = AuditReaderFactory.get(entityManager);

    List<?> personHistory = reader.createQuery().forRevisionsOfEntity(Person.class, false, true)
            .add(AuditEntity.id().eq(personId)).getResultList();

    if (personHistory.size() == 0) {
        sb.append("A person with id ").append(personId).append(" does not exist.\n");
    } else {//from w ww .  j a va2 s  .c om
        for (Object historyObj : personHistory) {
            Object[] history = (Object[]) historyObj;
            DefaultRevisionEntity revision = (DefaultRevisionEntity) history[1];
            sb.append("revision = ").append(revision.getId()).append(", ");
            printPerson(sb, (Person) history[0]);
            sb.append(" (").append(revision.getRevisionDate()).append(")\n");
        }
    }
}

From source file:TestConsole.java

License:Open Source License

private void printAddressHistory(StringBuilder sb, int addressId) {
    AuditReader reader = AuditReaderFactory.get(entityManager);

    List<?> addressHistory = reader.createQuery().forRevisionsOfEntity(Address.class, false, true)
            .add(AuditEntity.id().eq(addressId)).getResultList();

    if (addressHistory.size() == 0) {
        sb.append("A address with id ").append(addressId).append(" does not exist.\n");
    } else {/*w  w w .  j  a v a  2 s .c om*/
        for (Object historyObj : addressHistory) {
            Object[] history = (Object[]) historyObj;
            DefaultRevisionEntity revision = (DefaultRevisionEntity) history[1];
            sb.append("revision = ").append(revision.getId()).append(", ");
            printAddress(sb, (Address) history[0]);
            sb.append(" (").append(revision.getRevisionDate()).append(")\n");
        }
    }
}

From source file:com.impetus.ankush.common.service.ConfigurationManager.java

License:Open Source License

/**
 * Gets the configuration.//from w  ww. j  a v a 2  s .c  o  m
 * 
 * @param clusterId
 *            the cluster id
 * @return the configuration
 */
public List getConfiguration(Long clusterId) {
    try {
        AuditReader reader = AuditReaderFactory.get(HibernateUtils.getEntityManager());
        AuditQuery query = reader.createQuery().forRevisionsOfEntity(Configuration.class, false, true);

        // filter results besed on cluster id.
        query.add(AuditEntity.property(com.impetus.ankush2.constant.Constant.Keys.CLUSTERID).eq(clusterId));
        query.addOrder(
                AuditEntity.revisionProperty(com.impetus.ankush2.constant.Constant.Keys.TIMESTAMP).desc());

        // Getting Result list.
        List list = query.getResultList();

        // Creating List Object.
        List result = new ArrayList();
        for (Object object : list) {
            Object[] obj = (Object[]) object;
            Map map = new HashMap();
            // Mapping Revision Entity.
            DefaultRevisionEntity ri = (DefaultRevisionEntity) obj[1];
            map.putAll(JsonMapperUtil.mapFromObject(obj[0]));
            map.put(com.impetus.ankush2.constant.Constant.Keys.DATE, ri.getRevisionDate());
            map.put(com.impetus.ankush2.constant.Constant.Keys.REVISIONID, ri.getId());
            map.put(com.impetus.ankush2.constant.Constant.Keys.TYPE, obj[2]);
            result.add(map);
        }
        return result;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
    return null;

}

From source file:org.azafiu.hibernatetest.rest.ProductRESTService.java

License:Apache License

/**
 * Retrieve the active products that need to be checked
 * /*from w ww .  ja va2  s.c  o  m*/
 * @return a list of {@link ProductDTO} objects
 */
@RequestMapping(value = "/checker", method = RequestMethod.GET, produces = "application/json")
public List<ProductDTO> getAllActiveProductsForChecker() {

    /** Retrieve a list of products which need checker approval */
    final List<Object[]> productChanges = this.productDao.getAllProductsWaitingForApproval();

    final List<ProductDTO> results = new ArrayList<ProductDTO>();

    for (final Object[] revision : productChanges) {

        final ProductDTO dto = new ProductDTO();

        if (revision.length > 2 && ProductEntity.class.isInstance(revision[0])) {

            /** get the current value for the {@link ProductDetailsEntity} */
            final ProductEntity currentValue = (ProductEntity) revision[0];
            if (RevisionType.class.isInstance(revision[2])) {

                // get the {@link RevisionType} of the current change
                final RevisionType rt = (RevisionType) revision[2];
                dto.setOperation(rt.name());

                // get the {@link DefaultRevisionEntity} and retrieve the
                // revision date
                final DefaultRevisionEntity revEntity = (DefaultRevisionEntity) revision[1];
                final Date revDate = revEntity.getRevisionDate();
                dto.setRevision(revDate.getTime());

                // get all product details associated with the current
                // product at the given revision
                dto.setProductDetails(
                        this.getAllProductDetailsForProductAtRevision(currentValue.getId(), revDate.getTime()));

                // if the revision type was 'MOD', search for the previous
                // value of the product to construct the product dto
                if (rt == RevisionType.MOD) {
                    final ProductEntity previousValue = this.productDao
                            .getPreviousStateForProduct(currentValue.getId(), revEntity.getId());

                    dto.setInitial(previousValue);
                    dto.setChanges(currentValue);
                } else {
                    dto.setChanges(currentValue);
                }
            }
            results.add(dto);
        }
    }

    return results;
}

From source file:org.azafiu.hibernatetest.rest.ProductRESTService.java

License:Apache License

/**
 * Retrieve all {@link ProductDetailsDTO} related to the given product at
 * the given revision/*from  ww w  . java  2  s  .  c o  m*/
 * 
 * @param prodId
 *            the id of the {@link ProductEntity}
 * @param revisionDateAsLong
 *            the timestamp of the revision as long
 * @return a list of {@link ProductDetailsDTO}
 */
private List<ProductDetailsDTO> getAllProductDetailsForProductAtRevision(final Long prodId,
        final Long revisionDateAsLong) {

    /**
     * retrieve the information about related product details from the
     * {@link ProductDetailsDAO}
     */
    final List<Object[]> changes = this.productDetailsDao.getAllProductDetailsForProductAtRevision(prodId,
            new Date(revisionDateAsLong));

    final List<ProductDetailsDTO> results = new ArrayList<ProductDetailsDTO>();

    for (final Object[] revision : changes) {

        final ProductDetailsDTO dto = new ProductDetailsDTO();
        if (revision.length > 2 && ProductDetailsEntity.class.isInstance(revision[0])) {

            /** get the current value for the {@link ProductDetailsEntity} */
            final ProductDetailsEntity currentValue = (ProductDetailsEntity) revision[0];
            if (currentValue != null) {
                currentValue.setFkProduct(prodId);
            }

            if (RevisionType.class.isInstance(revision[2])) {

                // get the {@link RevisionType} of the current change
                final RevisionType rt = (RevisionType) revision[2];
                dto.setOperation(rt.name());

                // if the revision type was 'MOD' get the previous value of
                // the entity to be able to construct the DTO
                if (rt == RevisionType.MOD) {
                    final DefaultRevisionEntity dre = (DefaultRevisionEntity) revision[1];
                    final ProductDetailsEntity previousValue = this.productDetailsDao
                            .getPreviousStateForProductDetails(currentValue.getId(), dre.getId());

                    if (previousValue != null) {
                        previousValue.setFkProduct(prodId);
                    }

                    dto.setInitial(previousValue);
                    dto.setChanges(currentValue);
                } else {
                    dto.setChanges(currentValue);
                }
            }
            results.add(dto);
        }
    }

    return results;
}

From source file:org.jboss.pnc.datastore.repositories.BuildConfigurationAuditedRepositoryImpl.java

License:Open Source License

private BuildConfigurationAudited createAudited(Object entity, Object revision,
        List<BuildRecord> buildRecords) {
    BuildConfiguration buildConfiguration = (BuildConfiguration) entity;
    DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) revision;

    //preload generic parameters
    buildConfiguration.getGenericParameters().forEach((k, v) -> k.equals(null));

    return BuildConfigurationAudited.fromBuildConfiguration(buildConfiguration, revisionEntity.getId(),
            buildRecords);//w  ww.  j  a  v a 2s.  co  m
}

From source file:org.jboss.pnc.rest.provider.BuildRecordProvider.java

License:Open Source License

private IdRev toIdRev(Object entity, Object revision) {
    BuildConfiguration buildConfiguration = (BuildConfiguration) entity;
    DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) revision;
    return new IdRev(buildConfiguration.getId(), revisionEntity.getId());
}