Search in sources :

Example 1 with Pagination

use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.

the class PipelineHistoryController method list.

@RequestMapping(value = "/**/pipelineHistory.json", method = RequestMethod.GET)
public ModelAndView list(@RequestParam("pipelineName") String pipelineName, @RequestParam(value = "perPage", required = false) Integer perPageParam, @RequestParam(value = "start", required = false) Integer startParam, @RequestParam(value = "labelFilter", required = false) String labelFilter, HttpServletResponse response, HttpServletRequest request) throws NamingException {
    PipelineConfig pipelineConfig = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
    String username = CaseInsensitiveString.str(UserHelper.getUserName().getUsername());
    Pagination pagination;
    try {
        pagination = Pagination.pageStartingAt(startParam, pipelineHistoryService.totalCount(pipelineName), perPageParam);
    } catch (Exception e) {
        Map<String, Object> json = new LinkedHashMap<>();
        addDeveloperErrorMessage(json, e);
        return jsonNotAcceptable(json).respond(response);
    }
    PipelinePauseInfo pauseInfo = pipelinePauseService.pipelinePauseInfo(pipelineName);
    boolean hasBuildCauseInBuffer = pipelineScheduleQueue.hasBuildCause(CaseInsensitiveString.str(pipelineConfig.name()));
    PipelineInstanceModels pipelineHistory = StringUtil.isBlank(labelFilter) ? pipelineHistoryService.load(pipelineName, pagination, username, true) : pipelineHistoryService.findMatchingPipelineInstances(pipelineName, labelFilter, perPageParam, UserHelper.getUserName(), new HttpLocalizedOperationResult());
    boolean hasForcedBuildCause = pipelineScheduleQueue.hasForcedBuildCause(pipelineName);
    PipelineHistoryJsonPresentationModel historyJsonPresenter = new PipelineHistoryJsonPresentationModel(pauseInfo, pipelineHistory, pipelineConfig, pagination, canForce(pipelineConfig, username), hasForcedBuildCause, hasBuildCauseInBuffer, canPause(pipelineConfig, username));
    return jsonFound(historyJsonPresenter.toJson()).respond(response);
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) PipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels) PipelineHistoryJsonPresentationModel(com.thoughtworks.go.server.presentation.models.PipelineHistoryJsonPresentationModel) PipelinePauseInfo(com.thoughtworks.go.domain.PipelinePauseInfo) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) NamingException(javax.naming.NamingException) PipelineNotFoundException(com.thoughtworks.go.config.PipelineNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Pagination

use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.

the class PipelineSqlMapDao method getPageNumberForCounter.

public int getPageNumberForCounter(String pipelineName, int pipelineCounter, int limit) {
    Integer maxCounter = getCounterForPipeline(pipelineName);
    Pagination pagination = Pagination.pageStartingAt((maxCounter - pipelineCounter), maxCounter, limit);
    return pagination.getCurrentPage();
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination)

Example 3 with Pagination

use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntry.

@Test
public void shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntry() throws Exception {
    HgMaterial hg = new HgMaterial("url", null);
    String[] hg_revs = { "h1" };
    scheduleUtil.checkinInOrder(hg, hg_revs);
    String pipelineName = "p1";
    String stageName = "stage_name";
    ScheduleTestUtil.AddedPipeline p1 = scheduleUtil.saveConfigWith(pipelineName, stageName, scheduleUtil.m(hg));
    for (int i = 0; i < 11; i++) {
        scheduleUtil.runAndPass(p1, "h1");
    }
    StageHistoryPage historyPage = stageDao.findStageHistoryPage(pipelineName, stageName, new FuncVarArg<Pagination, Object>() {

        @Override
        public Pagination call(Object... args) {
            return Pagination.pageByNumber(2, 2, 10);
        }
    });
    StageHistoryEntry topOfSecondPage = historyPage.getStages().get(0);
    StageHistoryEntry bottomOfFirstPage = stageDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfSecondPage);
    assertThat(bottomOfFirstPage.getId(), is(topOfSecondPage.getId() + 1));
    assertThat(bottomOfFirstPage.getIdentifier().getPipelineName(), is(pipelineName));
    assertThat(bottomOfFirstPage.getIdentifier().getStageName(), is(stageName));
    assertThat(bottomOfFirstPage.getIdentifier().getPipelineCounter(), is(2));
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) ScheduleTestUtil(com.thoughtworks.go.server.service.ScheduleTestUtil) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.Test)

Example 4 with Pagination

use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.

the class JobInstanceServiceTest method shouldDelegateToDAO_findJobHistoryPage.

@Test
public void shouldDelegateToDAO_findJobHistoryPage() {
    when(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipeline"))).thenReturn(true);
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    when(securityService.hasViewPermissionForPipeline(Username.valueOf("looser"), "pipeline")).thenReturn(true);
    final JobInstanceService jobService = new JobInstanceService(jobInstanceDao, buildPropertiesService, topic, jobStatusCache, transactionTemplate, transactionSynchronizationManager, null, null, goConfigService, securityService, pluginManager, serverHealthService);
    Pagination pagination = Pagination.pageStartingAt(1, 1, 1);
    jobService.findJobHistoryPage("pipeline", "stage", "job", pagination, "looser", new HttpOperationResult());
    verify(jobInstanceDao).findJobHistoryPage("pipeline", "stage", "job", pagination.getPageSize(), pagination.getOffset());
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Test(org.junit.Test)

Example 5 with Pagination

use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.

the class StageSqlMapDaoTest method shouldLoadStageHistoryEntryForAStageRunAfterTheLatestRunThatIsRetrievedForStageHistory.

@Test
public void shouldLoadStageHistoryEntryForAStageRunAfterTheLatestRunThatIsRetrievedForStageHistory() throws Exception {
    String pipelineName = "some_pipeline_name";
    String stageName = "some_stage_name";
    FuncVarArg function = mock(FuncVarArg.class);
    Pagination pagination = mock(Pagination.class);
    when(pagination.getCurrentPage()).thenReturn(3);
    when(pagination.getPageSize()).thenReturn(10);
    when(function.call()).thenReturn(pagination);
    StageSqlMapDao spy = spy(stageSqlMapDao);
    List<StageHistoryEntry> expectedStageHistoryEntriesList = mock(ArrayList.class);
    StageHistoryEntry topOfThisPage = mock(StageHistoryEntry.class);
    when(expectedStageHistoryEntriesList.get(0)).thenReturn(topOfThisPage);
    StageHistoryEntry bottomOfLastPage = mock(StageHistoryEntry.class);
    doReturn(expectedStageHistoryEntriesList).when(spy).findStages(pagination, pipelineName, stageName);
    doReturn(bottomOfLastPage).when(spy).findImmediateChronologicallyForwardStageHistoryEntry(topOfThisPage);
    StageHistoryPage stageHistoryPage = spy.findStageHistoryPage(pipelineName, stageName, function);
    assertThat(stageHistoryPage.getStages(), is(expectedStageHistoryEntriesList));
    assertThat(stageHistoryPage.getImmediateChronologicallyForwardStageHistoryEntry(), is(bottomOfLastPage));
    verify(spy, times(1)).findStages(pagination, pipelineName, stageName);
    verify(spy, times(1)).findImmediateChronologicallyForwardStageHistoryEntry(expectedStageHistoryEntriesList.get(0));
}
Also used : FuncVarArg(com.thoughtworks.go.util.FuncVarArg) Pagination(com.thoughtworks.go.server.util.Pagination) StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.Test)

Aggregations

Pagination (com.thoughtworks.go.server.util.Pagination)24 Test (org.junit.Test)16 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)7 ScheduleTestUtil (com.thoughtworks.go.server.service.ScheduleTestUtil)7 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)6 StageHistoryEntry (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)5 StageHistoryPage (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage)5 StageInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels)4 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)3 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 Method (java.lang.reflect.Method)2 Date (java.util.Date)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 PipelineNotFoundException (com.thoughtworks.go.config.PipelineNotFoundException)1 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 PipelinePauseInfo (com.thoughtworks.go.domain.PipelinePauseInfo)1