// Path: src/main/java/com/labs64/netlicensing/gateway/domain/entity/StoredLog.java
// @Entity
// @Table(name = "LOGGING")
// public class StoredLog extends AbstractPersistable<String> {
// 
//     private static final long serialVersionUID = -8835218729902563568L;
// 
//     public enum Severity {
//         INFO, WARNING, ERROR
//     }
// 
//     public StoredLog() {
//     }
// 
//     @Column(name = "KEY", nullable = true)
//     private String key;
// 
//     @Column(name = "SECONDARY_KEY", nullable = true)
//     private String secondaryKey;
// 
//     @Column(name = "MESSAGE", nullable = true)
//     private String message;
// 
//     @Column(name = "SEVERITY", nullable = true)
//     private Severity severity;
// 
//     @Column(name = "TIMESTAMP", nullable = false)
//     @Temporal(value = TemporalType.TIMESTAMP)
//     private Date timestamp;
// 
//     public String getKey() {
//         return key;
//     }
// 
//     public void setKey(final String key) {
//         this.key = key;
//     }
// 
//     public String getSecondaryKey() {
//         return secondaryKey;
//     }
// 
//     public void setSecondaryKey(final String secondaryKey) {
//         this.secondaryKey = secondaryKey;
//     }
// 
//     public String getMessage() {
//         return message;
//     }
// 
//     public void setMessage(final String message) {
//         this.message = message;
//     }
// 
//     public Severity getSeverity() {
//         return severity;
//     }
// 
//     public void setSeverity(final Severity severity) {
//         this.severity = severity;
//     }
// 
//     public Date getTimestamp() {
//         if (timestamp == null) {
//             return null;
//         } else {
//             return new Date(timestamp.getTime());
//         }
//     }
// 
//     public void setTimestamp(final Date timestamp) {
//         if (timestamp == null) {
//             this.timestamp = new Date();
//         } else {
//             this.timestamp = new Date(timestamp.getTime());
//         }
//     }
// 
//     @Override
//     public String toString() {
//         final StringBuilder builder = new StringBuilder();
//         builder.append("key=");
//         builder.append(getKey());
//         builder.append(", severity=");
//         builder.append(getSeverity());
//         builder.append(", message=");
//         builder.append(getMessage());
//         builder.append(", timestamp=");
//         builder.append(getTimestamp());
//         return builder.toString();
//     }
// }
// 
// Path: src/main/java/com/labs64/netlicensing/gateway/domain/repositories/LogRepository.java
// public interface LogRepository extends CrudRepository<StoredLog, String> {
// 
//     List<StoredLog> findByKey(String key);
// 
//     List<StoredLog> findByKeyAndSecondaryKey(String key, String secondaryKey);
// 
//     void deleteByTimestampBefore(@Temporal(TemporalType.TIMESTAMP) Date date);
// 
// }
// 
// Path: src/main/java/com/labs64/netlicensing/gateway/util/Constants.java
// public class Constants {
// 
//     private Constants() {
//     }
// 
//     public static final String NEXT_CLEANUP_LOGGING_TAG = "NEXT_CLEANUP_LOGGING";
//     public static final int CLEANUP_PERIOD_MINUTES = 60;
//     public static final int LOG_PERSIST_DAYS = 30;
// 
//     public static final String QUANTITY_TO_LICENSEE = "quantityToLicensee";
//     public static final String ENDPOINT_PATH_CODEGEN = "codegen";
//     public static final String ENDPOINT_PATH_LOG = "log";
//     public static final String SAVE_USER_DATA = "saveUserData";
// 
//     public static final class NetLicensing {
//         public static final String PRODUCT_NUMBER = "productNumber";
//         public static final String LICENSE_TEMPLATE_NUMBER = "licenseTemplateNumber";
//         public static final String LICENSEE_NUMBER = "licenseeNumber";
//         public static final String LICENSEE_NAME = "name";
//         public static final String PROP_MARKED_FOR_TRANSFER = "markedForTransfer";
//         public static final String PROP_START_DATE = "startDate";
//     }
// 
//     public static final class Monitoring {
//         public static final String ENDPOINT_BASE_PATH = "monitoring";
//     }
// }


import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.labs64.netlicensing.gateway.domain.entity.StoredLog;
import com.labs64.netlicensing.gateway.domain.repositories.LogRepository;
import com.labs64.netlicensing.gateway.util.Constants;

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void log(final String key, final String secondaryKey, final StoredLog.Severity severity, final String msg) {
        log(key, secondaryKey, severity, msg, null);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void log(final String key, final String secondaryKey, final StoredLog.Severity severity, final String msg,
            final Logger logger) {
        if (logger != null) {
            switch (severity) {
            case ERROR:
                logger.error(msg);
                break;
            case WARNING:
                logger.warn(msg);
                break;
            case INFO:
                logger.info(msg);
                break;
            }
        }
        final StoredLog requestResponse = new StoredLog();
        requestResponse.setKey(key);
        requestResponse.setSecondaryKey(secondaryKey);
        requestResponse.setSeverity(severity);
        requestResponse.setMessage(msg);
        requestResponse.setTimestamp(new Date());
        logRepository.save(requestResponse);

// Path: src/main/java/com/labs64/netlicensing/gateway/domain/entity/StoredLog.java
// @Entity
// @Table(name = "LOGGING")
// public class StoredLog extends AbstractPersistable<String> {
// 
//     private static final long serialVersionUID = -8835218729902563568L;
// 
//     public enum Severity {
//         INFO, WARNING, ERROR
//     }
// 
//     public StoredLog() {
//     }
// 
//     @Column(name = "KEY", nullable = true)
//     private String key;
// 
//     @Column(name = "SECONDARY_KEY", nullable = true)
//     private String secondaryKey;
// 
//     @Column(name = "MESSAGE", nullable = true)
//     private String message;
// 
//     @Column(name = "SEVERITY", nullable = true)
//     private Severity severity;
// 
//     @Column(name = "TIMESTAMP", nullable = false)
//     @Temporal(value = TemporalType.TIMESTAMP)
//     private Date timestamp;
// 
//     public String getKey() {
//         return key;
//     }
// 
//     public void setKey(final String key) {
//         this.key = key;
//     }
// 
//     public String getSecondaryKey() {
//         return secondaryKey;
//     }
// 
//     public void setSecondaryKey(final String secondaryKey) {
//         this.secondaryKey = secondaryKey;
//     }
// 
//     public String getMessage() {
//         return message;
//     }
// 
//     public void setMessage(final String message) {
//         this.message = message;
//     }
// 
//     public Severity getSeverity() {
//         return severity;
//     }
// 
//     public void setSeverity(final Severity severity) {
//         this.severity = severity;
//     }
// 
//     public Date getTimestamp() {
//         if (timestamp == null) {
//             return null;
//         } else {
//             return new Date(timestamp.getTime());
//         }
//     }
// 
//     public void setTimestamp(final Date timestamp) {
//         if (timestamp == null) {
//             this.timestamp = new Date();
//         } else {
//             this.timestamp = new Date(timestamp.getTime());
//         }
//     }
// 
//     @Override
//     public String toString() {
//         final StringBuilder builder = new StringBuilder();
//         builder.append("key=");
//         builder.append(getKey());
//         builder.append(", severity=");
//         builder.append(getSeverity());
//         builder.append(", message=");
//         builder.append(getMessage());
//         builder.append(", timestamp=");
//         builder.append(getTimestamp());
//         return builder.toString();
//     }
// }
// 
// Path: src/main/java/com/labs64/netlicensing/gateway/domain/repositories/LogRepository.java
// public interface LogRepository extends CrudRepository<StoredLog, String> {
// 
//     List<StoredLog> findByKey(String key);
// 
//     List<StoredLog> findByKeyAndSecondaryKey(String key, String secondaryKey);
// 
//     void deleteByTimestampBefore(@Temporal(TemporalType.TIMESTAMP) Date date);
// 
// }
// 
// Path: src/main/java/com/labs64/netlicensing/gateway/util/Constants.java
// public class Constants {
// 
//     private Constants() {
//     }
// 
//     public static final String NEXT_CLEANUP_LOGGING_TAG = "NEXT_CLEANUP_LOGGING";
//     public static final int CLEANUP_PERIOD_MINUTES = 60;
//     public static final int LOG_PERSIST_DAYS = 30;
// 
//     public static final String QUANTITY_TO_LICENSEE = "quantityToLicensee";
//     public static final String ENDPOINT_PATH_CODEGEN = "codegen";
//     public static final String ENDPOINT_PATH_LOG = "log";
//     public static final String SAVE_USER_DATA = "saveUserData";
// 
//     public static final class NetLicensing {
//         public static final String PRODUCT_NUMBER = "productNumber";
//         public static final String LICENSE_TEMPLATE_NUMBER = "licenseTemplateNumber";
//         public static final String LICENSEE_NUMBER = "licenseeNumber";
//         public static final String LICENSEE_NAME = "name";
//         public static final String PROP_MARKED_FOR_TRANSFER = "markedForTransfer";
//         public static final String PROP_START_DATE = "startDate";
//     }
// 
//     public static final class Monitoring {
//         public static final String ENDPOINT_BASE_PATH = "monitoring";
//     }
// }


// Path: src/main/java/com/labs64/netlicensing/gateway/bl/PersistingLogger.java
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.labs64.netlicensing.gateway.domain.entity.StoredLog;
import com.labs64.netlicensing.gateway.domain.repositories.LogRepository;
import com.labs64.netlicensing.gateway.util.Constants;


    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void log(final String key, final String secondaryKey, final StoredLog.Severity severity, final String msg) {
        log(key, secondaryKey, severity, msg, null);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void log(final String key, final String secondaryKey, final StoredLog.Severity severity, final String msg,
            final Logger logger) {
        if (logger != null) {
            switch (severity) {
            case ERROR:
                logger.error(msg);
                break;
            case WARNING:
                logger.warn(msg);
                break;
            case INFO:
                logger.info(msg);
                break;
            }
        }
        final StoredLog requestResponse = new StoredLog();
        requestResponse.setKey(key);
        requestResponse.setSecondaryKey(secondaryKey);
        requestResponse.setSeverity(severity);
        requestResponse.setMessage(msg);
        requestResponse.setTimestamp(new Date());
        logRepository.save(requestResponse);

        if (timeStampTracker.isExpired(Constants.NEXT_CLEANUP_LOGGING_TAG, Constants.CLEANUP_PERIOD_MINUTES)) {