diff --git a/nb-configuration.xml b/nb-configuration.xml index 4e3da122e8b65b94f0568fb43b1dcaff88d35e25..febfa410f93499417bea36d5ce0de3915f0a79b1 100644 --- a/nb-configuration.xml +++ b/nb-configuration.xml @@ -15,5 +15,7 @@ Any value defined here will override the pom.xml file value but is only applicab --> <netbeans.hint.j2eeVersion>1.5</netbeans.hint.j2eeVersion> <org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>ide</org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type> + <org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder>js</org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder> + <org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>JBoss4</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server> </properties> </project-shared-configuration> diff --git a/src/main/java/no/bioforsk/vips/logic/VIPSLogicApplication.java b/src/main/java/no/bioforsk/vips/logic/VIPSLogicApplication.java index 342d21df3b3f68e6a58b0f68dbea03cc71b33e73..f2c98be2f194cecf11590ce2570f94426948cd65 100644 --- a/src/main/java/no/bioforsk/vips/logic/VIPSLogicApplication.java +++ b/src/main/java/no/bioforsk/vips/logic/VIPSLogicApplication.java @@ -37,7 +37,6 @@ public class VIPSLogicApplication extends Application */ private void addRestResourceClasses(Set<Class<?>> resources) { 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); } diff --git a/src/main/java/no/bioforsk/vips/logic/entity/PointOfInterest.java b/src/main/java/no/bioforsk/vips/logic/entity/PointOfInterest.java index 1f511a9ee659e5403dbb1454a035deeba681e24b..0b37ecbb48937d6fa6a060fd4bc2955d4e1aaa71 100644 --- a/src/main/java/no/bioforsk/vips/logic/entity/PointOfInterest.java +++ b/src/main/java/no/bioforsk/vips/logic/entity/PointOfInterest.java @@ -17,7 +17,6 @@ import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; -import javax.persistence.OneToOne; import javax.persistence.Table; import javax.validation.constraints.Size; import javax.xml.bind.annotation.XmlRootElement; @@ -43,10 +42,7 @@ import org.codehaus.jackson.annotate.JsonIgnore; @NamedQuery(name = "PointOfInterest.findByAltitude", query = "SELECT p FROM PointOfInterest p WHERE p.altitude = :altitude") }) public class PointOfInterest implements Serializable, Comparable { - /*@OneToOne(cascade = CascadeType.ALL, mappedBy = "pointOfInterest") - private PointOfInterestWeatherStation pointOfInterestWeatherStation; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "pointOfInterest") - private Set<PointOfInterestWeatherStation> pointOfInterestWeatherStationSet;*/ + private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -56,6 +52,9 @@ public class PointOfInterest implements Serializable, Comparable { @Size(max = 255) @Column(name = "name") private String name; + @Size(max = 255) + @Column(name = "time_zone") + private String timeZone; // @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation @Column(name = "longitude") private Double longitude; @@ -191,23 +190,19 @@ public class PointOfInterest implements Serializable, Comparable { return this.getName().compareToIgnoreCase(other.getName()); } - /* - @XmlTransient - @JsonIgnore - public Set<PointOfInterestWeatherStation> getPointOfInterestWeatherStationSet() { - return pointOfInterestWeatherStationSet; - } - - public void setPointOfInterestWeatherStationSet(Set<PointOfInterestWeatherStation> pointOfInterestWeatherStationSet) { - this.pointOfInterestWeatherStationSet = pointOfInterestWeatherStationSet; - } + - public PointOfInterestWeatherStation getPointOfInterestWeatherStation() { - return pointOfInterestWeatherStation; + /** + * @return the timeZone + */ + public String getTimeZone() { + return timeZone; } - public void setPointOfInterestWeatherStation(PointOfInterestWeatherStation pointOfInterestWeatherStation) { - this.pointOfInterestWeatherStation = pointOfInterestWeatherStation; + /** + * @param timeZone the timeZone to set + */ + public void setTimeZone(String timeZone) { + this.timeZone = timeZone; } -*/ } diff --git a/src/main/java/no/bioforsk/vips/logic/entity/PointOfInterestType.java b/src/main/java/no/bioforsk/vips/logic/entity/PointOfInterestType.java index bd0821b4506462ca970a23ff0f4a172f8bf34979..2abc622d892d21aedd94485034022d56d4185c1b 100644 --- a/src/main/java/no/bioforsk/vips/logic/entity/PointOfInterestType.java +++ b/src/main/java/no/bioforsk/vips/logic/entity/PointOfInterestType.java @@ -6,7 +6,6 @@ package no.bioforsk.vips.logic.entity; import java.io.Serializable; -import java.util.Set; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.DiscriminatorColumn; @@ -16,13 +15,10 @@ import javax.persistence.Inheritance; import javax.persistence.InheritanceType; 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; -import org.codehaus.jackson.annotate.JsonIgnore; /** * @copyright 2013 <a href="http://www.bioforsk.no/">Bioforsk</a> @@ -38,8 +34,7 @@ import org.codehaus.jackson.annotate.JsonIgnore; @NamedQuery(name = "PointOfInterestType.findByPointOfInterestTypeId", query = "SELECT p FROM PointOfInterestType p WHERE p.pointOfInterestTypeId = :pointOfInterestTypeId"), @NamedQuery(name = "PointOfInterestType.findByDefaultName", query = "SELECT p FROM PointOfInterestType p WHERE p.defaultName = :defaultName")}) public class PointOfInterestType implements Serializable { - /*@OneToMany(mappedBy = "pointOfInterestTypeId") - private Set<PointOfInterest> pointOfInterestSet;*/ + private static final long serialVersionUID = 1L; @Id @Basic(optional = false) @@ -98,15 +93,7 @@ public class PointOfInterestType implements Serializable { return "no.bioforsk.vips.logic.entity.PointOfInterestType[ pointOfInterestTypeId=" + pointOfInterestTypeId + " ]"; } - /* - @XmlTransient - @JsonIgnore - public Set<PointOfInterest> getPointOfInterestSet() { - return pointOfInterestSet; - } - - public void setPointOfInterestSet(Set<PointOfInterest> pointOfInterestSet) { - this.pointOfInterestSet = pointOfInterestSet; - }*/ + + } diff --git a/src/main/java/no/bioforsk/vips/logic/scheduling/model/AppleScabModelPreprocessor.java b/src/main/java/no/bioforsk/vips/logic/scheduling/model/AppleScabModelPreprocessor.java new file mode 100644 index 0000000000000000000000000000000000000000..9a9536fd56d11ca582017df3ac218259fb767a6c --- /dev/null +++ b/src/main/java/no/bioforsk/vips/logic/scheduling/model/AppleScabModelPreprocessor.java @@ -0,0 +1,66 @@ +package no.bioforsk.vips.logic.scheduling.model; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; +import no.bioforsk.vips.entity.ModelConfiguration; +import no.bioforsk.vips.entity.WeatherObservation; +import no.bioforsk.vips.logic.entity.PointOfInterestWeatherStation; +import no.bioforsk.vips.logic.util.SystemTime; + +/** + * Gathers necessary data to run the Apple Scab Model (APPLESCABM) + * @copyright 2013 <a href="http://www.bioforsk.no/">Bioforsk</a> + * @author Tor-Einar Skog <tor-einar.skog@bioforsk.no> + */ +public class AppleScabModelPreprocessor extends ModelRunPreprocessor{ + + public final static String APPLESCABM_START_DATE_ASCOSPORE_MATURITY = "APPLESCABM_START_DATE_ASCOSPORE_MATURITY"; + + @Override + public ModelConfiguration getModelConfiguration(ForecastConfiguration configuration) { + //configuration.getDateStart(); + PointOfInterestWeatherStation weatherStation = (PointOfInterestWeatherStation) configuration.getPointOfInterestId(); + // What timezone is the calculation for + TimeZone timeZone = TimeZone.getTimeZone(weatherStation.getTimeZone()); + System.out.println("timeZone ID in preprocessor=" + timeZone.getID()); + // When do we start calculation ascospore maturity + // Normally the date for "green tip" + Date startDateAscosporeMaturity = null; + // Check to see if forecast has ended + Date dateEndWeatherData = configuration.getDateEnd().compareTo(SystemTime.getSystemTime()) < 0 ? configuration.getDateEnd() : SystemTime.getSystemTime(); + // We need data until hour 23 of this date, need to fix that + Calendar cal = Calendar.getInstance(timeZone); + cal.setTime(dateEndWeatherData); + cal.set(Calendar.HOUR_OF_DAY, 23); + dateEndWeatherData = cal.getTime(); + try + { + startDateAscosporeMaturity = new SimpleDateFormat("yyyy-MM-dd").parse(configuration.getForecastModelConfigurationValue(APPLESCABM_START_DATE_ASCOSPORE_MATURITY)); + }catch (ParseException ex) + { + ex.printStackTrace(); + // TODO: Do something sensible!!!!! + } + + + // Use Jackson to parse JSON from server + // Weather data collections + List<WeatherObservation> observations = getWeatherObservations(weatherStation.getDataFetchUri(), WeatherObservation.LOG_INTERVAL_ID_1H, new String[]{"TM", "RR", "BT"}, startDateAscosporeMaturity, dateEndWeatherData, timeZone); + //System.out.println("Observations=" + observations.toString()); + + // Create the complete model configuration object + ModelConfiguration retVal = new ModelConfiguration(); + retVal.setModelId("APPLESCABM"); + + retVal.setConfigParameter("startDateAscosporeMaturity", new SimpleDateFormat("yyyy-MM-dd").format(startDateAscosporeMaturity)); + retVal.setConfigParameter("timeZone", timeZone.getID()); + retVal.setConfigParameter("observations", observations); + + return retVal; + } + +} diff --git a/src/main/java/no/bioforsk/vips/logic/scheduling/model/ForecastConfiguration.java b/src/main/java/no/bioforsk/vips/logic/scheduling/model/ForecastConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..40646b90893535f40143302b65a0bde19f0e13db --- /dev/null +++ b/src/main/java/no/bioforsk/vips/logic/scheduling/model/ForecastConfiguration.java @@ -0,0 +1,172 @@ +package no.bioforsk.vips.logic.scheduling.model; + +import java.io.Serializable; +import java.util.Date; +import java.util.Set; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import no.bioforsk.vips.logic.entity.PointOfInterest; +import org.codehaus.jackson.annotate.JsonIgnore; + +/** + * @copyright 2013 <a href="http://www.bioforsk.no/">Bioforsk</a> + * @author Tor-Einar Skog <tor-einar.skog@bioforsk.no> + */ +@Entity +@Table(name = "forecast_configuration") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "ForecastConfiguration.findAll", query = "SELECT f FROM ForecastConfiguration f"), + @NamedQuery(name = "ForecastConfiguration.findByForecastConfigurationId", query = "SELECT f FROM ForecastConfiguration f WHERE f.forecastConfigurationId = :forecastConfigurationId"), + @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.findByDateEnd", query = "SELECT f FROM ForecastConfiguration f WHERE f.dateEnd = :dateEnd"), + @NamedQuery(name = "ForecastConfiguration.findByVipsCoreUserId", query = "SELECT f FROM ForecastConfiguration f WHERE f.vipsCoreUserId = :vipsCoreUserId")}) +public class ForecastConfiguration implements Serializable { + @OneToMany(cascade = CascadeType.ALL, mappedBy = "forecastConfiguration") + private Set<ForecastModelConfiguration> forecastModelConfigurationSet; + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Basic(optional = false) + @Column(name = "forecast_configuration_id") + private Integer forecastConfigurationId; + @Size(max = 10) + @Column(name = "model_id") + private String modelId; + @Column(name = "date_start") + @Temporal(TemporalType.DATE) + private Date dateStart; + @Column(name = "date_end") + @Temporal(TemporalType.DATE) + private Date dateEnd; + @Column(name = "vips_core_user_id") + private Integer vipsCoreUserId; + @JoinColumn(name = "point_of_interest_id", referencedColumnName = "point_of_interest_id") + @ManyToOne + private PointOfInterest pointOfInterestId; + + public ForecastConfiguration() { + } + + public ForecastConfiguration(Integer forecastConfigurationId) { + this.forecastConfigurationId = forecastConfigurationId; + } + + public Integer getForecastConfigurationId() { + return forecastConfigurationId; + } + + public void setForecastConfigurationId(Integer forecastConfigurationId) { + this.forecastConfigurationId = forecastConfigurationId; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public Date getDateStart() { + return dateStart; + } + + public void setDateStart(Date dateStart) { + this.dateStart = dateStart; + } + + public Date getDateEnd() { + return dateEnd; + } + + public void setDateEnd(Date dateEnd) { + this.dateEnd = dateEnd; + } + + public Integer getVipsCoreUserId() { + return vipsCoreUserId; + } + + public void setVipsCoreUserId(Integer vipsCoreUserId) { + this.vipsCoreUserId = vipsCoreUserId; + } + + public PointOfInterest getPointOfInterestId() { + return pointOfInterestId; + } + + public void setPointOfInterestId(PointOfInterest pointOfInterestId) { + this.pointOfInterestId = pointOfInterestId; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (forecastConfigurationId != null ? forecastConfigurationId.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof ForecastConfiguration)) { + return false; + } + ForecastConfiguration other = (ForecastConfiguration) object; + if ((this.forecastConfigurationId == null && other.forecastConfigurationId != null) || (this.forecastConfigurationId != null && !this.forecastConfigurationId.equals(other.forecastConfigurationId))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "no.bioforsk.vips.logic.scheduling.model.ForecastConfiguration[ forecastConfigurationId=" + forecastConfigurationId + " ]"; + } + + @XmlTransient + @JsonIgnore + public Set<ForecastModelConfiguration> getForecastModelConfigurationSet() { + return forecastModelConfigurationSet; + } + + public void setForecastModelConfigurationSet(Set<ForecastModelConfiguration> forecastModelConfigurationSet) { + this.forecastModelConfigurationSet = forecastModelConfigurationSet; + } + + /** + * Util method to get a specific parameter value + * @param modelConfigParameter + * @return + */ + public String getForecastModelConfigurationValue(String modelConfigParameter) + { + for(ForecastModelConfiguration conf:this.forecastModelConfigurationSet) + { + if(conf.getForecastModelConfigurationPK().getModelConfigParameter().equals(modelConfigParameter)) + { + return conf.getParameterValue(); + } + } + return null; + } + +} diff --git a/src/main/java/no/bioforsk/vips/logic/scheduling/model/ForecastModelConfiguration.java b/src/main/java/no/bioforsk/vips/logic/scheduling/model/ForecastModelConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..f239936bacf3f526d4e40ae269785f40d357f7dd --- /dev/null +++ b/src/main/java/no/bioforsk/vips/logic/scheduling/model/ForecastModelConfiguration.java @@ -0,0 +1,104 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package no.bioforsk.vips.logic.scheduling.model; + +import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @copyright 2013 <a href="http://www.bioforsk.no/">Bioforsk</a> + * @author Tor-Einar Skog <tor-einar.skog@bioforsk.no> + */ +@Entity +@Table(name = "forecast_model_configuration") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "ForecastModelConfiguration.findAll", query = "SELECT f FROM ForecastModelConfiguration f"), + @NamedQuery(name = "ForecastModelConfiguration.findByForecastConfigurationId", query = "SELECT f FROM ForecastModelConfiguration f WHERE f.forecastModelConfigurationPK.forecastConfigurationId = :forecastConfigurationId"), + @NamedQuery(name = "ForecastModelConfiguration.findByModelConfigParameter", query = "SELECT f FROM ForecastModelConfiguration f WHERE f.forecastModelConfigurationPK.modelConfigParameter = :modelConfigParameter"), + @NamedQuery(name = "ForecastModelConfiguration.findByParameterValue", query = "SELECT f FROM ForecastModelConfiguration f WHERE f.parameterValue = :parameterValue")}) +public class ForecastModelConfiguration implements Serializable { + private static final long serialVersionUID = 1L; + @EmbeddedId + protected ForecastModelConfigurationPK forecastModelConfigurationPK; + @Size(max = 1024) + @Column(name = "parameter_value") + private String parameterValue; + @JoinColumn(name = "forecast_configuration_id", referencedColumnName = "forecast_configuration_id", insertable = false, updatable = false) + @ManyToOne(optional = false) + private ForecastConfiguration forecastConfiguration; + + public ForecastModelConfiguration() { + } + + public ForecastModelConfiguration(ForecastModelConfigurationPK forecastModelConfigurationPK) { + this.forecastModelConfigurationPK = forecastModelConfigurationPK; + } + + public ForecastModelConfiguration(int forecastConfigurationId, String modelConfigParameter) { + this.forecastModelConfigurationPK = new ForecastModelConfigurationPK(forecastConfigurationId, modelConfigParameter); + } + + public ForecastModelConfigurationPK getForecastModelConfigurationPK() { + return forecastModelConfigurationPK; + } + + public void setForecastModelConfigurationPK(ForecastModelConfigurationPK forecastModelConfigurationPK) { + this.forecastModelConfigurationPK = forecastModelConfigurationPK; + } + + public String getParameterValue() { + return parameterValue; + } + + public void setParameterValue(String parameterValue) { + this.parameterValue = parameterValue; + } + + public ForecastConfiguration getForecastConfiguration() { + return forecastConfiguration; + } + + public void setForecastConfiguration(ForecastConfiguration forecastConfiguration) { + this.forecastConfiguration = forecastConfiguration; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (forecastModelConfigurationPK != null ? forecastModelConfigurationPK.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof ForecastModelConfiguration)) { + return false; + } + ForecastModelConfiguration other = (ForecastModelConfiguration) object; + if ((this.forecastModelConfigurationPK == null && other.forecastModelConfigurationPK != null) || (this.forecastModelConfigurationPK != null && !this.forecastModelConfigurationPK.equals(other.forecastModelConfigurationPK))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "no.bioforsk.vips.logic.scheduling.model.ForecastModelConfiguration[ forecastModelConfigurationPK=" + forecastModelConfigurationPK + " ]"; + } + +} diff --git a/src/main/java/no/bioforsk/vips/logic/scheduling/model/ForecastModelConfigurationPK.java b/src/main/java/no/bioforsk/vips/logic/scheduling/model/ForecastModelConfigurationPK.java new file mode 100644 index 0000000000000000000000000000000000000000..5b62d508f881a5e77be5764224cb9f5948627856 --- /dev/null +++ b/src/main/java/no/bioforsk/vips/logic/scheduling/model/ForecastModelConfigurationPK.java @@ -0,0 +1,76 @@ +package no.bioforsk.vips.logic.scheduling.model; + +import java.io.Serializable; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +/** + * @copyright 2013 <a href="http://www.bioforsk.no/">Bioforsk</a> + * @author Tor-Einar Skog <tor-einar.skog@bioforsk.no> + */ +@Embeddable +public class ForecastModelConfigurationPK implements Serializable { + @Basic(optional = false) + @NotNull + @Column(name = "forecast_configuration_id") + private int forecastConfigurationId; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 255) + @Column(name = "model_config_parameter") + private String modelConfigParameter; + + public ForecastModelConfigurationPK() { + } + + public ForecastModelConfigurationPK(int forecastConfigurationId, String modelConfigParameter) { + this.forecastConfigurationId = forecastConfigurationId; + this.modelConfigParameter = modelConfigParameter; + } + + public int getForecastConfigurationId() { + return forecastConfigurationId; + } + + public void setForecastConfigurationId(int forecastConfigurationId) { + this.forecastConfigurationId = forecastConfigurationId; + } + + public String getModelConfigParameter() { + return modelConfigParameter; + } + + public void setModelConfigParameter(String modelConfigParameter) { + this.modelConfigParameter = modelConfigParameter; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (int) forecastConfigurationId; + hash += (modelConfigParameter != null ? modelConfigParameter.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof ForecastModelConfigurationPK)) { + return false; + } + ForecastModelConfigurationPK other = (ForecastModelConfigurationPK) object; + if (this.forecastConfigurationId != other.forecastConfigurationId) { + return false; + } + return (this.modelConfigParameter != null || other.modelConfigParameter == null) && (this.modelConfigParameter == null || this.modelConfigParameter.equals(other.modelConfigParameter)); + } + + @Override + public String toString() { + return "no.bioforsk.vips.logic.scheduling.model.ForecastModelConfigurationPK[ forecastConfigurationId=" + forecastConfigurationId + ", modelConfigParameter=" + modelConfigParameter + " ]"; + } + +} diff --git a/src/main/java/no/bioforsk/vips/logic/scheduling/model/ModelRunPreprocessor.java b/src/main/java/no/bioforsk/vips/logic/scheduling/model/ModelRunPreprocessor.java new file mode 100644 index 0000000000000000000000000000000000000000..e1784bf8dad59a5f86cf1d06d40a738ebfb4f970 --- /dev/null +++ b/src/main/java/no/bioforsk/vips/logic/scheduling/model/ModelRunPreprocessor.java @@ -0,0 +1,63 @@ +package no.bioforsk.vips.logic.scheduling.model; + +import java.io.IOException; +import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; +import no.bioforsk.vips.entity.ModelConfiguration; +import no.bioforsk.vips.entity.WeatherObservation; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.type.TypeReference; + +/** + * All model preprocessors must implement this + * @copyright 2013 <a href="http://www.bioforsk.no/">Bioforsk</a> + * @author Tor-Einar Skog <tor-einar.skog@bioforsk.no> + */ +public abstract class ModelRunPreprocessor { + + public abstract ModelConfiguration getModelConfiguration(ForecastConfiguration configuration); + + /** + * Collects weather observations from a data source + * @param fetchURI Base URI. E.g. http://lmt.bioforsk.no/agrometbase/export/getVIPS3JSONWeatherData.php?weatherStationId=13 + * @param logIntervalId + * @param elementMeasurementTypes + * @param startTime + * @param endTime + * @param timeZone + * @return + */ + protected List<WeatherObservation> getWeatherObservations(String fetchURI, Integer logIntervalId, String[] elementMeasurementTypes, Date startTime, Date endTime, TimeZone timeZone){ + SimpleDateFormat dateOutput = new SimpleDateFormat("yyyy-MM-dd"); + dateOutput.setTimeZone(timeZone); + SimpleDateFormat hourOutput = new SimpleDateFormat("H"); + hourOutput.setTimeZone(timeZone); + + StringBuilder URL = new StringBuilder(fetchURI) + .append("&logIntervalId=").append(logIntervalId) + .append("&timeZone=").append(timeZone.getID()) + .append("&startDate=").append(dateOutput.format(startTime)) + .append("&startTime=").append(hourOutput.format(startTime)) + .append("&endDate=").append(dateOutput.format(endTime)) + .append("&endTime=").append(hourOutput.format(endTime)); + for(String type: elementMeasurementTypes) + { + URL.append("&elementMeasurementTypes[]=").append(type); + } + System.out.println("URL = " + URL.toString()); + try + { + return new ObjectMapper().readValue(new URL(URL.toString()), new TypeReference<List<WeatherObservation>>(){}); + }catch(IOException ex) + { + // TODO: SOmething sensible + ex.printStackTrace(); + return null; + } + + } + +} diff --git a/src/main/java/no/bioforsk/vips/logic/session/SchedulingBean.java b/src/main/java/no/bioforsk/vips/logic/session/SchedulingBean.java index 5cc196c26cd4df82d2260d922b76526a65eaa1ae..2cc6233e420b3ed112314cd2af1acb8771b31889 100644 --- a/src/main/java/no/bioforsk/vips/logic/session/SchedulingBean.java +++ b/src/main/java/no/bioforsk/vips/logic/session/SchedulingBean.java @@ -5,10 +5,26 @@ import it.sauronsoftware.cron4j.SchedulingPattern; import it.sauronsoftware.cron4j.TaskCollector; import it.sauronsoftware.cron4j.TaskExecutor; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.Response; +import no.bioforsk.vips.coremanager.service.ManagerResource; +import no.bioforsk.vips.entity.ModelConfiguration; +import no.bioforsk.vips.entity.ModelRunRequest; +import no.bioforsk.vips.entity.Result; import no.bioforsk.vips.logic.scheduling.SchedulingTest; import no.bioforsk.vips.logic.scheduling.VIPSLogicTaskCollector; +import no.bioforsk.vips.logic.scheduling.model.AppleScabModelPreprocessor; +import no.bioforsk.vips.logic.scheduling.model.ForecastConfiguration; +import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; /** * @copyright 2013 <a href="http://www.bioforsk.no/">Bioforsk</a> @@ -17,6 +33,9 @@ import no.bioforsk.vips.logic.scheduling.VIPSLogicTaskCollector; @Stateless public class SchedulingBean { + @PersistenceContext(unitName="VIPSLogic-PU") + EntityManager em; + // There can be only one systemScheduler! private static Scheduler systemScheduler; @@ -58,5 +77,32 @@ public class SchedulingBean { public TaskExecutor[] getRunningTasks(){ return this.getSystemScheduler().getExecutingTasks(); } + + public List<Result> testPreprocessor() + { + + AppleScabModelPreprocessor p = new AppleScabModelPreprocessor(); + ForecastConfiguration c = em.find(ForecastConfiguration.class, 1); + ModelConfiguration config = p.getModelConfiguration(c); + + ModelRunRequest request = new ModelRunRequest(config); + Map<String,String> loginInfo = new HashMap<>(); + loginInfo.put("username","testuser"); + loginInfo.put("password","testpass"); + request.setLoginInfo(loginInfo); + + Response resp = this.getManagerResource().runModel("APPLESCABM", request); + List<Result> results = resp.readEntity(new GenericType<List<Result>>(){}); + return results; + } + + private ManagerResource getManagerResource() + { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(System.getProperty("no.bioforsk.vips.coremanager.VIPSCOREMANAGER_URL")); + ResteasyWebTarget rTarget = (ResteasyWebTarget) target; + ManagerResource resource = rTarget.proxy(ManagerResource.class); + return resource; + } } diff --git a/src/main/java/no/bioforsk/vips/logic/startup/StartupListener.java b/src/main/java/no/bioforsk/vips/logic/startup/StartupListener.java index 7c8b17c27ce97eb802e4638176760f751b1d7944..155711fd36920887a698ba202149cbe4decb3e7a 100644 --- a/src/main/java/no/bioforsk/vips/logic/startup/StartupListener.java +++ b/src/main/java/no/bioforsk/vips/logic/startup/StartupListener.java @@ -1,8 +1,6 @@ package no.bioforsk.vips.logic.startup; -import it.sauronsoftware.cron4j.Scheduler; import javax.servlet.ServletContextEvent; -import no.bioforsk.vips.logic.scheduling.SchedulingTest; import no.bioforsk.vips.logic.session.SchedulingBean; import no.bioforsk.vips.logic.session.SessionControllerGetter; @@ -25,7 +23,16 @@ public class StartupListener implements javax.servlet.ServletContextListener{ public void contextInitialized(ServletContextEvent sce) { System.out.println("VIPSLogic system initializing"); // Testing startup of scheduling - SessionControllerGetter.getSchedulingBean().startSystemScheduler(); + // Temporarily disabled + //SessionControllerGetter.getSchedulingBean().startSystemScheduler(); + /*try + { + SessionControllerGetter.getSchedulingBean().testPreprocessor(); + } + catch(Exception ex) + { + ex.printStackTrace(); + }*/ } @@ -37,6 +44,6 @@ public class StartupListener implements javax.servlet.ServletContextListener{ public void contextDestroyed(ServletContextEvent sce) { System.out.println("VIPSLogic system shutting down"); // Shutting down scheduler - SessionControllerGetter.getSchedulingBean().stopSystemScheduler(); + //SessionControllerGetter.getSchedulingBean().stopSystemScheduler(); } } diff --git a/src/main/webapp/TestPreprocessor.jsp b/src/main/webapp/TestPreprocessor.jsp new file mode 100644 index 0000000000000000000000000000000000000000..8a717d1ae16cfb35edc4fafc35b3487dd1c08803 --- /dev/null +++ b/src/main/webapp/TestPreprocessor.jsp @@ -0,0 +1,34 @@ +<%-- + Document : TestPreprocessor + Created on : Oct 29, 2013, 1:48:14 PM + Author : treinar +--%> +<%@page import="no.bioforsk.vips.entity.Result"%> +<%@page import="java.util.List"%> +<%@page import="no.bioforsk.vips.logic.util.SystemTime"%> +<%@page import="no.bioforsk.vips.logic.session.SessionControllerGetter"%> +<%@page import="no.bioforsk.vips.logic.session.SchedulingBean"%> +<%@page import="no.bioforsk.vips.logic.scheduling.model.ForecastConfiguration"%> +<%@page import="no.bioforsk.vips.logic.scheduling.model.AppleScabModelPreprocessor"%> +<% + SchedulingBean sBean = SessionControllerGetter.getSchedulingBean(); + List<Result> results = sBean.testPreprocessor(); +%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <title>TestPreprocessor</title> + </head> + <body> + <h1>TestPreprocessor</h1> + <p>System time = <%= SystemTime.getSystemTime()%></p> + <h2>Result</h2> + <table> + <% for(Result result:results) { %> + <tr><td><%=result.getResultValidTime()%></td><td><%=result.getWarningStatus()%></td></tr> + <% } %> + </table> + </body> +</html> diff --git a/src/main/webapp/templates/weatherstation.ftl b/src/main/webapp/templates/weatherstation.ftl index 4c127781e862d002753764671fa7813e6a210f4d..a70a8dbe37c4e9980b59cae46678a5dccb81bac3 100644 --- a/src/main/webapp/templates/weatherstation.ftl +++ b/src/main/webapp/templates/weatherstation.ftl @@ -37,7 +37,7 @@ <li>${i18nBundle.weatherStationRemoteId}: ${weatherStation.weatherStationRemoteId!i18nBundle.weatherStationRemoteIdMissing}</li> </ul> <h3>${i18nBundle.test} ${i18nBundle.dataSource?lower_case}</h3> - <form action="${dataRequestUri}" method="POST" target="new" class="form-horizontal" role="form"> + <form action="${weatherStation.dataFetchUri}" method="POST" target="new" class="form-horizontal" role="form"> <div class="form-group"> <label class="col-lg-4 control-label" for="elementMeasurementTypes[]">${i18nBundle.elementMeasurementTypes}</label> <div class="col-lg-8"> @@ -91,7 +91,7 @@ </#list> --> <#list availableTimeZones as timeZoneId> - <option value="${timeZoneId}"<#if timeZoneId == defaultTimeZoneId> selected="selected"</#if>>${timeZoneId}</option> + <option value="${timeZoneId}"<#if timeZoneId == weatherStation.timeZone> selected="selected"</#if>>${timeZoneId}</option> </#list> </select> </div>