1 package org.exoplatform.ecm.webui.component.explorer.auditing;
2
3
4 import java.util.ArrayList;
5 import java.util.Calendar;
6 import java.util.List;
7
8 import javax.jcr.Node;
9
10 import org.exoplatform.commons.utils.LazyPageList;
11 import org.exoplatform.commons.utils.ListAccess;
12 import org.exoplatform.commons.utils.ListAccessImpl;
13 import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
14 import org.exoplatform.ecm.webui.utils.Utils;
15 import org.exoplatform.services.jcr.ext.audit.AuditHistory;
16 import org.exoplatform.services.jcr.ext.audit.AuditRecord;
17 import org.exoplatform.services.jcr.ext.audit.AuditService;
18 import org.exoplatform.services.log.ExoLogger;
19 import org.exoplatform.services.log.Log;
20 import org.exoplatform.webui.config.annotation.ComponentConfig;
21 import org.exoplatform.webui.config.annotation.EventConfig;
22 import org.exoplatform.webui.core.UIContainer;
23 import org.exoplatform.webui.core.UIPageIterator;
24 import org.exoplatform.webui.core.UIPopupComponent;
25 import org.exoplatform.webui.event.Event;
26 import org.exoplatform.webui.event.EventListener;
27
28
29
30
31
32
33 @ComponentConfig(
34 template = "app:/groovy/webui/component/explorer/auditing/UIAuditingInfo.gtmpl",
35 events = {
36 @EventConfig(listeners = UIAuditingInfo.CloseActionListener.class)
37 }
38 )
39 public class UIAuditingInfo extends UIContainer implements UIPopupComponent {
40 private UIPageIterator uiPageIterator_ ;
41 private static final Log LOG = ExoLogger.getLogger(UIAuditingInfo.class.getName());
42 public UIAuditingInfo() throws Exception {
43 uiPageIterator_ = addChild(UIPageIterator.class, null, "AuditingInfoIterator");
44 }
45
46 public void activate() { }
47 public void deActivate() { }
48
49 public Node getCurrentNode() throws Exception {
50 return getAncestorOfType(UIJCRExplorer.class).getCurrentNode();
51 }
52
53 public UIPageIterator getUIPageIterator() { return uiPageIterator_; }
54
55 public List getListRecords() throws Exception { return uiPageIterator_.getCurrentPageData(); }
56
57 @SuppressWarnings("unchecked")
58 public void updateGrid() throws Exception {
59 ListAccess<AuditRecordData> recordList = new ListAccessImpl<AuditRecordData>(AuditRecordData.class,
60 getRecords());
61 LazyPageList<AuditRecordData> dataPageList = new LazyPageList<AuditRecordData>(recordList, 10);
62 uiPageIterator_.setPageList(dataPageList);
63 }
64
65 public List<AuditRecordData> getRecords() throws Exception {
66 List<AuditRecordData> listRec = new ArrayList<AuditRecordData>();
67 Node currentNode = getCurrentNode();
68 try {
69 AuditService auditService = getApplicationComponent(AuditService.class);
70 if(Utils.isAuditable(currentNode)){
71 if (auditService.hasHistory(currentNode)){
72 AuditHistory auHistory = auditService.getHistory(currentNode);
73 for(AuditRecord auditRecord : auHistory.getAuditRecords()) {
74 listRec.add(new AuditRecordData(auditRecord));
75 }
76 }
77 }
78 } catch(Exception e){
79 if (LOG.isErrorEnabled()) {
80 LOG.error("Unexpected error", e);
81 }
82 }
83 return listRec;
84 }
85
86 static public class CloseActionListener extends EventListener<UIAuditingInfo> {
87 public void execute(Event<UIAuditingInfo> event) throws Exception {
88 UIAuditingInfo uiAuditingInfo = event.getSource();
89 UIJCRExplorer uiExplorer = uiAuditingInfo.getAncestorOfType(UIJCRExplorer.class);
90 uiExplorer.cancelAction();
91 }
92 }
93
94 public static class AuditRecordData {
95 private String versionName_;
96 private String eventType_;
97 private String userId_;
98 private Calendar date_;
99
100 public AuditRecordData(AuditRecord auditRecord) {
101 versionName_ = null;
102 versionName_ = auditRecord.getVersionName();
103 eventType_ = String.valueOf(auditRecord.getEventType());
104 userId_ = auditRecord.getUserId();
105 date_ = auditRecord.getDate();
106 }
107
108 public String getVersionName() {
109 return versionName_;
110 }
111
112 public void setVersionName(String versionName) {
113 versionName_ = versionName;
114 }
115
116 public String getEventType() {
117 return eventType_;
118 }
119
120 public void setEventType(String eventType) {
121 eventType_ = eventType;
122 }
123
124 public String getUserId() {
125 return userId_;
126 }
127
128 public void setUserId(String userId) {
129 userId_ = userId;
130 }
131
132 public Calendar getDate() {
133 return date_;
134 }
135
136 public void setDate(Calendar date) {
137 date_ = date;
138 }
139 }
140 }