@SafeVarargs @SuppressWarnings({"unchecked", "varargs"}) public final <T extends WithId<T>> ListResult<T> fetchAll(Class<T> model, Function<ListResult<T>, ListResult<T>>... operators) { ListResult<T> result; if (getDataAccessObject(model) != null) { return doWithDataAccessObject(model, d -> d.fetchAll(operators)); } else { Kind kind = Kind.from(model); Map<String, T> cache = caches.getCache(kind.getModelName()); result = ListResult.of(cache.values()); if (operators == null) { return result; } for (Function<ListResult<T>, ListResult<T>> operator : operators) { result = operator.apply(result); } return result; } }
@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)); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path(value = "/overviews") public ListResult<IntegrationOverview> getOverviews(@Context UriInfo uriInfo) { Stream<Integration> stream = getDataManager().fetchAll(Integration.class, new DeletedFilter(), new ReflectiveSorter<>(Integration.class, new SortOptionsFromQueryParams(uriInfo)), new PaginationFilter<>(new PaginationOptionsFromQueryParams(uriInfo)) ).getItems().stream(); return ListResult.of(stream.map(integration -> { String id = integration.getId().get(); List<IntegrationDeployment> deployments = getDataManager().fetchAll(IntegrationDeployment.class, new IdPrefixFilter<>(id +":"), ReverseFilter.getInstance()) .getItems(); Optional<IntegrationBulletinBoard> bulletins = Optional .ofNullable(getDataManager().fetch(IntegrationBulletinBoard.class, id)); // find the deployment we want published.. return new IntegrationOverview(integration, bulletins, deployments.stream().findFirst()); }).collect(Collectors.toList())); }
.build(); when(dataManager.fetch(Connector.class, "connector-id")).thenReturn(connector); when(dataManager.fetchAll(Integration.class)).thenReturn(ListResult.of(Collections.emptyList()));
.build(); when(dataManager.fetch(Connector.class, "connector-id")).thenReturn(connector); when(dataManager.fetchAll(IntegrationDeployment.class)).thenReturn(ListResult.of(Collections.emptyList()));
@Test public void findTags() { Integration integration = new Integration.Builder() .addTag("tag1") .addTag("tag2") .build(); Connection connection = new Connection.Builder() .addTag("tag2") .addTag("tag3") .build(); ListResult<String> allTags = new TagFinder() .add(ListResult.of(integration)) .add(ListResult.of(connection)) .getResult(); Assert.assertEquals( 3, allTags.getTotalCount()); Assert.assertTrue(allTags.getItems().contains("tag1") ); Assert.assertTrue(allTags.getItems().contains("tag2") ); Assert.assertTrue(allTags.getItems().contains("tag3") ); }