Search in sources :

Example 1 with BuildNotFoundException

use of net.nemerosa.ontrack.model.exceptions.BuildNotFoundException in project ontrack by nemerosa.

the class GitChangeLogBranchGraphQLFieldContributor method gitChangeLogFetcher.

private DataFetcher gitChangeLogFetcher() {
    return fetcher(Branch.class, (DataFetchingEnvironment environment, Branch branch) -> {
        String from = GraphqlUtils.getStringArgument(environment, "from").orElseThrow(() -> new IllegalStateException("From argument is required."));
        String to = GraphqlUtils.getStringArgument(environment, "to").orElseThrow(() -> new IllegalStateException("To argument is required."));
        Build fromBuild = structureService.findBuildByName(branch.getProject().getName(), branch.getName(), from).orElseThrow(() -> new BuildNotFoundException(branch.getProject().getName(), branch.getName(), from));
        Build toBuild = structureService.findBuildByName(branch.getProject().getName(), branch.getName(), to).orElseThrow(() -> new BuildNotFoundException(branch.getProject().getName(), branch.getName(), to));
        return gitService.changeLog(new BuildDiffRequest(fromBuild.getId(), toBuild.getId()));
    });
}
Also used : BuildDiffRequest(net.nemerosa.ontrack.extension.api.model.BuildDiffRequest) BuildNotFoundException(net.nemerosa.ontrack.model.exceptions.BuildNotFoundException) GraphQLString(graphql.Scalars.GraphQLString) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment)

Example 2 with BuildNotFoundException

use of net.nemerosa.ontrack.model.exceptions.BuildNotFoundException in project ontrack by nemerosa.

the class CoreBuildFilterJdbcRepository method between.

@Override
public List<Build> between(Branch branch, String from, String to) {
    StringBuilder sql = new StringBuilder("SELECT ID FROM BUILDS WHERE " + "BRANCHID = :branchId ");
    MapSqlParameterSource params = params("branchId", branch.id());
    Integer fromId;
    Integer toId = null;
    // From build
    fromId = structureRepository.getBuildByName(branch.getProject().getName(), branch.getName(), from).orElseThrow(() -> new BuildNotFoundException(branch.getProject().getName(), branch.getName(), from)).id();
    // To build
    if (StringUtils.isNotBlank(to)) {
        toId = structureRepository.getBuildByName(branch.getProject().getName(), branch.getName(), to).orElseThrow(() -> new BuildNotFoundException(branch.getProject().getName(), branch.getName(), to)).id();
    }
    if (toId != null) {
        if (toId < fromId) {
            int i = toId;
            toId = fromId;
            fromId = i;
        }
    }
    sql.append(" AND ID >= :fromId");
    params.addValue("fromId", fromId);
    if (toId != null) {
        sql.append(" AND ID <= :toId");
        params.addValue("toId", toId);
    }
    // Ordering
    sql.append(" ORDER BY ID DESC");
    // Query
    return loadBuilds(sql.toString(), params);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) BuildNotFoundException(net.nemerosa.ontrack.model.exceptions.BuildNotFoundException)

Aggregations

BuildNotFoundException (net.nemerosa.ontrack.model.exceptions.BuildNotFoundException)2 GraphQLString (graphql.Scalars.GraphQLString)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 BuildDiffRequest (net.nemerosa.ontrack.extension.api.model.BuildDiffRequest)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1