@GET @Path(ROOT_PATH + "/{" + FORWARD_BASE_ADDRESS + "}") @ApiOperation(value = "listing forward destinations") @ApiImplicitParams({ @ApiImplicitParam(required = true, dataType = "string", name = FORWARD_BASE_ADDRESS, paramType = "path") }) @ApiResponses(value = { @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = List.class), @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "The forward is not an address"), @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The forward does not exist"), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public ImmutableSet<ForwardDestinationResponse> listForwardDestinations(Request request, Response response) throws RecipientRewriteTableException { MailAddress baseAddress = parseMailAddress(request.params(FORWARD_BASE_ADDRESS)); Mappings mappings = Optional.ofNullable(recipientRewriteTable.getUserDomainMappings(MappingSource.fromMailAddress(baseAddress))) .orElse(MappingsImpl.empty()) .select(Mapping.Type.Forward); ensureNonEmptyMappings(mappings); return mappings.asStream() .map(mapping -> mapping.asMailAddress() .orElseThrow(() -> new IllegalStateException(String.format("Can not compute address for mapping %s", mapping.asString())))) .map(MailAddress::asString) .sorted() .map(ForwardDestinationResponse::new) .collect(Guavate.toImmutableSet()); }
@Override public void addMapping(MappingSource source, Mapping mapping) { executor.executeVoid(insertStatement.bind() .setString(USER, source.getFixedUser()) .setString(DOMAIN, source.getFixedDomain()) .setString(MAPPING, mapping.asString())) .join(); }
@Override public void removeMapping(MappingSource source, Mapping mapping) { executor.executeVoid(deleteStatement.bind() .setString(USER, source.getFixedUser()) .setString(DOMAIN, source.getFixedDomain()) .setString(MAPPING, mapping.asString())) .join(); }
@Override public void removeMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException { Mappings map = getUserDomainMappings(source); if (map.size() > 1) { Mappings updatedMappings = map.remove(mapping); doUpdateMapping(source, updatedMappings.serialize()); } else { doRemoveMapping(source, mapping.asString()); } }
@Override public void addMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException { Mappings map = getUserDomainMappings(source); if (!map.isEmpty()) { Mappings updatedMappings = MappingsImpl.from(map).add(mapping).build(); doUpdateMapping(source, updatedMappings.serialize()); } else { doAddMapping(source, mapping.asString()); } }
@Override public void removeMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException { removeMappingFromConfiguration(source, mapping.getType().withoutPrefix(mapping.asString()), mapping.getType()); }
@Override public void addMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException { addMappingToConfiguration(source, mapping.getType().withoutPrefix(mapping.asString()), mapping.getType()); }