@Override public void handle(Request request, Response response) throws Exception { long id = request.mandatoryParamAsLong(PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectById(dbSession, id); checkArgument(customMeasure != null, "Custom measure with id '%s' does not exist", id); checkPermission(dbSession, customMeasure); dbClient.customMeasureDao().delete(dbSession, id); dbSession.commit(); } response.noContent(); }
@Override public void handle(Request request, Response response) { long qualityGateId = request.mandatoryParamAsLong(QualityGatesWsParameters.PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, qualityGateId); QualityGateDto defaultQualityGate = finder.getDefault(dbSession, organization); checkArgument(!defaultQualityGate.getId().equals(qualityGate.getId()), "The default quality gate cannot be removed"); wsSupport.checkCanEdit(qualityGate); dbClient.propertiesDao().deleteByKeyAndValue(dbSession, SONAR_QUALITYGATE_PROPERTY, String.valueOf(qualityGate.getId())); dbClient.qualityGateDao().delete(qualityGate, dbSession); dbSession.commit(); response.noContent(); } }
@Override public void handle(Request request, Response response) { long conditionId = request.mandatoryParamAsLong(PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QualityGateConditionDto condition = wsSupport.getCondition(dbSession, conditionId); QGateWithOrgDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndId(dbSession, organization, condition.getQualityGateId()); checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", conditionId, condition.getQualityGateId()); wsSupport.checkCanEdit(qualityGateDto); dbClient.gateConditionDao().delete(condition, dbSession); dbSession.commit(); response.noContent(); } }
@Override public void handle(Request request, Response response) { long gateId = request.mandatoryParamAsLong(PARAM_GATE_ID); String projectId = request.param(PARAM_PROJECT_ID); String projectKey = request.param(PARAM_PROJECT_KEY); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, gateId); ComponentDto project = getProject(dbSession, organization, projectId, projectKey); wsSupport.checkCanAdminProject(organization, project); dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey(SONAR_QUALITYGATE_PROPERTY) .setResourceId(project.getId()) .setValue(String.valueOf(qualityGate.getId()))); dbSession.commit(); } response.noContent(); }
@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) throws Exception { long id = request.mandatoryParamAsLong(PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectById(dbSession, id); checkArgument(customMeasure != null, "Custom measure with id '%s' does not exist", id); checkPermission(dbSession, customMeasure); dbClient.customMeasureDao().delete(dbSession, id); dbSession.commit(); } response.noContent(); }
@Override public void handle(Request request, Response response) { long qualityGateId = request.mandatoryParamAsLong(QualityGatesWsParameters.PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QGateWithOrgDto qualityGate = finder.getByOrganizationAndId(dbSession, organization, qualityGateId); QualityGateDto defaultQualityGate = finder.getDefault(dbSession, organization); checkArgument(!defaultQualityGate.getId().equals(qualityGate.getId()), "The default quality gate cannot be removed"); wsSupport.checkCanEdit(qualityGate); dbClient.propertiesDao().deleteByKeyAndValue(dbSession, SONAR_QUALITYGATE_PROPERTY, String.valueOf(qualityGate.getId())); dbClient.qualityGateDao().delete(qualityGate, dbSession); dbSession.commit(); response.noContent(); } }
@Override public void handle(Request request, Response response) { long conditionId = request.mandatoryParamAsLong(PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QualityGateConditionDto condition = wsSupport.getCondition(dbSession, conditionId); QGateWithOrgDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndId(dbSession, organization, condition.getQualityGateId()); checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", conditionId, condition.getQualityGateId()); wsSupport.checkCanEdit(qualityGateDto); dbClient.gateConditionDao().delete(condition, dbSession); dbSession.commit(); response.noContent(); } }
@Override public void handle(Request request, Response response) { long gateId = request.mandatoryParamAsLong(PARAM_GATE_ID); String projectId = request.param(PARAM_PROJECT_ID); String projectKey = request.param(PARAM_PROJECT_KEY); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QGateWithOrgDto qualityGate = qualityGateFinder.getByOrganizationAndId(dbSession, organization, gateId); ComponentDto project = getProject(dbSession, organization, projectId, projectKey); wsSupport.checkCanAdminProject(organization, project); dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey(SONAR_QUALITYGATE_PROPERTY) .setResourceId(project.getId()) .setValue(String.valueOf(qualityGate.getId()))); dbSession.commit(); } response.noContent(); }
@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); } }