From 3bcc0efe0d005f4762c0f6b7fe4c2b4fbcf3b41c Mon Sep 17 00:00:00 2001 From: _Bastler Date: Wed, 17 Nov 2021 19:35:43 +0100 Subject: [PATCH] fix for Partey, new streaming preparations --- .../partey/api/controller/RoomController.java | 15 +++-- .../validation/TimeslotValidator.java | 59 +++++++++++++++---- .../we/partey/timeslot/model/Timeslot.java | 16 +++++ .../partey/timeslot/model/TimeslotType.java | 2 +- pom.xml | 2 +- 5 files changed, 75 insertions(+), 19 deletions(-) diff --git a/partey/src/main/java/de/bstly/we/partey/api/controller/RoomController.java b/partey/src/main/java/de/bstly/we/partey/api/controller/RoomController.java index 43babb0..c9a6a9b 100644 --- a/partey/src/main/java/de/bstly/we/partey/api/controller/RoomController.java +++ b/partey/src/main/java/de/bstly/we/partey/api/controller/RoomController.java @@ -57,21 +57,24 @@ public class RoomController extends DebugLogger { * Access. * * @param userIdentifier the user identifier - * @param roomId the room id - * @param request the request + * @param roomId the room id + * @param request the request * @return the member data */ @GetMapping("/access") public MemberData access(@RequestParam("userIdentifier") String userIdentifier, - @RequestParam("roomId") String roomId, HttpServletRequest request) { + @RequestParam("roomId") Optional roomId, + @RequestParam("ipAddress") Optional ipAddress, HttpServletRequest request) { parteyApiAuthentication.authenticateRequest(request); debugPrintRequest(request); - Room room = parteyMapManager.parseRoom(roomId, request); + if (roomId.isPresent()) { + Room room = parteyMapManager.parseRoom(roomId.get(), request); - if (!worldMapCache.contains(room.getUrl())) { - worldMapCache.add(room.getUrl()); + if (!worldMapCache.contains(room.getUrl())) { + worldMapCache.add(room.getUrl()); + } } MemberData memberData = new MemberData(); diff --git a/partey/src/main/java/de/bstly/we/partey/timeslot/controller/validation/TimeslotValidator.java b/partey/src/main/java/de/bstly/we/partey/timeslot/controller/validation/TimeslotValidator.java index 7919238..13a479e 100644 --- a/partey/src/main/java/de/bstly/we/partey/timeslot/controller/validation/TimeslotValidator.java +++ b/partey/src/main/java/de/bstly/we/partey/timeslot/controller/validation/TimeslotValidator.java @@ -12,12 +12,14 @@ import org.springframework.util.StringUtils; import org.springframework.validation.Errors; import org.springframework.validation.Validator; +import com.google.common.collect.Lists; import com.querydsl.core.BooleanBuilder; import de.bstly.we.businesslogic.SystemPropertyManager; import de.bstly.we.partey.timeslot.businesslogic.TimeslotManager; import de.bstly.we.partey.timeslot.model.QTimeslot; import de.bstly.we.partey.timeslot.model.Timeslot; +import de.bstly.we.partey.timeslot.model.TimeslotType; import de.bstly.we.partey.timeslot.repository.TimeslotRepository; /** @@ -34,7 +36,6 @@ public class TimeslotValidator implements Validator { private SystemPropertyManager systemPropertyManager; private QTimeslot qTimeslot = QTimeslot.timeslot; - /* * @see org.springframework.validation.Validator#supports(java.lang.Class) */ @@ -43,9 +44,9 @@ public class TimeslotValidator implements Validator { return clazz.isAssignableFrom(Timeslot.class); } - /* - * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors) + * @see org.springframework.validation.Validator#validate(java.lang.Object, + * org.springframework.validation.Errors) */ @Override public void validate(Object target, Errors errors) { @@ -59,7 +60,7 @@ public class TimeslotValidator implements Validator { * Validate time. * * @param timeslot the timeslot - * @param errors the errors + * @param errors the errors */ public void validateTime(Timeslot timeslot, Errors errors) { if (timeslot.getStarts() == null) { @@ -80,6 +81,19 @@ public class TimeslotValidator implements Validator { // same type timeQuery.and(qTimeslot.type.eq(timeslot.getType())); + switch (timeslot.getType()) { + case AUDIO: + case AUDIO_STREAM: + timeQuery.and(qTimeslot.type + .in(Lists.newArrayList(TimeslotType.AUDIO, TimeslotType.AUDIO_STREAM))); + break; + case VIDEO: + case VIDEO_STREAM: + timeQuery.and(qTimeslot.type + .in(Lists.newArrayList(TimeslotType.VIDEO, TimeslotType.VIDEO_STREAM))); + break; + } + // ends after start timeQuery .and(qTimeslot.ends.after(timeslot.getStarts().minus( @@ -118,7 +132,7 @@ public class TimeslotValidator implements Validator { * Validate type. * * @param timeslot the timeslot - * @param errors the errors + * @param errors the errors */ public void validateType(Timeslot timeslot, Errors errors) { if (timeslot.getId() != null && timeslotRepository.existsById(timeslot.getId())) { @@ -128,10 +142,16 @@ public class TimeslotValidator implements Validator { switch (timeslot.getType()) { case AUDIO: - validateTypeAudio(timeslot, errors); + validateShare(timeslot, errors); break; case VIDEO: - validateTypeVideo(timeslot, errors); + validateShare(timeslot, errors); + break; + case AUDIO_STREAM: + validateTypeAudioStream(timeslot, errors); + break; + case VIDEO_STREAM: + validateTypeVideoStream(timeslot, errors); break; } @@ -141,10 +161,26 @@ public class TimeslotValidator implements Validator { * Validate type audio. * * @param timeslot the timeslot - * @param errors the errors + * @param errors the errors */ - public void validateTypeAudio(Timeslot timeslot, Errors errors) { + public void validateShare(Timeslot timeslot, Errors errors) { timeslot.setStream(null); + timeslot.setSecret(null); + + if (!StringUtils.hasText(timeslot.getShare())) { + errors.rejectValue("share", "REQUIRED"); + } + } + + /** + * Validate type audio. + * + * @param timeslot the timeslot + * @param errors the errors + */ + public void validateTypeAudioStream(Timeslot timeslot, Errors errors) { + timeslot.setStream(null); + timeslot.setShare(null); if (timeslot.getId() != null && timeslotRepository.existsById(timeslot.getId())) { Timeslot existing = timeslotRepository.findById(timeslot.getId()).get(); timeslot.setSecret(existing.getSecret()); @@ -159,10 +195,11 @@ public class TimeslotValidator implements Validator { * Validate type video. * * @param timeslot the timeslot - * @param errors the errors + * @param errors the errors */ - public void validateTypeVideo(Timeslot timeslot, Errors errors) { + public void validateTypeVideoStream(Timeslot timeslot, Errors errors) { timeslot.setSecret(null); + timeslot.setShare(null); if (!StringUtils.hasText(timeslot.getStream())) { errors.rejectValue("stream", "REQUIRED"); } diff --git a/partey/src/main/java/de/bstly/we/partey/timeslot/model/Timeslot.java b/partey/src/main/java/de/bstly/we/partey/timeslot/model/Timeslot.java index 984c99b..e3582d1 100644 --- a/partey/src/main/java/de/bstly/we/partey/timeslot/model/Timeslot.java +++ b/partey/src/main/java/de/bstly/we/partey/timeslot/model/Timeslot.java @@ -46,6 +46,8 @@ public class Timeslot implements UserData { @Column(name = "description", nullable = true) @Lob private String description; + @Column(name = "share", nullable = true) + private String share; @Column(name = "stream", nullable = true) private String stream; @Column(name = "secret", nullable = true) @@ -199,6 +201,20 @@ public class Timeslot implements UserData { this.description = description; } + /** + * @return the share + */ + public String getShare() { + return share; + } + + /** + * @param share the share to set + */ + public void setShare(String share) { + this.share = share; + } + /** * Gets the stream. * diff --git a/partey/src/main/java/de/bstly/we/partey/timeslot/model/TimeslotType.java b/partey/src/main/java/de/bstly/we/partey/timeslot/model/TimeslotType.java index 35f4d53..013478a 100644 --- a/partey/src/main/java/de/bstly/we/partey/timeslot/model/TimeslotType.java +++ b/partey/src/main/java/de/bstly/we/partey/timeslot/model/TimeslotType.java @@ -7,5 +7,5 @@ package de.bstly.we.partey.timeslot.model; * The Enum TimeslotType. */ public enum TimeslotType { - VIDEO, AUDIO + VIDEO, AUDIO, VIDEO_STREAM, AUDIO_STREAM } diff --git a/pom.xml b/pom.xml index cf68a00..dcdbd38 100755 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ UTF-8 11 - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT