Search in sources :

Example 1 with BlueOrganization

use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.

the class OrganizationStatePreloader method getStateJson.

@Override
public String getStateJson() {
    BlueOrganization organization = Iterables.getFirst(OrganizationFactory.getInstance().list(), null);
    if (organization != null) {
        // default is root group
        String organizationGroup = "/";
        if (organization instanceof AbstractOrganization) {
            organizationGroup = "/" + ((AbstractOrganization) organization).getGroup().getFullName();
        }
        StringWriter writer = new StringWriter();
        new JSONBuilder(writer).object().key("name").value(organization.getName()).key("displayName").value(organization.getDisplayName()).key("organizationGroup").value(organizationGroup).endObject();
        return writer.toString();
    } else {
        // if will happen only when there is no implementation of BlueOrganization found.
        return "{}";
    }
}
Also used : JSONBuilder(net.sf.json.util.JSONBuilder) StringWriter(java.io.StringWriter) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) AbstractOrganization(io.jenkins.blueocean.rest.factory.organization.AbstractOrganization)

Example 2 with BlueOrganization

use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.

the class BranchContainerImpl method iterator.

@Override
@SuppressWarnings("unchecked")
public Iterator<BluePipeline> iterator(int start, int limit) {
    final BlueOrganization organization = OrganizationFactory.getInstance().getContainingOrg(pipeline.mbp.getItemGroup());
    if (organization == null) {
        throw new ServiceException.UnexpectedErrorException("Could not find organization for " + pipeline.mbp.getFullName());
    }
    final Link link = getLink();
    // Filter will decide if the requester wants branches or pull requests
    Collection allJobsMatchinFilter = ContainerFilter.filter(pipeline.mbp.getAllJobs());
    // Transform all of these to branches (these represent branches or pull requests)
    Iterable<BluePipeline> branches = Iterables.transform(allJobsMatchinFilter, new Function<Job, BluePipeline>() {

        @Override
        public BluePipeline apply(Job input) {
            return new BranchImpl(organization, input, link);
        }
    });
    // Order them using the comparator
    branches = Ordering.from(BRANCH_COMPARATOR).sortedCopy(branches);
    // Return the page requested by the client
    return Iterables.limit(Iterables.skip(branches, start), limit).iterator();
}
Also used : BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) Collection(java.util.Collection) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) Job(hudson.model.Job) Link(io.jenkins.blueocean.rest.hal.Link)

Example 3 with BlueOrganization

use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.

the class BranchContainerImpl method get.

// TODO: implement rest of the methods
@Override
public BluePipeline get(String name) {
    Job job = pipeline.mbp.getItem(name);
    if (job == null) {
        return null;
    }
    BlueOrganization organization = OrganizationFactory.getInstance().getContainingOrg(job);
    if (organization == null) {
        return null;
    }
    return new BranchImpl(organization, job, getLink());
}
Also used : BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) Job(hudson.model.Job)

Example 4 with BlueOrganization

use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.

the class CredentialContainer method iterator.

@Override
public Iterator<CredentialApi> iterator() {
    List<CredentialApi> apis = new ArrayList<>();
    User user = User.current();
    if (user != null) {
        for (CredentialsStore store : CredentialsProvider.lookupStores(user)) {
            if (store.getStoreAction() != null) {
                apis.add(new CredentialApi(store.getStoreAction(), this));
            }
        }
    } else {
        Iterator<BlueOrganization> iterator = OrganizationFactory.getInstance().list().iterator();
        BlueOrganization organization = iterator.hasNext() ? iterator.next() : null;
        if (organization != null) {
            ModifiableTopLevelItemGroup itemGroup = OrganizationFactory.getItemGroup(organization.getName());
            for (CredentialsStore store : CredentialsProvider.lookupStores(itemGroup)) {
                if (store.getStoreAction() != null) {
                    apis.add(new CredentialApi(store.getStoreAction(), this));
                }
            }
        }
    }
    return apis.iterator();
}
Also used : User(hudson.model.User) ModifiableTopLevelItemGroup(jenkins.model.ModifiableTopLevelItemGroup) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) ArrayList(java.util.ArrayList) CredentialsStore(com.cloudbees.plugins.credentials.CredentialsStore)

Example 5 with BlueOrganization

use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.

the class CredentialSearch method getOrganization.

private BlueOrganization getOrganization(Query q) {
    String org = q.param("organization");
    if (org == null) {
        throw new ServiceException.BadRequestException("Credentials search query parameter 'organization' is required");
    }
    BlueOrganization organization = OrganizationFactory.getInstance().get(org);
    if (organization == null) {
        throw new ServiceException.BadRequestException(String.format("Organization %s not found. Query parameter 'organization' value: %s is invalid. ", org, org));
    }
    return organization;
}
Also used : BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization)

Aggregations

BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)19 Item (hudson.model.Item)4 Link (io.jenkins.blueocean.rest.hal.Link)4 BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Job (hudson.model.Job)3 Resource (io.jenkins.blueocean.rest.model.Resource)3 OrganizationFolder (jenkins.branch.OrganizationFolder)3 Run (hudson.model.Run)2 User (hudson.model.User)2 ModifiableTopLevelItemGroup (jenkins.model.ModifiableTopLevelItemGroup)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 CredentialsStore (com.cloudbees.plugins.credentials.CredentialsStore)1 Plugin (hudson.Plugin)1 FreeStyleProject (hudson.model.FreeStyleProject)1 ItemGroup (hudson.model.ItemGroup)1 Project (hudson.model.Project)1 Queue (hudson.model.Queue)1 TopLevelItem (hudson.model.TopLevelItem)1