Commit 31d94144 authored by Matija Obreza's avatar Matija Obreza

WorldClim work with Datasets

parent 2a5449fb
...@@ -498,6 +498,11 @@ ...@@ -498,6 +498,11 @@
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>4.3.6</version> <version>4.3.6</version>
</dependency> </dependency>
<dependency>
<groupId>org.genesys</groupId>
<artifactId>worldclim-reader</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -76,4 +76,46 @@ public abstract class AuditedModel extends BusinessModel { ...@@ -76,4 +76,46 @@ public abstract class AuditedModel extends BusinessModel {
this.lastModifiedDate = lastModifiedDate; this.lastModifiedDate = lastModifiedDate;
} }
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((createdBy == null) ? 0 : createdBy.hashCode());
result = prime * result + ((createdDate == null) ? 0 : createdDate.hashCode());
result = prime * result + ((lastModifiedBy == null) ? 0 : lastModifiedBy.hashCode());
result = prime * result + ((lastModifiedDate == null) ? 0 : lastModifiedDate.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
AuditedModel other = (AuditedModel) obj;
if (createdBy == null) {
if (other.createdBy != null)
return false;
} else if (!createdBy.equals(other.createdBy))
return false;
if (createdDate == null) {
if (other.createdDate != null)
return false;
} else if (!createdDate.equals(other.createdDate))
return false;
if (lastModifiedBy == null) {
if (other.lastModifiedBy != null)
return false;
} else if (!lastModifiedBy.equals(other.lastModifiedBy))
return false;
if (lastModifiedDate == null) {
if (other.lastModifiedDate != null)
return false;
} else if (!lastModifiedDate.equals(other.lastModifiedDate))
return false;
return true;
}
} }
...@@ -44,4 +44,28 @@ public abstract class BusinessModel implements EntityId, HibernateModel { ...@@ -44,4 +44,28 @@ public abstract class BusinessModel implements EntityId, HibernateModel {
this.id = id; this.id = id;
} }
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BusinessModel other = (BusinessModel) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
} }
/**
* Copyright 2015 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.model;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
@MappedSuperclass
public abstract class UuidModel {
@Id
@Column(name = "uuid", unique = true, nullable = false)
protected UUID uuid;
public UUID getUuid() {
return uuid;
}
protected void setUuid(UUID uuid) {
this.uuid = uuid;
}
@PrePersist
protected void pre() {
if (uuid == null)
uuid = UUID.randomUUID();
}
}
...@@ -33,4 +33,27 @@ public abstract class VersionedAuditedModel extends AuditedModel { ...@@ -33,4 +33,27 @@ public abstract class VersionedAuditedModel extends AuditedModel {
public void setVersion(long version) { public void setVersion(long version) {
this.version = version; this.version = version;
} }
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + (int) (version ^ (version >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VersionedAuditedModel other = (VersionedAuditedModel) obj;
if (version != other.version)
return false;
return true;
}
} }
...@@ -92,7 +92,7 @@ public class Accession extends VersionedAuditedModel { ...@@ -92,7 +92,7 @@ public class Accession extends VersionedAuditedModel {
@Column(name = "available") @Column(name = "available")
private Boolean availability; private Boolean availability;
@Column(name = "historic") @Column(name = "historic", nullable = false)
private boolean historic = false; private boolean historic = false;
@Column(name = "mlsStat") @Column(name = "mlsStat")
...@@ -280,11 +280,11 @@ public class Accession extends VersionedAuditedModel { ...@@ -280,11 +280,11 @@ public class Accession extends VersionedAuditedModel {
protected void setStorage(String storage) { protected void setStorage(String storage) {
this.storage = storage; this.storage = storage;
} }
public void setHistoric(boolean historic) { public void setHistoric(boolean historic) {
this.historic = historic; this.historic = historic;
} }
public boolean getHistoric() { public boolean getHistoric() {
return this.historic; return this.historic;
} }
......
...@@ -19,6 +19,7 @@ package org.genesys2.server.model.impl; ...@@ -19,6 +19,7 @@ package org.genesys2.server.model.impl;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
...@@ -26,6 +27,7 @@ import javax.persistence.Lob; ...@@ -26,6 +27,7 @@ import javax.persistence.Lob;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OrderBy; import javax.persistence.OrderBy;
import javax.persistence.PrePersist;
import javax.persistence.Table; import javax.persistence.Table;
import org.genesys2.server.model.BusinessModel; import org.genesys2.server.model.BusinessModel;
...@@ -63,6 +65,19 @@ public class Dataset extends BusinessModel { ...@@ -63,6 +65,19 @@ public class Dataset extends BusinessModel {
@OneToMany(cascade = {}, mappedBy = "dataset") @OneToMany(cascade = {}, mappedBy = "dataset")
private List<DatasetDescriptor> datasetDescriptors; private List<DatasetDescriptor> datasetDescriptors;
@Column(unique = true, columnDefinition = "BINARY(16)")
private UUID uuid;
/**
* Generate UUID if missing
*/
@PrePersist
protected void prepersist() {
if (this.uuid == null) {
this.uuid = UUID.randomUUID();
}
}
public License getLicense() { public License getLicense() {
return license; return license;
} }
...@@ -141,4 +156,12 @@ public class Dataset extends BusinessModel { ...@@ -141,4 +156,12 @@ public class Dataset extends BusinessModel {
public String toString() { public String toString() {
return MessageFormat.format("Dataset id={0,number,#} date={1,date,dd/MM/yyyy} name={2}", id, uploadDate, name); return MessageFormat.format("Dataset id={0,number,#} date={1,date,dd/MM/yyyy} name={2}", id, uploadDate, name);
} }
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public UUID getUuid() {
return uuid;
}
} }
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
package org.genesys2.server.model.impl; package org.genesys2.server.model.impl;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
...@@ -26,7 +28,6 @@ import javax.persistence.Inheritance; ...@@ -26,7 +28,6 @@ import javax.persistence.Inheritance;
import javax.persistence.InheritanceType; import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table; import javax.persistence.Table;
import org.genesys2.server.model.EntityId; import org.genesys2.server.model.EntityId;
...@@ -37,14 +38,14 @@ import org.genesys2.server.model.genesys.Accession; ...@@ -37,14 +38,14 @@ import org.genesys2.server.model.genesys.Accession;
* *
* @author mobreza * @author mobreza
*/ */
@Entity(name = "datasetval") @Entity
@Table(indexes = { @Index(name = "IX_datasetrow_dataset", unique = false, columnList = "datasetId, descriptorId, accessionId"), @Table(name = "datasetval", indexes = { @Index(name = "IX_datasetrow_dataset", unique = false, columnList = "datasetId, descriptorId, accessionId"),
@Index(name = "IX_datasetrow_accn", unique = false, columnList = "accessionId, descriptorId, datasetId") }) @Index(name = "IX_datasetrow_accn", unique = false, columnList = "accessionId, descriptorId, datasetId") })
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.INTEGER, name = "typ")
public abstract class DatasetRow<T> implements EntityId { public abstract class DatasetRow<T> implements EntityId {
@Id @Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "datasetrow_seq") @GeneratedValue(strategy = GenerationType.TABLE)
@SequenceGenerator(name = "datasetrow_seq", sequenceName = "datasetrow_seq", allocationSize = 10)
@Column(name = "id", unique = true, nullable = false, length = 20) @Column(name = "id", unique = true, nullable = false, length = 20)
protected Long id; protected Long id;
......
...@@ -17,17 +17,21 @@ ...@@ -17,17 +17,21 @@
package org.genesys2.server.model.impl; package org.genesys2.server.model.impl;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table;
/** /**
* A Descriptor represents a dimension of a sparse vector. * A Descriptor represents a dimension of a sparse vector.
* *
* @author mobreza * @author mobreza
*/ */
@Entity(name = "datasetdbl") @Entity
//@Table(name = "datasetdbl")
@DiscriminatorValue("2")
public class TraitDblValue extends DatasetRow<Double> { public class TraitDblValue extends DatasetRow<Double> {
@Column(nullable = false, name="vald") @Column(name="vald")
private Double val; private Double val;
@Override @Override
......
...@@ -17,19 +17,19 @@ ...@@ -17,19 +17,19 @@
package org.genesys2.server.model.impl; package org.genesys2.server.model.impl;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
/** /**
* A Descriptor represents a dimension of a sparse vector. * A Descriptor represents a dimension of a sparse vector.
* *
* @author mobreza * @author mobreza
*/ */
@Entity(name = "datasetint") @Entity
@Table(indexes={ @Index(name="IX_datasetint_val", unique=false, columnList="descriptorId, vali") }) //@Table(name = "datasetint", indexes={ @Index(name="IX_datasetint_val", unique=false, columnList="descriptorId, vali") })
@DiscriminatorValue("1")
public class TraitIntValue extends DatasetRow<Integer> { public class TraitIntValue extends DatasetRow<Integer> {
@Column(nullable = false, name="vali") @Column(name="vali")
private Integer val; private Integer val;
@Override @Override
......
...@@ -17,17 +17,21 @@ ...@@ -17,17 +17,21 @@
package org.genesys2.server.model.impl; package org.genesys2.server.model.impl;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table;
/** /**
* A Descriptor represents a dimension of a sparse vector. * A Descriptor represents a dimension of a sparse vector.
* *
* @author mobreza * @author mobreza
*/ */
@Entity(name = "datasetstr") @Entity
//@Table(name = "datasetstr")
@DiscriminatorValue("3")
public class TraitStrValue extends DatasetRow<String> { public class TraitStrValue extends DatasetRow<String> {
@Column(nullable = false, name="vals") @Column(name="vals")
private String val; private String val;
@Override @Override
......
...@@ -16,8 +16,12 @@ ...@@ -16,8 +16,12 @@
package org.genesys2.server.persistence.domain; package org.genesys2.server.persistence.domain;
import java.util.UUID;
import org.genesys2.server.model.impl.Dataset; import org.genesys2.server.model.impl.Dataset;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
public interface DatasetRepository extends JpaRepository<Dataset, Long> { public interface DatasetRepository extends JpaRepository<Dataset, Long> {
Dataset findByUuid(UUID uuid);
} }
...@@ -16,13 +16,21 @@ ...@@ -16,13 +16,21 @@
package org.genesys2.server.persistence.domain; package org.genesys2.server.persistence.domain;
import java.util.List;
import java.util.Set;
import org.genesys2.server.model.impl.Dataset; import org.genesys2.server.model.impl.Dataset;
import org.genesys2.server.model.impl.DatasetRow; import org.genesys2.server.model.impl.DatasetRow;
import org.genesys2.server.model.impl.Descriptor;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface DatasetRowRepository extends JpaRepository<DatasetRow<?>, Long> { public interface DatasetRowRepository extends JpaRepository<DatasetRow<?>, Long> {
Page<DatasetRow<?>> findByDataset(Dataset ds, Pageable page); Page<DatasetRow<?>> findByDataset(Dataset ds, Pageable page);
@Query("select dr from DatasetRow dr where dr.dataset=?1 and dr.descriptor=?2 and dr.accession.id in ( ?3 )")
List<DatasetRow<?>> list(Dataset dataset, Descriptor descriptor, Set<Long> ids);
} }
...@@ -41,9 +41,8 @@ import org.springframework.stereotype.Repository; ...@@ -41,9 +41,8 @@ import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@Repository @Repository
@Transactional(readOnly = true) public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepository {
public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository { public static final Log LOG = LogFactory.getLog(GenesysLowlevelRepositoryCustomImpl.class);
public static final Log LOG = LogFactory.getLog(GenesysLowlevelRepositoryImpl.class);
@Autowired @Autowired
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
...@@ -217,7 +216,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository ...@@ -217,7 +216,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
directQuery.jsonFilter(filter, new MethodResolver() { directQuery.jsonFilter(filter, new MethodResolver() {
@Override @Override
public Method getMethod(final long methodId) { public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryImpl.this.methodRepository.findOne(methodId); return GenesysLowlevelRepositoryCustomImpl.this.methodRepository.findOne(methodId);
} }
}); });
...@@ -231,7 +230,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository ...@@ -231,7 +230,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
directQuery.jsonFilter(filter, new MethodResolver() { directQuery.jsonFilter(filter, new MethodResolver() {
@Override @Override
public Method getMethod(final long methodId) { public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryImpl.this.methodRepository.findOne(methodId); return GenesysLowlevelRepositoryCustomImpl.this.methodRepository.findOne(methodId);
} }
}); });
...@@ -258,7 +257,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository ...@@ -258,7 +257,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
directQuery.jsonFilter(filter, new MethodResolver() { directQuery.jsonFilter(filter, new MethodResolver() {
@Override @Override
public Method getMethod(final long methodId) { public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryImpl.this.methodRepository.findOne(methodId); return GenesysLowlevelRepositoryCustomImpl.this.methodRepository.findOne(methodId);
} }
}); });
directQuery.sort(sort); directQuery.sort(sort);
...@@ -286,7 +285,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository ...@@ -286,7 +285,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
directQuery.jsonFilter(filter, new MethodResolver() { directQuery.jsonFilter(filter, new MethodResolver() {
@Override @Override
public Method getMethod(final long methodId) { public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryImpl.this.methodRepository.findOne(methodId); return GenesysLowlevelRepositoryCustomImpl.this.methodRepository.findOne(methodId);
} }
}); });
...@@ -314,7 +313,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository ...@@ -314,7 +313,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
directQuery.jsonFilter(filter, new MethodResolver() { directQuery.jsonFilter(filter, new MethodResolver() {
@Override @Override
public Method getMethod(final long methodId) { public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryImpl.this.methodRepository.findOne(methodId); return GenesysLowlevelRepositoryCustomImpl.this.methodRepository.findOne(methodId);
} }
}); });
...@@ -356,7 +355,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository ...@@ -356,7 +355,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
directQuery.jsonFilter(filter, new MethodResolver() { directQuery.jsonFilter(filter, new MethodResolver() {
@Override @Override
public Method getMethod(final long methodId) { public Method getMethod<