@VisibleForTesting Context maybeCopyContextAttributes(final Repository repository, final Request request, final Context existingContext) { Context context = new Context(repository, request); copyLocalContextAttributes(existingContext, context); return context; }
@Nonnull @Override public Content searchIndex(@Nullable final DateTime since) throws IOException { try { final Request getRequest = new Request.Builder() .action(GET) .path("/" + NpmFacetUtils.REPOSITORY_ROOT_ASSET) .build(); Context context = new Context(getRepository(), getRequest); context.getAttributes().set(ProxyTarget.class, ProxyTarget.SEARCH_INDEX); Content fullIndex = getRepository().facet(ProxyFacet.class).get(context); if (fullIndex == null) { throw new IOException("Could not retrieve registry root"); } return NpmSearchIndexFilter.filterModifiedSince(fullIndex, since); } catch (Exception e) { throw new IOException(e); } }
@Override public Content searchV1(final Parameters parameters) throws IOException { try { final Request getRequest = new Request.Builder() .action(GET) .path("/" + NpmFacetUtils.REPOSITORY_SEARCH_ASSET) .parameters(parameters) .build(); Context context = new Context(getRepository(), getRequest); context.getAttributes().set(ProxyTarget.class, ProxyTarget.SEARCH_V1_RESULTS); Content searchResults = getRepository().facet(ProxyFacet.class).get(context); if (searchResults == null) { throw new IOException("Could not retrieve registry search"); } return searchResults; } catch (Exception e) { throw new IOException(e); } } }
/** * Primes proxy cache with given path and return {@code true} if succeeds. Accepts only maven proxy type. */ private static boolean prefetch(final Repository repository, final String path) throws IOException { MavenPath mavenPath = repository.facet(MavenFacet.class).getMavenPathParser().parsePath(path); Request getRequest = new Request.Builder() .action(GET) .path(path) .build(); Context context = new Context(repository, getRequest); context.getAttributes().set(MavenPath.class, mavenPath); return repository.facet(ProxyFacet.class).get(context) != null; }