package me.adaptive.core.data.domain;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Map;

/**
 * Server information metrics
 * <p/>
 * Created by ferranvila on 10/08/15.
 */
@Entity
@Table(name = "metrics_server")
public class MetricServerEntity extends BaseEntity {

    @NotNull
    @Size(min = 3, max = 100, message = "Workspace id can't have more than 100 characters and less than 3")
    @Column(name = "hostname")
    private String hostname;

    /**
     * Possible attributes values:
     * cpu_load, memory_load, disk_usage
     */
    @ElementCollection(fetch = FetchType.EAGER)
    @MapKeyColumn(name = "name")
    @Column(name = "value")
    @CollectionTable(name = "metrics_server_attributes", joinColumns = @JoinColumn(name = "id_event"))
    private Map<String, String> attributes;

    @SuppressWarnings("unused")
    public MetricServerEntity() {
    }

    public Map<String, String> getAttributes() {
        return attributes;
    }

    @SuppressWarnings("unused")
    public void setAttributes(Map<String, String> attributes) {
        this.attributes = attributes;
    }

    public String getHostname() {
        return hostname;
    }

    @SuppressWarnings("unused")
    public void setHostname(String hostname) {
        this.hostname = hostname;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        MetricServerEntity that = (MetricServerEntity) o;

        return !(getHostname() != null ? !getHostname().equals(that.getHostname()) : that.getHostname() != null) && !(getAttributes() != null ? !getAttributes().equals(that.getAttributes()) : that.getAttributes() != null);

    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + (getHostname() != null ? getHostname().hashCode() : 0);
        result = 31 * result + (getAttributes() != null ? getAttributes().hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "MetricServerEntity{" +
                "hostname='" + hostname + '\'' +
                ", attributes=" + attributes +
                '}';
    }
}

@@ -265,24 +265,33 @@
 tity%0A@Table(
+%0A        
 name = %22metr
@@ -301,16 +301,134 @@
 _server%22
+,%0A        indexes = %7B%0A                @Index(name = %22idx_hostname%22, columnList = %22hostname%22, unique = false)%0A        %7D
 )%0Apublic

Add index to metrics server table