Skip to content

Commit 0c86926

Browse files
committed
added archiving changes, fixed test faliures
1 parent ba1cf30 commit 0c86926

17 files changed

+550
-124
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ public boolean audit(AnnotationAuditEvent annotationEvent) {
115115
* @return single instance of AuditHelper
116116
*/
117117
public static AuditManager getInstance() {
118+
init();
118119
synchronized (AuditManager.class) {
119120
if (auditManager == null) {
120121
auditManager = new AuditManager();
121-
init();
122122
}
123123
}
124124
return auditManager;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ public static void initWithConfiguration(String configFilePath) {
209209
*/
210210
final static void stop() {
211211
if (configContext.getRunStatus().equals(RunStatus.RUNNING)) {
212+
configContext.setRunStatus(RunStatus.STOPPED);
213+
initialized = false;
212214
Log.info("Preparing to shutdown Audit4j...");
213215

214216
Log.info("Closing Streams...");
@@ -222,8 +224,7 @@ final static void stop() {
222224
}
223225

224226
Log.info("Disposing configurations...");
225-
initialized = false;
226-
configContext.setRunStatus(RunStatus.STOPPED);
227+
227228
Log.info("Audit4j shutdown completed.");
228229
} else {
229230
Log.info("No active Audit4j instance. Cancelling shutdown request.");

src/main/java/org/audit4j/core/handler/file/FileAuditHandler.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525
import org.audit4j.core.exception.InitializationException;
2626
import org.audit4j.core.handler.Handler;
27-
import org.audit4j.core.handler.file.archive.ArchiveJob;
28-
import org.audit4j.core.handler.file.archive.ArchiveManager;
27+
import org.audit4j.core.handler.file.archive.AbstractArchiveJob;
2928

3029
/**
3130
* The Class FileAuditHandler.
@@ -54,7 +53,7 @@ public class FileAuditHandler extends Handler {
5453
private String cronPattern;
5554

5655
/** The job. */
57-
private ArchiveJob job;
56+
private AbstractArchiveJob job;
5857

5958
private String auditFilePrefix = "Audit_Log-";
6059

@@ -77,14 +76,14 @@ public void init() throws InitializationException {
7776
// + getProperty("log.file.location"));
7877
// }
7978

80-
if (null != archive && "true".equals(archive)) {
81-
ArchiveManager manager = new ArchiveManager();
82-
manager.setArchiveDate(datePattern);
83-
manager.setCronPattern(cronPattern);
84-
manager.setPath(getProperty("log.file.location"));
85-
manager.setJob(job);
86-
manager.init();
87-
}
79+
// if (null != archive && "true".equals(archive)) {
80+
// ArchiveManager manager = new ArchiveManager();
81+
// manager.setArchiveDate(datePattern);
82+
// manager.setCronPattern(cronPattern);
83+
// manager.setPath(getProperty("log.file.location"));
84+
// manager.setJob(job);
85+
// manager.init();
86+
// }
8887
}
8988

9089
/*

src/main/java/org/audit4j/core/handler/file/archive/ArchiveJob.java renamed to src/main/java/org/audit4j/core/handler/file/archive/AbstractArchiveJob.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.text.ParseException;
2525
import java.util.Date;
2626

27-
import org.audit4j.core.CoreConstants;
2827
import org.audit4j.core.Initializable;
2928
import org.audit4j.core.exception.Audit4jRuntimeException;
3029
import org.audit4j.core.util.AuditUtil;
@@ -36,7 +35,7 @@
3635
*
3736
* @since 1.0.1
3837
*/
39-
public abstract class ArchiveJob implements Initializable, Serializable {
38+
public abstract class AbstractArchiveJob implements Initializable, Serializable {
4039

4140
/** The archive date diff. */
4241
protected Integer archiveDateDiff;
@@ -47,26 +46,42 @@ public abstract class ArchiveJob implements Initializable, Serializable {
4746
/** The archive options. */
4847
protected String archiveOptions;
4948

49+
/** The compression extention. */
50+
protected String compressionExtention;
51+
5052
/**
5153
* Archive.
5254
*/
5355
abstract void archive();
5456

57+
/**
58+
* Gets the available files.
59+
*
60+
* @param logFileLocation the log file location
61+
* @param maxDate the max date
62+
* @return the available files
63+
*/
5564
protected File[] getAvailableFiles(final String logFileLocation, final Date maxDate) {
5665

5766
File dir = new File(logFileLocation);
5867

5968
return dir.listFiles(new FilenameFilter() {
6069
@Override
6170
public boolean accept(File dir, String fileName) {
62-
boolean extentionMatch = fileName.endsWith(CoreConstants.AUDIT_EXTENTION);
71+
boolean extentionMatch = fileName.endsWith(compressionExtention);
6372
boolean dateMatch = maxDate.before(fileCreatedDate(fileName));
6473
return dateMatch && extentionMatch;
6574
}
6675
});
6776

6877
}
6978

79+
/**
80+
* File created date.
81+
*
82+
* @param fileName the file name
83+
* @return the date
84+
*/
7085
private Date fileCreatedDate(String fileName) {
7186
String[] splittedWithoutExtention = fileName.split(".");
7287
String fileNameWithoutExtention = splittedWithoutExtention[0];
@@ -109,4 +124,13 @@ public void setArchiveOptions(String archiveOptions) {
109124
this.archiveOptions = archiveOptions;
110125
}
111126

127+
/**
128+
* Sets the compression extention.
129+
*
130+
* @param compressionExtention the new compression extention
131+
*/
132+
public void setCompressionExtention(String compressionExtention) {
133+
this.compressionExtention = compressionExtention;
134+
}
135+
112136
}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
package org.audit4j.core.handler.file.archive;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
/**
9+
* The Class ArchiveEnv.
10+
*
11+
* @author <a href="mailto:[email protected]">Janith Bandara</a>
12+
*/
13+
public class ArchiveEnv {
14+
15+
/** The date pattern. */
16+
private final String datePattern = "1d";
17+
18+
/** The cron pattern. */
19+
private String cronPattern;
20+
21+
/** The dir path. */
22+
private String dirPath;
23+
24+
/** The compression. */
25+
private Compression compression = Compression.ZIP;
26+
27+
/** The properties. */
28+
private Map<String, String> properties = new HashMap<String, String>();
29+
30+
/** The archive types. */
31+
private List<ArchiveType> archiveTypes = new ArrayList<ArchiveType>();
32+
33+
/** The archive method. */
34+
private ArchiveMethod archiveMethod = ArchiveMethod.SCHEDULED;
35+
36+
/** The compressor. */
37+
private Compressor compressor = new ZIPCompressor();
38+
39+
/**
40+
* Instantiates a new archive env.
41+
*/
42+
public ArchiveEnv() {
43+
archiveTypes.add(ArchiveType.LOCAL);
44+
}
45+
46+
/**
47+
* Gets the cron pattern.
48+
*
49+
* @return the cron pattern
50+
*/
51+
public String getCronPattern() {
52+
return cronPattern;
53+
}
54+
55+
/**
56+
* Sets the cron pattern.
57+
*
58+
* @param cronPattern
59+
* the new cron pattern
60+
*/
61+
public void setCronPattern(String cronPattern) {
62+
this.cronPattern = cronPattern;
63+
}
64+
65+
/**
66+
* Gets the dir path.
67+
*
68+
* @return the dir path
69+
*/
70+
public String getDirPath() {
71+
return dirPath;
72+
}
73+
74+
/**
75+
* Sets the dir path.
76+
*
77+
* @param dirPath
78+
* the new dir path
79+
*/
80+
public void setDirPath(String dirPath) {
81+
this.dirPath = dirPath;
82+
}
83+
84+
/**
85+
* Gets the date pattern.
86+
*
87+
* @return the date pattern
88+
*/
89+
public String getDatePattern() {
90+
return datePattern;
91+
}
92+
93+
/**
94+
* Gets the properties.
95+
*
96+
* @return the properties
97+
*/
98+
public Map<String, String> getProperties() {
99+
return properties;
100+
}
101+
102+
/**
103+
* Gets the compressor.
104+
*
105+
* @return the compressor
106+
*/
107+
public Compressor getCompressor() {
108+
return compressor;
109+
}
110+
111+
/**
112+
* Sets the properties.
113+
*
114+
* @param properties
115+
* the properties
116+
*/
117+
public void setProperties(Map<String, String> properties) {
118+
this.properties = properties;
119+
}
120+
121+
/**
122+
* Sets the compressor.
123+
*
124+
* @param compressor
125+
* the new compressor
126+
*/
127+
public void setCompressor(Compressor compressor) {
128+
this.compressor = compressor;
129+
}
130+
131+
/**
132+
* Gets the archive method.
133+
*
134+
* @return the archive method
135+
*/
136+
public ArchiveMethod getArchiveMethod() {
137+
return archiveMethod;
138+
}
139+
140+
/**
141+
* Sets the archive method.
142+
*
143+
* @param archiveMethod
144+
* the new archive method
145+
*/
146+
public void setArchiveMethod(ArchiveMethod archiveMethod) {
147+
this.archiveMethod = archiveMethod;
148+
}
149+
150+
/**
151+
* Gets the archive types.
152+
*
153+
* @return the archive types
154+
*/
155+
public List<ArchiveType> getArchiveTypes() {
156+
return archiveTypes;
157+
}
158+
159+
/**
160+
* Sets the archive types.
161+
*
162+
* @param archiveTypes
163+
* the new archive types
164+
*/
165+
public void setArchiveTypes(List<ArchiveType> archiveTypes) {
166+
this.archiveTypes = archiveTypes;
167+
}
168+
169+
/**
170+
* Gets the compression.
171+
*
172+
* @return the compression
173+
*/
174+
public Compression getCompression() {
175+
return compression;
176+
}
177+
178+
/**
179+
* Sets the compression.
180+
*
181+
* @param compression the new compression
182+
*/
183+
public void setCompression(Compression compression) {
184+
this.compression = compression;
185+
}
186+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.audit4j.core.handler.file.archive;
2+
3+
public class ArchiveEnvBuilder {
4+
5+
}

0 commit comments

Comments
 (0)