List<Connector> augmentedWithUsage(final List<Connector> connectors) { ListResult<Integration> integrationListResult = getDataManager().fetchAll(Integration.class); List<Integration> items = integrationListResult.getItems(); final Map<String, Long> connectorUsage = items.stream()// .filter(i -> !i.isDeleted())// .flatMap(i -> i.getUsedConnectorIds().stream())// .collect(Collectors.groupingBy(String::toString, Collectors.counting())); return connectors.stream().map(c -> { final int uses = connectorUsage.getOrDefault(c.getId().get(), 0L).intValue(); return c.builder().uses(uses).build(); }).collect(Collectors.toList()); }
@Override public ListResult<Integration> apply(ListResult<Integration> list) { List<Integration> filtered = list.getItems().stream() .filter(i -> !i.isDeleted()) .collect(Collectors.toList()); return new ListResult.Builder<Integration>() .totalCount(filtered.size()) .addAllItems(filtered).build(); } }
@Override public Integration get(String id) { Integration integration = Getter.super.get(id); if ( integration.isDeleted() ) { //Not sure if we need to do that for both current and desired status, //but If we don't do include the desired state, IntegrationITCase is not going to pass anytime soon. Why? //Cause that test, is using NoopHandlerProvider, so that means no controllers. throw new EntityNotFoundException(String.format("Integration %s has been deleted", integration.getId())); } // Get the latest connection configs. List<Connection> connections = integration.getConnections().stream() .map(this::toCurrentConnection) .collect(Collectors.toList()); List<Step> steps = integration.getSteps().stream() .map(this::toCurrentSteps) .collect(Collectors.toList()); return new Integration.Builder() .createFrom(integration) .connections(connections) .steps(steps) .build(); }