public Repo getRepo(Subject subject, int repoId) { if (!authzManager.canViewRepo(subject, repoId)) { throw new PermissionException("User [" + subject + "] cannot access the repo with id " + repoId); } Repo repo = entityManager.find(Repo.class, repoId); if ((repo != null) && (repo.getRepoContentSources() != null)) { // load content sources separately. we can't do this all at once via fetch join because // on Oracle we use a LOB column on a content source field and you can't DISTINCT on LOBs repo.getRepoContentSources().size(); } return repo; }
@RequiredPermission(Permission.MANAGE_REPOSITORIES) public void removeContentSourcesFromRepo(Subject subject, int repoId, int[] contentSourceIds) throws RepoException { Repo repo = getRepo(subject, repoId); log.debug("User [" + subject + "] is removing content sources from repository [" + repo + "]"); Set<RepoContentSource> currentSet = repo.getRepoContentSources(); if ((currentSet != null) && (currentSet.size() > 0)) { Set<RepoContentSource> toBeRemoved = new HashSet<RepoContentSource>(); for (RepoContentSource current : currentSet) { for (int id : contentSourceIds) { if (id == current.getRepoContentSourcePK().getContentSource().getId()) { toBeRemoved.add(current); break; } } } for (RepoContentSource doomed : toBeRemoved) { entityManager.remove(doomed); } currentSet.removeAll(toBeRemoved); } // note that we specifically do not disassociate package versions from the repo, even if those // package versions come from the content source that is being removed }