@GET @Path(ROOT_PATH) @ApiOperation(value = "getting groups list") @ApiResponses(value = { @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = List.class), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public Set<String> listGroups(Request request, Response response) throws RecipientRewriteTableException { return Optional.ofNullable(recipientRewriteTable.getAllMappings()) .map(mappings -> mappings.entrySet().stream() .filter(e -> e.getValue().contains(Mapping.Type.Group)) .map(Map.Entry::getKey) .flatMap(source -> OptionalUtils.toStream(source.asMailAddress())) .map(MailAddress::asString) .collect(Guavate.toImmutableSortedSet())) .orElse(ImmutableSortedSet.of()); }
@GET @Path(ROOT_PATH) @ApiOperation(value = "getting forwards list") @ApiResponses(value = { @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = List.class), @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.") }) public Set<String> listForwards(Request request, Response response) throws RecipientRewriteTableException { return Optional.ofNullable(recipientRewriteTable.getAllMappings()) .map(mappings -> mappings.entrySet().stream() .filter(e -> e.getValue().contains(Mapping.Type.Forward)) .map(Map.Entry::getKey) .flatMap(source -> OptionalUtils.toStream(source.asMailAddress())) .map(MailAddress::asString) .collect(Guavate.toImmutableSortedSet())) .orElse(ImmutableSortedSet.of()); }