diff --git a/docs/data_model.md b/docs/data_model.md index 1624ce8ea191c19ef26dc293c6292d307948bf36..5e811e13e49fcacb23964f48e57c5c483c32cbe7 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 af8f5bc657e6f5c7bb3ca9e9a7d9a5e3140b62bc..f9e40286478cbc17cd376d89b6a9f297eaa615f3 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 11a6db46018ca87a6c81d07bcfa778db121b1211..0fd87b88ae23815ad57d7a27246a025727af17c2 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