Commit 62df87bd authored by Matija Obreza's avatar Matija Obreza

DS2

parent 63795062
......@@ -152,6 +152,12 @@
<artifactId>commons-logging</artifactId>
<version>${commons.logging.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<!-- Logging dependencies -->
<dependency>
......
package org.genesys2.server.model.dataset;
import java.util.List;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import org.genesys2.server.model.BusinessModel;
@Entity
@Table(name = "ds2")
public class DS extends BusinessModel {
@Column(columnDefinition = "binary(16)")
private UUID uuid;
@OrderBy("index")
@OneToMany(mappedBy = "dataset")
private List<DSQualifier> qualifiers;
@OrderBy("index")
@OneToMany(mappedBy = "dataset")
private List<DSDescriptor> descriptors;
/**
* Generate UUID if missing
*/
@PrePersist
protected void prepersist() {
if (this.uuid == null) {
this.uuid = UUID.randomUUID();
}
}
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public List<DSQualifier> getQualifiers() {
return qualifiers;
}
public void setQualifiers(List<DSQualifier> qualifiers) {
this.qualifiers = qualifiers;
}
public List<DSDescriptor> getDescriptors() {
return descriptors;
}
public void setDescriptors(List<DSDescriptor> descriptors) {
this.descriptors = descriptors;
}
}
package org.genesys2.server.model.dataset;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.genesys2.server.model.BusinessModel;
import org.genesys2.server.model.impl.Descriptor;
/**
* Dataset descriptor
*/
@Entity
@Table(name = "ds2descriptor")
public class DSDescriptor extends BusinessModel {
@Column(name="idx")
private float index = 1.0f;
@ManyToOne(optional = false)
@JoinColumn(name="ds")
private DS dataset;
@ManyToOne(optional = false)
@JoinColumn(name="d")
private Descriptor descriptor;
public float getIndex() {
return index;
}
public void setIndex(float index) {
this.index = index;
}
public DS getDataset() {
return dataset;
}
public void setDataset(DS dataset) {
this.dataset = dataset;
}
public Descriptor getDescriptor() {
return descriptor;
}
public void setDescriptor(Descriptor descriptor) {
this.descriptor = descriptor;
}
@Override
public String toString() {
return "DSD " + this.getId();
}
}
package org.genesys2.server.model.dataset;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.genesys2.server.model.BusinessModel;
import org.genesys2.server.model.impl.Descriptor;
/**
* Dataset qualifier specification
*/
@Entity
@Table(name = "ds2qualifier")
public class DSQualifier extends BusinessModel {
@Column(name="idx")
private float index = 1.0f;
@ManyToOne(optional = false)
@JoinColumn(name="ds")
private DS dataset;
@ManyToOne(optional = false)
@JoinColumn(name="d")
private Descriptor descriptor;
public float getIndex() {
return index;
}
public void setIndex(float index) {
this.index = index;
}
public DS getDataset() {
return dataset;
}
public void setDataset(DS dataset) {
this.dataset = dataset;
}
public Descriptor getDescriptor() {
return descriptor;
}
public void setDescriptor(Descriptor descriptor) {
this.descriptor = descriptor;
}
@Override
public String toString() {
return "DSQ " + this.id + " [" + this.getId() + "]";
}
}
package org.genesys2.server.model.dataset;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.genesys2.server.model.EntityId;
@Entity
@Table(name = "ds2row", uniqueConstraints = { @UniqueConstraint(columnNames = { "md5", "sha1" }) })
public class DSRow implements EntityId {
@OneToMany(mappedBy = "row")
private List<DSRowQualifier<?>> rowQualifiers;
@OneToMany(mappedBy = "row")
private List<DSValue<?>> values;
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Long id;
@Column(columnDefinition="binary(16)")
private byte[] md5;
@Column(columnDefinition="binary(20)")
private byte[] sha1;
@Override
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public List<DSRowQualifier<?>> getRowQualifiers() {
return rowQualifiers;
}
public void setRowQualifiers(List<DSRowQualifier<?>> rowQualifiers) {
this.rowQualifiers = rowQualifiers;
}
public List<DSValue<?>> getValues() {
return values;
}
public void setValues(List<DSValue<?>> values) {
this.values = values;
}
@Override
public String toString() {
return "DSR " + id;
}
public void setMd5(byte[] md5) {
this.md5 = md5;
}
public byte[] getMd5() {
return md5;
}
public void setSha1(byte[] sha1) {
this.sha1 = sha1;
}
public byte[] getSha1() {
return sha1;
}
}
package org.genesys2.server.model.dataset;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "ds2rowqualifier", indexes = { @Index(columnList = "dsq, vall") })
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.INTEGER, name = "typ")
public abstract class DSRowQualifier<T> {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Long id;
@ManyToOne(optional = false)
@JoinColumn(name = "r")
private DSRow row;
@ManyToOne(optional = false)
@JoinColumn(name = "dsq")
private DSQualifier datasetQualifier;
public abstract T getValue();
public abstract void setValue(T value);
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public DSRow getRow() {
return row;
}
public void setRow(DSRow row) {
this.row = row;
}
public DSQualifier getDatasetQualifier() {
return datasetQualifier;
}
public void setDatasetQualifier(DSQualifier datasetQualifier) {
this.datasetQualifier = datasetQualifier;
}
public static DSRowQualifier<?> make(Object qualifier) {
if (qualifier == null) {
return null;
} else if (qualifier instanceof Long) {
DSRowQualifierLong dsrq = new DSRowQualifierLong();
dsrq.setValue((Long) qualifier);
return dsrq;
}
return null;
}
}
package org.genesys2.server.model.dataset;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
@DiscriminatorValue("1")
public class DSRowQualifierLong extends DSRowQualifier<Long> {
@Column(name = "vall")
private Long value;
@Override
public Long getValue() {
return this.value;
}
@Override
public void setValue(Long value) {
this.value = value;
}
}
package org.genesys2.server.model.dataset;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "ds2value", indexes = { @Index(columnList = "r,dsd"), @Index(columnList = "dsd,vall"), @Index(columnList = "dsd,vald") })
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.INTEGER, name = "typ")
public abstract class DSValue<T> {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Long id;
@ManyToOne(optional = false)
@JoinColumn(name = "r")
private DSRow row;
@ManyToOne(optional = false)
@JoinColumn(name = "dsd")
private DSDescriptor datasetDescriptor;
public abstract T getValue();
public abstract void setValue(T value);
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public DSRow getRow() {
return row;
}
public void setRow(DSRow row) {
this.row = row;
}
public DSDescriptor getDatasetDescriptor() {
return datasetDescriptor;
}
public void setDatasetDescriptor(DSDescriptor datasetDescriptor) {
this.datasetDescriptor = datasetDescriptor;
}
public static DSValue<?> make(Object v) {
if (v instanceof Long) {
return new DSValueLong();
} else if (v instanceof Double) {
return new DSValueDouble();
} else if (v instanceof String) {
return new DSValueString();
}
return null;
}
public void setValue2(Object v) {
setValue((T) v);
}
}
package org.genesys2.server.model.dataset;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
@DiscriminatorValue("2")
public class DSValueDouble extends DSValue<Double> {
private Double vald;
@Override
public Double getValue() {
return this.vald;
}
@Override
public void setValue(Double value) {
this.vald = value;
}
}
package org.genesys2.server.model.dataset;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
@DiscriminatorValue("1")
public class DSValueLong extends DSValue<Long> {
private Long vall;
@Override
public Long getValue() {
return vall;
}
@Override
public void setValue(Long value) {
this.vall = value;
}
}
package org.genesys2.server.model.dataset;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
@DiscriminatorValue("3")
public class DSValueString extends DSValue<String> {
@Column(length=500)
private String vals;
@Override
public String getValue() {
return vals;
}
@Override
public void setValue(String value) {
this.vals = value;
}
}
......@@ -55,6 +55,8 @@ public class AccessionGeo extends BusinessModel implements GeoReferencedEntity,
private String datum;
private String method;
private Long tileIndex;
public long getVersion() {
return version;
}
......@@ -128,6 +130,14 @@ public class AccessionGeo extends BusinessModel implements GeoReferencedEntity,
return method;
}
public Long getTileIndex() {
return tileIndex;
}
public void setTileIndex(Long tileIndex) {
this.tileIndex = tileIndex;
}
public boolean isEmpty() {
if (StringUtils.isNotBlank(datum))
return false;
......
......@@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
*/
public class WorldclimJson {
// Monthlies
private Integer[] precipitation = new Integer[12];
private Long[] precipitation = new Long[12];
private Double[] tempMin = new Double[12];
private Double[] tempMean = new Double[12];
private Double[] tempMax = new Double[12];
......@@ -20,7 +20,7 @@ public class WorldclimJson {
@JsonIgnore
private Map<Descriptor, Object> other = new HashMap<Descriptor, Object>();
public Integer[] getPrecipitation() {
public Long[] getPrecipitation() {
return precipitation;
}
......
......@@ -40,4 +40,7 @@ public interface AccessionGeoRepository extends JpaRepository<AccessionGeo, Long
@Query("from AccessionGeo ag where ag.accession.id in ?1")
List<AccessionGeo> findAllFor(Collection<Long> accessionIds);
@Query("select distinct(ag.tileIndex) from AccessionGeo ag where ag.tileIndex is not null")
Collection<Long> getTileIndexes();
}
package org.genesys2.server.persistence.domain.dataset;
import org.genesys2.server.model.dataset.DSDescriptor;
import org.springframework.data.jpa.repository.JpaRepository;
public interface DSDescriptorRepository extends JpaRepository<DSDescriptor, Long> {
}
package org.genesys2.server.persistence.domain.dataset;
import org.genesys2.server.model.dataset.DSQualifier;
import org.springframework.data.jpa.repository.JpaRepository;
public interface DSQualifierRepository extends JpaRepository<DSQualifier, Long> {
}
package org.genesys2.server.persistence.domain.dataset;
import java.util.UUID;
import org.genesys2.server.model.dataset.DS;
import org.springframework.data.jpa.repository.JpaRepository;
public interface DSRepository extends JpaRepository<DS, Long> {
DS getByUuid(UUID uuid);
DS findByUuid(UUID uuid);
}
package org.genesys2.server.persistence.domain.dataset;
import java.util.Collection;
import java.util.Map;