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

Adding services for the VIPSMobile app

parent 29db1414
No related branches found
No related tags found
No related merge requests found
Showing
with 2076 additions and 2 deletions
...@@ -25,7 +25,7 @@ import javax.ws.rs.core.Application; ...@@ -25,7 +25,7 @@ import javax.ws.rs.core.Application;
/** /**
* Responsible for adding REST resources * Responsible for adding REST resources
* @copyright 2013 {@link http://www.nibio.no NIBIO} * @copyright 2015 {@link http://www.nibio.no NIBIO}
* @author Tor-Einar Skog <tor-einar.skog@nibio.no> * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/ */
@ApplicationPath("/rest/") @ApplicationPath("/rest/")
...@@ -46,6 +46,7 @@ public class VIPSLogicApplication extends Application ...@@ -46,6 +46,7 @@ public class VIPSLogicApplication extends Application
*/ */
private void addRestResourceClassesManually(Set<Class<?>> resources) { private void addRestResourceClassesManually(Set<Class<?>> resources) {
resources.add(no.nibio.vips.logic.service.LogicService.class); resources.add(no.nibio.vips.logic.service.LogicService.class);
resources.add(no.nibio.vips.logic.service.VIPSMobileService.class);
resources.add(no.nibio.vips.logic.modules.barleynetblotch.BarleyNetBlotchModelService.class); resources.add(no.nibio.vips.logic.modules.barleynetblotch.BarleyNetBlotchModelService.class);
//resources.add(no.nibio.vips.logic.service.JacksonConfig.class); //resources.add(no.nibio.vips.logic.service.JacksonConfig.class);
//resources.add(no.nibio.vips.coremanager.service.ManagerResourceImpl.class); //resources.add(no.nibio.vips.coremanager.service.ManagerResourceImpl.class);
...@@ -61,6 +62,7 @@ public class VIPSLogicApplication extends Application ...@@ -61,6 +62,7 @@ public class VIPSLogicApplication extends Application
resources.add(no.nibio.vips.logic.modules.barleynetblotch.BarleyNetBlotchModelService.class); resources.add(no.nibio.vips.logic.modules.barleynetblotch.BarleyNetBlotchModelService.class);
resources.add(no.nibio.vips.logic.service.JacksonConfig.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.LogicService.class);
resources.add(no.nibio.vips.logic.service.VIPSMobileService.class);
} }
} }
\ No newline at end of file
...@@ -35,6 +35,7 @@ import de.micromata.opengis.kml.v_2_2_0.Vec2; ...@@ -35,6 +35,7 @@ import de.micromata.opengis.kml.v_2_2_0.Vec2;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
...@@ -79,7 +80,7 @@ import org.apache.commons.lang.StringUtils; ...@@ -79,7 +80,7 @@ import org.apache.commons.lang.StringUtils;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
/** /**
* @copyright 2013-2014 <a href="http://www.nibio.no/">NIBIO</a> * @copyright 2013-2015 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no> * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/ */
@Stateless @Stateless
...@@ -308,6 +309,16 @@ public class ForecastBean { ...@@ -308,6 +309,16 @@ public class ForecastBean {
.getResultList(); .getResultList();
} }
public List<ForecastConfiguration> getForecastConfigurations(PointOfInterestWeatherStation weatherStation,Date from, Date to)
{
return em
.createNamedQuery("ForecastConfiguration.findByWeatherStationPointOfInterestIdAndDate", ForecastConfiguration.class)
.setParameter("weatherStationPointOfInterestId", weatherStation)
.setParameter("from", from)
.setParameter("to", to)
.getResultList();
}
/** /**
* Deletes all forecasts and results from the given weather station * Deletes all forecasts and results from the given weather station
* @param weatherStation * @param weatherStation
...@@ -797,6 +808,22 @@ public class ForecastBean { ...@@ -797,6 +808,22 @@ public class ForecastBean {
.executeUpdate(); .executeUpdate();
} }
public List<ForecastConfiguration> getForecastConfigurationWithSummaries(List<Long> forecastConfigurationIds)
{
List<ForecastConfiguration> retVal = em.createNamedQuery("ForecastConfiguration.findByForecastConfigurationIds")
.setParameter("forecastConfigurationIds", forecastConfigurationIds)
.getResultList();
for(ForecastConfiguration config: retVal)
{
Query q = em.createNamedQuery("ForecastSummary.findByForecastConfigurationId");
config.setForecastSummaries(
q.setParameter("forecastConfigurationId", config.getForecastConfigurationId())
.getResultList()
);
}
return retVal;
}
public List<ForecastConfiguration> getForecastConfigurationSummaries(Integer organizationId) public List<ForecastConfiguration> getForecastConfigurationSummaries(Integer organizationId)
{ {
List<ForecastConfiguration> forecastConfigurations = this.getForecastConfigurations(em.find(Organization.class, organizationId)); List<ForecastConfiguration> forecastConfigurations = this.getForecastConfigurations(em.find(Organization.class, organizationId));
......
...@@ -56,6 +56,7 @@ import no.nibio.vips.util.WeatherUtil; ...@@ -56,6 +56,7 @@ import no.nibio.vips.util.WeatherUtil;
@NamedQueries({ @NamedQueries({
@NamedQuery(name = "ForecastConfiguration.findAll", query = "SELECT f FROM ForecastConfiguration f"), @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.findByForecastConfigurationId", query = "SELECT f FROM ForecastConfiguration f WHERE f.forecastConfigurationId = :forecastConfigurationId"),
@NamedQuery(name = "ForecastConfiguration.findByForecastConfigurationIds", query = "SELECT f FROM ForecastConfiguration f WHERE f.forecastConfigurationId IN(:forecastConfigurationIds)"),
@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.findByModelIds", query = "SELECT f FROM ForecastConfiguration f WHERE f.modelId IN (:modelIds)"), @NamedQuery(name = "ForecastConfiguration.findByModelIds", query = "SELECT f FROM ForecastConfiguration f WHERE f.modelId IN (:modelIds)"),
@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"),
...@@ -63,6 +64,7 @@ import no.nibio.vips.util.WeatherUtil; ...@@ -63,6 +64,7 @@ import no.nibio.vips.util.WeatherUtil;
@NamedQuery(name = "ForecastConfiguration.findActiveAtDate", query = "SELECT f FROM ForecastConfiguration f WHERE f.dateStart <= :currentDate AND f.dateEnd >= :currentDate"), @NamedQuery(name = "ForecastConfiguration.findActiveAtDate", query = "SELECT f FROM ForecastConfiguration f WHERE f.dateStart <= :currentDate AND f.dateEnd >= :currentDate"),
@NamedQuery(name = "ForecastConfiguration.findByLocationPointOfInterestId", query = "SELECT f FROM ForecastConfiguration f WHERE f.locationPointOfInterestId = :locationPointOfInterestId"), @NamedQuery(name = "ForecastConfiguration.findByLocationPointOfInterestId", query = "SELECT f FROM ForecastConfiguration f WHERE f.locationPointOfInterestId = :locationPointOfInterestId"),
@NamedQuery(name = "ForecastConfiguration.findByWeatherStationPointOfInterestId", query = "SELECT f FROM ForecastConfiguration f WHERE f.weatherStationPointOfInterestId = :weatherStationPointOfInterestId"), @NamedQuery(name = "ForecastConfiguration.findByWeatherStationPointOfInterestId", query = "SELECT f FROM ForecastConfiguration f WHERE f.weatherStationPointOfInterestId = :weatherStationPointOfInterestId"),
@NamedQuery(name = "ForecastConfiguration.findByWeatherStationPointOfInterestIdAndDate", query = "SELECT f FROM ForecastConfiguration f WHERE f.weatherStationPointOfInterestId = :weatherStationPointOfInterestId AND f.dateStart <= :to AND f.dateEnd >= :from"),
@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.findByVipsLogicUserIdAndDate", query = "SELECT f FROM ForecastConfiguration f WHERE f.vipsLogicUserId = :vipsLogicUserId AND f.dateStart <= :to AND f.dateEnd >= :from" ), @NamedQuery(name = "ForecastConfiguration.findByVipsLogicUserIdAndDate", query = "SELECT f FROM ForecastConfiguration f WHERE f.vipsLogicUserId = :vipsLogicUserId AND f.dateStart <= :to AND f.dateEnd >= :from" ),
@NamedQuery(name = "ForecastConfiguration.findByVipsLogicUserIdAndCropOrganismId", query = "SELECT f FROM ForecastConfiguration f WHERE f.vipsLogicUserId = :vipsLogicUserId AND f.cropOrganismId.organismId IN (:cropOrganismIds)"), @NamedQuery(name = "ForecastConfiguration.findByVipsLogicUserIdAndCropOrganismId", query = "SELECT f FROM ForecastConfiguration f WHERE f.vipsLogicUserId = :vipsLogicUserId AND f.cropOrganismId.organismId IN (:cropOrganismIds)"),
......
...@@ -41,6 +41,7 @@ import javax.xml.bind.annotation.XmlRootElement; ...@@ -41,6 +41,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@NamedQueries({ @NamedQueries({
@NamedQuery(name = "ForecastSummary.findAll", query = "SELECT f FROM ForecastSummary f"), @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.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.findBySummaryForDate", query = "SELECT f FROM ForecastSummary f WHERE f.forecastSummaryPK.summaryForDate = :summaryForDate"), @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.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")}) @NamedQuery(name = "ForecastSummary.findByWarningStatus", query = "SELECT f FROM ForecastSummary f WHERE f.warningStatus = :warningStatus")})
......
...@@ -32,6 +32,7 @@ import javax.persistence.NamedQuery; ...@@ -32,6 +32,7 @@ import javax.persistence.NamedQuery;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
...@@ -95,6 +96,12 @@ public class MessageLocale implements Serializable { ...@@ -95,6 +96,12 @@ public class MessageLocale implements Serializable {
public MessageLocale(int messageId, String locale) { public MessageLocale(int messageId, String locale) {
this.messageLocalePK = new MessageLocalePK(messageId, locale); this.messageLocalePK = new MessageLocalePK(messageId, locale);
} }
@Transient
public String getMessageLocaleSyntheticPK()
{
return this.messageLocalePK.getMessageId() + "_" + this.messageLocalePK.getLocale();
}
public MessageLocalePK getMessageLocalePK() { public MessageLocalePK getMessageLocalePK() {
return messageLocalePK; return messageLocalePK;
......
...@@ -28,6 +28,7 @@ import javax.persistence.ManyToOne; ...@@ -28,6 +28,7 @@ import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
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;
...@@ -67,6 +68,16 @@ public class MessageTagLocale implements Serializable { ...@@ -67,6 +68,16 @@ public class MessageTagLocale implements Serializable {
public MessageTagLocalePK getMessageTagLocalePK() { public MessageTagLocalePK getMessageTagLocalePK() {
return messageTagLocalePK; return messageTagLocalePK;
} }
/**
* Decorator for inferior JSON deserializers like Sencha Touch
* @return
*/
@Transient
public String getMessageTagLocaleSyntheticPK()
{
return this.messageTagLocalePK.getMessageTagId() + "_" + this.messageTagLocalePK.getLocale();
}
public void setMessageTagLocalePK(MessageTagLocalePK messageTagLocalePK) { public void setMessageTagLocalePK(MessageTagLocalePK messageTagLocalePK) {
this.messageTagLocalePK = messageTagLocalePK; this.messageTagLocalePK = messageTagLocalePK;
......
/*
* 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.entity.vipsmobile;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* Rip-off from old VIPS VarselBO
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public final class VIPSMobileForecast implements Comparable
{
private Integer DnmiSiteId;
private Map<String, Object> props;
/**
* Lager et nytt varsel Business Object
* @param varselId Unik identifikator for varsel
* @param lovligVarselId Id for lovligVarsel
* @param startDato Startdato for varselet
* @param sluttDato Sluttdato for varselet
* @param klimastasjonId Id for klimastasjon
* @param feltId Id for felt
* @param personlig Skiller offentlige og personlige varsel
* @param inaktiv Angir om varselet er aktivt eller ikke
* @param sistEndretAv Id til bruker som sist endret varselet
* @param sistEndretDato Tid for siste endring
* @param logiskSlettet Angir om varselet er logisk slettet
*/
public VIPSMobileForecast
(
long varselId,
long lovligVarselId,
Date startDato,
Date sluttDato,
long klimastasjonId,
String klimastasjonNavn,
long feltId,
String feltNavn,
boolean personlig,
boolean inaktiv,
long sistEndretAv,
Date sistEndretDato,
boolean logiskSlettet,
long organismeId,
String organismeNavn,
long kulturId,
String kulturNavn,
String modellId,
String modellNavn
)
{
setVarselId( varselId );
setLovligVarselId( lovligVarselId );
setStartDato( startDato );
setSluttDato( sluttDato );
setKlimastasjonId( klimastasjonId );
setKlimastasjonNavn(klimastasjonNavn);
setFeltId( feltId );
setFeltNavn(feltNavn);
setPersonlig( personlig );
setInaktiv( inaktiv );
setSistEndretAv( sistEndretAv );
setSistEndretDato( sistEndretDato );
setLogiskSlettet( logiskSlettet );
setOrganismeId(organismeId);
setOrganismeNavn(organismeNavn);
setKulturId(kulturId);
setKulturNavn(kulturNavn);
setModellId(modellId);
setModellNavn(modellNavn);
}
/**
* @param varselId Unik identifikator for varsel
*/
public final void setVarselId( long varselId )
{
setAttribute("varselId", varselId);
}
/**
* @param lovligVarselId Id for lovligVarsel
*/
public final void setLovligVarselId( long lovligVarselId )
{
setAttribute("lovligVarselId", lovligVarselId);
}
/**
* @param startDato StartDato for varselet
*/
public final void setStartDato( Date startDato )
{
setAttribute( "startDato", startDato );
}
/**
* @param sluttDato SluttDato for varselet
*/
public final void setSluttDato( Date sluttDato )
{
setAttribute( "sluttDato", sluttDato );
}
/**
* @param klimastasjonId Id for klimastasjon
*/
public final void setKlimastasjonId( long klimastasjonId )
{
setAttribute("klimastasjonId", klimastasjonId);
}
/**
* @param feltId Id for felt
*/
public final void setFeltId( long feltId )
{
setAttribute("feltId", feltId);
}
/**
* @param personlig Personlig eller offentlig varsel
*/
public final void setPersonlig( boolean personlig )
{
setAttribute("personlig", personlig);
}
/**
* @param inaktiv Aktivt eller inaktivt varsel
*/
public final void setInaktiv( boolean inaktiv )
{
setAttribute("inaktiv", inaktiv);
}
/**
* @param sistEndretAv Id til bruker som sist endret varselet
*/
public final void setSistEndretAv( long sistEndretAv )
{
setAttribute("sistEndretAv", sistEndretAv);
}
/**
* @param sistEndretAvBrukernavn Brukernavn til bruker som sist endret varselet
*/
public void setSistEndretAvBrukernavn( String sistEndretAvBrukernavn )
{
setAttribute( "sistEndretAvBrukernavn", sistEndretAvBrukernavn );
}
/**
* @param sistEndretDato Tid for siste endring
*/
public final void setSistEndretDato( Date sistEndretDato )
{
setAttribute( "sistEndretDato", sistEndretDato );
}
/**
* @param logiskSlettet Slettet eller ikke slettet varsel
*/
public final void setLogiskSlettet( boolean logiskSlettet )
{
setAttribute("logiskSlettet", logiskSlettet);
}
/**
* @param klimastasjonNavn Navn for klimastasjon
*/
public void setKlimastasjonNavn( String klimastasjonNavn )
{
setAttribute( "klimastasjonNavn", klimastasjonNavn );
}
/**
* @param feltNavn Navn for felt
*/
public void setFeltNavn( String feltNavn )
{
setAttribute( "feltNavn", feltNavn );
}
/**
* @param gaardNavn Navn for gaard
*/
public void setGaardNavn( String gaardNavn )
{
setAttribute( "gaardNavn", gaardNavn );
}
/**
* @param skifteNavn Navn for skifte
*/
public void setSkifteNavn( String skifteNavn )
{
setAttribute( "skifteNavn", skifteNavn );
}
/**
* @param modellId ModellID
*/
public void setModellId( String modellId )
{
setAttribute("modellId", modellId);
}
/**
* @param modellNavn ModellNavn
*/
public void setModellNavn( String modellNavn )
{
setAttribute( "modellNavn", modellNavn );
}
/**
* @param modellWebNavn ModellNavn for VIPS-forsiden
*/
public void setModellWebNavn( String modellWebNavn )
{
setAttribute( "modellWebNavn", modellWebNavn );
}
/**
* @param kulturId KulturID
*/
public void setKulturId( long kulturId )
{
setAttribute("kulturId", kulturId);
}
/**
* @param skifteKulturId Id til den nyeste kultur som er registrert p� skifte
*/
public void setSkifteKulturId( long skifteKulturId )
{
setAttribute("skifteKulturId", skifteKulturId);
}
/**
* @param kulturNavn Kulturnavn
*/
public void setKulturNavn( String kulturNavn )
{
setAttribute( "kulturNavn", kulturNavn );
}
/**
* @param organismeId OrganismeID
*/
public void setOrganismeId( long organismeId )
{
setAttribute("organismeId", organismeId);
}
/**
* @param organismeNavn Organismenavn
*/
public void setOrganismeNavn( String organismeNavn )
{
setAttribute( "organismeNavn", organismeNavn );
}
/**
* @return Unik identifikator for varsel
*/
public long getVarselId()
{
return ( ( Long )getAttribute( "varselId" ) );
}
/**
* @return LovligVarsel Id
*/
public long getLovligVarselId()
{
return ( ( Long )getAttribute( "lovligVarselId" ) );
}
/**
* @return Startdato for varselet
*/
public Date getStartDato()
{
return ( Date )getAttribute( "startDato" );
}
/**
* @return Sluttdato for varselet
*/
public Date getSluttDato()
{
return ( Date )getAttribute( "sluttDato" );
}
/**
* @return Id for klimastasjon
*/
public long getKlimastasjonId()
{
return ( ( Long )getAttribute( "klimastasjonId" ) );
}
/**
* @return Id for felt
*/
public long getFeltId()
{
return ( ( Long )getAttribute( "feltId" ) );
}
/**
* @return personlig
*/
public boolean getPersonlig()
{
return ( ( Boolean )getAttribute( "personlig" ) );
}
/**
* @return inaktiv
*/
public boolean getInaktiv()
{
return ( ( Boolean )getAttribute( "inaktiv" ) );
}
/**
* @return sistEndretAv
*/
public long getSistEndretAv()
{
return ( ( Long )getAttribute( "sistEndretAv" ) );
}
/**
* @return sistEndretAvBrukernavn
*/
public String getSistEndretAvBrukernavn()
{
return ( String )getAttribute( "sistEndretAvBrukernavn" );
}
/**
* @return sistEndretDato
*/
public Date getSistEndretDato()
{
return ( Date )getAttribute( "sistEndretDato" );
}
/**
* @return True hvis varselet er slettet, false ellers
*/
public boolean getLogiskSlettet()
{
if( getAttribute( "logiskSlettet" ) != null )
{
return ( ( Boolean )getAttribute( "logiskSlettet" ) );
}
else
{
return false;
}
}
/**
* @return Navn for klimastasjon
*/
public String getKlimastasjonNavn()
{
return ( String )getAttribute( "klimastasjonNavn" );
}
/**
* @return Id for modell
*/
public String getModellId()
{
return ( String )getAttribute( "modellId" ) ;
}
/**
* @return Navn p� modell
*/
public String getModellNavn()
{
return ( String )getAttribute( "modellNavn" );
}
/**
* @return Navn paa modell til bruk p� VIPS-forsiden
*/
public String getModellWebNavn()
{
return ( String )getAttribute( "modellWebNavn" );
}
/**
* @return Id for kultur
*/
public long getKulturId()
{
return ( ( Long )getAttribute( "kulturId" ) );
}
/**
* @return Id for kultur
*/
public long getSkifteKulturId()
{
Long retVal = ( Long )getAttribute( "skifteKulturId" );
if(retVal == null) return -1;
else return retVal;
}
/**
* @return Navn på kultur
*/
public String getKulturNavn()
{
return ( String )getAttribute( "kulturNavn" );
}
/**
* @return Id for organisme
*/
public long getOrganismeId()
{
return ( ( Long )getAttribute( "organismeId" ) );
}
/**
* @return Navn p� organisme
*/
public String getOrganismeNavn()
{
return ( String )getAttribute( "organismeNavn" );
}
/**
* @return Navnet p� feltet varselet utf�res for
*/
public String getFeltNavn()
{
return ( ( String )getAttribute( "feltNavn" ) );
}
/**
* @return Navnet p� g�rden varselet utf�res for
*/
public String getGaardNavn()
{
return ( ( String )getAttribute( "gaardNavn" ) );
}
/**
* @return Navnet p� skiftet varselet utf�res for
*/
public String getSkifteNavn()
{
return ( ( String )getAttribute( "skifteNavn" ) );
}
/**
* Sorterer alfabetisk p� klimastasjonNavn, hvis det er oppgitt
* @param o
* @return
*/
@Override
public int compareTo(Object o) {
VIPSMobileForecast other = (VIPSMobileForecast) o;
return this.compareTo(other);
}
/**
* Sorterer alfabetisk p� G�rd, Skifte, Felt og klimastasjonNavn, hvis det er oppgitt. Deretter kronologisk p� startDato
* @param other
* @return
*/
public int compareTo(VIPSMobileForecast other)
{
int retVal = 0;
try
{
retVal = this.getGaardNavn().compareTo(other.getGaardNavn());
if(retVal != 0) return retVal;
}catch(NullPointerException npe){}
try
{
retVal = this.getSkifteNavn().compareTo(other.getSkifteNavn());
if(retVal != 0) return retVal;
}catch(NullPointerException npe){}
try
{
retVal = this.getFeltNavn().compareTo(other.getFeltNavn());
if(retVal != 0) return retVal;
}catch(NullPointerException npe){}
try
{
retVal = this.getKlimastasjonNavn().compareTo(other.getKlimastasjonNavn());
if(retVal != 0) return retVal;
}catch(NullPointerException npe){}
try
{
retVal = this.getStartDato().compareTo(other.getStartDato());
if(retVal != 0) return retVal;
}catch(NullPointerException npe){}
return retVal;
}
/**
* @return the DnmiSiteId
*/
public Integer getDnmiSiteId() {
return DnmiSiteId;
}
/**
* @param DnmiSiteId the DnmiSiteId to set
*/
public void setDnmiSiteId(Integer DnmiSiteId) {
this.DnmiSiteId = DnmiSiteId;
}
private Object getAttribute(String key)
{
if(this.props != null)
{
return this.props.get(key);
}
else
{
return null;
}
}
private void setAttribute(String key, Object value)
{
if(this.props == null)
{
this.props = new HashMap<>();
}
this.props.put(key, value);
}
}
/*
* 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.entity.vipsmobile;
import java.util.Date;
/**
* @copyright 2015 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class VIPSMobileMessage {
private int meldingId;
private String tittel;
private String ingress;
private String tekst;
private Date registrertDato;
private Date gyldigTilDato;
private int meldingType;
private String bildeURL;
private String bildetekst;
public VIPSMobileMessage (
int meldingId,
String tittel,
String ingress,
String tekst,
Date registrertDato,
Date gyldigTilDato,
int meldingType,
String bildeURL,
String bildetekst
)
{
this.meldingId = meldingId;
this.tittel = tittel;
this.ingress = ingress;
this.tekst = tekst;
this.registrertDato = registrertDato;
this.gyldigTilDato = gyldigTilDato;
this.meldingType = meldingType;
this.bildeURL = bildeURL;
this.bildetekst = bildetekst;
}
/**
* @return the meldingId
*/
public int getMeldingId() {
return meldingId;
}
/**
* @param meldingId the meldingId to set
*/
public void setMeldingId(int meldingId) {
this.meldingId = meldingId;
}
/**
* @return the tittel
*/
public String getTittel() {
return tittel;
}
/**
* @param tittel the tittel to set
*/
public void setTittel(String tittel) {
this.tittel = tittel;
}
/**
* @return the ingress
*/
public String getIngress() {
return ingress;
}
/**
* @param ingress the ingress to set
*/
public void setIngress(String ingress) {
this.ingress = ingress;
}
/**
* @return the tekst
*/
public String getTekst() {
return tekst;
}
/**
* @param tekst the tekst to set
*/
public void setTekst(String tekst) {
this.tekst = tekst;
}
/**
* @return the registrertDato
*/
public Date getRegistrertDato() {
return registrertDato;
}
/**
* @param registrertDato the registrertDato to set
*/
public void setRegistrertDato(Date registrertDato) {
this.registrertDato = registrertDato;
}
/**
* @return the gyldigTilDato
*/
public Date getGyldigTilDato() {
return gyldigTilDato;
}
/**
* @param gyldigTilDato the gyldigTilDato to set
*/
public void setGyldigTilDato(Date gyldigTilDato) {
this.gyldigTilDato = gyldigTilDato;
}
/**
* @return the meldingType
*/
public int getMeldingType() {
return meldingType;
}
/**
* @param meldingType the meldingType to set
*/
public void setMeldingType(int meldingType) {
this.meldingType = meldingType;
}
/**
* @return the bildeURL
*/
public String getBildeURL() {
return bildeURL;
}
/**
* @param bildeURL the bildeURL to set
*/
public void setBildeURL(String bildeURL) {
this.bildeURL = bildeURL;
}
/**
* @return the bildetekst
*/
public String getBildetekst() {
return bildetekst;
}
/**
* @param bildetekst the bildetekst to set
*/
public void setBildetekst(String bildetekst) {
this.bildetekst = bildetekst;
}
public boolean getLeaf()
{
return true;
}
}
...@@ -285,6 +285,7 @@ public class LogicService { ...@@ -285,6 +285,7 @@ public class LogicService {
@Produces("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8")
public Response getMessageList( public Response getMessageList(
@QueryParam("publishedFrom") String publishedFrom , @QueryParam("publishedTo") String publishedTo, @QueryParam("publishedFrom") String publishedFrom , @QueryParam("publishedTo") String publishedTo,
@QueryParam("locale") String locale,
@PathParam("organizationId") Integer organizationId @PathParam("organizationId") Integer organizationId
) )
{ {
......
/*
* 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 java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TimeZone;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import no.nibio.vips.entity.Result;
import no.nibio.vips.logic.entity.ForecastConfiguration;
import no.nibio.vips.logic.entity.ForecastSummary;
import no.nibio.vips.logic.entity.Message;
import no.nibio.vips.logic.entity.MessageIllustration;
import no.nibio.vips.logic.entity.MessageLocale;
import no.nibio.vips.logic.entity.ModelInformation;
import no.nibio.vips.logic.entity.PointOfInterestWeatherStation;
import no.nibio.vips.logic.entity.VipsLogicUser;
import no.nibio.vips.logic.entity.vipsmobile.VIPSMobileForecast;
import no.nibio.vips.logic.entity.vipsmobile.VIPSMobileMessage;
import no.nibio.vips.logic.entity.vipsmobile.VIPSMobilePresentation;
import no.nibio.vips.logic.i18n.SessionLocaleUtil;
import no.nibio.vips.logic.util.SessionControllerGetter;
import no.nibio.vips.logic.util.SystemTime;
import no.nibio.vips.util.WeatherUtil;
import org.jboss.resteasy.spi.HttpRequest;
/**
* The purpose of this service is to mimic the services for VIPSMobile that
* were implemented in the old VIPS. It's assumed that it's easier to adapt the
* service layer than the client layer in Sencha Touch...
*
* @copyright 2015 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
@Path("rest/vipsmobile")
public class VIPSMobileService {
@Context
private HttpRequest httpRequest;
@Context
private HttpServletRequest httpServletRequest;
@GET
@Path("melding")
@Produces("application/json;charset=UTF-8")
public Response getMessages(
@QueryParam("organizationId") Integer organizationId,
@QueryParam("locale") String locale
)
{
Date datePublishedFrom = SystemTime.getSystemTime();
Date datePublishedTo = datePublishedFrom;
List<Message> messageList = SessionControllerGetter.getMessageBean().getMessageList(organizationId, datePublishedFrom, datePublishedTo);
List<VIPSMobileMessage> retVal = new ArrayList<>();
for(Message message: messageList)
{
// Determine language
// Priority: Preferred language, English, first available locale
Set<MessageLocale> messageLocales = message.getMessageLocaleSet();
MessageLocale first = null;
MessageLocale english = null;
MessageLocale optimal = null;
for(MessageLocale mLocale:messageLocales)
{
if(mLocale.getMessageLocalePK().getLocale().equals(locale))
{
optimal = mLocale;
break;
}
if(first == null)
{
first = mLocale;
}
if(mLocale.getMessageLocalePK().getLocale().equals("en"))
{
english = mLocale;
}
}
MessageLocale pragmaticBestLocale = optimal != null ? optimal
: english != null ? english
: first;
String imageURL = "";
String imageCaption = "";
try
{
MessageIllustration illustration = message.getMessageIllustrationSet().iterator().next();
imageURL = String.format("/static/images/messages/%s/%s", pragmaticBestLocale.getCreatedBy().getOrganizationId().getOrganizationId(), illustration.getMessageIllustrationPK().getFileName());
}catch(NoSuchElementException | NullPointerException ex){}
VIPSMobileMessage vmMessage = new VIPSMobileMessage(
message.getMessageId(),
pragmaticBestLocale.getHeading(),
pragmaticBestLocale.getLeadParagraph(),
pragmaticBestLocale.getBody(),
message.getDatePub(),
message.getDateValidTo(),
message.getMessageTagSet().iterator().next().getMessageTagId(),
imageURL,
"Test"
);
retVal.add(vmMessage);
}
return Response.ok().entity(retVal).build();
}
@GET
@Path("presentasjoner")
@Produces("application/json;charset=UTF-8")
public Response getPresentations(
@QueryParam("varselIder") String forecastConfigurationIds,
@QueryParam("timeZone") String timeZoneStr,
@QueryParam("locale") String locale
){
// Default locale is English
if(locale == null)
{
locale = "en";
}
// Get model info
Map<String, ModelInformation> modelInformationMap = SessionControllerGetter.getForecastBean().getIndexedModelInformation();
TimeZone timeZone = timeZoneStr != null ? TimeZone.getTimeZone(timeZoneStr)
: TimeZone.getDefault();
List<Long> parsedIds = new ArrayList<>();
for(String idCandidate:forecastConfigurationIds.split(","))
{
try
{
parsedIds.add(Long.valueOf(idCandidate));
}
catch(NumberFormatException ex){}
}
List<VIPSMobilePresentation> retVal = new ArrayList<>();
if(!parsedIds.isEmpty())
{
List<ForecastConfiguration> configsWithSummaries = SessionControllerGetter.getForecastBean().getForecastConfigurationWithSummaries(parsedIds);
// Initializing the array of summaries
Date today = new WeatherUtil().normalizeToExactDate(SystemTime.getSystemTime(), timeZone);
List<Date> datesList = new ArrayList<>();
Integer[] statusList = new Integer[11];
Calendar cal = Calendar.getInstance(timeZone);
cal.setTime(today);
cal.add(Calendar.DATE, -4);
for(int i=0;i<11;i++)
{
datesList.add(cal.getTime());
statusList[i] = Result.WARNING_STATUS_NO_WARNING_MISSING_DATA;
cal.add(Calendar.DATE, 1);
}
for(ForecastConfiguration config:configsWithSummaries)
{
List<ForecastSummary> summaries = config.getForecastSummaries();
if(summaries == null || summaries.isEmpty())
{
continue;
}
for(ForecastSummary summary:summaries)
{
for(int i=0;i<11;i++)
{
if(datesList.get(i).compareTo(summary.getForecastSummaryPK().getSummaryForDate()) == 0)
{
statusList[i] = summary.getWarningStatus();
}
}
}
VIPSMobilePresentation pres = new VIPSMobilePresentation(
-1,
today,
2,
statusList[0],
statusList[1],
statusList[2],
statusList[3],
statusList[4],
statusList[5],
statusList[6],
statusList[7],
statusList[8],
statusList[9],
statusList[10],
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
config.getWeatherStationPointOfInterestId().getPointOfInterestId(),
config.getPestOrganismId().getOrganismId(),
config.getCropOrganismId().getOrganismId(),
config.getLocationPointOfInterestId().getPointOfInterestId(),
config.getModelId(),
config.getWeatherStationPointOfInterestId().getName(),
config.getPestOrganismId().getLocalName(locale),
config.getCropOrganismId().getLocalName(locale),
config.getLocationPointOfInterestId().getName(),
SessionLocaleUtil.getI18nText(httpServletRequest, config.getModelId()),
"",
""
);
pres.setVarselId(config.getForecastConfigurationId());
retVal.add(pres);
// Reset statusList
for(int i=0;i<11;i++)
{
statusList[i] = Result.WARNING_STATUS_NO_WARNING_MISSING_DATA;
cal.add(Calendar.DATE, 1);
}
}
}
return Response.ok().entity(retVal).build();
}
@GET
@Path("varsler")
@Produces("application/json;charset=UTF-8")
public Response getForecastConfigurations(
@QueryParam("klimastasjonId") Integer klimastasjonId,
@QueryParam("kulturId") List<Integer> kulturIder,
@QueryParam("locale") String locale
)
{
// Default locale is English
if(locale == null)
{
locale = "en";
}
Date to = SystemTime.getSystemTime();
Calendar cal = Calendar.getInstance();
cal.setTime(to);
cal.add(Calendar.MONTH, -2);
Date from = cal.getTime();
PointOfInterestWeatherStation station = (PointOfInterestWeatherStation) SessionControllerGetter.getPointOfInterestBean().getPointOfInterest(klimastasjonId);
List<ForecastConfiguration> forecasts = SessionControllerGetter.getForecastBean().getForecastConfigurations(station, from, to);
List<VIPSMobileForecast> retVal = new ArrayList<>();
for(ForecastConfiguration forecast:forecasts)
{
for(Integer cropOrganismId:kulturIder)
{
if(cropOrganismId.equals(forecast.getCropOrganismId().getOrganismId()))
{
// Create old style VIPS forecast object, add to returned list
VIPSMobileForecast varsel = new VIPSMobileForecast(
forecast.getForecastConfigurationId(),
-1,
forecast.getDateStart(),
forecast.getDateEnd(),
forecast.getWeatherStationPointOfInterestId().getPointOfInterestId(),
forecast.getWeatherStationPointOfInterestId().getName(),
forecast.getLocationPointOfInterestId().getPointOfInterestId(),
forecast.getLocationPointOfInterestId().getName(),
false,
false,
-1,
null,
false,
forecast.getPestOrganismId() != null ? forecast.getPestOrganismId().getOrganismId() : -1l,
forecast.getPestOrganismId() != null ?
forecast.getPestOrganismId().getLocalName(locale) != null && ! forecast.getPestOrganismId().getLocalName(locale).isEmpty() ?
forecast.getPestOrganismId().getLocalName(locale)
: forecast.getPestOrganismId().getLatinName()
: "",
forecast.getCropOrganismId().getOrganismId(),
forecast.getCropOrganismId().getLocalName(locale),
forecast.getModelId(),
SessionLocaleUtil.getI18nText(httpServletRequest, forecast.getModelId())
);
retVal.add(varsel);
break;
}
}
}
return Response.ok().entity(retVal).build();
}
/**
* Returns a list of forecasts for given organization
* @param organizationId
* @return
*/
@GET
@Path("organizationforecastconfigurations/{organizationId}")
@Produces("application/json;charset=UTF-8")
public Response getForecastConfigurationsForOrganization(
@PathParam("organizationId") Integer organizationId,
@QueryParam("cropOrganismId") List<Integer> cropOrganismIds,
@QueryParam("from") Date from,
@QueryParam("to") Date to
)
{
if(from == null || to == null)
{
to = SystemTime.getSystemTime();
Calendar cal = Calendar.getInstance();
cal.setTime(to);
cal.add(Calendar.MONTH, -2);
from = cal.getTime();
}
// First: Get all users for organization
List<VipsLogicUser> organizationUsers = SessionControllerGetter.getUserBean().getUsersByOrganization(organizationId);
// Then: Get forecasts for these users, collate and return
List<ForecastConfiguration> forecasts = new ArrayList<>();
for(VipsLogicUser user:organizationUsers)
{
Integer userId = user.getUserId();
List<ForecastConfiguration> result = cropOrganismIds != null && ! cropOrganismIds.isEmpty() ?
SessionControllerGetter.getForecastBean().getForecastConfigurationsForUserAndCropsAndDate(userId,cropOrganismIds, from, to)
: SessionControllerGetter.getForecastBean().getForecastConfigurationsForUserAndDate(userId, from, to);
if(forecasts == null)
forecasts = result;
else
forecasts.addAll(result);
}
return Response.ok().entity(forecasts).build();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment