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 1d9a0a3dc3b5465195910894103e224786a0fdf9..0b16c62705c583f6ec075420a32f8ee154fa3fb6 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 8de4c36b950ec9b9ad16238cb21c3da4f9824595..83acad10e4c102b622ebf29bad989bd769d03888 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(); } }