Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: badfad6b by tchemit at 2019-05-20T11:19:29Z Fix trip vessel validator - - - - - 7 changed files: - persistence/src/main/java/fr/ird/observe/entities/data/ll/common/TripLonglineTopiaDao.java - persistence/src/main/java/fr/ird/observe/entities/data/ps/common/TripSeineTopiaDao.java - services-validation/src/main/java/fr/ird/observe/validation/validators/TripVesselDtoValidator.java - validation/src/main/resources/fr/ird/observe/dto/data/ll/common/TripLonglineDto-create-error-validation.xml - validation/src/main/resources/fr/ird/observe/dto/data/ll/common/TripLonglineDto-update-error-validation.xml - validation/src/main/resources/fr/ird/observe/dto/data/ps/common/TripSeineDto-create-error-validation.xml - validation/src/main/resources/fr/ird/observe/dto/data/ps/common/TripSeineDto-update-error-validation.xml Changes: ===================================== persistence/src/main/java/fr/ird/observe/entities/data/ll/common/TripLonglineTopiaDao.java ===================================== @@ -40,6 +40,7 @@ import java.util.Collections; import java.util.Date; import java.util.LinkedHashSet; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; public class TripLonglineTopiaDao extends AbstractTripLonglineTopiaDao<TripLongline> { @@ -152,13 +153,13 @@ public class TripLonglineTopiaDao extends AbstractTripLonglineTopiaDao<TripLongl } return this. <TripLongline>stream("From TripLonglineImpl Where vessel.id = :vesselId " + - "And (( startDate <= :startDate And endDate <= :endDate ) " + - " Or ( startDate >= :startDate And :endDate <= endDate )) " + + "And (( :startDate <= endDate And :endDate >= endDate ) " + + " Or ( :endDate <= startDate And :endDate >= startDate )) " + "Order By startDate, endDate", ImmutableMap.of( "vesselId", vesselId, "startDate", startDate, "endDate", endDate)) - .filter(t -> id == null || !id.equals(t.getTopiaId())) + .filter(t -> !Objects.equals(id ,t.getTopiaId())) .collect(Collectors.toList()); } private static class TripMapActivityObsPointQuery extends TopiaSqlQuery<List<TripMapPoint>> { ===================================== persistence/src/main/java/fr/ird/observe/entities/data/ps/common/TripSeineTopiaDao.java ===================================== @@ -38,6 +38,7 @@ import java.util.Collections; import java.util.Date; import java.util.LinkedHashSet; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -91,13 +92,13 @@ public class TripSeineTopiaDao extends AbstractTripSeineTopiaDao<TripSeine> { } return this. <TripSeine>stream("From TripSeineImpl Where vessel.id = :vesselId " + - "And (( startDate <= :startDate And endDate <= :endDate ) " + - " Or ( startDate >= :startDate And :endDate <= endDate )) " + + "And (( :startDate <= endDate And :endDate >= endDate ) " + + " Or ( :endDate <= startDate And :endDate >= startDate )) " + "Order By startDate, endDate", ImmutableMap.of( "vesselId", vesselId, "startDate", startDate, "endDate", endDate)) - .filter(t -> id == null || !id.equals(t.getTopiaId())) + .filter(t -> !Objects.equals(id , t.getTopiaId())) .collect(Collectors.toList()); } ===================================== services-validation/src/main/java/fr/ird/observe/validation/validators/TripVesselDtoValidator.java ===================================== @@ -24,12 +24,12 @@ package fr.ird.observe.validation.validators; import com.opensymphony.xwork2.validator.ValidationException; import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; -import fr.ird.observe.dto.data.TripDto; import fr.ird.observe.dto.data.TripReference; -import fr.ird.observe.dto.data.ll.common.TripLonglineDto; -import fr.ird.observe.dto.data.ps.common.TripSeineDto; +import fr.ird.observe.dto.referential.common.VesselReference; import fr.ird.observe.services.service.data.TripService; +import java.util.Date; +import java.util.Objects; import java.util.Set; import static io.ultreia.java4all.i18n.I18n.n; @@ -43,6 +43,8 @@ import static io.ultreia.java4all.i18n.I18n.n; */ public class TripVesselDtoValidator extends FieldValidatorSupport { + private String serviceName; + public TripVesselDtoValidator() { setDefaultMessage(n("observe.validation.trip.vessel.overlap")); } @@ -57,29 +59,27 @@ public class TripVesselDtoValidator extends FieldValidatorSupport { return "vessel"; } + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + @Override public void validate(Object object) throws ValidationException { - - TripSeineDto currentTripSeine = (TripSeineDto) getFieldValue("currentTripSeine", object); - if (currentTripSeine != null) { - validate(object, "servicesProvider.tripSeineService", currentTripSeine); - return; - } - TripLonglineDto currentTripLongline = (TripLonglineDto) getFieldValue("currentTripLongline", object); - if (currentTripLongline != null) { - validate(object, "servicesProvider.tripLonglineService", currentTripLongline); - return; - } - throw new IllegalStateException("Could not find any selected trip"); + Objects.requireNonNull(serviceName,"Service name can not be null"); + VesselReference vessel = (VesselReference) getFieldValue("vessel", object); + Date startDate = (Date) getFieldValue("startDate", object); + Date endDate = (Date) getFieldValue("endDate", object); + String id = (String) getFieldValue("id", object); + validate(object, id, vessel, startDate, endDate); } - private void validate(Object object, String tripServiceName, TripDto trip) throws ValidationException { + private void validate(Object object, String id, VesselReference vessel, Date startDate, Date endDate) throws ValidationException { - TripService tripService = (TripService) getFieldValue(tripServiceName, object); - Set<? extends TripReference> matchingTrips = tripService.getMatchingTripsVesselWithinDateRange(trip.getId(), - trip.getVessel().getVesselTypeId(), - trip.getStartDate(), - trip.getEndDate()); + TripService tripService = (TripService) getFieldValue(serviceName, object); + Set<? extends TripReference> matchingTrips = tripService.getMatchingTripsVesselWithinDateRange(id, + vessel.getId(), + startDate, + endDate); if (matchingTrips.size() > 0) { addFieldError(getFieldName(), object); ===================================== validation/src/main/resources/fr/ird/observe/dto/data/ll/common/TripLonglineDto-create-error-validation.xml ===================================== @@ -39,6 +39,7 @@ <message/> </field-validator> <field-validator type="tripVessel" short-circuit="true"> + <param name="serviceName">servicesProvider.tripLonglineService</param> <message/> </field-validator> </field> ===================================== validation/src/main/resources/fr/ird/observe/dto/data/ll/common/TripLonglineDto-update-error-validation.xml ===================================== @@ -41,6 +41,7 @@ <message/> </field-validator> <field-validator type="tripVessel" short-circuit="true"> + <param name="serviceName">servicesProvider.tripLonglineService</param> <message/> </field-validator> </field> ===================================== validation/src/main/resources/fr/ird/observe/dto/data/ps/common/TripSeineDto-create-error-validation.xml ===================================== @@ -36,6 +36,7 @@ <message/> </field-validator> <field-validator type="tripVessel" short-circuit="true"> + <param name="serviceName">servicesProvider.tripSeineService</param> <message/> </field-validator> </field> ===================================== validation/src/main/resources/fr/ird/observe/dto/data/ps/common/TripSeineDto-update-error-validation.xml ===================================== @@ -35,6 +35,7 @@ <message/> </field-validator> <field-validator type="tripVessel" short-circuit="true"> + <param name="serviceName">servicesProvider.tripSeineService</param> <message/> </field-validator> </field> View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/badfad6bfd0f882e908c29c53578... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/badfad6bfd0f882e908c29c53578... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT