@Override public void removeMapping(String user, String domain, String mapping) throws RecipientRewriteTableException { MappingSource source = MappingSource.fromUser(user, domain); rrt.removeMapping(source, Mapping.of(mapping)); }
@Override public void addMapping(String user, String domain, String mapping) throws RecipientRewriteTableException { MappingSource source = MappingSource.fromUser(user, domain); rrt.addMapping(source, Mapping.of(mapping)); }
private Mapping toMapping(User rewrittenUser, Type type) { switch (type) { case Forward: case Group: return Mapping.of(type, rewrittenUser.asString()); case Regex: case Domain: case Error: case Address: return Mapping.address(rewrittenUser.asString()); } throw new IllegalArgumentException("unhandled enum type"); }
protected void removeMappingFromConfiguration(MappingSource source, String mapping, Type type) throws RecipientRewriteTableException { Mappings oldMappings = Optional.ofNullable(virtualUserTable.getUserDomainMappings(source)) .orElseThrow(() -> new RecipientRewriteTableException("Cannot remove from null mappings")); Mappings updatedMappings = oldMappings.remove(Mapping.of(type, mapping)); updateConfiguration(source, oldMappings, updatedMappings); }
protected void addMappingToConfiguration(MappingSource source, String mapping, Type type) throws RecipientRewriteTableException { Mappings mappings = Optional.ofNullable(virtualUserTable.getUserDomainMappings(source)) .orElse(MappingsImpl.empty()); Mappings updatedMappings = MappingsImpl.from(mappings) .add(Mapping.of(type, mapping)) .build(); updateConfiguration(source, mappings, updatedMappings); }