Search in sources :

Example 6 with PropertyDto

use of org.sonar.db.property.PropertyDto in project sonarqube by SonarSource.

the class ServerIdManager method persistServerIdIfMissingOrOldFormatted.

/**
   * Insert or update {@link CoreProperties#SERVER_ID} property in DB to a UUID if it doesn't exist or if it's a date
   * (per the old format of {@link CoreProperties#SERVER_ID} before 6.1).
   */
private void persistServerIdIfMissingOrOldFormatted(DbSession dbSession, @Nullable PropertyDto dto) {
    if (dto == null || dto.getValue().isEmpty() || isDate(dto.getValue())) {
        dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(SERVER_ID).setValue(uuidFactory.create()));
        dbSession.commit();
    }
}
Also used : PropertyDto(org.sonar.db.property.PropertyDto)

Example 7 with PropertyDto

use of org.sonar.db.property.PropertyDto in project sonarqube by SonarSource.

the class StartupMetadataProvider method selectProperty.

private static String selectProperty(DbClient dbClient, DbSession dbSession, String key) {
    PropertyDto prop = dbClient.propertiesDao().selectGlobalProperty(dbSession, key);
    checkState(prop != null, "Property %s is missing in database", key);
    checkState(!isBlank(prop.getValue()), "Property %s is set but empty in database", key);
    return prop.getValue();
}
Also used : PropertyDto(org.sonar.db.property.PropertyDto)

Example 8 with PropertyDto

use of org.sonar.db.property.PropertyDto in project sonarqube by SonarSource.

the class SelectAction method doHandle.

private void doHandle(SelectWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        checkQualityGate(dbSession, request.getGateId());
        ComponentDto project = getProject(dbSession, request.getProjectId(), request.getProjectKey());
        dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(SONAR_QUALITYGATE_PROPERTY).setResourceId(project.getId()).setValue(String.valueOf(request.getGateId())));
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) PropertyDto(org.sonar.db.property.PropertyDto)

Example 9 with PropertyDto

use of org.sonar.db.property.PropertyDto in project sonarqube by SonarSource.

the class ShowAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkIsSystemAdministrator();
    try (DbSession dbSession = dbClient.openSession(true)) {
        Map<String, PropertyDto> properties = dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, SETTINGS_KEYS).stream().collect(Collectors.uniqueIndex(PropertyDto::getKey, Function.identity()));
        writeProtobuf(doHandle(properties), request, response);
    }
}
Also used : DbSession(org.sonar.db.DbSession) PropertyDto(org.sonar.db.property.PropertyDto)

Example 10 with PropertyDto

use of org.sonar.db.property.PropertyDto in project sonarqube by SonarSource.

the class SetAction method doHandle.

private void doHandle(DbSession dbSession, SetRequest request) {
    Optional<ComponentDto> component = searchComponent(dbSession, request);
    checkPermissions(component);
    PropertyDefinition definition = propertyDefinitions.get(request.getKey());
    String value;
    commonChecks(request, component);
    if (!request.getFieldValues().isEmpty()) {
        value = doHandlePropertySet(dbSession, request, definition, component);
    } else {
        validate(request);
        PropertyDto property = toProperty(request, component);
        value = property.getValue();
        dbClient.propertiesDao().saveProperty(dbSession, property);
    }
    dbSession.commit();
    if (!component.isPresent()) {
        settingsChangeNotifier.onGlobalPropertyChange(persistedKey(request), value);
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) PropertyDefinition(org.sonar.api.config.PropertyDefinition) PropertyDto(org.sonar.db.property.PropertyDto)

Aggregations

PropertyDto (org.sonar.db.property.PropertyDto)57 Test (org.junit.Test)25 ComponentDto (org.sonar.db.component.ComponentDto)23 OrganizationDto (org.sonar.db.organization.OrganizationDto)13 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)13 DbSession (org.sonar.db.DbSession)8 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)6 MapSettings (org.sonar.api.config.MapSettings)3 Settings (org.sonar.api.config.Settings)3 PropertyTesting.newComponentPropertyDto (org.sonar.db.property.PropertyTesting.newComponentPropertyDto)2 PropertyTesting.newGlobalPropertyDto (org.sonar.db.property.PropertyTesting.newGlobalPropertyDto)2 UserDto (org.sonar.db.user.UserDto)2 Date (java.util.Date)1 Matchers.anyString (org.mockito.Matchers.anyString)1 PropertyDefinition (org.sonar.api.config.PropertyDefinition)1 FilePathWithHashDto (org.sonar.db.component.FilePathWithHashDto)1 SnapshotDto (org.sonar.db.component.SnapshotDto)1 PropertyQuery (org.sonar.db.property.PropertyQuery)1 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)1 TestResponse (org.sonar.server.ws.TestResponse)1