Search in sources :

Example 6 with FeedEntries

use of com.thoughtworks.go.domain.feed.FeedEntries in project gocd by gocd.

the class StageService method feed.

public FeedEntries feed(String pipelineName, Username username) {
    String key = cacheKeyForLatestStageFeedForPipeline(pipelineName);
    List<StageFeedEntry> feedEntries = (List<StageFeedEntry>) goCache.get(key);
    if (feedEntries == null) {
        synchronized (key) {
            // Double check locking is done because the query is expensive (takes about 2 seconds)
            feedEntries = (List<StageFeedEntry>) goCache.get(key);
            if (feedEntries == null) {
                feedEntries = stageDao.findCompletedStagesFor(pipelineName, FeedModifier.Latest, -1, FEED_PAGE_SIZE);
                populateAuthors(feedEntries, pipelineName, username);
                goCache.put(key, feedEntries);
            }
        }
    }
    return cloner.deepClone(new FeedEntries(new ArrayList<>(feedEntries)));
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry)

Example 7 with FeedEntries

use of com.thoughtworks.go.domain.feed.FeedEntries in project gocd by gocd.

the class StageService method findStageFeedBy.

public FeedEntries findStageFeedBy(String pipelineName, Integer pipelineCounter, FeedModifier feedModifier, Username username) {
    if (pipelineCounter != null) {
        List<StageFeedEntry> feedBasedOnPipelineCounter = stageDao.findStageFeedBy(pipelineName, pipelineCounter, feedModifier, FEED_PAGE_SIZE);
        return cloner.deepClone(new FeedEntries(new ArrayList<>(feedBasedOnPipelineCounter)));
    }
    String key = cacheKeyForLatestStageFeedForPipelineSortedByPipelineCounter(pipelineName);
    List<StageFeedEntry> feedEntries = (List<StageFeedEntry>) goCache.get(key);
    if (feedEntries == null) {
        synchronized (key) {
            feedEntries = (List<StageFeedEntry>) goCache.get(key);
            if (feedEntries == null) {
                feedEntries = stageDao.findStageFeedBy(pipelineName, pipelineCounter, null, FEED_PAGE_SIZE);
                populateAuthors(feedEntries, pipelineName, username);
                goCache.put(key, feedEntries);
            }
        }
    }
    return cloner.deepClone(new FeedEntries(new ArrayList<>(feedEntries)));
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry)

Example 8 with FeedEntries

use of com.thoughtworks.go.domain.feed.FeedEntries in project gocd by gocd.

the class PipelineStagesFeedServiceTest method shouldReturnUnauthorizedIfUserDoesNotHaveViewPermissionOnThePipeline.

@Test
public void shouldReturnUnauthorizedIfUserDoesNotHaveViewPermissionOnThePipeline() {
    when(securityService.hasViewPermissionForPipeline(user, "cruise")).thenReturn(false);
    FeedEntries feedEntries = pipelineStagesFeedResolver.feed(user, operationResult);
    assertThat(feedEntries, is(nullValue()));
    verifyThatUserIsUnauthorized();
    verifyNoMoreInteractions(stageService);
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) Test(org.junit.jupiter.api.Test)

Example 9 with FeedEntries

use of com.thoughtworks.go.domain.feed.FeedEntries in project gocd by gocd.

the class PipelineStagesFeedServiceTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    user = new Username(new CaseInsensitiveString("barrow"));
    expected = new FeedEntries();
    stageService = mock(StageService.class);
    securityService = mock(SecurityService.class);
    operationResult = new HttpLocalizedOperationResult();
    pipelineStagesFeedResolver = new PipelineStagesFeedService(stageService, securityService).feedResolverFor("cruise");
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with FeedEntries

use of com.thoughtworks.go.domain.feed.FeedEntries in project gocd by gocd.

the class StageServiceIntegrationTest method shouldLoadStageAuthors_forFirstPageOfFeed.

@Test
public void shouldLoadStageAuthors_forFirstPageOfFeed() throws Exception {
    PipelineConfig downstream = setup2DependentInstances();
    FeedEntries feed = stageService.feed(downstream.name().toString(), new Username(new CaseInsensitiveString("loser")));
    assertStageEntryAuthor(feed);
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.jupiter.api.Test)

Aggregations

FeedEntries (com.thoughtworks.go.domain.feed.FeedEntries)18 Author (com.thoughtworks.go.domain.feed.Author)7 StageFeedEntry (com.thoughtworks.go.domain.feed.stage.StageFeedEntry)7 Username (com.thoughtworks.go.server.domain.Username)7 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 FeedEntry (com.thoughtworks.go.domain.feed.FeedEntry)4 Arrays.asList (java.util.Arrays.asList)4 List (java.util.List)3 XmlWriterContext (com.thoughtworks.go.domain.XmlWriterContext)2 FileSource (com.thoughtworks.go.junit5.FileSource)2 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)2 ArrayList (java.util.ArrayList)2 Document (org.dom4j.Document)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)1 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 NotAuthorizedException (com.thoughtworks.go.config.exceptions.NotAuthorizedException)1