@Test public void to_assoc_with_project_having_assoc() { ProjectQgateAssociation project = new ProjectQgateAssociationDto() .setId(1L) .setName("polop") .setGateId("10") .toQgateAssociation(); assertThat(project.id()).isEqualTo(1); assertThat(project.name()).isEqualTo("polop"); assertThat(project.isMember()).isTrue(); }
@Test public void to_assoc_with_project_not_having_assoc() { ProjectQgateAssociation project = new ProjectQgateAssociationDto() .setId(1L) .setName("polop") .setGateId(null) .toQgateAssociation(); assertThat(project.id()).isEqualTo(1); assertThat(project.name()).isEqualTo("polop"); assertThat(project.isMember()).isFalse(); }
@Override public void handle(Request request, Response response) { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, request.mandatoryParamAsLong(PARAM_GATE_ID)); Association associations = find(dbSession, ProjectQgateAssociationQuery.builder() .qualityGate(qualityGate) .membership(request.param(PARAM_QUERY) == null ? request.param(SELECTED) : ANY) .projectSearch(request.param(PARAM_QUERY)) .pageIndex(request.paramAsInt(PARAM_PAGE)) .pageSize(request.paramAsInt(PARAM_PAGE_SIZE)) .build()); Qualitygates.SearchResponse.Builder createResponse = Qualitygates.SearchResponse.newBuilder() .setMore(associations.hasMoreResults()); for (ProjectQgateAssociation project : associations.projects()) { createResponse.addResultsBuilder() .setId(project.id()) .setName(project.name()) .setSelected(project.isMember()); } writeProtobuf(createResponse.build(), request, response); } }
@Override public void handle(Request request, Response response) { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QGateWithOrgDto qualityGate = qualityGateFinder.getByOrganizationAndId(dbSession, organization, request.mandatoryParamAsLong(PARAM_GATE_ID)); Association associations = find(dbSession, ProjectQgateAssociationQuery.builder() .qualityGate(qualityGate) .membership(request.param(PARAM_QUERY) == null ? request.param(SELECTED) : ANY) .projectSearch(request.param(PARAM_QUERY)) .pageIndex(request.paramAsInt(PARAM_PAGE)) .pageSize(request.paramAsInt(PARAM_PAGE_SIZE)) .build()); Qualitygates.SearchResponse.Builder createResponse = Qualitygates.SearchResponse.newBuilder() .setMore(associations.hasMoreResults()); for (ProjectQgateAssociation project : associations.projects()) { createResponse.addResultsBuilder() .setId(project.id()) .setName(project.name()) .setSelected(project.isMember()); } writeProtobuf(createResponse.build(), request, response); } }