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

First version serving KML files with forecast aggregates for POIs

Added License notices to some files
parent e4b8ebe5
No related branches found
No related tags found
No related merge requests found
...@@ -58,6 +58,11 @@ ...@@ -58,6 +58,11 @@
<version>2.5</version> <version>2.5</version>
<type>jar</type> <type>jar</type>
</dependency> </dependency>
<dependency>
<groupId>de.micromata.jak</groupId>
<artifactId>JavaAPIforKml</artifactId>
<version>2.2.0</version>
</dependency>
<dependency> <dependency>
<groupId>javax</groupId> <groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId> <artifactId>javaee-web-api</artifactId>
...@@ -101,4 +106,5 @@ ...@@ -101,4 +106,5 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>
...@@ -37,6 +37,7 @@ public class VIPSLogicApplication extends Application ...@@ -37,6 +37,7 @@ public class VIPSLogicApplication extends Application
*/ */
private void addRestResourceClasses(Set<Class<?>> resources) { private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(no.bioforsk.vips.core.service.ModelResource.class); resources.add(no.bioforsk.vips.core.service.ModelResource.class);
resources.add(no.bioforsk.vips.coremanager.service.ManagerResource.class);
resources.add(no.bioforsk.vips.logic.service.LogicService.class); resources.add(no.bioforsk.vips.logic.service.LogicService.class);
} }
......
package no.bioforsk.vips.logic.controller.session; package no.bioforsk.vips.logic.controller.session;
import de.micromata.opengis.kml.v_2_2_0.Coordinate;
import de.micromata.opengis.kml.v_2_2_0.Document;
import de.micromata.opengis.kml.v_2_2_0.Kml;
import de.micromata.opengis.kml.v_2_2_0.KmlFactory;
import de.micromata.opengis.kml.v_2_2_0.Placemark;
import de.micromata.opengis.kml.v_2_2_0.Point;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -28,6 +35,7 @@ import no.bioforsk.vips.logic.entity.ForecastModelConfiguration; ...@@ -28,6 +35,7 @@ import no.bioforsk.vips.logic.entity.ForecastModelConfiguration;
import no.bioforsk.vips.logic.scheduling.model.ModelRunPreprocessor; import no.bioforsk.vips.logic.scheduling.model.ModelRunPreprocessor;
import no.bioforsk.vips.logic.scheduling.model.ModelRunPreprocessorFactory; import no.bioforsk.vips.logic.scheduling.model.ModelRunPreprocessorFactory;
import no.bioforsk.vips.logic.scheduling.model.PreprocessorException; import no.bioforsk.vips.logic.scheduling.model.PreprocessorException;
import no.bioforsk.vips.logic.util.Globals;
import no.bioforsk.vips.logic.util.RunModelException; import no.bioforsk.vips.logic.util.RunModelException;
import no.bioforsk.vips.logic.util.SessionControllerGetter; import no.bioforsk.vips.logic.util.SessionControllerGetter;
import no.bioforsk.web.forms.FormField; import no.bioforsk.web.forms.FormField;
...@@ -275,8 +283,8 @@ public class ForecastBean { ...@@ -275,8 +283,8 @@ public class ForecastBean {
ModelRunRequest request = new ModelRunRequest(config); ModelRunRequest request = new ModelRunRequest(config);
Map<String,String> loginInfo = new HashMap<>(); Map<String,String> loginInfo = new HashMap<>();
// VIPSLogic logs in on behalf of client // VIPSLogic logs in on behalf of client
//loginInfo.put("username",System.getProperty("no.bioforsk.vips.logic.CORE_BATCH_USERNAME")); loginInfo.put("username",System.getProperty("no.bioforsk.vips.logic.CORE_BATCH_USERNAME"));
loginInfo.put("username","wrongusername"); //loginInfo.put("username","wrongusername");
loginInfo.put("password",System.getProperty("no.bioforsk.vips.logic.CORE_BATCH_PASSWORD")); loginInfo.put("password",System.getProperty("no.bioforsk.vips.logic.CORE_BATCH_PASSWORD"));
request.setLoginInfo(loginInfo); request.setLoginInfo(loginInfo);
// We tell which client this is (the db Id in VIPSCoreManager) // We tell which client this is (the db Id in VIPSCoreManager)
...@@ -308,4 +316,96 @@ public class ForecastBean { ...@@ -308,4 +316,96 @@ public class ForecastBean {
ManagerResource resource = rTarget.proxy(ManagerResource.class); ManagerResource resource = rTarget.proxy(ManagerResource.class);
return resource; return resource;
} }
public Kml getForecastsAggregateKml(Date theDate)
{
// Initialization
final Kml kml = KmlFactory.createKml();
final Document document = kml.createAndSetDocument()
.withName("Forecast results - aggregates").withDescription("Worst forecasts for each POI");
document.createAndAddStyle()
.withId("warning_type_0")
.createAndSetIconStyle()
.withScale(0.55)
.createAndSetIcon()
.withHref("http://www.vips-landbruk.no/graphics/dot_grey.png");
document.createAndAddStyle()
.withId("warning_type_1")
.createAndSetIconStyle()
.withScale(0.55)
.createAndSetIcon()
.withHref("http://www.vips-landbruk.no/graphics/dot_blue.png");
document.createAndAddStyle()
.withId("warning_type_2")
.createAndSetIconStyle()
.withScale(0.55)
.createAndSetIcon()
.withHref("http://www.vips-landbruk.no/graphics/dot_green.png");
document.createAndAddStyle()
.withId("warning_type_3")
.createAndSetIconStyle()
.withScale(0.55)
.createAndSetIcon()
.withHref("http://www.vips-landbruk.no/graphics/dot_yellow.png");
document.createAndAddStyle()
.withId("warning_type_4")
.createAndSetIconStyle()
.withScale(0.55)
.createAndSetIcon()
.withHref("http://www.vips-landbruk.no/graphics/dot_red.png");
// Run through forecast configurations
List<PointOfInterest> poisWithAggregate = getPointOfInterestForecastsAggregate(theDate);
for(PointOfInterest poiWithAggregate:poisWithAggregate)
{
final Placemark placemark = document.createAndAddPlacemark()
.withName(poiWithAggregate.getName())
.withDescription("<![CDATA[Mangler informasjon om varsler for " + poiWithAggregate.getName() + "]]>")
.withStyleUrl("#warning_type_"
+ (poiWithAggregate.getProperties().get("forecastsAggregate") != null ? poiWithAggregate.getProperties().get("forecastsAggregate") : "0")
);
final Point point = placemark.createAndSetPoint();
List<Coordinate> coord = point.createAndSetCoordinates();
coord.add(new Coordinate(
poiWithAggregate.getLongitude(),
poiWithAggregate.getLatitude(),
poiWithAggregate.getAltitude() != null ? poiWithAggregate.getAltitude() : 0
));
}
System.out.println(kml.marshal());
return kml;
}
/**
* TODO: This should be cached somehow. Here in app or in web server???
* @param theDate
* @return
*/
private List<PointOfInterest> getPointOfInterestForecastsAggregate(Date theDate) {
// TODO: More precise gathering of POIs...
List<PointOfInterest> pois = em.createNamedQuery("PointOfInterest.findAll").getResultList();
SimpleDateFormat format = new SimpleDateFormat(Globals.defaultDateFormat);
for(PointOfInterest poi: pois)
{
Query q = em.createNativeQuery("SELECT max(warning_status) FROM forecast_result \n" +
"WHERE forecast_configuration_id IN( \n" +
" SELECT forecast_configuration_id \n" +
" FROM forecast_configuration \n" +
" WHERE location_point_of_interest_id=:locationPointOfInterestId \n" +
")\n" +
"AND to_char(result_valid_time, 'yyyy-MM-dd') = :dateStr");
q.setParameter("locationPointOfInterestId", poi.getPointOfInterestId());
q.setParameter("dateStr", format.format(theDate));
poi.getProperties().put("forecastsAggregate", (Integer) q.getSingleResult());
}
return pois;
}
} }
/*
* Copyright (c) 2013 Bioforsk <http://www.bioforsk.no/>.
*
* This file is part of VIPSLogic.
* VIPSLogic is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VIPSLogic 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
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with VIPSLogic. If not, see <http://www.gnu.org/licenses/>.
*
*/
package no.bioforsk.vips.logic.entity; package no.bioforsk.vips.logic.entity;
import java.io.Serializable; import java.io.Serializable;
...@@ -37,6 +55,7 @@ import org.codehaus.jackson.annotate.JsonIgnore; ...@@ -37,6 +55,7 @@ import org.codehaus.jackson.annotate.JsonIgnore;
@NamedQuery(name = "ForecastConfiguration.findByModelId", query = "SELECT f FROM ForecastConfiguration f WHERE f.modelId = :modelId"), @NamedQuery(name = "ForecastConfiguration.findByModelId", query = "SELECT f FROM ForecastConfiguration f WHERE f.modelId = :modelId"),
@NamedQuery(name = "ForecastConfiguration.findByDateStart", query = "SELECT f FROM ForecastConfiguration f WHERE f.dateStart = :dateStart"), @NamedQuery(name = "ForecastConfiguration.findByDateStart", query = "SELECT f FROM ForecastConfiguration f WHERE f.dateStart = :dateStart"),
@NamedQuery(name = "ForecastConfiguration.findByDateEnd", query = "SELECT f FROM ForecastConfiguration f WHERE f.dateEnd = :dateEnd"), @NamedQuery(name = "ForecastConfiguration.findByDateEnd", query = "SELECT f FROM ForecastConfiguration f WHERE f.dateEnd = :dateEnd"),
@NamedQuery(name = "ForecastConfiguration.findByLocationPointOfInterestId", query = "SELECT f FROM ForecastConfiguration f WHERE f.locationPointOfInterestId = :locationPointOfInterestId"),
@NamedQuery(name = "ForecastConfiguration.findByVipsLogicUserId", query = "SELECT f FROM ForecastConfiguration f WHERE f.vipsLogicUserId = :vipsLogicUserId"), @NamedQuery(name = "ForecastConfiguration.findByVipsLogicUserId", query = "SELECT f FROM ForecastConfiguration f WHERE f.vipsLogicUserId = :vipsLogicUserId"),
@NamedQuery(name = "ForecastConfiguration.findByVipsLogicUserIds", query = "SELECT f FROM ForecastConfiguration f WHERE f.vipsLogicUserId IN (:vipsLogicUserIds)") @NamedQuery(name = "ForecastConfiguration.findByVipsLogicUserIds", query = "SELECT f FROM ForecastConfiguration f WHERE f.vipsLogicUserId IN (:vipsLogicUserIds)")
}) })
......
/*
* Copyright (c) 2013 Bioforsk <http://www.bioforsk.no/>.
*
* This file is part of VIPSLogic.
* VIPSLogic is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VIPSLogic 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
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with VIPSLogic. If not, see <http://www.gnu.org/licenses/>.
*
*/
package no.bioforsk.vips.logic.entity; package no.bioforsk.vips.logic.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.persistence.Basic; import javax.persistence.Basic;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
...@@ -18,6 +38,7 @@ import javax.persistence.NamedQueries; ...@@ -18,6 +38,7 @@ import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlTransient;
...@@ -71,6 +92,11 @@ public class PointOfInterest implements Serializable, Comparable { ...@@ -71,6 +92,11 @@ public class PointOfInterest implements Serializable, Comparable {
@ManyToOne @ManyToOne
private PointOfInterestType pointOfInterestType; private PointOfInterestType pointOfInterestType;
// For attaching ad-hoc properties
// e.g. Worst warning for map
@Transient
private Map<String, Object> properties;
public PointOfInterest() { public PointOfInterest() {
} }
...@@ -205,4 +231,22 @@ public class PointOfInterest implements Serializable, Comparable { ...@@ -205,4 +231,22 @@ public class PointOfInterest implements Serializable, Comparable {
public void setTimeZone(String timeZone) { public void setTimeZone(String timeZone) {
this.timeZone = timeZone; this.timeZone = timeZone;
} }
/**
* @return the properties
*/
public Map<String,Object> getProperties() {
if(this.properties == null)
{
this.properties = new HashMap<>();
}
return properties;
}
/**
* @param properties the properties to set
*/
public void setProperties(Map<String,Object> properties) {
this.properties = properties;
}
} }
/*
* Copyright (c) 2013 Bioforsk <http://www.bioforsk.no/>.
*
* This file is part of VIPSLogic.
* VIPSLogic is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VIPSLogic 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
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with VIPSLogic. If not, see <http://www.gnu.org/licenses/>.
*
*/
package no.bioforsk.vips.logic.scheduling.model.preprocessor; package no.bioforsk.vips.logic.scheduling.model.preprocessor;
import java.io.IOException;
import no.bioforsk.vips.logic.entity.ForecastConfiguration; import no.bioforsk.vips.logic.entity.ForecastConfiguration;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
......
package no.bioforsk.vips.logic.service; package no.bioforsk.vips.logic.service;
import de.micromata.opengis.kml.v_2_2_0.Kml;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
...@@ -20,6 +21,7 @@ import no.bioforsk.vips.logic.i18n.SessionLocaleUtil; ...@@ -20,6 +21,7 @@ import no.bioforsk.vips.logic.i18n.SessionLocaleUtil;
import no.bioforsk.vips.logic.entity.ForecastConfiguration; import no.bioforsk.vips.logic.entity.ForecastConfiguration;
import no.bioforsk.vips.logic.entity.ForecastModelConfiguration; import no.bioforsk.vips.logic.entity.ForecastModelConfiguration;
import no.bioforsk.vips.logic.util.SessionControllerGetter; import no.bioforsk.vips.logic.util.SessionControllerGetter;
import no.bioforsk.vips.logic.util.SystemTime;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import org.jboss.resteasy.spi.HttpRequest; import org.jboss.resteasy.spi.HttpRequest;
...@@ -125,6 +127,15 @@ public class LogicService { ...@@ -125,6 +127,15 @@ public class LogicService {
return Response.ok().entity(forecastModelConfigurations).build(); return Response.ok().entity(forecastModelConfigurations).build();
} }
@GET
@Path("forecastresults/aggregate")
@Produces("application/vnd.google-earth.kml+xml;charset=utf-8")
public Response getForecastResultsAggregate()
{
Kml retVal = SessionControllerGetter.getForecastBean().getForecastsAggregateKml(SystemTime.getSystemTime());
return Response.ok().entity(retVal).build();
}
private ManagerResource getManagerResource() private ManagerResource getManagerResource()
{ {
Client client = ClientBuilder.newClient(); Client client = ClientBuilder.newClient();
......
package no.bioforsk.vips.logic.util; package no.bioforsk.vips.logic.util;
import java.util.Locale;
/** /**
* @copyright 2013 <a href="http://www.bioforsk.no/">Bioforsk</a> * @copyright 2013 <a href="http://www.bioforsk.no/">Bioforsk</a>
* @author Tor-Einar Skog <tor-einar.skog@bioforsk.no> * @author Tor-Einar Skog <tor-einar.skog@bioforsk.no>
...@@ -25,7 +23,8 @@ public class Globals { ...@@ -25,7 +23,8 @@ public class Globals {
"/rest", "/rest",
"/user", "/user",
"/test/testlogin.jsp", "/test/testlogin.jsp",
"/test/testloginsuccess.jsp" "/test/testloginsuccess.jsp",
"/test/mock.kml"
}; };
// Point of interest type IDs // Point of interest type IDs
...@@ -43,5 +42,6 @@ public class Globals { ...@@ -43,5 +42,6 @@ public class Globals {
public static Integer USER_STATUS_DISABLED = 5; public static Integer USER_STATUS_DISABLED = 5;
public static String defaultTimestampFormat = "yyyy-MM-dd HH:mm:ssXXX"; public static String defaultTimestampFormat = "yyyy-MM-dd HH:mm:ssXXX";
public static String defaultDateFormat = "yyyy-MM-dd";
} }
...@@ -93,15 +93,6 @@ ...@@ -93,15 +93,6 @@
<servlet-name>LoginController</servlet-name> <servlet-name>LoginController</servlet-name>
<servlet-class>no.bioforsk.vips.logic.controller.servlet.LoginController</servlet-class> <servlet-class>no.bioforsk.vips.logic.controller.servlet.LoginController</servlet-class>
</servlet> </servlet>
<servlet>
<servlet-name>TestFreemarker</servlet-name>
<servlet-class>no.bioforsk.vips.logic.controller.servlet.TestFreemarker</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestFreemarker</servlet-name>
<url-pattern>/testfreemarker</url-pattern>
<url-pattern>/userTEST</url-pattern>
</servlet-mapping>
<filter> <filter>
<description>Authenticates users</description> <description>Authenticates users</description>
<filter-name>AuthenticationFilter</filter-name> <filter-name>AuthenticationFilter</filter-name>
...@@ -115,6 +106,7 @@ ...@@ -115,6 +106,7 @@
<filter-name>AuthenticationFilter</filter-name> <filter-name>AuthenticationFilter</filter-name>
<url-pattern>*</url-pattern> <url-pattern>*</url-pattern>
</filter-mapping> </filter-mapping>
<!-- RestEASY listens to all requests with /rest/* PATH --> <!-- RestEASY listens to all requests with /rest/* PATH -->
<filter> <filter>
<filter-name>Resteasy</filter-name> <filter-name>Resteasy</filter-name>
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment