Search in sources :

Example 6 with Resource

use of io.jenkins.blueocean.rest.model.Resource 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

Resource (io.jenkins.blueocean.rest.model.Resource)6 Item (hudson.model.Item)3 Run (hudson.model.Run)3 BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)3 Job (hudson.model.Job)2 BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)2 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)2 ItemGroup (hudson.model.ItemGroup)1 Queue (hudson.model.Queue)1 TopLevelItem (hudson.model.TopLevelItem)1 BlueMultiBranchPipeline (io.jenkins.blueocean.rest.model.BlueMultiBranchPipeline)1 BlueQueueItem (io.jenkins.blueocean.rest.model.BlueQueueItem)1 IOException (java.io.IOException)1 BranchSource (jenkins.branch.BranchSource)1 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)1 ModifiableTopLevelItemGroup (jenkins.model.ModifiableTopLevelItemGroup)1 GitSCMSource (jenkins.plugins.git.GitSCMSource)1 SCMSource (jenkins.scm.api.SCMSource)1 JSONArray (net.sf.json.JSONArray)1 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)1