You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/10/07 08:22:30 UTC

[GitHub] [james-project] chibenwa commented on a change in pull request #681: JAMES-3657 Generalise entity validation Upon creation

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: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org