Skip to content
Snippets Groups Projects
Commit 7e3c7f4b authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Upgrade to new version of JTS, with all kinds of horrible repercussions

parent cfe14fdd
No related branches found
No related tags found
2 merge requests!17Develop,!13Spotit septoria map models
This commit is part of merge request !13. Comments created here will be created in the context of that merge request.
......@@ -15,10 +15,10 @@
<url>http://maven.apache.org</url>
<repositories>
<!--repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository-->
</repository>
<repository>
<id>mvnrepository.com</id>
<url>https://mvnrepository.com</url>
......@@ -189,7 +189,7 @@
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>1.16.0</version>
<version>1.16.1</version>
<type>jar</type>
</dependency>
<dependency>
......@@ -281,7 +281,7 @@
<dependency>
<groupId>com.bedatadriven</groupId>
<artifactId>jackson-datatype-jts</artifactId>
<version>2.2</version>
<version>2.4</version>
</dependency>
</dependencies>
......
......@@ -597,7 +597,7 @@ public class ForecastBean {
{
ex.printStackTrace();
}*/
Response resp = this.getManagerResource().runModel(config.getModelId(), request);
Response resp = this.getManagerResource().runModel(config.getModelId(), request);
if(resp.getStatus() == Response.Status.OK.getStatusCode())
{
//System.out.println(resp.readEntity(String.class));
......
......@@ -45,6 +45,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import no.nibio.vips.logic.entity.helpers.ForecastResultSerializer;
import org.locationtech.jts.geom.Geometry;
......@@ -62,6 +64,7 @@ import org.locationtech.jts.geom.Geometry;
@NamedQuery(name = "ForecastResult.findByForecastConfigurationIdAndPeriod", query = "SELECT f FROM ForecastResult f WHERE f.forecastConfigurationId = :forecastConfigurationId AND f.validTimeStart BETWEEN :timeStart AND :timeEnd ORDER BY f.validTimeStart ASC"),
@NamedQuery(name = "ForecastResult.findByValidTimeStart", query = "SELECT f FROM ForecastResult f WHERE f.validTimeStart = :validTimeStart ORDER BY f.validTimeStart ASC"),
@NamedQuery(name = "ForecastResult.findByWarningStatus", query = "SELECT f FROM ForecastResult f WHERE f.warningStatus = :warningStatus ORDER BY f.validTimeStart ASC")})
@JsonSerialize(using=ForecastResultSerializer.class)
public class ForecastResult implements Serializable, Comparable{
private static final long serialVersionUID = 1L;
@Id
......
/*
* Copyright (c) 2018 NIBIO <http://www.nibio.no/>.
*
* This file is part of VIPSCommon.
* VIPSCommon is free software: you can redistribute it and/or modify
* it under the terms of the NIBIO Open Source License as published by
* NIBIO, either version 1 of the License, or (at your option) any
* later version.
*
* VIPSCommon is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* NIBIO Open Source License for more details.
*
* You should have received a copy of the NIBIO Open Source License
* along with VIPSCommon. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.logic.entity.helpers;
import com.bedatadriven.jackson.datatype.jts.JtsModule;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Polygon;
import java.io.IOException;
import no.nibio.vips.gis.GISUtil;
import no.nibio.vips.logic.entity.ForecastResult;
/**
* Unfortunately, we have to do this, since Resteasy does not currently support the org.locationtech.jts package
* Ref http://www.baeldung.com/jackson-custom-serialization
* @copyright 2019 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class ForecastResultSerializer extends StdSerializer<ForecastResult>{
ObjectMapper objectMapper;
GeometryFactory gf;
GISUtil gisUtil;
public ForecastResultSerializer() {
this(null);
this.gisUtil = new GISUtil();
}
public ForecastResultSerializer(Class<ForecastResult> t) {
super(t);
this.objectMapper = new ObjectMapper();
this.objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
this.objectMapper.registerModule(new JtsModule());
}
@Override
public void serialize(ForecastResult t, JsonGenerator jg, SerializerProvider sp) throws IOException {
jg.writeStartObject();
jg.writeStringField("validTimeStart", this.objectMapper.writeValueAsString(t.getValidTimeStart()).replaceAll("\"", ""));
jg.writeStringField("validTimeEnd", this.objectMapper.writeValueAsString(t.getValidTimeEnd()).replaceAll("\"", ""));
String geoJSON = t.getValidGeometry() == null ? "null"
: t.getValidGeometry().getGeometryType().equals("Point") ? objectMapper.writeValueAsString(this.gisUtil.getVividPoint((Point) t.getValidGeometry()))
: t.getValidGeometry().getGeometryType().equals("LineString") ? objectMapper.writeValueAsString((LineString) t.getValidGeometry())
:t.getValidGeometry().getGeometryType().equals("Polygon") ? objectMapper.writeValueAsString((Polygon) t.getValidGeometry())
: "null";
//jg.writeObjectField("validGeometry", t.getValidGeometry());
//System.out.println(geoJSON);
jg.writeRaw(",\"validGeometry\":" + geoJSON);
//
jg.writeNumberField("warningStatus", t.getWarningStatus());
jg.writeNumberField("forecastResultId", t.getForecastResultId());
jg.writeNumberField("forecastConfigurationId", t.getForecastConfigurationId());
//System.out.println(t.getAllValues());
jg.writeRaw(",\"allValues\": " + t.getAllValues());
jg.writeRaw(",\"keys\": [" + "\"" + String.join("\",\"", t.getKeys()) + "\"]");
jg.writeEndObject();
}
}
......@@ -34,6 +34,7 @@ import java.util.stream.Stream;
import no.nibio.vips.entity.ModelConfiguration;
import no.nibio.vips.entity.PointWeatherObservationList;
import no.nibio.vips.entity.WeatherObservation;
import no.nibio.vips.gis.CoordinateProxy;
import no.nibio.vips.logic.entity.ForecastConfiguration;
import no.nibio.vips.logic.entity.PointOfInterestWeatherStation;
import no.nibio.vips.logic.scheduling.model.ModelRunPreprocessor;
......@@ -66,7 +67,7 @@ public class ZymoseptoriaSimpleRiskGridModelPreprocessor extends ModelRunPreproc
WeatherUtil wUtil = new WeatherUtil();
for(PointOfInterestWeatherStation station:stations)
{
Coordinate coordinate = new Coordinate(station.getPointOfInterest().getLongitude(), station.getPointOfInterest().getLatitude());
CoordinateProxy coordinate = new CoordinateProxy(station.getPointOfInterest().getLongitude(), station.getPointOfInterest().getLatitude());
List<WeatherObservation> stationObs = getStationObs(station, configuration);
try
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment