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

Adds collection of forecasts for an organization

parent 66ebdd6c
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ public class VIPSLogicApplication extends Application ...@@ -36,7 +36,7 @@ public class VIPSLogicApplication extends Application
* given list with all resources defined in the project. * given list with all resources defined in the project.
*/ */
private void addRestResourceClasses(Set<Class<?>> resources) { private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(no.bioforsk.vips.core.service.ModelResource.class); resources.add(no.bioforsk.vips.coremanager.service.ManagerResource.class);
resources.add(no.bioforsk.vips.logic.service.LogicService.class); resources.add(no.bioforsk.vips.logic.service.LogicService.class);
} }
......
...@@ -13,6 +13,7 @@ import javax.persistence.OneToOne; ...@@ -13,6 +13,7 @@ import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.codehaus.jackson.annotate.JsonIgnore;
/** /**
* Extension of {@see PointOfInterest}, with additional info for weather stations * Extension of {@see PointOfInterest}, with additional info for weather stations
...@@ -35,6 +36,7 @@ public class PointOfInterestWeatherStation extends PointOfInterest implements Se ...@@ -35,6 +36,7 @@ public class PointOfInterestWeatherStation extends PointOfInterest implements Se
@JoinColumn(name = "weather_station_data_source_id", referencedColumnName = "weather_station_data_source_id") @JoinColumn(name = "weather_station_data_source_id", referencedColumnName = "weather_station_data_source_id")
@ManyToOne @ManyToOne
private WeatherStationDataSource weatherStationDataSourceId; private WeatherStationDataSource weatherStationDataSourceId;
@JsonIgnore
@JoinColumn(name = "point_of_interest_id", referencedColumnName = "point_of_interest_id", insertable = false, updatable = false) @JoinColumn(name = "point_of_interest_id", referencedColumnName = "point_of_interest_id", insertable = false, updatable = false)
@OneToOne(optional = false) @OneToOne(optional = false)
private PointOfInterest pointOfInterest; private PointOfInterest pointOfInterest;
......
package no.bioforsk.vips.logic.service; package no.bioforsk.vips.logic.service;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.client.Client; import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.ClientBuilder;
...@@ -12,6 +14,7 @@ import javax.ws.rs.core.Context; ...@@ -12,6 +14,7 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import no.bioforsk.vips.coremanager.service.ManagerResource; import no.bioforsk.vips.coremanager.service.ManagerResource;
import no.bioforsk.vips.logic.entity.ForecastResult; import no.bioforsk.vips.logic.entity.ForecastResult;
import no.bioforsk.vips.logic.scheduling.model.ForecastConfiguration;
import no.bioforsk.vips.logic.session.SessionControllerGetter; import no.bioforsk.vips.logic.session.SessionControllerGetter;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import org.jboss.resteasy.spi.HttpRequest; import org.jboss.resteasy.spi.HttpRequest;
...@@ -38,6 +41,37 @@ public class LogicService { ...@@ -38,6 +41,37 @@ public class LogicService {
return Response.ok().entity(results).build(); return Response.ok().entity(results).build();
} }
@GET
@Path("forecastresults/{forecastResultId}")
@Produces("application/json;charset=UTF-8")
public Response getForecastResults(@PathParam("forecastResultId") Long forecastResultId)
{
List<ForecastResult> results = SessionControllerGetter.getForecastBean().getForecastResults();
return Response.ok().entity(results).build();
}
@GET
@Path("organizationforecastconfigurations/{organizationId}")
@Produces("application/json;charset=UTF-8")
public Response getForecastConfigurationsForOrganization(@PathParam("organizationId") Integer organizationId)
{
// First: Get all users for organization
// TODO: Should be authenticated
Response resp = this.getManagerResource().getUsersForOrganization(organizationId);
List<Map> userList = resp.readEntity(List.class);
// Then: Get forecasts for these users, collate and return
List<ForecastConfiguration> forecasts = null;
for(Map user:userList)
{
Integer userId = (Integer) user.get("vipsCoreUserId");
if(forecasts == null)
forecasts = SessionControllerGetter.getForecastBean().getForecastConfigurationsForUser(userId);
else
forecasts.addAll(SessionControllerGetter.getForecastBean().getForecastConfigurationsForUser(userId));
}
return Response.ok().entity(forecasts).build();
}
private ManagerResource getManagerResource() private ManagerResource getManagerResource()
{ {
......
...@@ -4,7 +4,9 @@ import java.util.List; ...@@ -4,7 +4,9 @@ import java.util.List;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import no.bioforsk.vips.logic.entity.ForecastResult; import no.bioforsk.vips.logic.entity.ForecastResult;
import no.bioforsk.vips.logic.scheduling.model.ForecastConfiguration;
/** /**
* @copyright 2013 <a href="http://www.bioforsk.no/">Bioforsk</a> * @copyright 2013 <a href="http://www.bioforsk.no/">Bioforsk</a>
...@@ -20,4 +22,18 @@ public class ForecastBean { ...@@ -20,4 +22,18 @@ public class ForecastBean {
{ {
return em.createNamedQuery("ForecastResult.findAll").getResultList(); return em.createNamedQuery("ForecastResult.findAll").getResultList();
} }
public List<ForecastResult> getForecastResults(Long forecastResultId)
{
Query q = em.createNamedQuery("ForecastResult.findByForecastResultId", ForecastResult.class);
q.setParameter("forecastResultId", forecastResultId);
return q.getResultList();
}
public List<ForecastConfiguration> getForecastConfigurationsForUser(Integer userId)
{
Query q = em.createNamedQuery("ForecastConfiguration.findByVipsCoreUserId");
q.setParameter("vipsCoreUserId", userId);
return q.getResultList();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment