Search in sources :

Example 1 with ResetRequest

use of org.sonarqube.ws.client.setting.ResetRequest in project sonarqube by SonarSource.

the class WebhooksTest method setProperty.

private void setProperty(@Nullable String componentKey, String key, @Nullable String value) {
    if (value == null) {
        ResetRequest req = ResetRequest.builder().setKeys(key).setComponent(componentKey).build();
        adminWs.settingsService().reset(req);
    } else {
        SetRequest req = SetRequest.builder().setKey(key).setValue(value).setComponent(componentKey).build();
        adminWs.settingsService().set(req);
    }
}
Also used : SetRequest(org.sonarqube.ws.client.setting.SetRequest) ResetRequest(org.sonarqube.ws.client.setting.ResetRequest)

Example 2 with ResetRequest

use of org.sonarqube.ws.client.setting.ResetRequest in project sonarqube by SonarSource.

the class ResetAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ResetRequest resetRequest = toWsRequest(request);
        Optional<ComponentDto> component = getComponent(dbSession, resetRequest);
        checkPermissions(component);
        resetRequest.getKeys().forEach(key -> {
            SettingData data = new SettingData(key, emptyList(), component.orElse(null));
            ImmutableList.of(validations.scope(), validations.qualifier()).forEach(validation -> validation.accept(data));
        });
        List<String> keys = getKeys(resetRequest);
        if (component.isPresent()) {
            settingsUpdater.deleteComponentSettings(dbSession, component.get(), keys);
        } else {
            settingsUpdater.deleteGlobalSettings(dbSession, keys);
        }
        dbSession.commit();
        response.noContent();
    }
}
Also used : DbSession(org.sonar.db.DbSession) SettingData(org.sonar.server.setting.ws.SettingValidations.SettingData) ComponentDto(org.sonar.db.component.ComponentDto) ResetRequest(org.sonarqube.ws.client.setting.ResetRequest)

Aggregations

ResetRequest (org.sonarqube.ws.client.setting.ResetRequest)2 DbSession (org.sonar.db.DbSession)1 ComponentDto (org.sonar.db.component.ComponentDto)1 SettingData (org.sonar.server.setting.ws.SettingValidations.SettingData)1 SetRequest (org.sonarqube.ws.client.setting.SetRequest)1