/** * Method that actually performs group GET. Override if needed. */ protected Response doGet(@Nonnull final Context context, @Nonnull final DispatchedRepositories dispatched) throws Exception { final GroupFacet groupFacet = context.getRepository().facet(GroupFacet.class); return getFirst(context, groupFacet.members(), dispatched); }
private boolean containsGroup(Repository root, String repositoryName, Set<Repository> checkedGroups) { return root.facet(GroupFacet.class).members().stream().anyMatch((repository) -> { return checkedGroups.add(repository) && (repository.getName().equals(repositoryName) || (groupType.equals(repository.getType()) && containsGroup(repository, repositoryName, checkedGroups))); }); }
/** * Searches the member repositories, returning the merged response for all contacted member repositories that returned * a valid search response. */ private NpmSearchResponse searchMembers(final Context context, final DispatchedRepositories dispatched, final Parameters parameters) throws Exception { // preserve original from and size for repeated queries int from = npmSearchParameterExtractor.extractFrom(parameters); int size = npmSearchParameterExtractor.extractSize(parameters); // if the text is empty, then we override the original parameters to return a full set from each upstream source // we could make multiple queries to make this more efficient, but this is the simplest implementation for now parameters.replace("from", "0"); parameters.replace("size", Integer.toString(v1SearchMaxResults)); // sort all the merged results by normalized search score, then build the result responses to send back GroupFacet groupFacet = context.getRepository().facet(GroupFacet.class); Set<Entry<Repository, Response>> entries = getAll(context, groupFacet.members(), dispatched).entrySet(); List<NpmSearchResponseObject> mergedResponses = mergeAndNormalizeResponses(entries); mergedResponses.sort(comparingDouble(NpmSearchResponseObject::getSearchScore).reversed()); List<NpmSearchResponseObject> mergedResponseObjects = mergedResponses.stream() .skip(from) .limit(size) .collect(toList()); return npmSearchResponseFactory.buildResponseForObjects(mergedResponseObjects); }
@Override protected final Response doGet(@Nonnull final Context context, @Nonnull final GroupHandler.DispatchedRepositories dispatched) throws Exception { Repository repository = context.getRepository(); GroupFacet groupFacet = repository.facet(GroupFacet.class); makeUnconditional(context.getRequest()); Map<Repository, Response> responses; try { responses = getAll(context, groupFacet.members(), dispatched); } finally { makeConditional(context.getRequest()); } List<Payload> payloads = responses.values().stream() .filter(response -> response.getStatus().getCode() == HttpStatus.OK && response.getPayload() != null) .map(Response::getPayload) .collect(Collectors.toList()); if (payloads.isEmpty()) { return notFoundResponse(context); } return HttpResponses.ok(merge(repository, payloads)); }
@Override protected void execute(final Repository repository) { if (hasBeenProcessed(repository)) { log.debug("Skipping repository '{}'; it has already been processed"); return; } if (isGroupRepository(repository)) { markProcessed(repository); // nothing to do for the group itself repository.facet(GroupFacet.class).members().stream().filter(this::appliesTo).forEach(this::execute); } else { log.info("Executing removal of snapshots on repository '{}'", repository.getName()); TaskConfiguration config = getConfiguration(); RemoveSnapshotsConfig removeSnapshotsConfig = new RemoveSnapshotsConfig( config.getInteger(MINIMUM_SNAPSHOT_RETAINED_COUNT, 1), config.getInteger(SNAPSHOT_RETENTION_DAYS, 30), config.getBoolean(REMOVE_IF_RELEASED, false), config.getInteger(GRACE_PERIOD, -1)); repository.facet(RemoveSnapshotsFacet.class).removeSnapshots(removeSnapshotsConfig); markProcessed(repository); } }