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

Added isPositive to the observation filter

parent ebb4a0ee
No related branches found
No related tags found
No related merge requests found
...@@ -606,7 +606,8 @@ public class ObservationBean { ...@@ -606,7 +606,8 @@ public class ObservationBean {
Integer cropId, Integer cropId,
List<Integer> cropCategoryId, List<Integer> cropCategoryId,
Date from, Date from,
Date to Date to,
Boolean isPositive
) )
{ {
// The minimum SQL // The minimum SQL
...@@ -651,6 +652,12 @@ public class ObservationBean { ...@@ -651,6 +652,12 @@ public class ObservationBean {
sql += "AND time_of_observation <= :to \n"; sql += "AND time_of_observation <= :to \n";
parameters.put("to", to); parameters.put("to", to);
} }
// Filter for positive/negative registrations
if(isPositive != null)
{
sql += "AND is_positive = :isPositive \n";
parameters.put("isPositive", isPositive);
}
Query q = em.createNativeQuery(sql, Observation.class); Query q = em.createNativeQuery(sql, Observation.class);
// Setting the parameters one by one // Setting the parameters one by one
......
...@@ -126,8 +126,8 @@ public class ObservationService { ...@@ -126,8 +126,8 @@ public class ObservationService {
@QueryParam("cropId") Integer cropId, @QueryParam("cropId") Integer cropId,
@QueryParam("cropCategoryId") List<Integer> cropCategoryId, @QueryParam("cropCategoryId") List<Integer> cropCategoryId,
@QueryParam("from") String fromStr, @QueryParam("from") String fromStr,
@QueryParam("to") String toStr @QueryParam("to") String toStr,
@QueryParam("isPositive") Boolean isPositive
) )
{ {
return Response.ok().entity(getFilteredObservationsFromBackend( return Response.ok().entity(getFilteredObservationsFromBackend(
...@@ -136,7 +136,8 @@ public class ObservationService { ...@@ -136,7 +136,8 @@ public class ObservationService {
cropId, cropId,
cropCategoryId, cropCategoryId,
fromStr, fromStr,
toStr toStr,
isPositive
)).build(); )).build();
} }
...@@ -163,7 +164,8 @@ public class ObservationService { ...@@ -163,7 +164,8 @@ public class ObservationService {
@QueryParam("from") String fromStr, @QueryParam("from") String fromStr,
@QueryParam("to") String toStr, @QueryParam("to") String toStr,
@QueryParam("userUUID") String userUUID, @QueryParam("userUUID") String userUUID,
@QueryParam("locale") String localeStr @QueryParam("locale") String localeStr,
@QueryParam("isPositive") Boolean isPositive
) )
{ {
VipsLogicUser user = (VipsLogicUser) httpServletRequest.getSession().getAttribute("user"); VipsLogicUser user = (VipsLogicUser) httpServletRequest.getSession().getAttribute("user");
...@@ -175,7 +177,7 @@ public class ObservationService { ...@@ -175,7 +177,7 @@ public class ObservationService {
ULocale locale = new ULocale(localeStr != null ? localeStr : ULocale locale = new ULocale(localeStr != null ? localeStr :
user != null ? user.getOrganizationId().getDefaultLocale() : user != null ? user.getOrganizationId().getDefaultLocale() :
userBean.getOrganization(organizationId).getDefaultLocale()); userBean.getOrganization(organizationId).getDefaultLocale());
List<ObservationListItem> observations = getFilteredObservationsFromBackend( List<ObservationListItem> observations = getFilteredObservationsFromBackend(
organizationId, organizationId,
pestId, pestId,
...@@ -183,6 +185,7 @@ public class ObservationService { ...@@ -183,6 +185,7 @@ public class ObservationService {
cropCategoryId, cropCategoryId,
fromStr, fromStr,
toStr, toStr,
isPositive,
user user
).stream().map(obs -> { ).stream().map(obs -> {
try { try {
...@@ -220,7 +223,8 @@ public class ObservationService { ...@@ -220,7 +223,8 @@ public class ObservationService {
Integer cropId, Integer cropId,
List<Integer> cropCategoryId, List<Integer> cropCategoryId,
String fromStr, String fromStr,
String toStr String toStr,
Boolean isPositive
) )
{ {
SimpleDateFormat format = new SimpleDateFormat(Globals.defaultDateFormat); SimpleDateFormat format = new SimpleDateFormat(Globals.defaultDateFormat);
...@@ -240,7 +244,8 @@ public class ObservationService { ...@@ -240,7 +244,8 @@ public class ObservationService {
cropId, cropId,
cropCategoryId, cropCategoryId,
from, from,
to to,
isPositive
); );
} }
...@@ -366,7 +371,8 @@ public class ObservationService { ...@@ -366,7 +371,8 @@ public class ObservationService {
@QueryParam("cropId") Integer cropId, @QueryParam("cropId") Integer cropId,
@QueryParam("cropCategoryId") List<Integer> cropCategoryId, @QueryParam("cropCategoryId") List<Integer> cropCategoryId,
@QueryParam("from") String fromStr, @QueryParam("from") String fromStr,
@QueryParam("to") String toStr @QueryParam("to") String toStr,
@QueryParam("to") Boolean isPositive
) )
{ {
...@@ -387,7 +393,8 @@ public class ObservationService { ...@@ -387,7 +393,8 @@ public class ObservationService {
cropId, cropId,
cropCategoryId, cropCategoryId,
from, from,
to to,
isPositive
); );
GISEntityUtil gisUtil = new GISEntityUtil(); GISEntityUtil gisUtil = new GISEntityUtil();
...@@ -758,9 +765,10 @@ public class ObservationService { ...@@ -758,9 +765,10 @@ public class ObservationService {
List<Integer> cropCategoryId, List<Integer> cropCategoryId,
String fromStr, String fromStr,
String toStr, String toStr,
Boolean isPositive,
VipsLogicUser user VipsLogicUser user
) { ) {
List<Observation> filteredObservations = this.getFilteredObservationsFromBackend(organizationId, pestId, cropId, cropCategoryId, fromStr, toStr); List<Observation> filteredObservations = this.getFilteredObservationsFromBackend(organizationId, pestId, cropId, cropCategoryId, fromStr, toStr, isPositive);
//filteredObservations.forEach(o->System.out.println(o.getObservationId())); //filteredObservations.forEach(o->System.out.println(o.getObservationId()));
// If superuser or orgadmin: Return everything, unchanged, uncensored // If superuser or orgadmin: Return everything, unchanged, uncensored
if(user != null && (user.isSuperUser() || user.isOrganizationAdmin())) if(user != null && (user.isSuperUser() || user.isOrganizationAdmin()))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment