-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from UW-Madison-DoIT/service-one-message
feat: add single message path
- Loading branch information
Showing
16 changed files
with
913 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/edu/wisc/my/messages/exception/ExpiredMessageException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package edu.wisc.my.messages.exception; | ||
|
||
import edu.wisc.my.messages.model.Message; | ||
import java.time.LocalDateTime; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(value = HttpStatus.FORBIDDEN, reason = "Requested message is expired.") | ||
public class ExpiredMessageException | ||
extends ForbiddenMessageException { | ||
|
||
private final Message expiredMessage; | ||
|
||
/** | ||
* Time of consideration. The frame of reference for considering the message expired. Typically, | ||
* this is "now". | ||
*/ | ||
private final LocalDateTime asOfWhen; | ||
|
||
public ExpiredMessageException(Message messageWithRequestedId, LocalDateTime asOfWhen) { | ||
super("Message " + | ||
((messageWithRequestedId == null) ? | ||
"" : | ||
(" with id [" + messageWithRequestedId.getId() + "] ")) | ||
+ "is expired as of " + asOfWhen); | ||
this.expiredMessage = messageWithRequestedId; | ||
this.asOfWhen = asOfWhen; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/edu/wisc/my/messages/exception/ForbiddenMessageException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package edu.wisc.my.messages.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
/** | ||
* Message representing that access to a requested message is forbidden. Sub-classes represent | ||
* specific reasons why access might be forbidden. | ||
*/ | ||
@ResponseStatus(value = HttpStatus.FORBIDDEN, reason = "Access denied to requested message.") | ||
public class ForbiddenMessageException | ||
extends Exception { | ||
|
||
public ForbiddenMessageException(String message) { | ||
super(message); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/edu/wisc/my/messages/exception/MessageNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package edu.wisc.my.messages.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
/** | ||
* Represents case where requested message was not found. | ||
*/ | ||
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Did not find requested message.") | ||
public class MessageNotFoundException | ||
extends Exception { | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/edu/wisc/my/messages/exception/PrematureMessageException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package edu.wisc.my.messages.exception; | ||
|
||
import edu.wisc.my.messages.model.Message; | ||
import java.time.LocalDateTime; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
/** | ||
* Thrown on un-privileged request for a message that has not yet gone live. | ||
*/ | ||
@ResponseStatus(value = HttpStatus.FORBIDDEN, reason = "Requested message is premature.") | ||
public class PrematureMessageException | ||
extends ForbiddenMessageException { | ||
|
||
private Message prematureMessage; | ||
private LocalDateTime asOfWhen; | ||
|
||
public PrematureMessageException(Message prematureMessage, LocalDateTime asOfWhen) { | ||
super("Message with id " + | ||
((null == prematureMessage) ? | ||
"" : | ||
prematureMessage.getId() + " ") | ||
+ "is premature as of " + asOfWhen); | ||
this.prematureMessage = prematureMessage; | ||
this.asOfWhen = asOfWhen; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/edu/wisc/my/messages/exception/UserNotInMessageAudienceException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package edu.wisc.my.messages.exception; | ||
|
||
import edu.wisc.my.messages.model.Message; | ||
import edu.wisc.my.messages.model.User; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(value = HttpStatus.FORBIDDEN, reason = "Requesting user not in audience for requested message") | ||
public class UserNotInMessageAudienceException extends ForbiddenMessageException { | ||
|
||
private final Message messageNotForUser; | ||
private final User userNotInMessageAudience; | ||
|
||
public UserNotInMessageAudienceException(Message message, User user) { | ||
super("User not within audience of requested message"); | ||
this.messageNotForUser = message; | ||
this.userNotInMessageAudience = user; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/edu/wisc/my/messages/service/MessageIdPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package edu.wisc.my.messages.service; | ||
|
||
import edu.wisc.my.messages.model.Message; | ||
import java.util.Objects; | ||
import java.util.function.Predicate; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Predicate that is true where the tested message has a (potentially null) ID matching that | ||
* (potentially null) ID given at construction. | ||
*/ | ||
public class MessageIdPredicate | ||
implements Predicate<Message> { | ||
|
||
private final String idToMatch; | ||
protected Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
/** | ||
* Instantiate a MessageIdPredicate that tests for a specific ID. | ||
* | ||
* @param idToMatch potentially null message identifier to look for | ||
*/ | ||
public MessageIdPredicate(String idToMatch) { | ||
this.idToMatch = idToMatch; | ||
} | ||
|
||
@Override | ||
public boolean test(Message message) { | ||
boolean result = (null != message | ||
&& Objects.equals(this.idToMatch, message.getId())); | ||
logger.trace("{} result testing for id {} in message {}", result, idToMatch, message); | ||
return result; | ||
} | ||
} |
Oops, something went wrong.