From 45b62af068fd22b2e9534a2fb6d9ee4e110e97d7 Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Fri, 5 Apr 2019 12:00:29 +0200 Subject: [PATCH] Allowing for more than one organization's stations to be shown on the front page map --- .../controller/session/ForecastBean.java | 17 +++++++++-- .../vips/logic/service/LogicService.java | 30 ++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/main/java/no/nibio/vips/logic/controller/session/ForecastBean.java b/src/main/java/no/nibio/vips/logic/controller/session/ForecastBean.java index 1d9a0a3d..0b16c627 100755 --- a/src/main/java/no/nibio/vips/logic/controller/session/ForecastBean.java +++ b/src/main/java/no/nibio/vips/logic/controller/session/ForecastBean.java @@ -659,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/"; @@ -696,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(); diff --git a/src/main/java/no/nibio/vips/logic/service/LogicService.java b/src/main/java/no/nibio/vips/logic/service/LogicService.java index 8de4c36b..83acad10 100755 --- a/src/main/java/no/nibio/vips/logic/service/LogicService.java +++ b/src/main/java/no/nibio/vips/logic/service/LogicService.java @@ -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(); } } -- GitLab