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 }
public Repo updateRepo(Subject subject, Repo repo) throws RepoException { validateFields(repo); if (!authzManager.hasGlobalPermission(subject, Permission.MANAGE_REPOSITORIES)) { if (!authzManager.canUpdateRepo(subject, repo.getId())) { throw new PermissionException("User [" + subject + "] can't update repo with id " + repo.getId()); } //only the repo manager can update the owner of a repo. //make sure that's the case. repo.setOwner(subject); } // HHH-2864 - Leave this in until we move to hibernate > 3.2.r14201-2 getRepo(subject, repo.getId()); // should we check non-null repo relationships and warn that we aren't changing them? log.debug("User [" + subject + "] is updating [" + repo + "]..."); repo = entityManager.merge(repo); log.debug("User [" + subject + "] updated [" + repo + "]."); try { ContentServerPluginContainer pc = ContentManagerHelper.getPluginContainer(); pc.unscheduleRepoSyncJob(repo); pc.scheduleRepoSyncJob(repo); } catch (Exception e) { log.warn("Failed to reschedule repository synchronization job for [" + repo + "].", e); } return repo; }