Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
badfad6b
by tchemit at 2019-05-20T11:19:29Z
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:
| ... | ... | @@ -40,6 +40,7 @@ import java.util.Collections; |
| 40 | 40 |
import java.util.Date;
|
| 41 | 41 |
import java.util.LinkedHashSet;
|
| 42 | 42 |
import java.util.List;
|
| 43 |
+import java.util.Objects;
|
|
| 43 | 44 |
import java.util.stream.Collectors;
|
| 44 | 45 |
|
| 45 | 46 |
public class TripLonglineTopiaDao extends AbstractTripLonglineTopiaDao<TripLongline> {
|
| ... | ... | @@ -152,13 +153,13 @@ public class TripLonglineTopiaDao extends AbstractTripLonglineTopiaDao<TripLongl |
| 152 | 153 |
}
|
| 153 | 154 |
return this.
|
| 154 | 155 |
<TripLongline>stream("From TripLonglineImpl Where vessel.id = :vesselId " +
|
| 155 |
- "And (( startDate <= :startDate And endDate <= :endDate ) " +
|
|
| 156 |
- " Or ( startDate >= :startDate And :endDate <= endDate )) " +
|
|
| 156 |
+ "And (( :startDate <= endDate And :endDate >= endDate ) " +
|
|
| 157 |
+ " Or ( :endDate <= startDate And :endDate >= startDate )) " +
|
|
| 157 | 158 |
"Order By startDate, endDate", ImmutableMap.of(
|
| 158 | 159 |
"vesselId", vesselId,
|
| 159 | 160 |
"startDate", startDate,
|
| 160 | 161 |
"endDate", endDate))
|
| 161 |
- .filter(t -> id == null || !id.equals(t.getTopiaId()))
|
|
| 162 |
+ .filter(t -> !Objects.equals(id ,t.getTopiaId()))
|
|
| 162 | 163 |
.collect(Collectors.toList());
|
| 163 | 164 |
}
|
| 164 | 165 |
private static class TripMapActivityObsPointQuery extends TopiaSqlQuery<List<TripMapPoint>> {
|
| ... | ... | @@ -38,6 +38,7 @@ import java.util.Collections; |
| 38 | 38 |
import java.util.Date;
|
| 39 | 39 |
import java.util.LinkedHashSet;
|
| 40 | 40 |
import java.util.List;
|
| 41 |
+import java.util.Objects;
|
|
| 41 | 42 |
import java.util.stream.Collectors;
|
| 42 | 43 |
|
| 43 | 44 |
/**
|
| ... | ... | @@ -91,13 +92,13 @@ public class TripSeineTopiaDao extends AbstractTripSeineTopiaDao<TripSeine> { |
| 91 | 92 |
}
|
| 92 | 93 |
return this.
|
| 93 | 94 |
<TripSeine>stream("From TripSeineImpl Where vessel.id = :vesselId " +
|
| 94 |
- "And (( startDate <= :startDate And endDate <= :endDate ) " +
|
|
| 95 |
- " Or ( startDate >= :startDate And :endDate <= endDate )) " +
|
|
| 95 |
+ "And (( :startDate <= endDate And :endDate >= endDate ) " +
|
|
| 96 |
+ " Or ( :endDate <= startDate And :endDate >= startDate )) " +
|
|
| 96 | 97 |
"Order By startDate, endDate", ImmutableMap.of(
|
| 97 | 98 |
"vesselId", vesselId,
|
| 98 | 99 |
"startDate", startDate,
|
| 99 | 100 |
"endDate", endDate))
|
| 100 |
- .filter(t -> id == null || !id.equals(t.getTopiaId()))
|
|
| 101 |
+ .filter(t -> !Objects.equals(id , t.getTopiaId()))
|
|
| 101 | 102 |
.collect(Collectors.toList());
|
| 102 | 103 |
}
|
| 103 | 104 |
|
| ... | ... | @@ -24,12 +24,12 @@ package fr.ird.observe.validation.validators; |
| 24 | 24 |
|
| 25 | 25 |
import com.opensymphony.xwork2.validator.ValidationException;
|
| 26 | 26 |
import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
|
| 27 |
-import fr.ird.observe.dto.data.TripDto;
|
|
| 28 | 27 |
import fr.ird.observe.dto.data.TripReference;
|
| 29 |
-import fr.ird.observe.dto.data.ll.common.TripLonglineDto;
|
|
| 30 |
-import fr.ird.observe.dto.data.ps.common.TripSeineDto;
|
|
| 28 |
+import fr.ird.observe.dto.referential.common.VesselReference;
|
|
| 31 | 29 |
import fr.ird.observe.services.service.data.TripService;
|
| 32 | 30 |
|
| 31 |
+import java.util.Date;
|
|
| 32 |
+import java.util.Objects;
|
|
| 33 | 33 |
import java.util.Set;
|
| 34 | 34 |
|
| 35 | 35 |
import static io.ultreia.java4all.i18n.I18n.n;
|
| ... | ... | @@ -43,6 +43,8 @@ import static io.ultreia.java4all.i18n.I18n.n; |
| 43 | 43 |
*/
|
| 44 | 44 |
public class TripVesselDtoValidator extends FieldValidatorSupport {
|
| 45 | 45 |
|
| 46 |
+ private String serviceName;
|
|
| 47 |
+ |
|
| 46 | 48 |
public TripVesselDtoValidator() {
|
| 47 | 49 |
setDefaultMessage(n("observe.validation.trip.vessel.overlap"));
|
| 48 | 50 |
}
|
| ... | ... | @@ -57,29 +59,27 @@ public class TripVesselDtoValidator extends FieldValidatorSupport { |
| 57 | 59 |
return "vessel";
|
| 58 | 60 |
}
|
| 59 | 61 |
|
| 62 |
+ public void setServiceName(String serviceName) {
|
|
| 63 |
+ this.serviceName = serviceName;
|
|
| 64 |
+ }
|
|
| 65 |
+ |
|
| 60 | 66 |
@Override
|
| 61 | 67 |
public void validate(Object object) throws ValidationException {
|
| 62 |
- |
|
| 63 |
- TripSeineDto currentTripSeine = (TripSeineDto) getFieldValue("currentTripSeine", object);
|
|
| 64 |
- if (currentTripSeine != null) {
|
|
| 65 |
- validate(object, "servicesProvider.tripSeineService", currentTripSeine);
|
|
| 66 |
- return;
|
|
| 67 |
- }
|
|
| 68 |
- TripLonglineDto currentTripLongline = (TripLonglineDto) getFieldValue("currentTripLongline", object);
|
|
| 69 |
- if (currentTripLongline != null) {
|
|
| 70 |
- validate(object, "servicesProvider.tripLonglineService", currentTripLongline);
|
|
| 71 |
- return;
|
|
| 72 |
- }
|
|
| 73 |
- throw new IllegalStateException("Could not find any selected trip");
|
|
| 68 |
+ Objects.requireNonNull(serviceName,"Service name can not be null");
|
|
| 69 |
+ VesselReference vessel = (VesselReference) getFieldValue("vessel", object);
|
|
| 70 |
+ Date startDate = (Date) getFieldValue("startDate", object);
|
|
| 71 |
+ Date endDate = (Date) getFieldValue("endDate", object);
|
|
| 72 |
+ String id = (String) getFieldValue("id", object);
|
|
| 73 |
+ validate(object, id, vessel, startDate, endDate);
|
|
| 74 | 74 |
}
|
| 75 | 75 |
|
| 76 |
- private void validate(Object object, String tripServiceName, TripDto trip) throws ValidationException {
|
|
| 76 |
+ private void validate(Object object, String id, VesselReference vessel, Date startDate, Date endDate) throws ValidationException {
|
|
| 77 | 77 |
|
| 78 |
- TripService tripService = (TripService) getFieldValue(tripServiceName, object);
|
|
| 79 |
- Set<? extends TripReference> matchingTrips = tripService.getMatchingTripsVesselWithinDateRange(trip.getId(),
|
|
| 80 |
- trip.getVessel().getVesselTypeId(),
|
|
| 81 |
- trip.getStartDate(),
|
|
| 82 |
- trip.getEndDate());
|
|
| 78 |
+ TripService tripService = (TripService) getFieldValue(serviceName, object);
|
|
| 79 |
+ Set<? extends TripReference> matchingTrips = tripService.getMatchingTripsVesselWithinDateRange(id,
|
|
| 80 |
+ vessel.getId(),
|
|
| 81 |
+ startDate,
|
|
| 82 |
+ endDate);
|
|
| 83 | 83 |
|
| 84 | 84 |
if (matchingTrips.size() > 0) {
|
| 85 | 85 |
addFieldError(getFieldName(), object);
|
| ... | ... | @@ -39,6 +39,7 @@ |
| 39 | 39 |
<message/>
|
| 40 | 40 |
</field-validator>
|
| 41 | 41 |
<field-validator type="tripVessel" short-circuit="true">
|
| 42 |
+ <param name="serviceName">servicesProvider.tripLonglineService</param>
|
|
| 42 | 43 |
<message/>
|
| 43 | 44 |
</field-validator>
|
| 44 | 45 |
</field>
|
| ... | ... | @@ -41,6 +41,7 @@ |
| 41 | 41 |
<message/>
|
| 42 | 42 |
</field-validator>
|
| 43 | 43 |
<field-validator type="tripVessel" short-circuit="true">
|
| 44 |
+ <param name="serviceName">servicesProvider.tripLonglineService</param>
|
|
| 44 | 45 |
<message/>
|
| 45 | 46 |
</field-validator>
|
| 46 | 47 |
</field>
|
| ... | ... | @@ -36,6 +36,7 @@ |
| 36 | 36 |
<message/>
|
| 37 | 37 |
</field-validator>
|
| 38 | 38 |
<field-validator type="tripVessel" short-circuit="true">
|
| 39 |
+ <param name="serviceName">servicesProvider.tripSeineService</param>
|
|
| 39 | 40 |
<message/>
|
| 40 | 41 |
</field-validator>
|
| 41 | 42 |
</field>
|
| ... | ... | @@ -35,6 +35,7 @@ |
| 35 | 35 |
<message/>
|
| 36 | 36 |
</field-validator>
|
| 37 | 37 |
<field-validator type="tripVessel" short-circuit="true">
|
| 38 |
+ <param name="serviceName">servicesProvider.tripSeineService</param>
|
|
| 38 | 39 |
<message/>
|
| 39 | 40 |
</field-validator>
|
| 40 | 41 |
</field>
|