org.bdware.doip.audit.writer.ConfigurableAuditConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
package org.bdware.doip.audit.writer;
import com.google.gson.Gson;
import java.util.List;
public class ConfigurableAuditConfig extends AuditConfig {
private AuditConfig auditConfig;
ConfigurableLogWriter writer;
public ConfigurableAuditConfig(AuditConfig config) {
super(config.auditRepo);
this.auditConfig = config;
writer = new ConfigurableLogWriter();
}
public void changeAuditConfig(AuditConfig config) {
if (auditConfig instanceof OriginalAuditConfig) {
((OriginalAuditConfig) auditConfig).clearPruner();
}
auditConfig = config;
writer.setWriter(config.createLogWriterInstance());
}
@Override
public LogWriter createLogWriterInstance() {
writer.setWriter(auditConfig.createLogWriterInstance());
return writer;
}
@Override
public void setAuditRepo(AuditRepo auditRepo) {
if (this.auditConfig != null)
this.auditConfig.setAuditRepo(auditRepo);
super.setAuditRepo(auditRepo);
changeAuditConfig(this.auditConfig);
}
@Override
public AuditType getAuditType() {
return auditConfig.getAuditType();
}
public String toString() {
assert !(auditConfig instanceof ConfigurableAuditConfig);
return new Gson().toJson(auditConfig);
}
public List getOriginalLogByHash(String requestHash, String responseHash) {
if (auditConfig instanceof OriginalAuditConfig) {
OriginalAuditConfig oac = (OriginalAuditConfig) auditConfig;
return oac.getOriginalLogByHash(requestHash, responseHash);
}
return null;
}
public boolean isExist(String requestHash, String responseHash) {
if (auditConfig instanceof OriginalAuditConfig) {
OriginalAuditConfig oac = (OriginalAuditConfig) auditConfig;
return oac.isExist(requestHash, responseHash);
}
return false;
}
}