Package org.rhq.core.domain.content

Examples of org.rhq.core.domain.content.Repo


    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;
    }
View Full Code Here


        }
       
        List<SubscribedRepo> list = new ArrayList<SubscribedRepo>();
        PageControl pc = new PageControl();
        for (RepoComposite repoComposite : findResourceSubscriptions(subject, resourceId, pc)) {
            Repo repo = repoComposite.getRepo();
            SubscribedRepo summary = new SubscribedRepo(repo.getId(), repo.getName());
            list.add(summary);
        }
        return list;
    }
View Full Code Here

    }

    @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);
        }
    }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    @RequiredPermission(Permission.MANAGE_REPOSITORIES)
    public void addContentSourcesToRepo(Subject subject, int repoId, int[] contentSourceIds) throws Exception {
        Repo repo = entityManager.find(Repo.class, repoId);
        if (repo == null) {
            throw new Exception("There is no repo with an ID [" + repoId + "]");
        }

        repo.setLastModifiedDate(System.currentTimeMillis());

        log.debug("User [" + subject + "] is adding content sources to repo [" + repo + "]");

        ContentServerPluginContainer pc = ContentManagerHelper.getPluginContainer();
        Query q = entityManager.createNamedQuery(PackageVersionContentSource.QUERY_FIND_BY_CONTENT_SOURCE_ID_NO_FETCH);

        for (int id : contentSourceIds) {
            ContentSource contentSource = entityManager.find(ContentSource.class, id);
            if (contentSource == null) {
                throw new Exception("There is no content source with id [" + id + "]");
            }

            Set<ContentSource> alreadyAssociatedContentSources = repo.getContentSources();
            // Only add it if it's not already associated with this repo.
            if (!alreadyAssociatedContentSources.contains(contentSource)) {
                RepoContentSource repoContentSourceMapping = repo.addContentSource(contentSource);
                entityManager.persist(repoContentSourceMapping);
            }
            Set<PackageVersion> alreadyAssociatedPackageVersions = new HashSet<PackageVersion>(
                repo.getPackageVersions());

            // Automatically associate all of the content source's package versions with this repo,
            // but *skip* over the ones that are already linked to this repo from a previous association.
            q.setParameter("id", contentSource.getId());
            List<PackageVersionContentSource> pvcss = q.getResultList();
View Full Code Here

            entityManager.clear();
        }
    }

    public void simpleAddContentSourcesToRepo(Subject subject, int repoId, int[] contentSourceIds) throws Exception {
        Repo repo = entityManager.find(Repo.class, repoId);
        if (repo == null) {
            throw new Exception("There is no repo with an ID [" + repoId + "]");
        }

        for (int id : contentSourceIds) {
            ContentSource cs = entityManager.find(ContentSource.class, id);
            if (cs == null) {
                throw new Exception("There is no content source with id [" + id + "]");
            }

            RepoContentSource ccsmapping = repo.addContentSource(cs);
            entityManager.persist(ccsmapping);
        }
    }
View Full Code Here

    public void addPackageVersionsToRepo(Subject subject, int repoId, int[] packageVersionIds) {
        if (!authzManager.canUpdateRepo(subject, repoId)) {
            throw new PermissionException("User [" + subject + "] can't update repo with id " + repoId);
        }
               
        Repo repo = entityManager.find(Repo.class, repoId);

        for (int packageVersionId : packageVersionIds) {
            PackageVersion packageVersion = entityManager.find(PackageVersion.class, packageVersionId);

            RepoPackageVersion mapping = new RepoPackageVersion(repo, packageVersion);
View Full Code Here

        }
    }

    @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) {
View Full Code Here

    @RequiredPermission(Permission.MANAGE_REPOSITORIES)
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void addRepoRelationship(Subject subject, int repoId, int relatedRepoId, String relationshipTypeName) {

        Repo repo = entityManager.find(Repo.class, repoId);
        Repo relatedRepo = entityManager.find(Repo.class, relatedRepoId);

        Query typeQuery = entityManager.createNamedQuery(RepoRelationshipType.QUERY_FIND_BY_NAME);
        typeQuery.setParameter("name", relationshipTypeName);
        RepoRelationshipType relationshipType = (RepoRelationshipType) typeQuery.getSingleResult();

        RepoRelationship repoRelationship = new RepoRelationship();
        repoRelationship.setRelatedRepo(relatedRepo);
        repoRelationship.setRepoRelationshipType(relationshipType);
        repoRelationship.addRepo(repo);

        entityManager.persist(repoRelationship);
        relatedRepo.addRepoRelationship(repoRelationship);

        RepoRepoRelationship repoRepoRelationship = new RepoRepoRelationship(repo, repoRelationship);

        entityManager.persist(repoRepoRelationship);
        repo.addRepoRelationship(repoRelationship);
View Full Code Here

        if (!authzManager.canViewRepo(subject, repoId)) {
            throw new PermissionException("User [" + subject + "] cannot access a repo with id " + repoId);
        }

        //check that the provided package version actually belongs to the repo
        Repo repo = entityManager.find(Repo.class, repoId);

        PackageVersion pv = entityManager.find(PackageVersion.class, packageVersionId);
        if (pv == null || !pv.getRepos().contains(repo)) {
            throw new IllegalArgumentException("The package version with id " + packageVersionId
                + " does not belong to the repo with id " + repoId + " or does not exist.");
View Full Code Here

            }
            return false;
        }

        // The repo doesn't exist yet in the system - create it.
        Repo addMe = new Repo(name);
        addMe.setCandidate(!autoImport);
        addMe.setDescription(createMe.getDescription());

        String createMeGroup = createMe.getRepoGroup();
        if (createMeGroup != null) {
            RepoGroup group = getRepoGroupByName(createMeGroup);
            addMe.addRepoGroup(group);
        }

        // Add the new candidate to the database
        addMe = createRepo(overlord, addMe);

        // Associate the content source that introduced the candidate with the repo
        addContentSourcesToRepo(overlord, addMe.getId(), new int[] { contentSourceId });

        // If the repo indicates it has a parent, create that relationship
        String parentName = createMe.getParentRepoName();
        if (parentName != null) {
            List<Repo> parentList = getRepoByName(parentName);

            if (parentList.size() == 0) {
                String error = "Attempting to create repo [" + name + "] with parent [" + parentName
                    + "] but cannot find the parent";
                log.error(error);
                throw new RepoException(error);
            } else {
                Repo parent = parentList.get(0);
                addRepoRelationship(overlord, addMe.getId(), parent.getId(), PARENT_RELATIONSHIP_NAME);
            }
        }

        return true;
    }
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.content.Repo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.