From 4b20918221231b36d6f2b4073eae41506df8ca8f Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Thu, 13 Mar 2025 09:15:05 +0100 Subject: [PATCH] Feat: Fetch weather stations available to a user VIPSUTV-1035 --- .../nibio/vips/logic/service/POIService.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/no/nibio/vips/logic/service/POIService.java b/src/main/java/no/nibio/vips/logic/service/POIService.java index 06899674..65641115 100644 --- a/src/main/java/no/nibio/vips/logic/service/POIService.java +++ b/src/main/java/no/nibio/vips/logic/service/POIService.java @@ -244,6 +244,34 @@ public class POIService { List<PointOfInterest> retVal = pointOfInterestBean.getRelevantPointOfInterestsForUser(user); return Response.ok().entity(retVal).build(); } + + /** + * If used outside of VIPSLogic: Requires a valid UUID to be provided in the + * Authorization header + * + * @return a list of weather stations, including the ones belonging to the user's organization and any private stations belonging to the user + */ + @GET + @Path("weatherstation/user") + @Produces("application/json;charset=UTF-8") + @Facet("restricted") + @TypeHint(PointOfInterest[].class) + public Response getWeatherStationsForCurrentUser() { + VipsLogicUser user = (VipsLogicUser) httpServletRequest.getSession().getAttribute("user"); + // Could be the VIPS obs app or some other client using UUID + if (user == null) { + String uuidStr = httpServletRequest.getHeader(HttpHeaders.AUTHORIZATION); + UUID uuid = UUID.fromString(uuidStr); + user = userBean.findVipsLogicUser(uuid); + if (user == null) { + return Response.status(Status.UNAUTHORIZED).build(); + } + } + List<PointOfInterestWeatherStation> retVal = pointOfInterestBean.getRelevantPointOfInterestsForUser(user).stream() + .filter(poi->poi instanceof PointOfInterestWeatherStation) + .map(poi->(PointOfInterestWeatherStation) poi).collect(Collectors.toList()); + return Response.ok().entity(retVal).build(); + } /** * This service is used by the VIPS Field observation app to sync data stored locally on the smartphone with the -- GitLab