From a6f8e040d820285dd4d30115940942b1e3fd33ec Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Tue, 23 Feb 2021 10:55:05 +0100 Subject: [PATCH] Added observations for user as endpoint --- docs/data_model.md | 5 +++- .../logic/service/AuthenticationService.java | 2 +- .../logic/service/ObservationService.java | 26 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/data_model.md b/docs/data_model.md index 1624ce8e..5e811e13 100644 --- a/docs/data_model.md +++ b/docs/data_model.md @@ -37,4 +37,7 @@ Crops, pests, diseases and weeds are all organisms subject to [classification](h ### Crop categories -Each organization (NIBIO, Jordbruksverket, ADAS etc.) has their own set of crop categories. They can be e.g. cereals, fruit, vegetables. Each of these links to one or more organisms. \ No newline at end of file +Each organization (NIBIO, Jordbruksverket, ADAS etc.) has their own set of crop categories. They can be e.g. cereals, fruit, vegetables. Each of these links to one or more organisms. + +### Field observations +An Observation is a registration of a pest in space and time. \ No newline at end of file diff --git a/src/main/java/no/nibio/vips/logic/service/AuthenticationService.java b/src/main/java/no/nibio/vips/logic/service/AuthenticationService.java index af8f5bc6..f9e40286 100644 --- a/src/main/java/no/nibio/vips/logic/service/AuthenticationService.java +++ b/src/main/java/no/nibio/vips/logic/service/AuthenticationService.java @@ -100,7 +100,7 @@ public class AuthenticationService { } /** - * + * Provide the UUID as the contents of the Authorization header * @return The VIPSLogic user associated with this uuid, or 404 if not found */ @GET diff --git a/src/main/java/no/nibio/vips/logic/service/ObservationService.java b/src/main/java/no/nibio/vips/logic/service/ObservationService.java index 11a6db46..0fd87b88 100755 --- a/src/main/java/no/nibio/vips/logic/service/ObservationService.java +++ b/src/main/java/no/nibio/vips/logic/service/ObservationService.java @@ -49,8 +49,11 @@ import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + import no.nibio.vips.logic.entity.Gis; import no.nibio.vips.logic.entity.Observation; import no.nibio.vips.logic.entity.PolygonService; @@ -277,6 +280,29 @@ public class ObservationService { return Response.ok().entity(SessionControllerGetter.getObservationBean().getObservations(organizationId, Observation.STATUS_TYPE_ID_APPROVED)).build(); } + /** + * Get observations for a user + * Requires a valid UUID to be provided in the Authorization header + * @return + */ + @GET + @Path("list/user") + @Produces("application/json;charset=UTF-8") + public Response getObservationsForUser() + { + String uuidStr = httpServletRequest.getHeader(HttpHeaders.AUTHORIZATION); + UUID uuid = UUID.fromString(uuidStr); + VipsLogicUser user = SessionControllerGetter.getUserBean().findVipsLogicUser(uuid); + if(user != null) + { + return Response.ok().entity(SessionControllerGetter.getObservationBean().getObservationsForUser(user)).build(); + } + else + { + return Response.status(Status.NOT_FOUND).build(); + } + } + /** * Publicly available observations per organization * @param organizationId -- GitLab