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);
}
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();
}
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));
}
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());
}
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));
}
Aggregations