-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/pl/softwaremill/demo/view/PersonHistoryBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package pl.softwaremill.demo.view; | ||
|
||
import org.hibernate.envers.AuditReader; | ||
import org.hibernate.envers.AuditReaderFactory; | ||
import org.hibernate.envers.DefaultRevisionEntity; | ||
import org.hibernate.envers.query.AuditEntity; | ||
import org.jboss.seam.transaction.Transactional; | ||
import pl.softwaremill.demo.domain.Person; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.persistence.EntityManager; | ||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Adam Warski (adam at warski dot org) | ||
*/ | ||
@Transactional | ||
@Named | ||
@RequestScoped | ||
public class PersonHistoryBean { | ||
@Inject | ||
private EntityManager entityManager; | ||
|
||
private List<PersonHistoryEntry> list; | ||
|
||
public List<PersonHistoryEntry> getList() { | ||
if (list == null) { | ||
AuditReader auditReader = AuditReaderFactory.get(entityManager); | ||
@SuppressWarnings({"unchecked"}) List<Object[]> revDatas = (List<Object[]>) auditReader | ||
.createQuery() | ||
.forRevisionsOfEntity(Person.class, false, false) | ||
.add(AuditEntity.id().eq(id)) | ||
.getResultList(); | ||
|
||
list = new ArrayList<PersonHistoryEntry>(); | ||
for (Object[] revData : revDatas) { | ||
list.add(new PersonHistoryEntry((Person) revData[0], (DefaultRevisionEntity) revData[1])); | ||
} | ||
} | ||
|
||
return list; | ||
} | ||
|
||
private Long id; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public static class PersonHistoryEntry { | ||
private final Person person; | ||
private final String changeDate; | ||
|
||
public PersonHistoryEntry(Person person, DefaultRevisionEntity revision) { | ||
this.person = person; | ||
this.changeDate = DateFormat.getTimeInstance().format(revision.getRevisionDate()); | ||
} | ||
|
||
public String getChangeDate() { | ||
return changeDate; | ||
} | ||
|
||
public Person getPerson() { | ||
return person; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version='1.0' encoding='UTF-8' ?> | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:h="http://java.sun.com/jsf/html" | ||
xmlns:f="http://java.sun.com/jsf/core" | ||
xmlns:ui="http://java.sun.com/jsf/facelets" | ||
xmlns:m="http://metawidget.org/faces" | ||
xmlns:c="http://java.sun.com/jsp/jstl/core"> | ||
|
||
<f:metadata> | ||
<f:viewParam name="id" value="#{personHistoryBean.id}"> | ||
<f:validateLongRange minimum="1" /> | ||
</f:viewParam> | ||
</f:metadata> | ||
|
||
<ui:composition template="/resources/scaffold/forge-template.xhtml"> | ||
|
||
<ui:param name="pageTitle" value="View Person History" /> | ||
|
||
<ui:define name="header"> | ||
Person History | ||
</ui:define> | ||
|
||
<ui:define name="subheader"> | ||
Changes made to your object | ||
</ui:define> | ||
|
||
<ui:define name="footer"> | ||
</ui:define> | ||
|
||
<ui:define name="main"> | ||
<h:form id="form"> | ||
<h:messages globalOnly="true"/> | ||
<br/> | ||
|
||
<ui:repeat var="entry" value="#{personHistoryBean.list}"> | ||
|
||
<li> | ||
<m:metawidget value="#{entry.person}" readOnly="true" rendererType="simple" style="margin-right: 0.5em"/> | ||
changed on | ||
#{entry.changeDate} | ||
</li> | ||
|
||
</ui:repeat> | ||
|
||
<br/> | ||
|
||
<h:link value="Back" outcome="view"> | ||
<f:param name="id" value="#{personHistoryBean.id}" /> | ||
<f:param name="edit" value="false" /> | ||
</h:link> | ||
</h:form> | ||
</ui:define> | ||
|
||
</ui:composition> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters