List of usage examples for org.hibernate.envers DefaultRevisionEntity getRevisionDate
@Transient
public Date getRevisionDate()
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 w w . j av a 2 s . c o m*/ 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 {//from w w w . ja v a 2 s . c o m 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 a2 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 * // ww w. jav a 2 s. co 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.cast.cwm.admin.UserContentLogPage.java
License:Open Source License
protected List<IDataColumn<AuditTriple<UserContent, DefaultRevisionEntity>>> makeColumns() { List<IDataColumn<AuditTriple<UserContent, DefaultRevisionEntity>>> columns = new ArrayList<IDataColumn<AuditTriple<UserContent, DefaultRevisionEntity>>>( 10);//from w w w .j ava2 s. c o m columns.add(new PropertyDataColumn<AuditTriple<UserContent, DefaultRevisionEntity>>("Rev ID", "info.id")); columns.add(new AbstractDataColumn<AuditTriple<UserContent, DefaultRevisionEntity>>("Rev Date") { private static final long serialVersionUID = 1L; @Override public void populateItem(Item<ICellPopulator<AuditTriple<UserContent, DefaultRevisionEntity>>> cellItem, String componentId, IModel<AuditTriple<UserContent, DefaultRevisionEntity>> rowModel) { cellItem.add(DateLabel.forDatePattern(componentId, new PropertyModel<Date>(rowModel, "info.revisionDate"), eventDateFormat)); } @Override public String getItemString(IModel<AuditTriple<UserContent, DefaultRevisionEntity>> rowModel) { AuditTriple<UserContent, DefaultRevisionEntity> triple = rowModel.getObject(); DefaultRevisionEntity info = triple.getInfo(); Date revisionDate = info.getRevisionDate(); return new SimpleDateFormat(eventDateFormat).format(revisionDate); } }); columns.add(new PropertyDataColumn<AuditTriple<UserContent, DefaultRevisionEntity>>("Rev Type", "type")); columns.add(new PropertyDataColumn<AuditTriple<UserContent, DefaultRevisionEntity>>("UC ID", "entity.id")); columns.add(new PropertyDataColumn<AuditTriple<UserContent, DefaultRevisionEntity>>("User", "entity.user.subjectId")); columns.add( new PropertyDataColumn<AuditTriple<UserContent, DefaultRevisionEntity>>("Type", "entity.dataType")); columns.add( new PropertyDataColumn<AuditTriple<UserContent, DefaultRevisionEntity>>("Title", "entity.title")); // What to do with the content column depends on the data type. columns.add(new AbstractDataColumn<AuditTriple<UserContent, DefaultRevisionEntity>>("Content") { private static final long serialVersionUID = 1L; @Override public void populateItem(Item<ICellPopulator<AuditTriple<UserContent, DefaultRevisionEntity>>> item, String componentId, IModel<AuditTriple<UserContent, DefaultRevisionEntity>> rowModel) { UserContent uc = rowModel.getObject().getEntity(); if (!rowModel.getObject().getType().equals(RevisionType.DEL)) { if (uc.getDataType().getName().equals("TEXT")) item.add(new Label(componentId, new PropertyModel<String>(rowModel, "entity.text"))); else item.add(new ContentLinkPanel(componentId, rowModel.getObject().getEntity().getId(), rowModel.getObject().getInfo().getId())); } else { item.add(new EmptyPanel(componentId)); } } @Override public String getItemString(IModel<AuditTriple<UserContent, DefaultRevisionEntity>> rowModel) { UserContent uc = rowModel.getObject().getEntity(); if (uc.getDataType().getName().equals("TEXT")) { return rowModel.getObject().getEntity().getText(); } else { // output a text link for the spreadsheet Url path = Url.parse(urlFor(UserContentViewPage.class, getPageParameters( rowModel.getObject().getEntity().getId(), rowModel.getObject().getInfo().getId())) .toString()); return getRequestCycle().getUrlRenderer().renderFullUrl(path); // TODO, if we have a urlPrefix, replace Tomcat's idea of the URL with the given prefix. } } }); return columns; }