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

Merge branch 'Ny_server_2019' into 'develop'

Ny server 2019

See merge request !12
parents e54bb0eb ef74ffdf
No related branches found
No related tags found
2 merge requests!17Develop,!12Ny server 2019
This commit is part of merge request !17. Comments created here will be created in the context of that merge request.
Showing
with 1526 additions and 103 deletions
......@@ -25,5 +25,6 @@ Any value defined here will override the pom.xml file value but is only applicab
<org-netbeans-modules-css-prep.less_2e_compiler_2e_options/>
<org-netbeans-modules-projectapi.jsf_2e_language>Facelets</org-netbeans-modules-projectapi.jsf_2e_language>
<netbeans.compile.on.save>none</netbeans.compile.on.save>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>WildFly</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
</properties>
</project-shared-configuration>
......@@ -57,7 +57,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.0.10.Final</version>
<version>5.3.9.Final</version>
<exclusions>
<exclusion>
<artifactId>postgresql</artifactId>
......@@ -75,13 +75,13 @@
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.9.Final</version>
<version>3.6.3.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.9.Final</version>
<version>3.6.3.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
......@@ -140,19 +140,19 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.4</version>
<version>2.9.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.4</version>
<version>2.9.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.4</version>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
......@@ -168,7 +168,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.10.Final</version>
<version>5.3.9.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
......@@ -180,20 +180,20 @@
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-csv</artifactId>
<version>2.6.2</version>
<version>2.9.8</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<version>8.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<version>8.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
......
......@@ -56,6 +56,7 @@ public class VIPSLogicApplication extends Application
resources.add(no.nibio.vips.logic.service.ObservationService.class);
resources.add(no.nibio.vips.logic.service.ModelFormService.class);
resources.add(no.nibio.vips.logic.service.JacksonConfig.class);
//resources.add(no.nibio.vips.logic.service.JSONBConfig.class);
//resources.add(no.nibio.vips.coremanager.service.ManagerResourceImpl.class);
}
......@@ -70,6 +71,7 @@ public class VIPSLogicApplication extends Application
resources.add(no.nibio.vips.logic.modules.barleynetblotch.BarleyNetBlotchModelService.class);
resources.add(no.nibio.vips.logic.modules.roughage.RoughageService.class);
resources.add(no.nibio.vips.logic.modules.wheatleafblotch.WheatLeafBlotchModelService.class);
resources.add(no.nibio.vips.logic.service.JSONBConfig.class);
resources.add(no.nibio.vips.logic.service.JacksonConfig.class);
resources.add(no.nibio.vips.logic.service.LogicService.class);
resources.add(no.nibio.vips.logic.service.ModelFormService.class);
......
......@@ -361,6 +361,7 @@ public class PointOfInterestController extends HttpServlet {
request.setAttribute("weatherStation", weatherStation);
request.setAttribute("defaultMapCenter",user.getOrganizationId().getDefaultMapCenter());
request.setAttribute("defaultMapZoom", user.getOrganizationId().getDefaultMapZoom());
request.setAttribute("returnURL","weatherStation?organizationId=" + user.getOrganizationId().getOrganizationId());
request.getSession().setAttribute("dataSources", SessionControllerGetter.getPointOfInterestBean().getWeatherStationDataSources());
request.getSession().setAttribute("availableTimeZones", Globals.availableTimeZones);
request.getSession().setAttribute("defaultTimeZoneId", user.getOrganizationId().getDefaultTimeZone());
......
......@@ -22,6 +22,8 @@ package no.nibio.vips.logic.controller.servlet;
import it.sauronsoftware.cron4j.Scheduler;
import it.sauronsoftware.cron4j.TaskExecutor;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.Date;
import java.util.HashMap;
......@@ -214,7 +216,7 @@ public class SchedulingController extends HttpServlet {
schedulingBean.getOneOffSchedulers().add(oneTimeScheduler);
}
String message = MessageFormat.format(SessionLocaleUtil.getI18nText(request, "taskXWasLaunched"), task.getName(SessionLocaleUtil.getCurrentLocale(request).getLanguage()));
response.sendRedirect(new StringBuilder(Globals.PROTOCOL + "://").append(ServletUtil.getServerName(request)).append("/scheduling?message=").append(message).toString());
response.sendRedirect(Globals.PROTOCOL + "://" + ServletUtil.getServerName(request) + "/scheduling?message=" + URLEncoder.encode(message, StandardCharsets.UTF_8.toString()));
}
else
{
......
......@@ -20,6 +20,7 @@
package no.nibio.vips.logic.controller.session;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.base.Functions;
import java.util.Calendar;
import java.util.TimeZone;
import de.micromata.opengis.kml.v_2_2_0.Coordinate;
......@@ -50,6 +51,7 @@ import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
......@@ -597,18 +599,19 @@ public class ForecastBean {
{
ex.printStackTrace();
}*/
Response resp = this.getManagerResource().runModel(config.getModelId(), request);
if(resp.getStatus() == Response.Status.OK.getStatusCode())
{
List<Result> results = (List<Result>) resp.readEntity(new GenericType<List<Result>>(){});
//System.out.println("ForecastConfigId=" + forecastConfiguration.getForecastConfigurationId() + ", resultsize=" + results.size());
// We delete all former results before we store the new ones
SessionControllerGetter.getForecastBean().storeResults(forecastConfiguration,results);
}
else
{
throw new RunModelException(resp.readEntity(String.class));
}
Response resp = this.getManagerResource().runModel(config.getModelId(), request);
if(resp.getStatus() == Response.Status.OK.getStatusCode())
{
//System.out.println(resp.readEntity(String.class));
List<Result> results = (List<Result>) resp.readEntity(new GenericType<List<Result>>(){});
//System.out.println("ForecastConfigId=" + forecastConfiguration.getForecastConfigurationId() + ", resultsize=" + results.size());
// We delete all former results before we store the new ones
SessionControllerGetter.getForecastBean().storeResults(forecastConfiguration,results);
}
else
{
throw new RunModelException(resp.readEntity(String.class));
}
//System.out.println("Finished runModel for wsId" + forecastConfiguration.getWeatherStationPointOfInterestId());
}
......@@ -656,7 +659,7 @@ public class ForecastBean {
return resource;
}
public Kml getForecastsAggregateKml(Integer organizationId, List<Integer> cropOrganismIds, Date theDate, String serverName)
public Kml getForecastsAggregateKml(List<Integer> organizationIds, List<Integer> cropOrganismIds, Date theDate, String serverName)
{
//String iconPath = Globals.PROTOCOL + "://" + serverName + "/public/images/";
String iconPath = "//" + serverName + "/public/images/";
......@@ -693,7 +696,20 @@ public class ForecastBean {
// Run through forecast configurations
//Date benchmark = new Date();
List<PointOfInterest> poisWithAggregate = getPointOfInterestForecastsAggregate(organizationId, cropOrganismIds, theDate);
List<PointOfInterest> poisWithAggregate = new ArrayList<>();
if(organizationIds.size() == 1 && organizationIds.get(0).equals(-1))
{
em.createNamedQuery("Organization.findAll",Organization.class).getResultStream().forEach(
org-> poisWithAggregate.addAll(getPointOfInterestForecastsAggregate(org.getOrganizationId(), cropOrganismIds, theDate))
);
}
else
{
organizationIds.stream().forEach(
orgId-> poisWithAggregate.addAll(getPointOfInterestForecastsAggregate(orgId, cropOrganismIds, theDate))
);
}
//System.out.println(this.getClass().getName() + " DEBUG: getPointOfInterestForecastsAggregate took " + (new Date().getTime() - benchmark.getTime()) + " ms to complete.");
GISEntityUtil gisUtil = new GISEntityUtil();
......@@ -906,29 +922,29 @@ public class ForecastBean {
return retVal;
}
/**
* Finds the forecast configuration summaries for a given organization
* @param organizationId
* @return
*/
public List<ForecastConfiguration> getForecastConfigurationSummaries(Integer organizationId)
{
List<ForecastConfiguration> forecastConfigurations = this.getForecastConfigurations(em.find(Organization.class, organizationId));
// TODO: Filter forecastconfigurations based on criteria (activity, crops, geography etc)
List<ForecastConfiguration> filteredConfigs = new ArrayList<>();
Query q = em.createNamedQuery("ForecastSummary.findByForecastConfigurationId");
for(ForecastConfiguration config: forecastConfigurations)
{
if(config.getForecastConfigurationId() < 0)
{
continue;
}
config.setForecastSummaries(
q.setParameter("forecastConfigurationId", config.getForecastConfigurationId())
.getResultList()
);
if(config.getForecastSummaries() != null && !config.getForecastSummaries().isEmpty())
{
filteredConfigs.add(config);
}
}
return filteredConfigs;
List<ForecastSummary> summaries = em.createNamedQuery("ForecastSummary.findByOrganizationId")
.setParameter("organizationId", em.find(Organization.class, organizationId))
.getResultList();
Map<Long, List<ForecastSummary>> mappedSummaries = new HashMap<>();
summaries.forEach((s) -> {
List<ForecastSummary> summaryForForecast = mappedSummaries.get(s.getForecastSummaryPK().getForecastConfigurationId()) != null ?
mappedSummaries.get(s.getForecastSummaryPK().getForecastConfigurationId()) :
new ArrayList<>();
summaryForForecast.add(s);
mappedSummaries.put(s.getForecastSummaryPK().getForecastConfigurationId(), summaryForForecast);
});
List<ForecastConfiguration> configurations = em.createNamedQuery("ForecastConfiguration.findByForecastConfigurationIds").setParameter("forecastConfigurationIds", mappedSummaries.keySet()).getResultList();
configurations.forEach((conf) -> {
conf.setForecastSummaries(mappedSummaries.get(conf.getForecastConfigurationId()));
});
return configurations;
}
/**
......
......@@ -42,6 +42,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@NamedQuery(name = "ForecastSummary.findAll", query = "SELECT f FROM ForecastSummary f"),
@NamedQuery(name = "ForecastSummary.findByForecastConfigurationId", query = "SELECT f FROM ForecastSummary f WHERE f.forecastSummaryPK.forecastConfigurationId = :forecastConfigurationId"),
@NamedQuery(name = "ForecastSummary.findByForecastConfigurationIds", query = "SELECT f FROM ForecastSummary f WHERE f.forecastSummaryPK.forecastConfigurationId IN(:forecastConfigurationIds)"),
@NamedQuery(name = "ForecastSummary.findByOrganizationId", query = "SELECT f FROM ForecastSummary f WHERE f.forecastSummaryPK.forecastConfigurationId IN(SELECT f1.forecastConfigurationId FROM ForecastConfiguration f1 WHERE f1.vipsLogicUserId IN (SELECT v.userId FROM VipsLogicUser v WHERE v.organizationId=:organizationId))"),
@NamedQuery(name = "ForecastSummary.findBySummaryForDate", query = "SELECT f FROM ForecastSummary f WHERE f.forecastSummaryPK.summaryForDate = :summaryForDate"),
@NamedQuery(name = "ForecastSummary.findBySummaryCreatedTime", query = "SELECT f FROM ForecastSummary f WHERE f.summaryCreatedTime = :summaryCreatedTime"),
@NamedQuery(name = "ForecastSummary.findByWarningStatus", query = "SELECT f FROM ForecastSummary f WHERE f.warningStatus = :warningStatus")})
......
......@@ -20,20 +20,16 @@
package no.nibio.vips.logic.messaging;
import java.io.Serializable;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
......
......@@ -92,9 +92,10 @@ public class ZymoseptoriaSimpleRiskGridModelPreprocessor extends ModelRunPreproc
System.out.println("Problem with station " + station.getPointOfInterest().getName() + " (#" + station.getPointOfInterestId() + "): " + ex.getMessage());
}
/*
// TODO: Remove this debug
if(station.getPointOfInterestId().equals(302))
/*
if(station.getPointOfInterestId().equals(345))
{
Collections.sort(stationObs);
stationObs.forEach(obs->System.out.println(obs));
......@@ -120,7 +121,6 @@ public class ZymoseptoriaSimpleRiskGridModelPreprocessor extends ModelRunPreproc
{
List<WeatherObservation> stationObs;// = new ArrayList<>();
WeatherDataSourceUtil wdsUtil = new WeatherDataSourceUtil();
WeatherUtil wUtil = new WeatherUtil();
// We run this for max 1 week back in time to make sure it doesn't crash
ZonedDateTime aWeekAgo = ZonedDateTime.ofInstant(SystemTime.getSystemTime().toInstant(), ZoneId.of("Europe/Oslo")).minus(1, ChronoUnit.WEEKS);
......@@ -141,7 +141,6 @@ public class ZymoseptoriaSimpleRiskGridModelPreprocessor extends ModelRunPreproc
true,
new HashSet<>(Arrays.asList(WeatherObservation.LOG_INTERVAL_ID_1H,WeatherObservation.LOG_INTERVAL_ID_3H, WeatherObservation.LOG_INTERVAL_ID_6H))
);
//stationObs = wUtil.checkForAndFixHourlyTimeSeriesHoles(stationObs,6);
return stationObs;
} catch (WeatherDataSourceException ex ) {
throw new PreprocessorException(ex.getMessage());
......
/*
* Copyright (c) 2015 NIBIO <http://www.nibio.no/>.
*
* This file is part of VIPSLogic.
* VIPSLogic 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.
*
* 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
* NIBIO Open Source License for more details.
*
* You should have received a copy of the NIBIO Open Source License
* along with VIPSLogic. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.logic.service;
import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;
import javax.json.bind.JsonbConfig;
import javax.json.bind.annotation.JsonbDateFormat;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Add this to no.nibio.vips.logic.VIPSLogicApplication if you want all
* dates to be serialized as ISO formatted date strings
* @copyright 2018 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
@Provider
@Produces(MediaType.APPLICATION_JSON)
//@Consumes(MediaType.APPLICATION_JSON)
public class JSONBConfig implements ContextResolver<javax.json.bind.Jsonb>
{
//private final ObjectMapper objectMapper;
private final Jsonb jsonB;
private Logger log;
public JSONBConfig() throws Exception
{
log = Logger.getLogger(JacksonConfig.class.getName());
log.log(Level.INFO,"Created JSONBConfig");
//System.out.println("This is what you should expect");
JsonbConfig config = new JsonbConfig();
config.setProperty(JsonbConfig.DATE_FORMAT, JsonbDateFormat.DEFAULT_FORMAT);
jsonB = JsonbBuilder.create(config);
}
@Override
public Jsonb getContext(Class objectType)
{
log.log(Level.INFO,"Retrieved Objectmapper "+objectType.toGenericString());
return jsonB;
}
}
\ No newline at end of file
......@@ -20,8 +20,11 @@
package no.nibio.vips.logic.service;
import com.bedatadriven.jackson.datatype.jts.JtsModule;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import java.text.SimpleDateFormat;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
......@@ -45,6 +48,8 @@ public class JacksonConfig implements ContextResolver<ObjectMapper>
{
objectMapper = new ObjectMapper().configure(
SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"));
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.registerModule(new JtsModule());
}
......
......@@ -429,6 +429,8 @@ public class LogicService {
@PathParam("organizationId") Integer organizationId,
@QueryParam("cropCategoryId") List<Integer> cropCategoryIds)
{
List<Integer> organizationIds = new ArrayList<>();
organizationIds.add(organizationId);
if(cropCategoryIds == null || cropCategoryIds.isEmpty())
{
return Response.noContent().build();
......@@ -436,7 +438,33 @@ public class LogicService {
else
{
List<Integer> cropOrganismIds = SessionControllerGetter.getOrganismBean().getCropCategoryOrganismIds(cropCategoryIds);
Kml retVal = SessionControllerGetter.getForecastBean().getForecastsAggregateKml(organizationId, cropOrganismIds, SystemTime.getSystemTime(), ServletUtil.getServerName(httpServletRequest));
Kml retVal = SessionControllerGetter.getForecastBean().getForecastsAggregateKml(organizationIds, cropOrganismIds, SystemTime.getSystemTime(), ServletUtil.getServerName(httpServletRequest));
return Response.ok().entity(retVal).build();
}
}
/**
*
* @param organizationId
* @param cropCategoryIds
* @return
*/
@GET
@Path("forecastresults/aggregate/orgspan")
@GZIP
@Produces("application/vnd.google-earth.kml+xml;charset=utf-8")
@Facet("restricted")
public Response getForecastResultsAggregate(
@QueryParam("organizationId") List<Integer> organizationIds,
@QueryParam("cropCategoryId") List<Integer> cropCategoryIds)
{
if(cropCategoryIds == null || cropCategoryIds.isEmpty())
{
return Response.noContent().build();
}
else
{
List<Integer> cropOrganismIds = SessionControllerGetter.getOrganismBean().getCropCategoryOrganismIds(cropCategoryIds);
Kml retVal = SessionControllerGetter.getForecastBean().getForecastsAggregateKml(organizationIds, cropOrganismIds, SystemTime.getSystemTime(), ServletUtil.getServerName(httpServletRequest));
return Response.ok().entity(retVal).build();
}
}
......
......@@ -27,11 +27,12 @@ import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.usertype.UserType;
/**
* Adapted from this: http://stackoverflow.com/questions/21940642/hibernate-postgres-array-type
* @copyright 2015 <a href="http://www.nibio.no/">NIBIO</a>
* @copyright 2015-2019 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
......@@ -99,7 +100,7 @@ public class IntegerArrayUserType implements UserType {
*
* @throws java.sql.SQLException
*/
@Override
//@Override
public Object nullSafeGet(
ResultSet rs,
String[] names,
......@@ -133,7 +134,7 @@ public class IntegerArrayUserType implements UserType {
*
* @throws java.sql.SQLException
*/
@Override
//@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, Types.OTHER);
......@@ -216,5 +217,57 @@ public class IntegerArrayUserType implements UserType {
return original;
}
/**
* Retrieve an instance of the mapped class from a JDBC resultset. Implementors
* should handle possibility of null values.
*
* @param rs a JDBC result set
* @param strings the column names
* @param ssci
* @throws org.hibernate.HibernateException
*
* @throws java.sql.SQLException
*/
@Override
public Object nullSafeGet(ResultSet rs, String[] strings, SharedSessionContractImplementor ssci, Object o) throws HibernateException, SQLException {
if (rs.wasNull()) {
return null;
}
try
{
Integer[] array = (Integer[]) rs.getArray(strings[0]).getArray();
return array;
}
catch(NullPointerException ex)
{
return new Integer[0];
}
}
/**
* Write an instance of the mapped class to a prepared statement. Implementors
* should handle possibility of null values. A multi-column type should be written
* to parameters starting from <tt>index</tt>.
*
* @param ps a JDBC prepared statement
* @param o the object to write
* @param i statement parameter index
* @param ssci
* @throws org.hibernate.HibernateException
*
* @throws java.sql.SQLException
*/
@Override
public void nullSafeSet(PreparedStatement ps, Object o, int i, SharedSessionContractImplementor ssci) throws HibernateException, SQLException {
if (o == null) {
ps.setNull(i, Types.OTHER);
return;
}
Integer[] castObject = (Integer[]) o;
Array array = ssci.connection().createArrayOf("integer", castObject); // The postgres array data type
ps.setArray(i, array);
}
}
......@@ -26,10 +26,11 @@ import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.usertype.UserType;
/**
* @copyright 2015 <a href="http://www.nibio.no/">NIBIO</a>
* @copyright 2015-2019 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
......@@ -97,7 +98,7 @@ public class StringJsonUserType implements UserType {
*
* @throws java.sql.SQLException
*/
@Override
//@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
if(rs.getString(names[0]) == null){
return null;
......@@ -118,7 +119,7 @@ public class StringJsonUserType implements UserType {
*
* @throws java.sql.SQLException
*/
@Override
//@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, Types.OTHER);
......@@ -199,5 +200,48 @@ public class StringJsonUserType implements UserType {
return original;
}
/**
* Retrieve an instance of the mapped class from a JDBC resultset. Implementors
* should handle possibility of null values.
*
* @param rs a JDBC result set
* @param strings the column names
* @param ssci
* @throws org.hibernate.HibernateException
*
* @throws java.sql.SQLException
*/
@Override
public Object nullSafeGet(ResultSet rs, String[] strings, SharedSessionContractImplementor ssci, Object o) throws HibernateException, SQLException {
if(rs.getString(strings[0]) == null){
return null;
}
return rs.getString(strings[0]);
}
/**
* Write an instance of the mapped class to a prepared statement. Implementors
* should handle possibility of null values. A multi-column type should be written
* to parameters starting from <tt>index</tt>.
*
* @param ps a JDBC prepared statement
* @param o the object to write
* @param i statement parameter index
* @param ssci
* @throws org.hibernate.HibernateException
*
* @throws java.sql.SQLException
*/
@Override
public void nullSafeSet(PreparedStatement ps, Object o, int i, SharedSessionContractImplementor ssci) throws HibernateException, SQLException {
if (o == null) {
ps.setNull(i, Types.OTHER);
return;
}
ps.setObject(i, o, Types.OTHER);
}
}
......@@ -6,5 +6,8 @@
<module name="com.fasterxml.jackson.core.jackson-core" />
<module name="org.apache.httpcomponents" />
</dependencies>
<exclusions>
<module name="org.jboss.resteasy.resteasy-json-binding-provider"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
\ No newline at end of file
This diff is collapsed.
/*
* Copyright (c) 2018 NIBIO <http://www.nibio.no/>.
* Copyright (c) 2019 NIBIO <http://www.nibio.no/>.
*
* This file is part of VIPSLogic.
* VIPSLogic is free software: you can redistribute it and/or modify
......@@ -19,7 +19,7 @@
/**
* Self contained application for displaying several maps with risk assesments
* @copyright 2018 NIBIO https://www.nibio.no/
* @copyright 2019 NIBIO https://www.nibio.no/
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
......@@ -84,12 +84,14 @@ var initMap = function ()
ajax(hostName + "/rest/forecastresults/-1000", function(e){
//ajax("http://vipslogic-local.no/rest/forecastresults/-1000", function(e){
results = JSON.parse(e.target.responseText);
console.info(todayAtMidnight);
//console.info(todayAtMidnight);
var currentDay = todayAtMidnight;
for(var mapName in maps)
{
//console.info("currentDay=" + currentDay.format());
displayResults(mapName, currentDay);
currentDay.setDate(currentDay.getDate()+1);
//currentDay.setDate(currentDay.getDate()+1);
currentDay.add(1,"days");
}
// This is here to fix an apparent bug in having Vector tiles
// within the CSS grid system
......@@ -127,10 +129,12 @@ var getFeatureStyle = function(feature)
var displayResults = function(mapName, date){
var features = [];
//var momentDate = moment(date);
for(var i in results)
{
//console.info(parseJSONDate(results[i].validTimeStart).getTime() + "==" + date.getTime());
if(parseJSONDate(results[i].validTimeStart).getTime() == date.getTime()){
//console.info(moment(results[i].validTimeStart).format() + "==" + date.format());
if(moment(results[i].validTimeStart).isSame(date)){
//console.info(results[i].validGeometry.coordinates);
var feature = new ol.Feature({
geometry:new ol.geom.Point(ol.proj.fromLonLat(results[i].validGeometry.coordinates)),
......@@ -146,7 +150,7 @@ var displayResults = function(mapName, date){
featureOverlays[mapName].getSource().addFeatures(features);
//console.info(featureOverlays.mainMap.getSource().getFeatures());
// Setting the results date
document.getElementById(mapName + "DateField").innerHTML = date.getFullYear() + "-" + ("0" + (date.getMonth()+1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2);
document.getElementById(mapName + "DateField").innerHTML = date.format("YYYY-MM-DD");//date.getFullYear() + "-" + ("0" + (date.getMonth()+1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2);
};
var ajax = function(url, callback)
......@@ -157,42 +161,16 @@ var ajax = function(url, callback)
xhr.send();
};
function parseJSONDate(theDateString)
{
// The format is "2017-09-09T22:00:00.000+0000"
var dateParts = theDateString.split("T")[0].split("-");
var timeParts = theDateString.split("T")[1].split(".")[0].split(":");
var timeZoneOffset = parseInt(theDateString.substring(24,26));
var retVal = new Date(Date.UTC(
parseInt(dateParts[0]), // Year
parseInt(dateParts[1])-1, // Month
parseInt(dateParts[2]), // Date
parseInt(timeParts[0]) - parseInt(timeZoneOffset), // Hour taking timezone into account
parseInt(timeParts[1]), // Minutes
0,0) // Seconds and milliseconds
);
//console.info(retVal);
return retVal;
// This actually does the trick pretty well (on Chrome and Firefox...)
//return new Date(theDateString);
}
function getTodayAtMidnight()
{
//return moment("");
// TODO:Add momentjs support here!!!
var now = new Date();
var midnightString = now.getFullYear() + "-" +
('0' + (now.getMonth()+1)).slice(-2) + "-" +
('0' + (now.getDate()-1)).slice(-2) +
"T23:00:00.000+0000";
return new Date(midnightString);
// OR RETURN A FIXED DATE FOR TESTING
//return new Date("2018-08-16T22:00:00.000+0000");
var timeZone="Europe/Oslo";
var today = moment().tz(timeZone)
today.set("hour",0);
today.set("minute",0);
today.set("second",0);
today.set("millisecond",0);
return today;
}
......@@ -240,7 +218,14 @@ document.addEventListener("DOMContentLoaded", function() {
{
src: hostName + "/public/nordic_septoria_whs/moment.min.js"
},
initMap
function() {
loadHeadElement("script",
{
src: hostName + "/public/nordic_septoria_whs/moment-timezone-with-data.js"
},
initMap
);
}
);
}
);
......@@ -267,6 +252,12 @@ var loadScript = function(url, callback)
document.head.appendChild(script);
};
/**
* Loads elements (e.g. script elements) into the parent page
* @param {type} type the type of element
* @param {type} attributes the attributes (like src) of the element
* @param {type} callback What do do after the loading is done
*/
var loadHeadElement = function(type, attributes, callback)
{
var elm = document.createElement(type);
......
......@@ -164,6 +164,8 @@
</select>
<span class="help-block" id="${formId}_userId_validation"></span>
</div>
<#else>
<input type="hidden" name="userId" value="<#if weatherStation.userId?has_content>${weatherStation.userId.userId}<#else>${user.userId}</#if>"/>
</#if>
<button type="submit" class="btn btn-default">${i18nBundle.submit}</button>
<#if weatherStation.pointOfInterestId?has_content>
......
......@@ -89,7 +89,7 @@
</#if>
<td>
<#if weatherStation.weatherStationDataSourceId?has_content>
<a href="${weatherStation.weatherStationDataSourceId.uri}">${weatherStation.weatherStationDataSourceId.name}</a>
<a href="${weatherStation.weatherStationDataSourceId.uri!""}">${weatherStation.weatherStationDataSourceId.name!""}</a>
</#if>
</td>
</tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment