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(); } }
private Optional<ServerId> readCurrentServerId(DbSession dbSession) { PropertyDto dto = dbClient.propertiesDao().selectGlobalProperty(dbSession, SERVER_ID); if (dto == null) { return Optional.empty(); } String value = dto.getValue(); if (isEmpty(value)) { return Optional.empty(); } return Optional.of(ServerId.parse(value)); }
private void ensureServerIdIsValid(DbSession dbSession) { PropertyDto id = dbClient.propertiesDao().selectGlobalProperty(dbSession, SERVER_ID); checkState(id != null, "Property %s is missing in database", SERVER_ID); checkState(isNotEmpty(id.getValue()), "Property %s is empty in database", SERVER_ID); Optional<String> checksum = dbClient.internalPropertiesDao().selectByKey(dbSession, SERVER_ID_CHECKSUM); checkState(checksum.isPresent(), "Internal property %s is missing in database", SERVER_ID_CHECKSUM); checkState(checksum.get().equals(serverIdChecksum.computeFor(id.getValue())), "Server ID is invalid"); }
public static Set<String> extractPropertySetKeys(PropertyDto propertyDto, PropertyDefinition definition) { Set<String> propertySetKeys = new HashSet<>(); definition.fields() .forEach(field -> COMMA_SPLITTER.splitToList(propertyDto.getValue()) .forEach(setId -> propertySetKeys.add(generatePropertySetKey(propertyDto.getKey(), setId, field.key())))); return propertySetKeys; }
@Override public String load(String key) { PropertyDto dto = dbClient.propertiesDao().selectGlobalProperty(key); if (dto != null) { return defaultString(dto.getValue()); } return null; }
@Override public Map<String, String> loadAll() { try (DbSession dbSession = dbClient.openSession(false)) { return dbClient.propertiesDao().selectGlobalProperties(dbSession) .stream() .collect(MoreCollectors.uniqueIndex(PropertyDto::getKey, p -> defaultString(p.getValue()))); } }
private Setting(PropertyDto propertyDto, List<PropertyDto> propertyDtoSetValues, @Nullable PropertyDefinition definition) { this.key = propertyDto.getKey(); this.value = propertyDto.getValue(); this.componentId = propertyDto.getResourceId(); this.definition = definition; this.propertySets = buildPropertySetValuesAsMap(key, propertyDtoSetValues); this.isDefault = false; }
private Map<String, ChildSettings> loadMainBranchConfigurations(DbSession dbSession, Set<String> dbKeys) { return dbKeys.stream().collect(uniqueIndex(Function.identity(), dbKey -> { ChildSettings settings = new ChildSettings(globalSettings); List<PropertyDto> propertyDtos = dbClient.propertiesDao() .selectProjectProperties(dbSession, dbKey); propertyDtos .forEach(property -> settings.setProperty(property.getKey(), property.getValue())); return settings; })); } }
private void addSettings(Settings settings, String componentDbKey) { dbClient.propertiesDao() .selectProjectProperties(componentDbKey) .forEach(property -> settings.setProperty(property.getKey(), property.getValue())); } }
@Override public Map<String, Configuration> loadProjectConfigurations(DbSession dbSession, Set<ComponentDto> projects) { Set<String> mainBranchDbKeys = projects.stream().map(ComponentDto::getKey).collect(Collectors.toSet()); Map<String, ChildSettings> mainBranchSettingsByDbKey = loadMainBranchConfigurations(dbSession, mainBranchDbKeys); return projects.stream() .collect(uniqueIndex(ComponentDto::uuid, component -> { if (component.getDbKey().equals(component.getKey())) { return mainBranchSettingsByDbKey.get(component.getKey()).asConfiguration(); } ChildSettings settings = new ChildSettings(mainBranchSettingsByDbKey.get(component.getKey())); dbClient.propertiesDao() .selectProjectProperties(dbSession, component.getDbKey()) .forEach(property -> settings.setProperty(property.getKey(), property.getValue())); return settings.asConfiguration(); })); }
@Override public void onGlobalPropertyChange(String key, @Nullable String value) { wasCalled = true; PropertyDto property = dbClient.propertiesDao().selectGlobalProperty(key); assertThat(property.getValue()).isEqualTo(value); }
private void assertSelected(String qGateId, long projectId) { assertThat(dbClient.propertiesDao().selectProjectProperty(projectId, SONAR_QUALITYGATE_PROPERTY).getValue()).isEqualTo(qGateId); } }
/** * Saves the specified property and its value. * <p> * If {@link PropertyDto#getValue()} is {@code null} or empty, the properties is persisted as empty. * </p> * * @throws IllegalArgumentException if {@link PropertyDto#getKey()} is {@code null} or empty */ public void saveProperty(DbSession session, PropertyDto property) { save(getMapper(session), property.getKey(), property.getUserId(), property.getResourceId(), property.getValue()); }
private void assertSelected(QualityGateDto qualityGate, ComponentDto project) { assertThat(dbClient.propertiesDao().selectProjectProperty(project.getId(), SONAR_QUALITYGATE_PROPERTY).getValue()).isEqualTo(qualityGate.getId().toString()); }
public void assertExists(String channel, String dispatcher, int userId, @Nullable ComponentDto component) { List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel)) .setComponentId(component == null ? null : component.getId()) .setUserId(userId) .build(), dbSession).stream() .filter(prop -> component == null ? prop.getResourceId() == null : prop.getResourceId() != null) .collect(MoreCollectors.toList()); assertThat(result).hasSize(1); assertThat(result.get(0).getValue()).isEqualTo("true"); }
private void assertPersistedProperty(String propertyKey, String expectedValue) { PropertyDto prop = dbTester.getDbClient().propertiesDao().selectGlobalProperty(dbTester.getSession(), propertyKey); assertThat(prop.getValue()).isEqualTo(expectedValue); }
private void assertPersistedProperty(String propertyKey, String expectedValue) { PropertyDto prop = dbTester.getDbClient().propertiesDao().selectGlobalProperty(dbTester.getSession(), propertyKey); assertThat(prop.getValue()).isEqualTo(expectedValue); } }
@Test public void insert_property_into_database_and_notify_extensions() { assertThat(underTest.getString("foo")).isNull(); underTest.saveProperty("foo", "bar"); assertThat(underTest.getString("foo")).isEqualTo("bar"); assertThat(dbTester.getDbClient().propertiesDao().selectGlobalProperty("foo").getValue()).isEqualTo("bar"); verify(changeNotifier).onGlobalPropertyChange("foo", "bar"); }
private void setValue(PropertyDto propertyDto, Property property) { String value = propertyDto.getValue(); property.setValue(value); PropertyDefinition definition = propertyDefinitions.get(propertyDto.getKey()); if (definition != null && (definition.multiValues() || definition.type().equals(PROPERTY_SET))) { property.setValues(createValues(value)); } }