/** * Fetch the Connectors */ protected static Map<String, Connector> fetchConnectorsMap(DataManager dataManager) { return dataManager.fetchAll(Connector.class).getItems() .stream() .collect(Collectors.toMap(o -> o.getId().get(), Function.identity())); } }
/** * Fetch the Connectors */ protected static Map<String, Connector> fetchConnectorsMap(DataManager dataManager) { return dataManager.fetchAll(Connector.class).getItems() .stream() .collect(Collectors.toMap(o -> o.getId().get(), Function.identity())); } }
private List<Connection> findAssociatedConnections(Connector connector) { return dataManager.fetchAll(Connection.class).getItems().stream() .filter(c -> connector.getId().equals(c.getConnectorId())) .collect(Collectors.toList()); }
private void scanIntegrationsForWork() { executor.execute(() -> { dataManager.fetchAll(IntegrationDeployment.class).getItems().forEach(integration -> { LOG.info("Checking integrations for their status."); checkIntegrationStatus(integration); }); }); }
private void scanIntegrationsForWork() { executor.execute(() -> { dataManager.fetchAll(IntegrationDeployment.class).getItems().forEach(integration -> { LOG.info("Checking integrations for their status."); checkIntegrationStatus(integration); }); }); }
private Set<ResourceIdentifier> integrations(Extension extension) { return getDataManager().fetchAll(IntegrationDeployment.class).getItems().stream() .filter(integrationDeployment -> isIntegrationActiveAndUsingExtension(integrationDeployment, extension)) .map(this::toIntegrationResourceIdentifier) .distinct() .collect(Collectors.toSet()); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path(value = "") public List<OAuthApp> get() { ArrayList<OAuthApp> apps = new ArrayList<>(); List<Connector> items = dataMgr.fetchAll(Connector.class).getItems(); items.forEach(connector -> { if (isOauthConnector(connector)) { apps.add(createOAuthApp(connector)); } }); return apps; }
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 IntegrationMetricsSummary getTotalIntegrationMetricsSummary() { ListResult<IntegrationMetricsSummary> integrationMetricsList = dataMgr.fetchAll( IntegrationMetricsSummary.class); return rollup(integrationMetricsList.getItems()); }
@Override public ListResult<IntegrationDeployment> apply(ListResult<IntegrationDeployment> list) { List<IntegrationDeployment> filtered = list.getItems().stream() .filter(i -> integrationId == null || integrationId.equals(i.getIntegrationId().orElse(null))) .collect(Collectors.toList()); return new ListResult.Builder<IntegrationDeployment>() .totalCount(filtered.size()) .addAllItems(filtered).build(); } }
@Override public ListResult<T> apply(ListResult<T> result) { List<T> list = result.getItems().stream().filter(filter).collect(Collectors.toList()); return new ListResult.Builder<T>().createFrom(result).items(list).totalCount(list.size()).build(); }
default void deleteAll() { ListResult<T> l = fetchAll(); for (T entity : l.getItems()) { delete(entity); } }
@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 ListResult<T> apply(ListResult<T> result) { List<T> list = new ArrayList<>(result.getItems()); if (delegate != null) { // We are sorting inline when a delegate is given. Otherwise its a no-op list.sort(this); } return new ListResult.Builder<T>().createFrom(result).items(list).build(); }
@Test public void shouldCollectFromEmptyStream() { final ListResult<Object> collected = Stream.of().collect(ListResult.collector()).build(); assertThat(collected).isNotNull(); assertThat(collected.getItems()).isEmpty(); }
@Test public void shouldCollectFromStreamWithSomeElements() { final ListResult<String> collected = IntStream.range(1, 11).mapToObj(String::valueOf) .collect(ListResult.collector()).build(); assertThat(collected).isNotNull(); assertThat(collected.getItems()).containsExactly("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); } }
@Override public ListResult<Connector> list(final UriInfo uriInfo) { final List<Connector> connectors = Lister.super.list(uriInfo).getItems().stream() .map(c -> { final ConnectorSummary summary = new ConnectorSummary.Builder().createFrom(c).build(); return c.builder().actionsSummary(summary.getActionsSummary()).build(); }) .collect(Collectors.toList()); return ListResult.of(augmentedWithUsage(connectors)); }
@Test public void shouldCollectFromSingletonStream() { final ListResult<String> collected = Stream.of("item").collect(ListResult.collector()).build(); assertThat(collected).isNotNull(); assertThat(collected.getItems()).containsExactly("item"); }
@Test public void getConnectors() { @SuppressWarnings("unchecked") ListResult<Connector> connectors = dataManager.fetchAll(Connector.class); assertThat(connectors.getItems().stream().map(Connector::getId).map(Optional::get)) .containsExactlyInAnyOrder("activemq", "amqp", "ftp","sftp", "sql", "salesforce", "twitter", "aws-s3", "mqtt"); Assert.assertTrue(connectors.getTotalCount() > 1); Assert.assertTrue(connectors.getItems().size() > 1); Assert.assertEquals(connectors.getTotalCount(), connectors.getItems().size()); }
@Test public void getConnections() { ListResult<Connection> connections = dataManager.fetchAll(Connection.class); assertThat(connections.getItems().stream().map(Connection::getId).map(Optional::get)).containsOnly("5"); Assert.assertEquals(1, connections.getTotalCount()); Assert.assertEquals(1, connections.getItems().size()); Assert.assertEquals(connections.getTotalCount(), connections.getItems().size()); }