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

Supporting private forecasts in KML

parent f21ae8ee
No related branches found
No related tags found
2 merge requests!22Develop,!20Privat varsel
This commit is part of merge request !20. Comments created here will be created in the context of that merge request.
......@@ -710,7 +710,7 @@ public class ForecastBean {
return resource;
}
public Kml getForecastsAggregateKml(List<Integer> organizationIds, List<Integer> cropOrganismIds, Date theDate, String serverName)
public Kml getForecastsAggregateKml(List<Integer> organizationIds, List<Integer> cropOrganismIds, Date theDate, String serverName, VipsLogicUser user)
{
//String iconPath = Globals.PROTOCOL + "://" + serverName + "/public/images/";
String iconPath = "//" + serverName + "/public/images/";
......@@ -751,13 +751,13 @@ public class ForecastBean {
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))
org-> poisWithAggregate.addAll(getPointOfInterestForecastsAggregate(org.getOrganizationId(), cropOrganismIds, theDate, user))
);
}
else
{
organizationIds.stream().forEach(
orgId-> poisWithAggregate.addAll(getPointOfInterestForecastsAggregate(orgId, cropOrganismIds, theDate))
orgId-> poisWithAggregate.addAll(getPointOfInterestForecastsAggregate(orgId, cropOrganismIds, theDate, user))
);
}
......@@ -1015,9 +1015,15 @@ public class ForecastBean {
* @param organizationId Filter for organization
* @param cropOrganismIds Filter for crops
* @param theDate Filter for date. If theDate=systemDate, data is fetched from the caching table forecast_result_cache
* @param user if not null: Include private forecasts for this user
* @return
*/
private List<PointOfInterest> getPointOfInterestForecastsAggregate(Integer organizationId, List<Integer> cropOrganismIds, Date theDate) {
private List<PointOfInterest> getPointOfInterestForecastsAggregate(
Integer organizationId,
List<Integer> cropOrganismIds,
Date theDate,
VipsLogicUser user
) {
// TODO: More precise gathering of POIs...
List<PointOfInterest> pois;
if(organizationId != null && organizationId > 0)
......@@ -1050,14 +1056,22 @@ public class ForecastBean {
"WHERE forecast_configuration_id IN( \n" +
" SELECT forecast_configuration_id \n" +
" FROM forecast_configuration \n" +
" WHERE is_private IS FALSE \n" +
" AND forecast_configuration_id > 0 \n" +
" WHERE forecast_configuration_id > 0 \n" +
(user == null ?
" AND is_private IS FALSE \n"
:" AND (is_private IS FALSE OR (is_private IS TRUE AND vips_logic_user_id=:vipsLogicUserId))"
) +
" AND location_point_of_interest_id=:locationPointOfInterestId \n" +
(cropOrganismIds != null && ! cropOrganismIds.isEmpty() ? " AND crop_organism_id IN (" + StringUtils.join(cropOrganismIds, ",") + ") " : "") +
")\n" +
"AND valid_time_start between :midnight AND :nextMidnight";
//System.out.println(poi.getName() + " SQL=" + sql);
Query q = em.createNativeQuery(sql);
if(user != null)
{
q.setParameter("vipsLogicUserId", user);
}
q.setParameter("locationPointOfInterestId", poi.getPointOfInterestId());
q.setParameter("midnight", midnight);
q.setParameter("nextMidnight", nextMidnight);
......
......@@ -534,7 +534,6 @@ public class LogicService {
}
/**
*
* @param organizationId
* @param cropCategoryIds
* @return
......@@ -546,8 +545,22 @@ public class LogicService {
@Facet("restricted")
public Response getForecastResultsAggregate(
@PathParam("organizationId") Integer organizationId,
@QueryParam("cropCategoryId") List<Integer> cropCategoryIds)
@QueryParam("cropCategoryId") List<Integer> cropCategoryIds,
@QueryParam("userUUID") String userUUID)
{
VipsLogicUser viewUser = null;
if(userUUID != null)
{
try
{
UUID uUUID = UUID.fromString(userUUID);
viewUser = SessionControllerGetter.getUserBean().findVipsLogicUser(uUUID);
}
catch(IllegalArgumentException ex)
{
// Skip this
}
}
List<Integer> organizationIds = new ArrayList<>();
organizationIds.add(organizationId);
if(cropCategoryIds == null || cropCategoryIds.isEmpty())
......@@ -557,7 +570,7 @@ public class LogicService {
else
{
List<Integer> cropOrganismIds = SessionControllerGetter.getOrganismBean().getCropCategoryOrganismIds(cropCategoryIds);
Kml retVal = SessionControllerGetter.getForecastBean().getForecastsAggregateKml(organizationIds, cropOrganismIds, SystemTime.getSystemTime(), ServletUtil.getServerName(httpServletRequest));
Kml retVal = SessionControllerGetter.getForecastBean().getForecastsAggregateKml(organizationIds, cropOrganismIds, SystemTime.getSystemTime(), ServletUtil.getServerName(httpServletRequest), viewUser);
return Response.ok().entity(retVal).build();
}
}
......@@ -574,7 +587,8 @@ public class LogicService {
@Facet("restricted")
public Response getForecastResultsAggregate(
@QueryParam("organizationId") List<Integer> organizationIds,
@QueryParam("cropCategoryId") List<Integer> cropCategoryIds)
@QueryParam("cropCategoryId") List<Integer> cropCategoryIds,
@QueryParam("userUUID") String userUUID)
{
if(cropCategoryIds == null || cropCategoryIds.isEmpty())
{
......@@ -582,8 +596,21 @@ public class LogicService {
}
else
{
VipsLogicUser viewUser = null;
if(userUUID != null)
{
try
{
UUID uUUID = UUID.fromString(userUUID);
viewUser = SessionControllerGetter.getUserBean().findVipsLogicUser(uUUID);
}
catch(IllegalArgumentException ex)
{
// Skip this
}
}
List<Integer> cropOrganismIds = SessionControllerGetter.getOrganismBean().getCropCategoryOrganismIds(cropCategoryIds);
Kml retVal = SessionControllerGetter.getForecastBean().getForecastsAggregateKml(organizationIds, cropOrganismIds, SystemTime.getSystemTime(), ServletUtil.getServerName(httpServletRequest));
Kml retVal = SessionControllerGetter.getForecastBean().getForecastsAggregateKml(organizationIds, cropOrganismIds, SystemTime.getSystemTime(), ServletUtil.getServerName(httpServletRequest), viewUser);
return Response.ok().entity(retVal).build();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment