Skip to content

Commit ef6abc2

Browse files
committed
Added event builder
1 parent 7172d74 commit ef6abc2

File tree

3 files changed

+153
-9
lines changed

3 files changed

+153
-9
lines changed

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

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2014 Janith Bandara, This source is a part of Audit4j -
3-
* An open-source audit platform for Enterprise java platform.
3+
* An open-source audit suit for Enterprise java platform.
44
* http://mechanizedspace.com/audit4j
55
* http://audit4j.org
66
*
@@ -44,6 +44,27 @@ public class AuditEvent extends AuditBase {
4444
/** The action item. */
4545
private List<Field> fields = new ArrayList<Field>();
4646

47+
public AuditEvent() {
48+
49+
}
50+
51+
public AuditEvent(String actor, String action, Field... fields) {
52+
this.actor = actor;
53+
this.action = action;
54+
for (Field field : fields) {
55+
addField(field);
56+
}
57+
}
58+
59+
public AuditEvent(String actor, String action, String origin, Field... fields) {
60+
this.actor = actor;
61+
this.action = action;
62+
this.origin = origin;
63+
for (Field field : fields) {
64+
addField(field);
65+
}
66+
}
67+
4768
/**
4869
* Gets the actor.
4970
*
@@ -111,8 +132,12 @@ public void setAction(String action) {
111132
* @param type
112133
* the type
113134
*/
114-
public void addField(String name, String value, String type) {
115-
this.fields.add(new Field(name, value, type));
135+
public void addField(String name, String value, Object type) {
136+
this.fields.add(new Field(name, value, type.toString()));
137+
}
138+
139+
public void addField(String name, Object value) {
140+
this.fields.add(new Field(name, value.toString(), value.getClass().getName()));
116141
}
117142

118143
/**
@@ -121,13 +146,13 @@ public void addField(String name, String value, String type) {
121146
* @param element
122147
* the element
123148
*/
124-
public void addField(Field element) {
125-
this.fields.add(element);
149+
public void addField(Field field) {
150+
this.fields.add(field);
126151
}
127152

128153
/**
129154
* Gets the fields.
130-
*
155+
*
131156
* @return the fields
132157
*/
133158
public List<Field> getFields() {
@@ -136,8 +161,9 @@ public List<Field> getFields() {
136161

137162
/**
138163
* Sets the fields.
139-
*
140-
* @param fields the new fields
164+
*
165+
* @param fields
166+
* the new fields
141167
*/
142168
public void setFields(List<Field> fields) {
143169
this.fields = fields;
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright 2014 Janith Bandara, This source is a part of Audit4j -
3+
* An open-source audit suit for Enterprise java platform.
4+
* http://mechanizedspace.com/audit4j
5+
* http://audit4j.org
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
package org.audit4j.core.dto;
21+
22+
import java.util.Date;
23+
24+
/**
25+
* The Class EventBuilder.
26+
*
27+
* @author <a href="mailto:[email protected]">Janith Bandara</a>
28+
*/
29+
public class EventBuilder {
30+
31+
/** The event. */
32+
private AuditEvent event = null;
33+
34+
/**
35+
* Instantiates a new event builder.
36+
*/
37+
public EventBuilder(){
38+
event = new AuditEvent();
39+
}
40+
41+
/**
42+
* Adds the actor.
43+
*
44+
* @param actor the actor
45+
* @return the event builder
46+
*/
47+
public EventBuilder addActor(String actor){
48+
event.setActor(actor);
49+
return this;
50+
}
51+
52+
/**
53+
* Adds the action.
54+
*
55+
* @param action the action
56+
* @return the event builder
57+
*/
58+
public EventBuilder addAction(String action){
59+
event.setAction(action);
60+
return this;
61+
}
62+
63+
/**
64+
* Adds the origin.
65+
*
66+
* @param origin the origin
67+
* @return the event builder
68+
*/
69+
public EventBuilder addOrigin(String origin){
70+
event.setOrigin(origin);
71+
return this;
72+
}
73+
74+
/**
75+
* Adds the timestamp.
76+
*
77+
* @param timestamp the timestamp
78+
* @return the event builder
79+
*/
80+
public EventBuilder addTimestamp(Date timestamp){
81+
event.setTimestamp(timestamp);
82+
return this;
83+
}
84+
85+
/**
86+
* Adds the field.
87+
*
88+
* @param name the name
89+
* @param value the value
90+
* @return the event builder
91+
*/
92+
public EventBuilder addField(String name, Object value){
93+
event.addField(name, value);
94+
return this;
95+
}
96+
97+
/**
98+
* Builds the.
99+
*
100+
* @return the audit event
101+
*/
102+
public AuditEvent build(){
103+
return event;
104+
}
105+
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2014 Janith Bandara, This source is a part of Audit4j -
3-
* An open-source audit platform for Enterprise java platform.
3+
* An open-source audit suit for Enterprise java platform.
44
* http://mechanizedspace.com/audit4j
55
* http://audit4j.org
66
*
@@ -57,6 +57,19 @@ public Field(String name, String value, String type){
5757
this.value=value;
5858
this.type=type;
5959
}
60+
61+
/**
62+
* Instantiates a new element.
63+
*
64+
* @param name the name
65+
* @param value the value
66+
* @param type the type
67+
*/
68+
public Field(String name, String value){
69+
this.name=name;
70+
this.value=value;
71+
this.type=value.getClass().getName();
72+
}
6073
/**
6174
* Gets the name.
6275
*

0 commit comments

Comments
 (0)