1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.audit;
35
36 import info.magnolia.jcr.decoration.ContentDecoratorNodeWrapper;
37
38 import java.io.InputStream;
39 import java.math.BigDecimal;
40 import java.util.Calendar;
41 import java.util.LinkedHashMap;
42 import java.util.LinkedList;
43 import java.util.Map;
44 import java.util.Map.Entry;
45
46 import javax.jcr.AccessDeniedException;
47 import javax.jcr.Binary;
48 import javax.jcr.InvalidItemStateException;
49 import javax.jcr.ItemExistsException;
50 import javax.jcr.Node;
51 import javax.jcr.PathNotFoundException;
52 import javax.jcr.Property;
53 import javax.jcr.ReferentialIntegrityException;
54 import javax.jcr.RepositoryException;
55 import javax.jcr.Value;
56 import javax.jcr.ValueFormatException;
57 import javax.jcr.lock.LockException;
58 import javax.jcr.nodetype.ConstraintViolationException;
59 import javax.jcr.nodetype.NoSuchNodeTypeException;
60 import javax.jcr.nodetype.NodeType;
61 import javax.jcr.version.VersionException;
62
63
64
65
66
67
68 public class MgnlAuditLoggingContentDecoratorNodeWrapper extends ContentDecoratorNodeWrapper<MgnlAuditLoggingContentDecorator> {
69
70 public MgnlAuditLoggingContentDecoratorNodeWrapper(Node node, MgnlAuditLoggingContentDecorator contentDecorator) {
71 super(node, contentDecorator);
72 }
73
74 @Override
75 public Node addNode(String relPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException {
76 Node node = super.addNode(relPath);
77 getContentDecorator().logActionCreate(node);
78 return node;
79 }
80
81 @Override
82 public Node addNode(String relPath, String primaryNodeTypeName) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException {
83 Node node = super.addNode(relPath, primaryNodeTypeName);
84 getContentDecorator().logActionCreate(node);
85 return node;
86 }
87
88 @Override
89 public void remove() throws VersionException, LockException, ConstraintViolationException, AccessDeniedException, RepositoryException {
90 final NodeType nodeType = getPrimaryNodeType();
91 final String path = getPath();
92 final String workspace = getSession().getWorkspace().getName();
93 super.remove();
94 getContentDecorator().logActionDelete(path, workspace, nodeType);
95
96 }
97
98 @Override
99 public void addMixin(String mixinName) throws NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException {
100 super.addMixin(mixinName);
101 getContentDecorator().logActionModify(this);
102 }
103
104 @Override
105 public void removeMixin(String mixinName) throws NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException {
106 super.removeMixin(mixinName);
107 getContentDecorator().logActionModify(this);
108 }
109
110 @Override
111 public void setPrimaryType(String nodeTypeName) throws NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException {
112 super.setPrimaryType(nodeTypeName);
113 getContentDecorator().logActionModify(this);
114 }
115
116 @Override
117 public Property setProperty(String name, Value value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
118 Property property = super.setProperty(name, value);
119 getContentDecorator().logActionModify(this);
120 return property;
121 }
122
123 @Override
124 public Property setProperty(String name, Value[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
125 Property property = super.setProperty(name, values);
126 getContentDecorator().logActionModify(this);
127 return property;
128 }
129
130 @Override
131 public Property setProperty(String name, String[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
132 Property property = super.setProperty(name, values);
133 getContentDecorator().logActionModify(this);
134 return property;
135 }
136
137 @Override
138 public Property setProperty(String name, String value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
139 Property property = super.setProperty(name, value);
140 getContentDecorator().logActionModify(this);
141 return property;
142 }
143
144 @Override
145 public Property setProperty(String name, InputStream value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
146 Property property = super.setProperty(name, value);
147 getContentDecorator().logActionModify(this);
148 return property;
149 }
150
151 @Override
152 public Property setProperty(String name, Binary value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
153 Property property = super.setProperty(name, value);
154 getContentDecorator().logActionModify(this);
155 return property;
156 }
157
158 @Override
159 public Property setProperty(String name, boolean value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
160 Property property = super.setProperty(name, value);
161 getContentDecorator().logActionModify(this);
162 return property;
163 }
164
165 @Override
166 public Property setProperty(String name, double value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
167 Property property = super.setProperty(name, value);
168 getContentDecorator().logActionModify(this);
169 return property;
170 }
171
172 @Override
173 public Property setProperty(String name, BigDecimal value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
174 Property property = super.setProperty(name, value);
175 getContentDecorator().logActionModify(this);
176 return property;
177 }
178
179 @Override
180 public Property setProperty(String name, long value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
181 Property property = super.setProperty(name, value);
182 getContentDecorator().logActionModify(this);
183 return property;
184 }
185
186 @Override
187 public Property setProperty(String name, Calendar value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
188 Property property = super.setProperty(name, value);
189 getContentDecorator().logActionModify(this);
190 return property;
191 }
192
193 @Override
194 public Property setProperty(String name, Node value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
195 Property property = super.setProperty(name, value);
196 getContentDecorator().logActionModify(this);
197 return property;
198 }
199
200 @Override
201 public Property setProperty(String name, Value value, int type) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
202 Property property = super.setProperty(name, value);
203 getContentDecorator().logActionModify(this);
204 return property;
205 }
206
207 @Override
208 public Property setProperty(String name, Value[] values, int type) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
209 Property property = super.setProperty(name, values);
210 getContentDecorator().logActionModify(this);
211 return property;
212 }
213
214 @Override
215 public Property setProperty(String name, String[] values, int type) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
216 Property property = super.setProperty(name, values);
217 getContentDecorator().logActionModify(this);
218 return property;
219 }
220
221 @Override
222 public Property setProperty(String name, String value, int type) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
223 Property property = super.setProperty(name, value);
224 getContentDecorator().logActionModify(this);
225 return property;
226 }
227
228
229
230
231 @Override
232 public void save() throws AccessDeniedException, ItemExistsException, ConstraintViolationException, InvalidItemStateException, ReferentialIntegrityException, VersionException, LockException, NoSuchNodeTypeException, RepositoryException {
233 super.save();
234
235 Map<String, LinkedList<MgnlAuditLogEntry>> logMap = getContentDecorator().getLogEntries();
236 Map<String, LinkedList<MgnlAuditLogEntry>> temp = new LinkedHashMap<String, LinkedList<MgnlAuditLogEntry>>();
237 temp.putAll(logMap);
238 final String path = getPath();
239 for (Entry<String, LinkedList<MgnlAuditLogEntry>> pathLogEntries : temp.entrySet()) {
240 if (pathLogEntries.getKey().equals(path) || pathLogEntries.getKey().startsWith(path + "/")) {
241 for (MgnlAuditLogEntry entry : pathLogEntries.getValue()) {
242 AuditLoggingUtil.log(entry.getAction(), entry.getTimeStamp(), entry.getWorkspace(), entry.getNodeType(), entry.getPath(), entry.getPathTo());
243 }
244 logMap.remove(pathLogEntries.getKey());
245 }
246 }
247 }
248
249 }