Skip to content

Commit 85d5e79

Browse files
committed
Revamping code
1 parent 0c86926 commit 85d5e79

26 files changed

+265
-89
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@
100100
<version>2.5</version>
101101
<scope>provided</scope>
102102
</dependency>
103+
<dependency>
104+
<groupId>javax.servlet</groupId>
105+
<artifactId>javax.servlet-api</artifactId>
106+
<version>3.1.0</version>
107+
<scope>provided</scope>
108+
</dependency>
103109
</dependencies>
104110

105111

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
public class AnnotationTransformer {
3939

4040
/**
41-
* Transform to event.
41+
* Transform annotation informations to Audit Event object.
4242
*
4343
* @param annotationEvent
4444
* the annotation event

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ protected void executeHandlers(AuditEvent event) {
6565
}
6666
}
6767
if (execute) {
68-
// event.setActor(getConf().getMetaData().getActor());
6968
String formattedEvent = configContext.getLayout().format(event);
7069
for (final Handler handler : configContext.getHandlers()) {
7170
handler.setAuditEvent(event);
@@ -79,6 +78,11 @@ protected void executeHandlers(AuditEvent event) {
7978
}
8079
}
8180

81+
/**
82+
* Sets the config context.
83+
*
84+
* @param configContext the new config context
85+
*/
8286
public void setConfigContext(ConcurrentConfigurationContext configContext) {
8387
this.configContext = configContext;
8488
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
* </ul>
4747
*
4848
* @author <a href="mailto:[email protected]">Janith Bandara</a>
49+
*
50+
* @since 2.3.0
4951
*/
5052
@ThreadSafe
5153
public final class ConcurrentConfigurationContext {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ private ConfigUtil() {
4949

5050
/**
5151
* Generate config from object.
52+
* @throws ConfigurationException
5253
*/
53-
static void generateConfigFromObject() {
54+
static void generateConfigFromObject() throws ConfigurationException {
5455
YamlWriter writer;
5556
try {
5657
writer = new YamlWriter(new FileWriter("audit4j.conf.yml"));
5758
writer.getConfig().setClassTag("Configuration", Configuration.class);
5859
writer.write(Configuration.DEFAULT);
5960
writer.close();
6061
} catch (IOException e) {
61-
// TODO Auto-generated catch block
62-
e.printStackTrace();
62+
throw new ConfigurationException("Configuration Exception", "CONF_002");
6363
}
6464
}
6565

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.audit4j.core.dto.AuditEvent;
2222
import org.audit4j.core.exception.ConfigurationException;
23+
import org.audit4j.core.exception.InitializationException;
2324
import org.audit4j.core.exception.TroubleshootException;
2425
import org.audit4j.core.util.Log;
2526

@@ -79,22 +80,15 @@ public static void troubleshootConfiguration(ConfigurationException e) {
7980
if (e.getId().equals("CONF_001")) {
8081
Log.warn("Initial confguration file not found. Creating a new configuration file - ",
8182
CoreConstants.CONFIG_FILE_NAME);
82-
ConfigUtil.generateConfigFromObject();
83+
try {
84+
ConfigUtil.generateConfigFromObject();
85+
} catch (ConfigurationException e1) {
86+
throw new InitializationException("Initialization Failed.! Unable to create new configuration file.");
87+
}
8388
} else if (e.getId().equals("CONF_002")) {
8489
Log.error("Configuration file currupted or invalid configuration. ",
8590
ErrorGuide.getGuide(ErrorGuide.CONFIG_ERROR));
8691
throw new TroubleshootException("Configuration error", e);
8792
}
8893
}
89-
90-
/**
91-
* Checks if is windows.
92-
*
93-
* @return true, if is windows
94-
*/
95-
public static boolean isWindows() {
96-
String os = System.getProperty("os.name");
97-
return os.startsWith("Windows");
98-
}
99-
10094
}

src/main/java/org/audit4j/core/annotation/Audit.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626

2727
import javax.interceptor.InterceptorBinding;
2828

29-
3029
/**
31-
* The Interface Audit.
32-
*
30+
* The Audit annotation.
31+
*
32+
* This annotation can be used either in class level or method level. When
33+
* applying this annotation, the class or methos is marked as auditable.
34+
*
3335
* @author <a href="mailto:[email protected]">Janith Bandara</a>
3436
*
3537
* @since 1.0.0
@@ -39,18 +41,18 @@
3941
@Retention(RetentionPolicy.RUNTIME)
4042
@Target(value = { ElementType.TYPE, ElementType.METHOD })
4143
public @interface Audit {
42-
43-
/**
44-
* Action.
45-
*
46-
* @return the string
47-
*/
48-
public String action() default "action";
4944

50-
/**
51-
* Selection.
52-
*
53-
* @return the string
54-
*/
55-
public SelectionType selection() default SelectionType.ALL;
45+
/**
46+
* Action.
47+
*
48+
* @return the string
49+
*/
50+
public String action() default "action";
51+
52+
/**
53+
* Selection.
54+
*
55+
* @return the string
56+
*/
57+
public SelectionType selection() default SelectionType.ALL;
5658
}

src/main/java/org/audit4j/core/annotation/AuditField.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
import java.lang.annotation.Target;
2626

2727
/**
28-
* The Interface AuditField.
29-
*
28+
* The AuditField annotation.
29+
*
30+
* This Annotation is used to mark parameters which will include in the audit
31+
* event.
32+
*
3033
* @author <a href="mailto:[email protected]">Janith Bandara</a>
3134
*
3235
* @since 1.0.0
@@ -36,10 +39,10 @@
3639
@Target(value = { ElementType.PARAMETER })
3740
public @interface AuditField {
3841

39-
/**
40-
* Field.
41-
*
42-
* @return the string
43-
*/
44-
public String field();
42+
/**
43+
* Field.
44+
*
45+
* @return the string
46+
*/
47+
public String field();
4548
}

src/main/java/org/audit4j/core/annotation/DeIdentify.java

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
import java.lang.annotation.Target;
2626

2727
/**
28-
* The Interface DeIdentify.
29-
*
28+
* The DeIdentify annotation.
29+
*
30+
* This can be used to deidentify certain fields. This applies a mask for
31+
* certain characters with ‘*’ charactor.
32+
*
3033
* @author <a href="mailto:[email protected]">Janith Bandara</a>
3134
*
3235
* @since 2.0
@@ -36,32 +39,32 @@
3639
@Target(value = { ElementType.PARAMETER })
3740
public @interface DeIdentify {
3841

39-
/**
40-
* Left.
41-
*
42-
* @return the int
43-
*/
44-
public int left() default 0;
42+
/**
43+
* Left.
44+
*
45+
* @return the int
46+
*/
47+
public int left() default 0;
4548

46-
/**
47-
* Right.
48-
*
49-
* @return the int
50-
*/
51-
public int right() default 0;
49+
/**
50+
* Right.
51+
*
52+
* @return the int
53+
*/
54+
public int right() default 0;
5255

53-
/**
54-
* From left.
55-
*
56-
* @return the int
57-
*/
58-
public int fromLeft() default 0;
56+
/**
57+
* From left.
58+
*
59+
* @return the int
60+
*/
61+
public int fromLeft() default 0;
5962

60-
/**
61-
* From right.
62-
*
63-
* @return the int
64-
*/
65-
public int fromRight() default 0;
63+
/**
64+
* From right.
65+
*
66+
* @return the int
67+
*/
68+
public int fromRight() default 0;
6669

6770
}

src/main/java/org/audit4j/core/annotation/IgnoreAudit.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
/**
2828
* Audit Ignore Annotation.
2929
*
30+
* When The particular class marked for audit using @Audit annotation but
31+
* specific method should not be audited, This annotation can be added.
32+
*
3033
* @author <a href="mailto:[email protected]">Janith Bandara</a>
3134
*
3235
* @since 2.2.0

0 commit comments

Comments
 (0)