Search in sources :

Example 1 with Reachable

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

the class RunSearch method collectRuns.

private static List<BlueRun> collectRuns(Iterator<? extends Run> runIterator, final Link parent, int start, int limit) {
    List<BlueRun> runs = new ArrayList<>();
    // Skip up to the start
    int skipCount = start;
    while (runIterator.hasNext()) {
        if (skipCount > 0) {
            runIterator.next();
            skipCount--;
        } else {
            BlueRun run = BlueRunFactory.getRun(runIterator.next(), new Reachable() {

                @Override
                public Link getLink() {
                    return parent;
                }
            });
            if (run != null) {
                runs.add(run);
            }
        }
        if (runs.size() >= limit) {
            return runs;
        }
    }
    return runs;
}
Also used : BlueRun(io.jenkins.blueocean.rest.model.BlueRun) ArrayList(java.util.ArrayList) Reachable(io.jenkins.blueocean.rest.Reachable) Link(io.jenkins.blueocean.rest.hal.Link)

Example 2 with Reachable

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

the class OrganizationFolderTest method testOrganizationFolderFactoryNoPermissionsFolder.

@Test(expected = ServiceException.ForbiddenException.class)
public void testOrganizationFolderFactoryNoPermissionsFolder() throws Exception {
    List<OrganizationFolderPipelineImpl.OrganizationFolderFactory> organizationFolderFactoryList = ExtensionList.lookup(OrganizationFolderPipelineImpl.OrganizationFolderFactory.class);
    OrganizationFolderFactoryTestImpl organizationFolderFactoryTest = ((ExtensionList<OrganizationFolderPipelineImpl.OrganizationFolderFactory>) organizationFolderFactoryList).get(OrganizationFolderFactoryTestImpl.class);
    assertNotNull(organizationFolderFactoryTest);
    OrganizationFolderPipelineImpl folderPipeline = organizationFolderFactoryTest.getFolder(orgFolder, new Reachable() {

        @Override
        public Link getLink() {
            return organization.getLink().rel("/pipelines/");
        }
    }, mockOrganization());
    assertNotNull(folderPipeline);
    assertNotNull(folderPipeline.getQueue());
    assertNotNull(folderPipeline.getQueue().iterator());
    // Make sure the user does not have permissions to that folder
    PowerMockito.when(orgFolder.getACL()).thenReturn(new ACL() {

        @Override
        public boolean hasPermission(Authentication arg0, Permission arg1) {
            return false;
        }
    });
    ScmResourceImpl scmResource = new ScmResourceImpl(orgFolder, folderPipeline);
    StaplerRequest staplerRequest = PowerMockito.mock(StaplerRequest.class);
    assertEquals("hello", scmResource.getContent(staplerRequest));
}
Also used : StaplerRequest(org.kohsuke.stapler.StaplerRequest) ACL(hudson.security.ACL) Authentication(org.acegisecurity.Authentication) ExtensionList(hudson.ExtensionList) Reachable(io.jenkins.blueocean.rest.Reachable) Permission(hudson.security.Permission) Link(io.jenkins.blueocean.rest.hal.Link) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with Reachable

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

the class ChangeSetResourceTest method testChangeSet.

@Test
public void testChangeSet() {
    Reachable reachable = mock(Reachable.class);
    when(reachable.getLink()).thenReturn(new Link("/foo/bar"));
    User user = mock(User.class);
    when(user.getId()).thenReturn("vivek");
    ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);
    when(entry.getAuthor()).thenReturn(user);
    when(entry.getTimestamp()).thenReturn(System.currentTimeMillis());
    when(entry.getCommitId()).thenReturn("12345");
    when(entry.getMsg()).thenReturn("test changeset");
    when(entry.getAffectedPaths()).thenReturn(Collections.singleton("/foo/bar"));
    ChangeSetResource changeSetResource = new ChangeSetResource(new OrganizationImpl("testorg", mock(Folder.class)), entry, reachable);
    assertEquals(user.getId(), changeSetResource.getAuthor().getId());
    assertEquals(entry.getCommitId(), changeSetResource.getCommitId());
    assertEquals(entry.getMsg(), changeSetResource.getMsg());
}
Also used : User(hudson.model.User) ChangeLogSet(hudson.scm.ChangeLogSet) Reachable(io.jenkins.blueocean.rest.Reachable) ChangeSetResource(io.jenkins.blueocean.service.embedded.rest.ChangeSetResource) Link(io.jenkins.blueocean.rest.hal.Link) OrganizationImpl(io.jenkins.blueocean.service.embedded.rest.OrganizationImpl) Test(org.junit.Test)

Example 4 with Reachable

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

the class OrganizationFolderTest method testOrgFolderRun.

@Test
@WithoutJenkins
public void testOrgFolderRun() {
    OrganizationFolderPipelineImpl organizationFolder = new OrganizationFolderPipelineImpl(mockOrganization(), orgFolder, new Link("/a/b/")) {
    };
    OrganizationFolderRunImpl organizationFolderRun = new OrganizationFolderRunImpl(organizationFolder, new Reachable() {

        @Override
        public Link getLink() {
            return new Link("/a/b/");
        }
    });
    assertEquals(orgFolder.getName(), organizationFolderRun.getPipeline());
    assertEquals(organization.getName(), organizationFolderRun.getOrganization());
    assertNotNull(organizationFolder.getRuns());
}
Also used : Reachable(io.jenkins.blueocean.rest.Reachable) Link(io.jenkins.blueocean.rest.hal.Link) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) WithoutJenkins(org.jvnet.hudson.test.WithoutJenkins)

Example 5 with Reachable

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

the class FavoritesStatePreloader method getFetchData.

@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
    User jenkinsUser = User.current();
    if (jenkinsUser != null) {
        BlueOrganization organization = IterableUtils.getFirst(OrganizationFactory.getInstance().list(), null);
        if (organization != null) {
            String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
            // don't need this list when at pipeline pages
            if (pipelineFullName != null) {
                return null;
            }
            UserImpl blueUser = new UserImpl(organization, jenkinsUser, organization.getUsers());
            BlueFavoriteContainer favoritesContainer = blueUser.getFavorites();
            if (favoritesContainer != null) {
                JSONArray favorites = new JSONArray();
                // Limit the number of favorites to return to a sane amount
                Iterator<BlueFavorite> favoritesIterator = favoritesContainer.iterator(0, DEFAULT_LIMIT);
                while (favoritesIterator.hasNext()) {
                    Reachable favorite = favoritesIterator.next();
                    try {
                        favorites.add(JSONObject.fromObject(Export.toJson(favorite)));
                    } catch (IOException e) {
                        LOGGER.log(Level.FINE, String.format("Unable to preload favorites for User '%s'. Serialization error.", jenkinsUser.getFullName()), e);
                        return null;
                    }
                }
                return new FetchData(favoritesContainer.getLink().getHref() + "?start=0&limit=" + DEFAULT_LIMIT, favorites.toString());
            }
        }
    }
    // Don't preload any data on the page.
    return null;
}
Also used : BlueFavoriteContainer(io.jenkins.blueocean.rest.model.BlueFavoriteContainer) BlueFavorite(io.jenkins.blueocean.rest.model.BlueFavorite) User(hudson.model.User) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) UserImpl(io.jenkins.blueocean.service.embedded.rest.UserImpl) JSONArray(net.sf.json.JSONArray) Reachable(io.jenkins.blueocean.rest.Reachable) IOException(java.io.IOException)

Aggregations

Reachable (io.jenkins.blueocean.rest.Reachable)5 Link (io.jenkins.blueocean.rest.hal.Link)4 Test (org.junit.Test)3 User (hudson.model.User)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ExtensionList (hudson.ExtensionList)1 ChangeLogSet (hudson.scm.ChangeLogSet)1 ACL (hudson.security.ACL)1 Permission (hudson.security.Permission)1 BlueFavorite (io.jenkins.blueocean.rest.model.BlueFavorite)1 BlueFavoriteContainer (io.jenkins.blueocean.rest.model.BlueFavoriteContainer)1 BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)1 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)1 ChangeSetResource (io.jenkins.blueocean.service.embedded.rest.ChangeSetResource)1 OrganizationImpl (io.jenkins.blueocean.service.embedded.rest.OrganizationImpl)1 UserImpl (io.jenkins.blueocean.service.embedded.rest.UserImpl)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 JSONArray (net.sf.json.JSONArray)1 Authentication (org.acegisecurity.Authentication)1