public Repo createRepo(Subject subject, Repo repo) throws RepoException { validateRepo(repo); if (!authzManager.hasGlobalPermission(subject, Permission.MANAGE_REPOSITORIES)) { //only the repo manager can update the owner of a repo. //make sure that's the case. repo.setOwner(subject); } log.debug("User [" + subject + "] is creating [" + repo + "]..."); entityManager.persist(repo); log.info("User [" + subject + "] created [" + repo + "]."); // If this repo is imported, schedule the repo sync job. if (!repo.isCandidate()) { try { ContentServerPluginContainer pc = ContentManagerHelper.getPluginContainer(); pc.scheduleRepoSyncJob(repo); } catch (Exception e) { log.error("Failed to schedule repository synchronization job for [" + repo + "].", e); throw new RuntimeException(e); } } return repo; // now has the id set }
@RequiredPermission(Permission.MANAGE_REPOSITORIES) public void importCandidateRepo(Subject subject, List<Integer> repoIds) throws RepoException { for (Integer repoId : repoIds) { Repo repo = entityManager.find(Repo.class, repoId); if (repo == null) { throw new RepoException("Unable to find candidate repository with id " + repoId + " for import."); } if (!repo.isCandidate()) { throw new RepoException("Unable to import repository with id " + repoId + ", because it is already imported."); } repo.setCandidate(false); } }