Search in sources :

Example 16 with BlueOrganization

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

the class UserSearch method search.

@Override
public Pageable<BlueUser> search(Query q) {
    List<BlueUser> users = new ArrayList<>();
    BlueOrganization organization = getOrganization(q);
    if (organization == null) {
        organization = OrganizationFactory.getInstance().list().iterator().next();
    }
    for (hudson.model.User u : hudson.model.User.getAll()) {
        users.add(new UserImpl(organization, u));
    }
    return Pageables.wrap(users);
}
Also used : BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) BlueUser(io.jenkins.blueocean.rest.model.BlueUser) ArrayList(java.util.ArrayList)

Example 17 with BlueOrganization

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

the class UserSearch method getOrganization.

/**
 * Obtains the organization from the query. It will return an error if the parameter is absent or the organization
 * could not be found.
 *
 * @param q the query parameter
 * @return the organization if found
 */
public BlueOrganization getOrganization(Query q) {
    String org = q.param("organization");
    if (org == null) {
        return null;
    }
    // This could return null and is ok for the UserImpl which will use Jenkins base.
    BlueOrganization organization = OrganizationFactory.getInstance().get(org);
    return organization;
}
Also used : BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization)

Example 18 with BlueOrganization

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

the class BlueTrendTest method testTrendsIdCollision.

@Test
public void testTrendsIdCollision() throws Exception {
    // verify the extension did register correctly
    ExtensionList<BlueTrendFactory> extensionList = ExtensionList.lookup(BlueTrendFactory.class);
    Assert.assertEquals(2, extensionList.size());
    Project project = j.createProject(FreeStyleProject.class, "freestyle1");
    BlueOrganization org = new OrganizationImpl("jenkins", j.jenkins);
    BluePipeline pipeline = new AbstractPipelineImpl(org, project);
    BlueTrendContainer trends = pipeline.getTrends();
    BlueTrend trend = trends.get("junit");
    Assert.assertEquals("junit", trend.getId());
    Assert.assertEquals("JUnit", trend.getDisplayName());
}
Also used : BlueTrendFactory(io.jenkins.blueocean.rest.factory.BlueTrendFactory) BlueTrendContainer(io.jenkins.blueocean.rest.model.BlueTrendContainer) Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) BlueTrend(io.jenkins.blueocean.rest.model.BlueTrend) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) Test(org.junit.Test) BaseTest(io.jenkins.blueocean.service.embedded.BaseTest)

Example 19 with BlueOrganization

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

the class BlueOceanUrlMapperImpl method getUrl.

@Override
public String getUrl(@Nonnull ModelObject modelObject) {
    BlueOrganization organization = getOrganization(modelObject);
    if (organization == null) {
        // no organization, best we can do is to land user on landing page
        return getLandingPagePath();
    }
    String organizationName = organization.getName();
    String baseUrl = getOrgPrefix(organizationName);
    if (modelObject instanceof ModifiableTopLevelItemGroup) {
        return baseUrl;
    } else if (modelObject instanceof Job) {
        BluePipeline blueResource = getJobResource(modelObject);
        if (blueResource != null) {
            return getPipelineUrl(baseUrl, blueResource);
        }
    } else if (modelObject instanceof Run) {
        Run run = (Run) modelObject;
        Job job = run.getParent();
        BluePipeline blueResource = getJobResource(job);
        if (blueResource != null) {
            // encoded and re-encode to do the full monty. Nasty :)
            return baseUrl + "/" + encodeURIComponent(blueResource.getFullName()) + "/detail/" + encodeURIComponent(decodeURIComponent(job.getName())) + "/" + encodeURIComponent(run.getId());
        }
    } else if (modelObject instanceof Item) {
        Resource bluePipeline = BluePipelineFactory.resolve((Item) modelObject);
        if (bluePipeline instanceof BlueMultiBranchPipeline) {
            return getPipelineUrl(baseUrl, (BluePipeline) bluePipeline);
        }
    }
    return null;
}
Also used : Item(hudson.model.Item) ModifiableTopLevelItemGroup(jenkins.model.ModifiableTopLevelItemGroup) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) Resource(io.jenkins.blueocean.rest.model.Resource) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) Run(hudson.model.Run) Job(hudson.model.Job) BlueMultiBranchPipeline(io.jenkins.blueocean.rest.model.BlueMultiBranchPipeline)

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