Commit 8ad4bee5 authored by Matija Obreza's avatar Matija Obreza

AccessionGeoFilter with ClimateFilter

parent f180ebab
......@@ -57,6 +57,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.annotation.JsonView;
import com.querydsl.core.annotations.QueryInit;
@MappedSuperclass
public abstract class AccessionData extends AuditedVersionedModel implements IdUUID, AccessionIdentifier3, Serializable, SelfCleaning {
......@@ -68,6 +69,7 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
@JoinColumn(name = "id")
@JsonUnwrapped
@Field(type=FieldType.Auto)
@QueryInit({ "geo.*", "coll.*" })
private AccessionId accessionId;
@Column(name = "doi")
......@@ -88,7 +90,7 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
@JsonView({ JsonViews.Minimal.class })
@Field(type = FieldType.Object)
@JsonIgnoreProperties({"settings"})
// @QueryInit({ "country.region.*" })
@QueryInit({ "country.*" })
private FaoInstitute institute;
@Size(max = 128)
......
......@@ -17,9 +17,12 @@
package org.genesys2.server.model.genesys;
import javax.persistence.Column;
import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
......@@ -29,9 +32,13 @@ import javax.persistence.Version;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.auditlog.annotations.Audited;
import org.genesys.blocks.model.BasicModel;
import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.model.SelfCleaning;
import org.genesys.worldclim.WorldClimUtil;
import org.genesys2.server.model.impl.GeoReferencedEntity;
import org.genesys2.server.model.impl.TileClimate;
import com.fasterxml.jackson.annotation.JsonView;
@Entity
@Table(name = "accession_geo", indexes = { @Index(unique = false, columnList = "latitude, longitude"), @Index(unique = false, columnList = "tileIndex") })
......@@ -60,6 +67,11 @@ public class AccessionGeo extends BasicModel implements GeoReferencedEntity, Acc
private String method;
private Long tileIndex;
@ManyToOne(cascade = {}, fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "tileIndex", nullable = true, insertable = false, updatable = false, foreignKey = @javax.persistence.ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
@JsonView({ JsonViews.Protected.class })
private TileClimate climate;
/**
* Recalculate {@link #tileIndex} on insert and update
......@@ -158,6 +170,14 @@ public class AccessionGeo extends BasicModel implements GeoReferencedEntity, Acc
public void setTileIndex(final Long tileIndex) {
this.tileIndex = tileIndex;
}
public TileClimate getClimate() {
return climate;
}
public void setClimate(TileClimate climate) {
this.climate = climate;
}
public boolean isEmpty() {
if (StringUtils.isNotBlank(datum)) {
......
......@@ -40,6 +40,9 @@ public class AccessionGeoFilter extends BasicModelFilter<AccessionGeoFilter, Acc
public NumberFilter<Double> elevation;
public Boolean referenced;
/** The climate. */
public ClimateFilter climate;
/**
* Builds the query.
......@@ -78,6 +81,9 @@ public class AccessionGeoFilter extends BasicModelFilter<AccessionGeoFilter, Acc
if (elevation != null) {
and.and(elevation.buildQuery(accessiongeo.elevation));
}
if (climate != null) {
and.and(climate.buildQuery(accessiongeo.climate));
}
return and;
}
......
/*
* Copyright 2018 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.service.filter;
import java.util.Set;
import org.apache.commons.collections.CollectionUtils;
import org.genesys.blocks.model.filters.NumberFilter;
import org.genesys2.server.model.impl.QTileClimate;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
/**
* The Class ClimateFilter.
*/
public class ClimateFilter {
/** The latitude. */
public Set<Long> tileIndex;
public NumberFilter<Double> alt;
public NumberFilter<Double> bio1;
public NumberFilter<Double> bio2;
public NumberFilter<Double> bio3;
public NumberFilter<Double> bio4;
public NumberFilter<Double> bio5;
public NumberFilter<Double> bio6;
public NumberFilter<Double> bio7;
public NumberFilter<Double> bio8;
public NumberFilter<Double> bio9;
public NumberFilter<Double> bio10;
public NumberFilter<Double> bio11;
public NumberFilter<Double> bio12;
public NumberFilter<Double> bio13;
public NumberFilter<Double> bio14;
public NumberFilter<Double> bio15;
public NumberFilter<Double> prec1;
public NumberFilter<Double> prec2;
public NumberFilter<Double> prec3;
public NumberFilter<Double> prec4;
public NumberFilter<Double> prec5;
public NumberFilter<Double> prec6;
public NumberFilter<Double> prec7;
public NumberFilter<Double> prec8;
public NumberFilter<Double> prec9;
public NumberFilter<Double> prec10;
public NumberFilter<Double> prec11;
public NumberFilter<Double> prec12;
public NumberFilter<Double> tmax1;
public NumberFilter<Double> tmax2;
public NumberFilter<Double> tmax3;
public NumberFilter<Double> tmax4;
public NumberFilter<Double> tmax5;
public NumberFilter<Double> tmax6;
public NumberFilter<Double> tmax7;
public NumberFilter<Double> tmax8;
public NumberFilter<Double> tmax9;
public NumberFilter<Double> tmax10;
public NumberFilter<Double> tmax11;
public NumberFilter<Double> tmax12;
public NumberFilter<Double> tmean1;
public NumberFilter<Double> tmean2;
public NumberFilter<Double> tmean3;
public NumberFilter<Double> tmean4;
public NumberFilter<Double> tmean5;
public NumberFilter<Double> tmean6;
public NumberFilter<Double> tmean7;
public NumberFilter<Double> tmean8;
public NumberFilter<Double> tmean9;
public NumberFilter<Double> tmean10;
public NumberFilter<Double> tmean11;
public NumberFilter<Double> tmean12;
public NumberFilter<Double> tmin1;
public NumberFilter<Double> tmin2;
public NumberFilter<Double> tmin3;
public NumberFilter<Double> tmin4;
public NumberFilter<Double> tmin5;
public NumberFilter<Double> tmin6;
public NumberFilter<Double> tmin7;
public NumberFilter<Double> tmin8;
public NumberFilter<Double> tmin9;
public NumberFilter<Double> tmin10;
public NumberFilter<Double> tmin11;
public NumberFilter<Double> tmin12;
/**
* Builds the query.
*
* @param qtileClimate the qtile climate
* @return the predicate
*/
public Predicate buildQuery(QTileClimate qtileClimate) {
final BooleanBuilder and = new BooleanBuilder();
if (!CollectionUtils.isEmpty(tileIndex)) {
and.and(qtileClimate.tileIndex.in(tileIndex));
}
if (alt != null) {
and.and(alt.buildQuery(qtileClimate.alt));
}
if (bio1 != null) {
and.and(bio1.buildQuery(qtileClimate.bio1));
}
if (bio2 != null) {
and.and(bio2.buildQuery(qtileClimate.bio2));
}
if (bio3 != null) {
and.and(bio3.buildQuery(qtileClimate.bio3));
}
if (bio4 != null) {
and.and(bio4.buildQuery(qtileClimate.bio4));
}
if (bio5 != null) {
and.and(bio5.buildQuery(qtileClimate.bio5));
}
if (bio6 != null) {
and.and(bio6.buildQuery(qtileClimate.bio6));
}
if (bio7 != null) {
and.and(bio7.buildQuery(qtileClimate.bio7));
}
if (bio8 != null) {
and.and(bio8.buildQuery(qtileClimate.bio8));
}
if (bio9 != null) {
and.and(bio9.buildQuery(qtileClimate.bio9));
}
if (bio10 != null) {
and.and(bio10.buildQuery(qtileClimate.bio10));
}
if (bio11 != null) {
and.and(bio11.buildQuery(qtileClimate.bio11));
}
if (bio12 != null) {
and.and(bio12.buildQuery(qtileClimate.bio12));
}
if (bio13 != null) {
and.and(bio13.buildQuery(qtileClimate.bio13));
}
if (bio14 != null) {
and.and(bio14.buildQuery(qtileClimate.bio14));
}
if (bio15 != null) {
and.and(bio15.buildQuery(qtileClimate.bio15));
}
if (prec1 != null) {
and.and(prec1.buildQuery(qtileClimate.prec1));
}
if (prec2 != null) {
and.and(prec2.buildQuery(qtileClimate.prec2));
}
if (prec3 != null) {
and.and(prec3.buildQuery(qtileClimate.prec3));
}
if (prec4 != null) {
and.and(prec4.buildQuery(qtileClimate.prec4));
}
if (prec5 != null) {
and.and(prec5.buildQuery(qtileClimate.prec5));
}
if (prec6 != null) {
and.and(prec6.buildQuery(qtileClimate.prec6));
}
if (prec7 != null) {
and.and(prec7.buildQuery(qtileClimate.prec7));
}
if (prec8 != null) {
and.and(prec8.buildQuery(qtileClimate.prec8));
}
if (prec9 != null) {
and.and(prec9.buildQuery(qtileClimate.prec9));
}
if (prec10 != null) {
and.and(prec10.buildQuery(qtileClimate.prec10));
}
if (prec11 != null) {
and.and(prec11.buildQuery(qtileClimate.prec11));
}
if (prec12 != null) {
and.and(prec12.buildQuery(qtileClimate.prec12));
}
if (tmax1 != null) {
and.and(tmax1.buildQuery(qtileClimate.tmax1));
}
if (tmax2 != null) {
and.and(tmax2.buildQuery(qtileClimate.tmax2));
}
if (tmax3 != null) {
and.and(tmax3.buildQuery(qtileClimate.tmax3));
}
if (tmax4 != null) {
and.and(tmax4.buildQuery(qtileClimate.tmax4));
}
if (tmax5 != null) {
and.and(tmax5.buildQuery(qtileClimate.tmax5));
}
if (tmax6 != null) {
and.and(tmax6.buildQuery(qtileClimate.tmax6));
}
if (tmax7 != null) {
and.and(tmax7.buildQuery(qtileClimate.tmax7));
}
if (tmax8 != null) {
and.and(tmax8.buildQuery(qtileClimate.tmax8));
}
if (tmax9 != null) {
and.and(tmax9.buildQuery(qtileClimate.tmax9));
}
if (tmax10 != null) {
and.and(tmax10.buildQuery(qtileClimate.tmax10));
}
if (tmax11 != null) {
and.and(tmax11.buildQuery(qtileClimate.tmax11));
}
if (tmax12 != null) {
and.and(tmax12.buildQuery(qtileClimate.tmax12));
}
if (tmean1 != null) {
and.and(tmean1.buildQuery(qtileClimate.tmean1));
}
if (tmean2 != null) {
and.and(tmean2.buildQuery(qtileClimate.tmean2));
}
if (tmean3 != null) {
and.and(tmean3.buildQuery(qtileClimate.tmean3));
}
if (tmean4 != null) {
and.and(tmean4.buildQuery(qtileClimate.tmean4));
}
if (tmean5 != null) {
and.and(tmean5.buildQuery(qtileClimate.tmean5));
}
if (tmean6 != null) {
and.and(tmean6.buildQuery(qtileClimate.tmean6));
}
if (tmean7 != null) {
and.and(tmean7.buildQuery(qtileClimate.tmean7));
}
if (tmean8 != null) {
and.and(tmean8.buildQuery(qtileClimate.tmean8));
}
if (tmean9 != null) {
and.and(tmean9.buildQuery(qtileClimate.tmean9));
}
if (tmean10 != null) {
and.and(tmean10.buildQuery(qtileClimate.tmean10));
}
if (tmean11 != null) {
and.and(tmean11.buildQuery(qtileClimate.tmean11));
}
if (tmean12 != null) {
and.and(tmean12.buildQuery(qtileClimate.tmean12));
}
if (tmin1 != null) {
and.and(tmin1.buildQuery(qtileClimate.tmin1));
}
if (tmin2 != null) {
and.and(tmin2.buildQuery(qtileClimate.tmin2));
}
if (tmin3 != null) {
and.and(tmin3.buildQuery(qtileClimate.tmin3));
}
if (tmin4 != null) {
and.and(tmin4.buildQuery(qtileClimate.tmin4));
}
if (tmin5 != null) {
and.and(tmin5.buildQuery(qtileClimate.tmin5));
}
if (tmin6 != null) {
and.and(tmin6.buildQuery(qtileClimate.tmin6));
}
if (tmin7 != null) {
and.and(tmin7.buildQuery(qtileClimate.tmin7));
}
if (tmin8 != null) {
and.and(tmin8.buildQuery(qtileClimate.tmin8));
}
if (tmin9 != null) {
and.and(tmin9.buildQuery(qtileClimate.tmin9));
}
if (tmin10 != null) {
and.and(tmin10.buildQuery(qtileClimate.tmin10));
}
if (tmin11 != null) {
and.and(tmin11.buildQuery(qtileClimate.tmin11));
}
if (tmin12 != null) {
and.and(tmin12.buildQuery(qtileClimate.tmin12));
}
return and;
}
}
......@@ -30,7 +30,6 @@ import org.apache.commons.collections.CollectionUtils;
import org.genesys.blocks.auditlog.service.AuditTrailService;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.service.DatasetService;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.service.ImageGalleryService;
......@@ -129,6 +128,9 @@ public class AccessionServiceImpl implements AccessionService {
}
if (accessionId.getGeo() != null) {
accessionId.getGeo().getId();
if (accessionId.getGeo().getClimate() != null) {
accessionId.getGeo().getClimate().getTileIndex();
}
}
if (accessionId.getPdci() != null)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment