Skip to content

Commit 5df7b77

Browse files
committed
Added uuid generation in audit events
1 parent 281153e commit 5df7b77

File tree

4 files changed

+40
-59
lines changed

4 files changed

+40
-59
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275
</plugins>
276276
</build>
277277

278-
<!-- Execute this mvn -DperformRelease=true -->
278+
<!-- Execute this mvn -DperformRelease=true -->
279279
<profiles>
280280
<profile>
281281
<id>release-sign-artifacts</id>

src/main/java/org/audit4j/core/ObjectToFieldsSerializer.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,18 @@ public final class ObjectToFieldsSerializer implements ObjectSerializer {
4747
* Converts an object to a string representation that lists all fields.
4848
*
4949
* @param auditFields the audit fields
50-
* @param object an object
50+
* @param object an object
5151
* @param objectName the object name
5252
* @param deidentify the de-identify
5353
*/
5454
public final void toFields(List<Field> auditFields, Object object, String objectName, DeIdentify deidentify) {
5555
String localOjectName = objectName;
5656
if (object == null) {
5757
auditFields.add(new Field(localOjectName, CoreConstants.NULL));
58+
return;
5859
}
60+
5961
Class<?> clazz = object.getClass();
60-
6162
if (!visited.contains(object)) {
6263
visited.add(object);
6364
if (isPrimitive(object)) {
@@ -85,7 +86,6 @@ public final void toFields(List<Field> auditFields, Object object, String object
8586
else if (objVal != null) {
8687
toFields(auditFields, objVal, internalLocalOjectName, null);
8788
}
88-
8989
}
9090
}
9191
} else if (object instanceof Collection<?>) {
@@ -113,12 +113,9 @@ else if (objVal != null) {
113113
do {
114114
java.lang.reflect.Field[] fields = clazz.getDeclaredFields();
115115
AccessibleObject.setAccessible(fields, true);
116-
117116
for (java.lang.reflect.Field field : fields) {
118117
if (!Modifier.isStatic(field.getModifiers()) && !field.isAnnotationPresent(IgnoreAudit.class)) {
119-
120118
String internalLocalOjectName2 = internalLocalOjectName + CoreConstants.DOLLAR_CHAR + field.getName();
121-
122119
boolean deidentifyFlag = false;
123120
DeIdentify deidentifyAnn = null;
124121
if (field.isAnnotationPresent(DeIdentify.class)) {

src/main/java/org/audit4j/core/dto/Event.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class Event implements Serializable {
4949
* Instantiates a new event.
5050
*/
5151
public Event() {
52+
uuid = java.util.UUID.randomUUID().getMostSignificantBits();
5253
this.timestamp = new Date();
5354
}
5455

@@ -112,7 +113,8 @@ public void setTimestamp(Date timestamp) {
112113
/**
113114
* Sets the repository.
114115
*
115-
* @param repository the new repository
116+
* @param repository
117+
* the new repository
116118
*/
117119
public void setRepository(String repository) {
118120
if (meta == null) {
@@ -124,7 +126,8 @@ public void setRepository(String repository) {
124126
/**
125127
* Sets the client.
126128
*
127-
* @param client the new client
129+
* @param client
130+
* the new client
128131
*/
129132
public void setClient(String client) {
130133
if (meta == null) {

src/test/java/org/audit4j/core/dto/AuditEventTest.java

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
import org.junit.Test;
1313

1414
/**
15-
* The class <code>AuditEventTest</code> contains tests for the class <code>{@link AuditEvent}</code>.
15+
* The class <code>AuditEventTest</code> contains tests for the class
16+
* <code>{@link AuditEvent}</code>.
1617
*
1718
* @generatedBy CodePro at 2/4/15 9:27 AM
1819
* @author JanithB
@@ -27,8 +28,7 @@ public class AuditEventTest {
2728
* @generatedBy CodePro at 2/4/15 9:27 AM
2829
*/
2930
@Test
30-
public void testAuditEvent_1()
31-
throws Exception {
31+
public void testAuditEvent_1() throws Exception {
3232

3333
AuditEvent result = new AuditEvent();
3434

@@ -38,7 +38,7 @@ public void testAuditEvent_1()
3838
assertEquals(null, result.getAction());
3939
assertEquals(null, result.getActor());
4040
assertEquals(null, result.getAuditId());
41-
assertEquals(null, result.getUuid());
41+
assertNotNull(result.getUuid());
4242
}
4343

4444
/**
@@ -49,8 +49,7 @@ public void testAuditEvent_1()
4949
* @generatedBy CodePro at 2/4/15 9:27 AM
5050
*/
5151
@Test
52-
public void testAuditEvent_2()
53-
throws Exception {
52+
public void testAuditEvent_2() throws Exception {
5453
String actor = "";
5554
String action = "";
5655

@@ -62,7 +61,7 @@ public void testAuditEvent_2()
6261
assertEquals("", result.getAction());
6362
assertEquals("", result.getActor());
6463
assertEquals(null, result.getAuditId());
65-
assertEquals(null, result.getUuid());
64+
assertNotNull(result.getUuid());
6665
}
6766

6867
/**
@@ -73,8 +72,7 @@ public void testAuditEvent_2()
7372
* @generatedBy CodePro at 2/4/15 9:27 AM
7473
*/
7574
@Test
76-
public void testAuditEvent_3()
77-
throws Exception {
75+
public void testAuditEvent_3() throws Exception {
7876
String actor = "";
7977
String action = "";
8078

@@ -86,8 +84,7 @@ public void testAuditEvent_3()
8684
assertEquals("", result.getAction());
8785
assertEquals("", result.getActor());
8886
assertEquals(null, result.getAuditId());
89-
assertEquals(null, result.getUuid());
90-
}
87+
assertNotNull(result.getUuid()); }
9188

9289
/**
9390
* Run the AuditEvent(String,String,String,Field[]) constructor test.
@@ -97,8 +94,7 @@ public void testAuditEvent_3()
9794
* @generatedBy CodePro at 2/4/15 9:27 AM
9895
*/
9996
@Test
100-
public void testAuditEvent_4()
101-
throws Exception {
97+
public void testAuditEvent_4() throws Exception {
10298
String actor = "";
10399
String action = "";
104100
String origin = "";
@@ -111,7 +107,7 @@ public void testAuditEvent_4()
111107
assertEquals("", result.getAction());
112108
assertEquals("", result.getActor());
113109
assertEquals(null, result.getAuditId());
114-
assertEquals(null, result.getUuid());
110+
assertNotNull(result.getUuid());
115111
}
116112

117113
/**
@@ -122,8 +118,7 @@ public void testAuditEvent_4()
122118
* @generatedBy CodePro at 2/4/15 9:27 AM
123119
*/
124120
@Test
125-
public void testAuditEvent_5()
126-
throws Exception {
121+
public void testAuditEvent_5() throws Exception {
127122
String actor = "";
128123
String action = "";
129124
String origin = "";
@@ -136,7 +131,7 @@ public void testAuditEvent_5()
136131
assertEquals("", result.getAction());
137132
assertEquals("", result.getActor());
138133
assertEquals(null, result.getAuditId());
139-
assertEquals(null, result.getUuid());
134+
assertNotNull(result.getUuid());
140135
}
141136

142137
/**
@@ -147,8 +142,7 @@ public void testAuditEvent_5()
147142
* @generatedBy CodePro at 2/4/15 9:27 AM
148143
*/
149144
@Test
150-
public void testAddField_1()
151-
throws Exception {
145+
public void testAddField_1() throws Exception {
152146
AuditEvent fixture = new AuditEvent("", "", "", new Field[] {});
153147
fixture.setFields(new ReadMostlyVector());
154148
Field field = new Field();
@@ -166,8 +160,7 @@ public void testAddField_1()
166160
* @generatedBy CodePro at 2/4/15 9:27 AM
167161
*/
168162
@Test
169-
public void testAddField_2()
170-
throws Exception {
163+
public void testAddField_2() throws Exception {
171164
AuditEvent fixture = new AuditEvent("", "", "", new Field[] {});
172165
fixture.setFields(new ReadMostlyVector());
173166
String name = "";
@@ -186,8 +179,7 @@ public void testAddField_2()
186179
* @generatedBy CodePro at 2/4/15 9:27 AM
187180
*/
188181
@Test
189-
public void testAddField_3()
190-
throws Exception {
182+
public void testAddField_3() throws Exception {
191183
AuditEvent fixture = new AuditEvent("", "", "", new Field[] {});
192184
fixture.setFields(new ReadMostlyVector());
193185
String name = "";
@@ -206,8 +198,7 @@ public void testAddField_3()
206198
* @generatedBy CodePro at 2/4/15 9:27 AM
207199
*/
208200
@Test
209-
public void testAddField_4()
210-
throws Exception {
201+
public void testAddField_4() throws Exception {
211202
AuditEvent fixture = new AuditEvent("", "", "", new Field[] {});
212203
fixture.setFields(new ReadMostlyVector());
213204
String name = "";
@@ -227,8 +218,7 @@ public void testAddField_4()
227218
* @generatedBy CodePro at 2/4/15 9:27 AM
228219
*/
229220
@Test
230-
public void testAddField_5()
231-
throws Exception {
221+
public void testAddField_5() throws Exception {
232222
AuditEvent fixture = new AuditEvent("", "", "", new Field[] {});
233223
fixture.setFields(new ReadMostlyVector());
234224
String name = "";
@@ -248,8 +238,7 @@ public void testAddField_5()
248238
* @generatedBy CodePro at 2/4/15 9:27 AM
249239
*/
250240
@Test
251-
public void testGetAction_1()
252-
throws Exception {
241+
public void testGetAction_1() throws Exception {
253242
AuditEvent fixture = new AuditEvent("", "", "", new Field[] {});
254243
fixture.setFields(new ReadMostlyVector());
255244

@@ -267,8 +256,7 @@ public void testGetAction_1()
267256
* @generatedBy CodePro at 2/4/15 9:27 AM
268257
*/
269258
@Test
270-
public void testGetActor_1()
271-
throws Exception {
259+
public void testGetActor_1() throws Exception {
272260
AuditEvent fixture = new AuditEvent("", "", "", new Field[] {});
273261
fixture.setFields(new ReadMostlyVector());
274262

@@ -286,8 +274,7 @@ public void testGetActor_1()
286274
* @generatedBy CodePro at 2/4/15 9:27 AM
287275
*/
288276
@Test
289-
public void testGetFields_1()
290-
throws Exception {
277+
public void testGetFields_1() throws Exception {
291278
AuditEvent fixture = new AuditEvent("", "", "", new Field[] {});
292279
fixture.setFields(new ReadMostlyVector());
293280

@@ -306,8 +293,7 @@ public void testGetFields_1()
306293
* @generatedBy CodePro at 2/4/15 9:27 AM
307294
*/
308295
@Test
309-
public void testGetOrigin_1()
310-
throws Exception {
296+
public void testGetOrigin_1() throws Exception {
311297
AuditEvent fixture = new AuditEvent("", "", "", new Field[] {});
312298
fixture.setFields(new ReadMostlyVector());
313299

@@ -325,8 +311,7 @@ public void testGetOrigin_1()
325311
* @generatedBy CodePro at 2/4/15 9:27 AM
326312
*/
327313
@Test
328-
public void testSetAction_1()
329-
throws Exception {
314+
public void testSetAction_1() throws Exception {
330315
AuditEvent fixture = new AuditEvent("", "", "", new Field[] {});
331316
fixture.setFields(new ReadMostlyVector());
332317
String action = "";
@@ -344,8 +329,7 @@ public void testSetAction_1()
344329
* @generatedBy CodePro at 2/4/15 9:27 AM
345330
*/
346331
@Test
347-
public void testSetActor_1()
348-
throws Exception {
332+
public void testSetActor_1() throws Exception {
349333
AuditEvent fixture = new AuditEvent("", "", "", new Field[] {});
350334
fixture.setFields(new ReadMostlyVector());
351335
String actor = "";
@@ -363,8 +347,7 @@ public void testSetActor_1()
363347
* @generatedBy CodePro at 2/4/15 9:27 AM
364348
*/
365349
@Test
366-
public void testSetFields_1()
367-
throws Exception {
350+
public void testSetFields_1() throws Exception {
368351
AuditEvent fixture = new AuditEvent("", "", "", new Field[] {});
369352
fixture.setFields(new ReadMostlyVector());
370353
List<Field> fields = new ReadMostlyVector();
@@ -382,8 +365,7 @@ public void testSetFields_1()
382365
* @generatedBy CodePro at 2/4/15 9:27 AM
383366
*/
384367
@Test
385-
public void testSetOrigin_1()
386-
throws Exception {
368+
public void testSetOrigin_1() throws Exception {
387369
AuditEvent fixture = new AuditEvent("", "", "", new Field[] {});
388370
fixture.setFields(new ReadMostlyVector());
389371
String origin = "";
@@ -397,34 +379,33 @@ public void testSetOrigin_1()
397379
* Perform pre-test initialization.
398380
*
399381
* @throws Exception
400-
* if the initialization fails for some reason
382+
* if the initialization fails for some reason
401383
*
402384
* @generatedBy CodePro at 2/4/15 9:27 AM
403385
*/
404386
@Before
405-
public void setUp()
406-
throws Exception {
387+
public void setUp() throws Exception {
407388
// add additional set up code here
408389
}
409390

410391
/**
411392
* Perform post-test clean-up.
412393
*
413394
* @throws Exception
414-
* if the clean-up fails for some reason
395+
* if the clean-up fails for some reason
415396
*
416397
* @generatedBy CodePro at 2/4/15 9:27 AM
417398
*/
418399
@After
419-
public void tearDown()
420-
throws Exception {
400+
public void tearDown() throws Exception {
421401
// Add additional tear down code here
422402
}
423403

424404
/**
425405
* Launch the test.
426406
*
427-
* @param args the command line arguments
407+
* @param args
408+
* the command line arguments
428409
*
429410
* @generatedBy CodePro at 2/4/15 9:27 AM
430411
*/

0 commit comments

Comments
 (0)