ConfigurationDO.java

  1. package org.europa.together.domain;

  2. import java.io.Serializable;
  3. import java.util.Objects;
  4. import jakarta.persistence.Column;
  5. import jakarta.persistence.Entity;
  6. import jakarta.persistence.Id;
  7. import jakarta.persistence.Index;
  8. import jakarta.persistence.PrePersist;
  9. import jakarta.persistence.Table;
  10. import jakarta.persistence.UniqueConstraint;
  11. import org.europa.together.application.LogbackLogger;
  12. import org.europa.together.business.Logger;
  13. import org.europa.together.utils.StringUtils;

  14. /**
  15.  * Application wide configuration with key=value entries. For an easier
  16.  * maintenance are entries with module-name, module-version and a deprecated
  17.  * marker extended.
  18.  */
  19. @Entity
  20. @Table(name = "APP_CONFIG",
  21.         //CHECKSTYLE:OFF
  22.         indexes = {
  23.             @Index(columnList = "CONF_KEY", name = "configuration_key"),
  24.             @Index(columnList = "MODUL_NAME", name = "modul_name"),
  25.             @Index(columnList = "CONF_SET", name = "configuration_set")
  26.         },
  27.         //CHECKSTYLE:ON
  28.         uniqueConstraints = {
  29.             @UniqueConstraint(columnNames
  30.                     = {"MODUL_NAME", "SERVICE_VERSION", "CONF_KEY"})
  31.         }
  32. )
  33. public class ConfigurationDO implements Serializable {

  34.     private static final long serialVersionUID = 102L;
  35.     private static final Logger LOGGER = new LogbackLogger(ConfigurationDO.class);

  36.     /**
  37.      * The name of the used database table for this domain object.
  38.      */
  39.     public static final String TABLE_NAME = "APP_CONFIG";

  40.     @Id //validate uuid
  41.     @Column(name = "IDX")
  42.     private String uuid;

  43.     @Column(name = "CONF_KEY", nullable = false)
  44.     private String key;

  45.     @Column(name = "CONF_VALUE")
  46.     private String value;

  47.     @Column(name = "DEFAULT_VALUE", nullable = false)
  48.     private String defaultValue;

  49.     @Column(name = "MODUL_NAME", nullable = false)
  50.     private String modulName;

  51.     @Column(name = "SERVICE_VERSION", nullable = false)
  52.     private String version;

  53.     @Column(name = "CONF_SET", nullable = false)
  54.     private String configurationSet;

  55.     @Column(name = "DEPRECATED", nullable = false)
  56.     private boolean deprecated;

  57.     @Column(name = "MANDATORY", nullable = false)
  58.     private boolean mandatory;

  59.     @Column(name = "COMMENT")
  60.     private String comment;

  61.     /**
  62.      * Constructor.
  63.      */
  64.     public ConfigurationDO() {
  65.         //PreSet
  66.         this.uuid = StringUtils.generateUUID();
  67.     }

  68.     /**
  69.      * Constructor.
  70.      *
  71.      * @param key as String
  72.      * @param value as String
  73.      * @param modulName as String
  74.      * @param version as String
  75.      */
  76.     public ConfigurationDO(final String key, final String value, final String modulName,
  77.             final String version) {
  78.         //PreSet
  79.         this.uuid = StringUtils.generateUUID();
  80.         //mandatory
  81.         this.modulName = modulName;
  82.         this.version = version;
  83.         this.key = key;
  84.         this.value = value;
  85.         //optional
  86.         this.configurationSet = "default";
  87.         this.defaultValue = "NIL";
  88.         this.deprecated = false;
  89.         this.mandatory = false;
  90.         this.comment = "";
  91.     }

  92.     /**
  93.      * Actions who have to performed before objects get persisted. e.g. cerate
  94.      * default entries in the database.
  95.      */
  96.     @PrePersist
  97.     public void prePersist() {
  98.         this.configurationSet = "default";
  99.         this.defaultValue = "NIL";
  100.         this.deprecated = false;
  101.         this.mandatory = false;
  102.         LOGGER.log("@PrePersist [ConfigurationDO]", LogLevel.INFO);
  103.     }

  104.     //<editor-fold defaultstate="collapsed" desc="Getter / Setter">
  105.     /**
  106.      * Show if entry is deprecated.
  107.      *
  108.      * @return true if is deprecated
  109.      */
  110.     public boolean isDeprecated() {
  111.         return deprecated;
  112.     }

  113.     /**
  114.      * Mark if an configuration entry is mandatory.
  115.      *
  116.      * @return true if is mandatory
  117.      */
  118.     public boolean isMandatory() {
  119.         return mandatory;
  120.     }

  121.     /**
  122.      * Set the comment.
  123.      *
  124.      * @param comment as String
  125.      */
  126.     public void setComment(final String comment) {
  127.         this.comment = comment;
  128.     }

  129.     /**
  130.      * Set the configuration set.
  131.      *
  132.      * @param configurationSet as String
  133.      */
  134.     public void setConfigurationSet(final String configurationSet) {
  135.         this.configurationSet = configurationSet;
  136.     }

  137.     /**
  138.      * Set the default value.
  139.      *
  140.      * @param defaultValue as String
  141.      */
  142.     public void setDefaultValue(final String defaultValue) {
  143.         this.defaultValue = defaultValue;
  144.     }

  145.     /**
  146.      * Set if a entry is deprecated.
  147.      *
  148.      * @param deprecated as boolean
  149.      */
  150.     public void setDeprecated(final boolean deprecated) {
  151.         this.deprecated = deprecated;
  152.     }

  153.     /**
  154.      * Set if a entry is mandatory.
  155.      *
  156.      * @param mandatory as boolean
  157.      */
  158.     public void setMandatory(final boolean mandatory) {
  159.         this.mandatory = mandatory;
  160.     }

  161.     /**
  162.      * Set key.
  163.      *
  164.      * @param key as String
  165.      */
  166.     public void setKey(final String key) {
  167.         this.key = key;
  168.     }

  169.     /**
  170.      * Set moduleĀ“name.
  171.      *
  172.      * @param modulName as String
  173.      */
  174.     public void setModulName(final String modulName) {
  175.         this.modulName = modulName;
  176.     }

  177.     /**
  178.      * Set the UUID.
  179.      *
  180.      * @param uuid as String
  181.      */
  182.     public void setUuid(final String uuid) {
  183.         this.uuid = uuid;
  184.     }

  185.     /**
  186.      * Set value.
  187.      *
  188.      * @param value as String
  189.      */
  190.     public void setValue(final String value) {
  191.         this.value = value;
  192.     }

  193.     /**
  194.      * Set version of module.
  195.      *
  196.      * @param version as String
  197.      */
  198.     public void setVersion(final String version) {
  199.         this.version = version;
  200.     }

  201.     /**
  202.      * Get the comment.
  203.      *
  204.      * @return comment as String
  205.      */
  206.     public String getComment() {
  207.         return comment;
  208.     }

  209.     /**
  210.      * Get the configuration set.
  211.      *
  212.      * @return ConfigurationSet as String.
  213.      */
  214.     public String getConfigurationSet() {
  215.         return configurationSet;
  216.     }

  217.     /**
  218.      * Get the default value.
  219.      *
  220.      * @return dafaultValue as String
  221.      */
  222.     public String getDefaultValue() {
  223.         return defaultValue;
  224.     }

  225.     /**
  226.      * Get the key.
  227.      *
  228.      * @return key as String
  229.      */
  230.     public String getKey() {
  231.         return key;
  232.     }

  233.     /**
  234.      * Get Modulename.
  235.      *
  236.      * @return modulename as String
  237.      */
  238.     public String getModulName() {
  239.         return modulName;
  240.     }

  241.     /**
  242.      * Get the UUID.
  243.      *
  244.      * @return UUID as String
  245.      */
  246.     public String getUuid() {
  247.         return uuid;
  248.     }

  249.     /**
  250.      * Get value.
  251.      *
  252.      * @return value as String
  253.      */
  254.     public String getValue() {
  255.         return value;
  256.     }

  257.     /**
  258.      * Get module version.
  259.      *
  260.      * @return moduleversion as String
  261.      */
  262.     public String getVersion() {
  263.         return version;
  264.     }
  265.     //</editor-fold>

  266.     @Override
  267.     public boolean equals(final Object obj) {

  268.         boolean success = false;
  269.         if (obj != null && obj instanceof ConfigurationDO) {

  270.             if (this == obj) {
  271.                 success = true;
  272.             } else {

  273.                 final ConfigurationDO other = (ConfigurationDO) obj;
  274.                 if (Objects.equals(this.key, other.key)
  275.                         && Objects.equals(this.modulName, other.modulName)
  276.                         && Objects.equals(this.version, other.version)) {
  277.                     success = true;
  278.                 }
  279.             }
  280.         }
  281.         return success;
  282.     }

  283.     @Override
  284.     public int hashCode() {
  285.         int hash = Objects.hashCode(this.key);
  286.         hash += Objects.hashCode(this.modulName);
  287.         hash += Objects.hashCode(this.version);
  288.         return hash;
  289.     }

  290.     @Override
  291.     public String toString() {
  292.         return "ConfigurationDO{" + "uuid=" + uuid
  293.                 + ", key=" + key
  294.                 + ", value=" + value
  295.                 + ", defaultValue=" + defaultValue
  296.                 + ", modulName=" + modulName
  297.                 + ", configurationSet=" + configurationSet
  298.                 + ", version=" + version
  299.                 + ", deprecated=" + deprecated
  300.                 + ", mandatory=" + mandatory
  301.                 + ", comment=" + comment + '}';
  302.     }
  303. }