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