Search in sources :

Example 1 with PipelineRunIdInfo

use of com.thoughtworks.go.domain.PipelineRunIdInfo in project gocd by gocd.

the class MaterialServiceTest method shouldReturnNullIfNoInstanceIsPresent.

@Test
public void shouldReturnNullIfNoInstanceIsPresent() {
    GitMaterialConfig materialConfig = git("http://test.com");
    when(materialRepository.findMaterialInstance(materialConfig)).thenReturn(null);
    PipelineRunIdInfo info = materialService.getLatestAndOldestModification(materialConfig, "");
    verify(materialRepository, never()).getOldestAndLatestModificationId(anyLong(), anyString());
    assertThat(info, is(nullValue()));
}
Also used : PipelineRunIdInfo(com.thoughtworks.go.domain.PipelineRunIdInfo) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with PipelineRunIdInfo

use of com.thoughtworks.go.domain.PipelineRunIdInfo in project gocd by gocd.

the class ModificationsRepresenter method toJSON.

public static void toJSON(OutputWriter outputWriter, List<Modification> modifications, PipelineRunIdInfo latestAndOldestModId, String fingerprint, String pattern, Integer pageSize) {
    if (modifications == null || modifications.isEmpty()) {
        outputWriter.addChildList("modifications", emptyList());
        return;
    }
    if (latestAndOldestModId != null) {
        Modification latest = modifications.get(0);
        Modification oldest = modifications.get(modifications.size() - 1);
        String previousLink = null, nextLink = null;
        if (latest.getId() != latestAndOldestModId.getLatestRunId()) {
            previousLink = Routes.InternalMaterialConfig.previous(fingerprint, latest.getId(), pattern, pageSize);
        }
        if (oldest.getId() != latestAndOldestModId.getOldestRunId()) {
            nextLink = Routes.InternalMaterialConfig.next(fingerprint, oldest.getId(), pattern, pageSize);
        }
        if (isNotBlank(previousLink) || isNotBlank(nextLink)) {
            String finalPreviousLink = previousLink;
            String finalNextLink = nextLink;
            outputWriter.addLinks(outputLinkWriter -> {
                outputLinkWriter.addLinkIfPresent("previous", finalPreviousLink);
                outputLinkWriter.addLinkIfPresent("next", finalNextLink);
            });
        }
    }
    outputWriter.addChildList("modifications", childWriter -> {
        modifications.forEach((mod) -> childWriter.addChild(writer -> ModificationRepresenter.toJSON(writer, mod)));
    });
}
Also used : OutputWriter(com.thoughtworks.go.api.base.OutputWriter) List(java.util.List) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) Collections.emptyList(java.util.Collections.emptyList) PipelineRunIdInfo(com.thoughtworks.go.domain.PipelineRunIdInfo) Modification(com.thoughtworks.go.domain.materials.Modification) Routes(com.thoughtworks.go.spark.Routes) Modification(com.thoughtworks.go.domain.materials.Modification)

Example 3 with PipelineRunIdInfo

use of com.thoughtworks.go.domain.PipelineRunIdInfo in project gocd by gocd.

the class StageInstanceControllerV3 method history.

public String history(Request request, Response response) throws IOException {
    String pipelineName = request.params("pipeline_name");
    String stageName = request.params("stage_name");
    Long after = getCursor(request, "after");
    Long before = getCursor(request, "before");
    int pageSize = getPageSize(request);
    StageInstanceModels stageInstanceModels = stageService.findStageHistoryViaCursor(currentUsername(), pipelineName, stageName, after, before, pageSize);
    PipelineRunIdInfo latestAndOldestPipelineIds = stageService.getOldestAndLatestStageInstanceId(currentUsername(), pipelineName, stageName);
    return writerForTopLevelObject(request, response, writer -> StageInstancesRepresenter.toJSON(writer, stageInstanceModels, latestAndOldestPipelineIds));
}
Also used : PipelineRunIdInfo(com.thoughtworks.go.domain.PipelineRunIdInfo) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels)

Example 4 with PipelineRunIdInfo

use of com.thoughtworks.go.domain.PipelineRunIdInfo in project gocd by gocd.

the class MaterialServiceTest method shouldCallDaoToFetchLatestAndOlderModification.

@Test
public void shouldCallDaoToFetchLatestAndOlderModification() {
    GitMaterialConfig materialConfig = git("http://test.com");
    GitMaterialInstance gitMaterialInstance = new GitMaterialInstance("http://test.com", null, null, null, "flyweight");
    PipelineRunIdInfo value = new PipelineRunIdInfo(1, 2);
    when(materialRepository.findMaterialInstance(materialConfig)).thenReturn(gitMaterialInstance);
    when(materialRepository.getOldestAndLatestModificationId(anyLong(), anyString())).thenReturn(value);
    PipelineRunIdInfo info = materialService.getLatestAndOldestModification(materialConfig, "");
    verify(materialRepository).getOldestAndLatestModificationId(anyLong(), eq(""));
    assertThat(info, is(value));
}
Also used : PipelineRunIdInfo(com.thoughtworks.go.domain.PipelineRunIdInfo) GitMaterialInstance(com.thoughtworks.go.domain.materials.git.GitMaterialInstance) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with PipelineRunIdInfo

use of com.thoughtworks.go.domain.PipelineRunIdInfo in project gocd by gocd.

the class PipelineInstanceControllerV1 method getHistoryInfo.

String getHistoryInfo(Request request, Response response) throws IOException {
    String pipelineName = request.params("pipeline_name");
    Integer pageSize = getPageSize(request);
    Long after = getCursor(request, "after");
    Long before = getCursor(request, "before");
    PipelineInstanceModels pipelineInstanceModels = pipelineHistoryService.loadPipelineHistoryData(currentUsername(), pipelineName, after, before, pageSize);
    PipelineRunIdInfo latestAndOldestPipelineIds = pipelineHistoryService.getOldestAndLatestPipelineId(pipelineName, currentUsername());
    return writerForTopLevelObject(request, response, (outputWriter) -> PipelineInstanceModelsRepresenter.toJSON(outputWriter, pipelineInstanceModels, latestAndOldestPipelineIds));
}
Also used : PipelineRunIdInfo(com.thoughtworks.go.domain.PipelineRunIdInfo) PipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)

Aggregations

PipelineRunIdInfo (com.thoughtworks.go.domain.PipelineRunIdInfo)7 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 OutputWriter (com.thoughtworks.go.api.base.OutputWriter)1 JobInstances (com.thoughtworks.go.domain.JobInstances)1 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)1 GitMaterialInstance (com.thoughtworks.go.domain.materials.git.GitMaterialInstance)1 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)1 StageInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels)1 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)1 Routes (com.thoughtworks.go.spark.Routes)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 StringUtils.isNotBlank (org.apache.commons.lang3.StringUtils.isNotBlank)1