List of usage examples for org.hibernate.envers RevisionType MOD
RevisionType MOD
To view the source code for org.hibernate.envers RevisionType MOD.
Click Source Link
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// w w w .j av a 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.jasig.ssp.dao.PersonCoachAuditDao.java
License:Apache License
/** * Normally Coach changes are automatically logged by Envers, but in the case of Bulk Coach Re-Assign, * which uses HQL, it cannot be intercepted by Envers. * @return int saved result count (-1) on error/null parameter or (0) on empty parameter *///from w ww.j a va2 s.com public int auditBatchCoachAssignment(Person coachToSet, List<String> batchOfStudentSchoolIds) { if (coachToSet != null && batchOfStudentSchoolIds != null) { if (coachToSet.getId() != null && batchOfStudentSchoolIds.size() > 0) { try { final Session session = sessionFactory.getCurrentSession(); final UUID currentUserUUID = securityService.currentlyAuthenticatedUser().getPerson().getId(); final Date currentTimestamp = new Date(); final PersonCoachRevisionEntity revInfoEntity = new PersonCoachRevisionEntity(); //create new revinfo revInfoEntity.setTimestamp(currentTimestamp.getTime()); revInfoEntity.setModifiedDate(currentTimestamp); revInfoEntity.setModifiedBy(new AuditPerson(currentUserUUID)); session.save(revInfoEntity); //enter new row into revision info table and return auto-generated id if (revInfoEntity != null && revInfoEntity.getId() > -1) { final List<UUID> studentUUIDs = createHqlQuery(UUIDS_FROM_SCHOOLIDS_HQL_QUERY) .setParameterList("schoolIds", batchOfStudentSchoolIds).list(); //get UUIDS from SchoolIds for the batch for (UUID studentId : studentUUIDs) { final Map<String, Object> personAuditOriginalId = Maps.newHashMap(); //creates originalId portion of Person_Coach_AUD personAuditOriginalId.put("REV", revInfoEntity); personAuditOriginalId.put("id", studentId); final Map<String, Object> personAuditEntity = Maps.newHashMap(); //creates the Person_Coach_AUD record personAuditEntity.put("REVTYPE", RevisionType.MOD); personAuditEntity.put("coach_id", coachToSet.getId()); personAuditEntity.put("originalId", personAuditOriginalId); session.save("org.jasig.ssp.model.Person_AUD", personAuditEntity); } session.flush(); session.clear(); return studentUUIDs.size(); } } catch (ClassCastException | NullPointerException cne) { LOGGER.error("Error inserting batched Coach Audit records in bulk Caseload Assign!" + cne); } } else { return 0; } } return -1; }
From source file:org.jboss.pressgang.ccms.filter.utils.EntityUtilities.java
License:Open Source License
@SuppressWarnings("unchecked") public static <T extends AuditedEntity> List<Integer> getEditedBy(final EntityManager entityManager, final Class<T> clazz, final String idName, final String username) { final AuditReader reader = AuditReaderFactory.get(entityManager); final AuditQuery query = reader.createQuery().forRevisionsOfEntity(clazz, true, false) .addProjection(AuditEntity.property("originalId." + idName).distinct()) .add(AuditEntity.revisionProperty("userName").eq(username)) .add(AuditEntity.revisionType().eq(RevisionType.MOD)); return query.getResultList(); }