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

Improving documentation for the endpoints in ObservationService

parent 13796403
Branches
Tags
No related merge requests found
/* /*
* Copyright (c) 2016 NIBIO <http://www.nibio.no/>. * Copyright (c) 2022 NIBIO <http://www.nibio.no/>.
* *
* This file is part of VIPSLogic. * This file is part of VIPSLogic.
* VIPSLogic is free software: you can redistribute it and/or modify * VIPSLogic is free software: you can redistribute it and/or modify
...@@ -22,6 +22,7 @@ package no.nibio.vips.logic.service; ...@@ -22,6 +22,7 @@ package no.nibio.vips.logic.service;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.ibm.icu.util.ULocale; import com.ibm.icu.util.ULocale;
import com.webcohesion.enunciate.metadata.rs.TypeHint;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
...@@ -80,13 +81,13 @@ import org.slf4j.Logger; ...@@ -80,13 +81,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* @copyright 2016-2021 <a href="http://www.nibio.no/">NIBIO</a> * @copyright 2016-2022 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no> * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/ */
@Path("rest/observation") @Path("rest/observation")
public class ObservationService { public class ObservationService {
private static Logger LOGGER = LoggerFactory.getLogger(ObservationService.class); private final static Logger LOGGER = LoggerFactory.getLogger(ObservationService.class);
@Context @Context
private HttpServletRequest httpServletRequest; private HttpServletRequest httpServletRequest;
...@@ -115,14 +116,15 @@ public class ObservationService { ...@@ -115,14 +116,15 @@ public class ObservationService {
* @param pestId * @param pestId
* @param cropId * @param cropId
* @param cropCategoryId * @param cropCategoryId
* @param from * @param fromStr
* @param to * @param toStr
* @return Observation objects with all data (full tree) * @return Observation objects with all data (full tree)
*/ */
@GET @GET
@Path("filter/{organizationId}") @Path("filter/{organizationId}")
@GZIP @GZIP
@Produces("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8")
@TypeHint(Observation[].class)
public Response getFilteredObservations( public Response getFilteredObservations(
@PathParam("organizationId") Integer organizationId, @PathParam("organizationId") Integer organizationId,
@QueryParam("pestId") Integer pestId, @QueryParam("pestId") Integer pestId,
...@@ -157,6 +159,7 @@ public class ObservationService { ...@@ -157,6 +159,7 @@ public class ObservationService {
@Path("list/filter/{organizationId}") @Path("list/filter/{organizationId}")
@GZIP @GZIP
@Produces("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8")
@TypeHint(ObservationListItem.class)
public Response getFilteredObservationListItems( public Response getFilteredObservationListItems(
@PathParam("organizationId") Integer organizationId, @PathParam("organizationId") Integer organizationId,
@QueryParam("pestId") Integer pestId, @QueryParam("pestId") Integer pestId,
...@@ -206,7 +209,16 @@ public class ObservationService { ...@@ -206,7 +209,16 @@ public class ObservationService {
return Response.ok().entity(observations).build(); return Response.ok().entity(observations).build();
} }
/**
*
* @param organizationId
* @param pestId
* @param cropId
* @param cropCategoryId
* @param fromStr
* @param toStr
* @return
*/
private List<Observation> getFilteredObservationsFromBackend( private List<Observation> getFilteredObservationsFromBackend(
Integer organizationId, Integer organizationId,
Integer pestId, Integer pestId,
...@@ -287,6 +299,7 @@ public class ObservationService { ...@@ -287,6 +299,7 @@ public class ObservationService {
@GET @GET
@Path("pest/{organizationId}") @Path("pest/{organizationId}")
@Produces("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8")
@TypeHint(Observation[].class)
public Response getObservedPests(@PathParam("organizationId") Integer organizationId) public Response getObservedPests(@PathParam("organizationId") Integer organizationId)
{ {
return Response.ok().entity(observationBean.getObservedPests(organizationId)).build(); return Response.ok().entity(observationBean.getObservedPests(organizationId)).build();
...@@ -302,6 +315,7 @@ public class ObservationService { ...@@ -302,6 +315,7 @@ public class ObservationService {
@GET @GET
@Path("crop/{organizationId}") @Path("crop/{organizationId}")
@Produces("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8")
@TypeHint(Observation[].class)
public Response getObservedCrops(@PathParam("organizationId") Integer organizationId) public Response getObservedCrops(@PathParam("organizationId") Integer organizationId)
{ {
return Response.ok().entity(observationBean.getObservedCrops(organizationId)).build(); return Response.ok().entity(observationBean.getObservedCrops(organizationId)).build();
...@@ -317,6 +331,7 @@ public class ObservationService { ...@@ -317,6 +331,7 @@ public class ObservationService {
@Path("list/{organizationId}") @Path("list/{organizationId}")
@GZIP @GZIP
@Produces("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8")
@TypeHint(Observation[].class)
public Response getObservations(@PathParam("organizationId") Integer organizationId){ public Response getObservations(@PathParam("organizationId") Integer organizationId){
return Response.ok().entity(observationBean.getObservations(organizationId, Observation.STATUS_TYPE_ID_APPROVED)).build(); return Response.ok().entity(observationBean.getObservations(organizationId, Observation.STATUS_TYPE_ID_APPROVED)).build();
} }
...@@ -324,11 +339,13 @@ public class ObservationService { ...@@ -324,11 +339,13 @@ public class ObservationService {
/** /**
* Get observations for a user * Get observations for a user
* Requires a valid UUID to be provided in the Authorization header * Requires a valid UUID to be provided in the Authorization header
* @param observationIds
* @return * @return
*/ */
@GET @GET
@Path("list/user") @Path("list/user")
@Produces("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8")
@TypeHint(Observation[].class)
public Response getObservationsForUser( public Response getObservationsForUser(
@QueryParam("observationIds") String observationIds @QueryParam("observationIds") String observationIds
) )
...@@ -365,13 +382,14 @@ public class ObservationService { ...@@ -365,13 +382,14 @@ public class ObservationService {
} }
/** /**
* Get observations for a user * Get minimized (only synchronization info) observations for a user
* Requires a valid UUID to be provided in the Authorization header * Requires a valid UUID to be provided in the Authorization header
* @return * @return
*/ */
@GET @GET
@Path("list/minimized/user") @Path("list/minimized/user")
@Produces("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8")
@TypeHint(ObservationSyncInfo[].class)
public Response getMinimizedObservationsForUser() public Response getMinimizedObservationsForUser()
{ {
VipsLogicUser user = userBean.getUserFromUUID(httpServletRequest); VipsLogicUser user = userBean.getUserFromUUID(httpServletRequest);
...@@ -395,6 +413,7 @@ public class ObservationService { ...@@ -395,6 +413,7 @@ public class ObservationService {
@Path("broadcast/list/{organizationId}") @Path("broadcast/list/{organizationId}")
@GZIP @GZIP
@Produces("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8")
@TypeHint(Observation[].class)
public Response getBroadcastObservations( public Response getBroadcastObservations(
@PathParam("organizationId") Integer organizationId, @PathParam("organizationId") Integer organizationId,
@QueryParam("season") Integer season, @QueryParam("season") Integer season,
...@@ -434,6 +453,7 @@ public class ObservationService { ...@@ -434,6 +453,7 @@ public class ObservationService {
@GET @GET
@Path("{observationId}") @Path("{observationId}")
@Produces("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8")
@TypeHint(Observation.class)
public Response getObservation( public Response getObservation(
@PathParam("observationId") Integer observationId, @PathParam("observationId") Integer observationId,
@QueryParam("userUUID") String userUUID @QueryParam("userUUID") String userUUID
...@@ -482,9 +502,15 @@ public class ObservationService { ...@@ -482,9 +502,15 @@ public class ObservationService {
return Response.ok().entity(o).build(); return Response.ok().entity(o).build();
} }
/**
*
* @param organizationId
* @return
*/
@GET @GET
@Path("polygonservices/{organizationId}") @Path("polygonservices/{organizationId}")
@Produces("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8")
@TypeHint(PolygonService[].class)
public Response getPolygonServicesForOrganization( public Response getPolygonServicesForOrganization(
@PathParam("organizationId") Integer organizationId @PathParam("organizationId") Integer organizationId
) )
...@@ -492,8 +518,11 @@ public class ObservationService { ...@@ -492,8 +518,11 @@ public class ObservationService {
return Response.ok().entity(observationBean.getPolygonServicesForOrganization(organizationId)).build(); return Response.ok().entity(observationBean.getPolygonServicesForOrganization(organizationId)).build();
} }
/** /**
* Deletes a gis entity and its corresponding observation * Deletes a gis entity and its corresponding observation
* @param gisId
* @return
*/ */
@DELETE @DELETE
@Path("gisobservation/{gisId}") @Path("gisobservation/{gisId}")
...@@ -570,6 +599,7 @@ public class ObservationService { ...@@ -570,6 +599,7 @@ public class ObservationService {
@GET @GET
@Path("first/{organismId}") @Path("first/{organismId}")
@Produces("text/plain;charset=UTF-8") @Produces("text/plain;charset=UTF-8")
@TypeHint(Date.class)
public Response getFirstObservation(@PathParam("organismId") Integer organismId) public Response getFirstObservation(@PathParam("organismId") Integer organismId)
{ {
Date firstObsTime = observationBean.getFirstObservationTime(organismId); Date firstObsTime = observationBean.getFirstObservationTime(organismId);
...@@ -579,12 +609,13 @@ public class ObservationService { ...@@ -579,12 +609,13 @@ public class ObservationService {
/** /**
* When was the last time a change was made in cropCategories or organisms? * When was the last time a change was made in cropCategories or organisms?
* * @return last time a change was made in cropCategories or organisms
* @responseExample application/json {"lastUpdated": "2021-02-08T00:00:00Z"} * @responseExample application/json {"lastUpdated": "2021-02-08T00:00:00Z"}
*/ */
@GET @GET
@Path("organismsystemupdated") @Path("organismsystemupdated")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@TypeHint(Date.class)
public Response getDateOfLastOrganismSystemUpdate() public Response getDateOfLastOrganismSystemUpdate()
{ {
HashMap<String, Object> result = new HashMap<>(); HashMap<String, Object> result = new HashMap<>();
...@@ -594,6 +625,17 @@ public class ObservationService { ...@@ -594,6 +625,17 @@ public class ObservationService {
} }
/**
*
* @param organizationId
* @param pestId
* @param cropId
* @param cropCategoryId
* @param fromStr
* @param toStr
* @param user
* @return
*/
private List<Observation> getFilteredObservationsFromBackend(Integer organizationId, Integer pestId, Integer cropId, List<Integer> cropCategoryId, String fromStr, String toStr, VipsLogicUser user) { private List<Observation> getFilteredObservationsFromBackend(Integer organizationId, Integer pestId, Integer cropId, List<Integer> cropCategoryId, String fromStr, String toStr, VipsLogicUser user) {
List<Observation> filteredObservations = this.getFilteredObservationsFromBackend(organizationId, pestId, cropId, cropCategoryId, fromStr, toStr); List<Observation> filteredObservations = this.getFilteredObservationsFromBackend(organizationId, pestId, cropId, cropCategoryId, fromStr, toStr);
//filteredObservations.forEach(o->System.out.println(o.getObservationId())); //filteredObservations.forEach(o->System.out.println(o.getObservationId()));
...@@ -708,6 +750,11 @@ public class ObservationService { ...@@ -708,6 +750,11 @@ public class ObservationService {
return observations; return observations;
} }
/**
*
* @param observationJson
* @return
*/
@POST @POST
@Path("syncobservationfromapp") @Path("syncobservationfromapp")
@Consumes("application/json;charset=UTF-8") @Consumes("application/json;charset=UTF-8")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment