All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bdware.doip.audit.writer.ConfigurableAuditConfig Maven / Gradle / Ivy

The newest version!
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy