@Override protected void execute(final Repository repository) { MavenIndexFacet mavenIndexFacet = repository.facet(MavenIndexFacet.class); try { mavenIndexFacet.unpublishIndex(); } catch (IOException e) { throw new RuntimeException(e); } }
private ComponentMaintenance getComponentMaintenanceFacet(final Repository repository) { try { return repository.facet(ComponentMaintenance.class); } catch (MissingFacetException e) { throw new IllegalOperationException( format("Deleting from repository %s of type %s is not supported", repository.getName(), repository.getFormat()), e); } } }
@VisibleForTesting Map<String, List<String>> getRepoToContainedGroupMap(List<Repository> repositories) { Map<String, List<String>> repoToContainedGroupMap = new HashMap<>(); for (Repository repository : repositories) { List<String> groupNames = new ArrayList<>(); groupNames.add(repository.getName()); groupNames.addAll(repositories.stream().filter(groupRepository -> { Optional<GroupFacet> groupFacet = groupRepository.optionalFacet(GroupFacet.class); return groupFacet.isPresent() && groupFacet.get().leafMembers().stream() .anyMatch(leafMember -> repository.getName().equals(leafMember.getName())); }).map(groupRepository -> groupRepository.getName()).collect(Collectors.toSet())); repoToContainedGroupMap.put(repository.getName(), groupNames); } return repoToContainedGroupMap; }
@Override protected boolean appliesTo(final Repository repository) { return maven2Format.equals(repository.getFormat()) && repository.optionalFacet(RemoveSnapshotsFacet.class).isPresent() && repository.facet(MavenFacet.class).getVersionPolicy() != VersionPolicy.RELEASE; }
private void validateRepositoryConfiguration(final Repository repository) { checkArgument(repository.getConfiguration().getAttributes() != null, "Repository configuration not found " + repository.getName()); checkArgument(repository.getConfiguration().getAttributes().get(STORAGE_KEY) != null, "No storage configuration found for the repository " + repository.getName()); checkArgument( isNotBlank((String) repository.getConfiguration().getAttributes().get(STORAGE_KEY).get(BLOB_STORE_NAME_KEY)), "Blob store name not set for repository " + repository.getName()); } }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { State state = context.getAttributes().require(TokenMatcher.State.class); Repository repository = context.getRepository(); log.debug("[deleteToken] repository: {} tokens: {}", repository.getName(), state.getTokens()); return repository.facet(NpmTokenFacet.class).logout(context); } };
/** * Untrack repository. */ private void untrack(final Repository repository) { log.debug("Untracking: {}", repository); repositories.remove(repository.getName()); // tear down security securityContributor.remove(repository); }
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))); }); }
private Asset getAssetById(final Repository repository, final EntityId assetId) { Optional<GroupFacet> optionalGroupFacet = repository.optionalFacet(GroupFacet.class); List<Repository> members = optionalGroupFacet.isPresent() ? optionalGroupFacet.get().allMembers() : Collections.singletonList(repository); return Transactional.operation.withDb(repository.facet(StorageFacet.class).txSupplier()).call(() -> { StorageTx tx = UnitOfWork.currentTx(); Asset candidate = tx.findAsset(assetId); if (candidate != null) { final String asssetBucketRepositoryName = bucketStore.getById(candidate.bucketId()).getRepositoryName(); if (members.stream().anyMatch(repo -> repo.getName().equals(asssetBucketRepositoryName))) { return candidate; } } return null; }); }
@Subscribe @AllowConcurrentEvents public void on(final RepositoryEvent event) { if (isRecording()) { Repository repository = event.getRepository(); AuditData data = new AuditData(); data.setDomain(DOMAIN); data.setType(type(event.getClass())); data.setContext(repository.getName()); Map<String, String> attributes = data.getAttributes(); attributes.put("name", repository.getName()); attributes.put("type", repository.getType().getValue()); attributes.put("format", repository.getFormat().getValue()); record(data); } } }
@Nullable protected String processBatch(final Repository repository, final String lastId) throws Exception { log.info("Processing next batch of {} packages for repair. Starting at id = {} with max batch size = {}", repository.getFormat(), lastId, BATCH_SIZE); return TransactionalStoreMetadata.operation .withDb(repository.facet(StorageFacet.class).txSupplier()) .throwing(Exception.class) .call(() -> { Iterable<Asset> assets = readAssets(repository, lastId); return updateAssets(repository, assets); }); }
@Override @Nullable public URL getIndexSettings(final Repository repository) { checkNotNull(repository); if (format.equals(repository.getFormat())) { return Resources.getResource(getClass(), MAPPING_JSON); } return null; } }
ConstraintViolation<?> validateGroupDoesNotContainItself(String repositoryName, Config config) { Set<Repository> checkedGroups = new HashSet<>(); for (String memberName : config.memberNames) { Repository repository = repositoryManager.get(memberName); if (repository.getName().equals(repositoryName) || (groupType.equals(repository.getType()) && containsGroup(repository, repositoryName, checkedGroups))) { return constraintViolationFactory.createViolation(P_ATTRIBUTES + "." + CONFIG_KEY + ".memberNames", "Group '" + repository.getName() + "' has a member repository '" + repositoryName + "' and cannot be added to this list."); } } return null; }
private void doUpdateSearchIndex(final Repository repository, final IndexRequest indexRequest) { repository.optionalFacet(SearchFacet.class).ifPresent(searchFacet -> { UnitOfWork.begin(repository.facet(StorageFacet.class).txSupplier()); try { if (bulkProcessing) { indexRequest.bulkApply(searchFacet); } else { indexRequest.apply(searchFacet); } } finally { UnitOfWork.end(); } }); } }
@Override protected boolean appliesTo(final Repository repository) { return repository.optionalFacet(NpmSearchFacet.class).isPresent(); }
/** * Returns true if the repository is of type {@link GroupType} * * @since 3.6.1 */ protected boolean isGroupRepository(final Repository repository) { return groupType.equals(repository.getType()); }
private static boolean repoOnlineAndHasSearchFacet(final Repository repo) { return repo.optionalFacet(SearchFacet.class).isPresent() && repo.getConfiguration().isOnline(); }