truncate seconds
This commit is contained in:
parent
430d1c731d
commit
9ad604d012
@ -6,6 +6,7 @@ package de.bstly.we.borrow.controller.validation;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -21,6 +22,7 @@ import de.bstly.we.borrow.model.BorrowRequest;
|
||||
import de.bstly.we.borrow.model.BorrowRequestStatus;
|
||||
import de.bstly.we.borrow.model.QBorrowRequest;
|
||||
import de.bstly.we.borrow.repository.BorrowRequestRepository;
|
||||
import de.bstly.we.businesslogic.support.InstantHelper;
|
||||
|
||||
/**
|
||||
* The Class BorrowRequestValidator.
|
||||
@ -61,22 +63,30 @@ public class BorrowRequestValidator implements Validator {
|
||||
return;
|
||||
}
|
||||
|
||||
validateTime(borrowRequest, borrowItem, errors);
|
||||
}
|
||||
|
||||
public void validateTime(BorrowRequest borrowRequest, BorrowItem borrowItem, Errors errors) {
|
||||
if (borrowRequest.getStarts() == null) {
|
||||
errors.rejectValue("starts", "REQUIRED");
|
||||
return;
|
||||
}
|
||||
|
||||
if (borrowRequest.getEnds() == null) {
|
||||
errors.rejectValue("ends", "REQUIRED");
|
||||
return;
|
||||
}
|
||||
|
||||
borrowRequest
|
||||
.setStarts(InstantHelper.truncate(borrowRequest.getStarts(), ChronoUnit.SECONDS));
|
||||
borrowRequest.setEnds(InstantHelper.truncate(borrowRequest.getEnds(), ChronoUnit.SECONDS));
|
||||
|
||||
// expiry + start
|
||||
if (borrowRequest.getEnds() != null && borrowRequest.getStarts() != null) {
|
||||
if (borrowRequest.getStarts().isAfter(borrowRequest.getEnds())
|
||||
|| borrowRequestRepository.exists(qBorrowRequest.item
|
||||
.eq(borrowRequest.getItem())
|
||||
|| borrowRequestRepository.exists(qBorrowRequest.item.eq(borrowRequest.getItem())
|
||||
// exlude self
|
||||
.and(qBorrowRequest.id.ne(
|
||||
borrowRequest.getId() == null ? -1L : borrowRequest.getId()))
|
||||
.and(qBorrowRequest.id
|
||||
.ne(borrowRequest.getId() == null ? -1L : borrowRequest.getId()))
|
||||
// accepted
|
||||
.and(qBorrowRequest.status.eq(BorrowRequestStatus.ACCEPTED))
|
||||
// expires after start
|
||||
@ -131,18 +141,14 @@ public class BorrowRequestValidator implements Validator {
|
||||
if (borrowRequest.getStarts().atZone(ZoneOffset.UTC).getDayOfWeek()
|
||||
.compareTo(borrowItemPeriodSlot.getStartDay()) >= 0
|
||||
&& LocalTime
|
||||
.ofInstant(borrowRequest.getStarts(),
|
||||
ZoneOffset.UTC)
|
||||
.compareTo(
|
||||
borrowItemPeriodSlot.getStartTime()) >= 0) {
|
||||
.ofInstant(borrowRequest.getStarts(), ZoneOffset.UTC)
|
||||
.compareTo(borrowItemPeriodSlot.getStartTime()) >= 0) {
|
||||
validStart = true;
|
||||
}
|
||||
if (borrowRequest.getEnds().atZone(ZoneOffset.UTC).getDayOfWeek()
|
||||
.compareTo(borrowItemPeriodSlot.getEndDay()) <= 0
|
||||
&& LocalTime
|
||||
.ofInstant(borrowRequest.getEnds(), ZoneOffset.UTC)
|
||||
.compareTo(
|
||||
borrowItemPeriodSlot.getEndTime()) <= 0) {
|
||||
&& LocalTime.ofInstant(borrowRequest.getEnds(), ZoneOffset.UTC)
|
||||
.compareTo(borrowItemPeriodSlot.getEndTime()) <= 0) {
|
||||
validEnd = true;
|
||||
}
|
||||
if (validStart && validEnd) {
|
||||
@ -168,5 +174,3 @@ public class BorrowRequestValidator implements Validator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
package de.bstly.we.jitsi.controller.validation;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -13,6 +14,7 @@ import org.springframework.validation.Validator;
|
||||
|
||||
import de.bstly.we.businesslogic.SystemPropertyManager;
|
||||
import de.bstly.we.businesslogic.UserManager;
|
||||
import de.bstly.we.businesslogic.support.InstantHelper;
|
||||
import de.bstly.we.jitsi.model.JitsiRoom;
|
||||
import de.bstly.we.jitsi.model.QJitsiRoom;
|
||||
import de.bstly.we.jitsi.repository.JitsiRoomRepository;
|
||||
@ -117,6 +119,20 @@ public class JitsiRoomValidator implements Validator {
|
||||
*/
|
||||
public void validateExpiry(JitsiRoom jitsiRoom, Errors errors) {
|
||||
|
||||
if (jitsiRoom.getStarts() != null) {
|
||||
jitsiRoom.setStarts(InstantHelper.truncate(jitsiRoom.getStarts(), ChronoUnit.SECONDS));
|
||||
}
|
||||
|
||||
if (jitsiRoom.getModerationStarts() != null) {
|
||||
jitsiRoom.setModerationStarts(
|
||||
InstantHelper.truncate(jitsiRoom.getModerationStarts(), ChronoUnit.SECONDS));
|
||||
}
|
||||
|
||||
if (jitsiRoom.getExpires() != null) {
|
||||
jitsiRoom
|
||||
.setExpires(InstantHelper.truncate(jitsiRoom.getExpires(), ChronoUnit.SECONDS));
|
||||
}
|
||||
|
||||
// no moderation start without start
|
||||
if (jitsiRoom.getStarts() == null && jitsiRoom.getModerationStarts() != null) {
|
||||
errors.rejectValue("moderationStarts", "NOT_VALID");
|
||||
|
@ -16,6 +16,7 @@ import com.google.common.collect.Lists;
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
|
||||
import de.bstly.we.businesslogic.SystemPropertyManager;
|
||||
import de.bstly.we.businesslogic.support.InstantHelper;
|
||||
import de.bstly.we.partey.timeslot.businesslogic.TimeslotManager;
|
||||
import de.bstly.we.partey.timeslot.model.QTimeslot;
|
||||
import de.bstly.we.partey.timeslot.model.Timeslot;
|
||||
@ -65,13 +66,17 @@ public class TimeslotValidator implements Validator {
|
||||
public void validateTime(Timeslot timeslot, Errors errors) {
|
||||
if (timeslot.getStarts() == null) {
|
||||
errors.rejectValue("starts", "REQUIRED");
|
||||
return;
|
||||
}
|
||||
|
||||
if (timeslot.getEnds() == null) {
|
||||
errors.rejectValue("ends", "REQUIRED");
|
||||
return;
|
||||
}
|
||||
|
||||
if (timeslot.getStarts() != null && timeslot.getEnds() != null) {
|
||||
timeslot.setStarts(InstantHelper.truncate(timeslot.getStarts(), ChronoUnit.SECONDS));
|
||||
timeslot.setEnds(InstantHelper.truncate(timeslot.getEnds(), ChronoUnit.SECONDS));
|
||||
|
||||
if (timeslot.getStarts().isAfter(timeslot.getStarts())) {
|
||||
errors.rejectValue("starts", "NOT_VALID");
|
||||
errors.rejectValue("ends", "NOT_VALID");
|
||||
@ -96,15 +101,15 @@ public class TimeslotValidator implements Validator {
|
||||
|
||||
// ends after start
|
||||
timeQuery
|
||||
.and(qTimeslot.ends.after(timeslot.getStarts().minus(
|
||||
systemPropertyManager.getLong(TimeslotManager.TIMESLOT_TOLERANCE,
|
||||
.and(qTimeslot.ends.after(timeslot.getStarts()
|
||||
.minus(systemPropertyManager.getLong(TimeslotManager.TIMESLOT_TOLERANCE,
|
||||
TimeslotManager.TIMESLOT_TOLERANCE_DEFAULT),
|
||||
ChronoUnit.MINUTES)));
|
||||
|
||||
// starts before end
|
||||
timeQuery
|
||||
.and(qTimeslot.starts.before(timeslot.getEnds().plus(
|
||||
systemPropertyManager.getLong(TimeslotManager.TIMESLOT_TOLERANCE,
|
||||
.and(qTimeslot.starts.before(timeslot.getEnds()
|
||||
.plus(systemPropertyManager.getLong(TimeslotManager.TIMESLOT_TOLERANCE,
|
||||
TimeslotManager.TIMESLOT_TOLERANCE_DEFAULT),
|
||||
ChronoUnit.MINUTES)));
|
||||
|
||||
@ -116,8 +121,8 @@ public class TimeslotValidator implements Validator {
|
||||
errors.rejectValue("starts", "ALREADY_EXISTS");
|
||||
errors.rejectValue("ends", "ALREADY_EXISTS");
|
||||
} else if (((timeslot.getEnds().getEpochSecond()
|
||||
- timeslot.getStarts().getEpochSecond()) / 60) > systemPropertyManager
|
||||
.getLong(TimeslotManager.TIMESLOT_MINUTES,
|
||||
- timeslot.getStarts().getEpochSecond()) / 60) > systemPropertyManager.getLong(
|
||||
TimeslotManager.TIMESLOT_MINUTES,
|
||||
TimeslotManager.TIMESLOT_MINUTES_DEFAULT)) {
|
||||
errors.rejectValue("ends", "TOO_LONG",
|
||||
String.valueOf(
|
||||
@ -126,7 +131,6 @@ public class TimeslotValidator implements Validator {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate type.
|
||||
|
Loading…
Reference in New Issue
Block a user