org.bdware.doip.audit.writer.AuditConfig 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.JsonObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bdware.doip.audit.AuditRule;
import org.bdware.doip.audit.AuditRuleDB;
public abstract class AuditConfig {
static Logger LOGGER = LogManager.getLogger(AuditConfig.class);
AuditRepo auditRepo;
public AuditConfig(AuditRepo repo) {
auditRepo = repo;
}
public String getAuditUrl() {
if (auditRepo != null)
return auditRepo.auditUrl;
return null;
}
public String getAuditDoid() {
if (auditRepo != null)
return auditRepo.auditDoid;
return null;
}
public AuditRepo getAuditRepo() {
return auditRepo;
}
public void setAuditRepo(AuditRepo auditRepo) {
this.auditRepo = auditRepo;
}
public static AuditConfig newInstance(AuditRepo repo, AuditType type, JsonObject config) {
return newInstanceInternal(repo, type, config);
}
public static ConfigurableAuditConfig newConfigurableInstance(AuditRepo repo, AuditType type, JsonObject config) {
return new ConfigurableAuditConfig(newInstanceInternal(repo, type, config));
}
private static AuditConfig newInstanceInternal(AuditRepo repo, AuditType type, JsonObject config) {
if (type == null)
return new NoneAuditConfig(repo);
switch (type) {
case OnlyHash:
return new HashAuditConfig(repo);
case WithOriginal:
return new OriginalAuditConfig(repo, config);
case None:
default:
return new NoneAuditConfig(repo);
}
}
public static boolean storeAuditRule(JsonObject config, String repoId, AuditRule auditRule) {
try {
JsonObject auditRuleConfig = config.get("originalDBConfig").getAsJsonObject();
String driverClass = auditRuleConfig.get("driverClass").getAsString();
String url = auditRuleConfig.get("url").getAsString();
String user = auditRuleConfig.get("user").getAsString();
String password = auditRuleConfig.get("password").getAsString();
String tableName = auditRuleConfig.get("tableName").getAsString();
AuditRuleDB auditRuleDB = new AuditRuleDB(driverClass, url, user, password);
int count = auditRuleDB.add(tableName, repoId, auditRule);
if (count > 0)
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public abstract LogWriter createLogWriterInstance();
public abstract AuditType getAuditType();
}