chibenwa commented on a change in pull request #681:
URL: https://github.com/apache/james-project/pull/681#discussion_r723956698



##########
File path: 
server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
##########
@@ -309,6 +332,22 @@ public void addGroupMapping(MappingSource source, String 
address) throws Recipie
         addMapping(source, mapping);
     }
 
+    private void ensureGroupNotShadowingAnotherAddress(MailAddress 
groupAddress) throws Exception {
+        ensureNoConflict(GROUP, groupAddress);
+    }
+
+    private void ensureAliasNotShadowingAnotherAddress(MailAddress 
groupAddress) throws Exception {
+        ensureNoConflict(ALIAS, groupAddress);
+    }
+
+    private void ensureNoConflict(UserEntityValidator.EntityType entity, 
MailAddress groupAddress) throws Exception {
+        Username username = usersRepository.getUsername(groupAddress);
+        Optional<UserEntityValidator.ValidationFailure> validationFailure = 
userEntityValidator.canCreate(username, ImmutableSet.of(entity));

Review comment:
       Well, typed exceptions prevents from writing good functional code.
   
   I'm not really keen on turning:
   
   ```
           if (validationFailure.isPresent()) {
               throw new 
MappingConflictException(validationFailure.get().errorMessage());
           }
   ```
   
   into
   
   ```
           
validationFailure.ifPresent(Throwing.<ValidationFailure>consumer(failure -> {
               throw new MappingConflictException(failure.errorMessage());
           }).sneakyThrow());
   ```
   
   If you don't mind I propose we keep today version.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to