private static PropertyDto toFieldProperty(KeyValue keyValue, @Nullable Long componentId) { return new PropertyDto().setKey(keyValue.key).setValue(keyValue.value).setResourceId(componentId); }
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; }
/** * 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 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 PropertyDto newPropertyDto(String projectKey1, String projectValue1) { return new PropertyDto() .setKey(projectKey1) .setValue(projectValue1); } }
@Test public void ignore_project_setting_when_removing_global_setting() { logInAsSystemAdministrator(); propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one")); propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("value")); executeRequestOnGlobalSetting("foo"); assertGlobalPropertyDoesNotExist("foo"); assertProjectPropertyExists("foo"); }
@CheckForNull public PropertyDto selectProjectProperty(DbSession dbSession, long componentId, String propertyKey) { return getMapper(dbSession).selectByKey(new PropertyDto().setKey(propertyKey).setResourceId(componentId)); }
@Test public void testHashCode() { assertThat(new PropertyDto().setKey("123").setResourceId(123L).hashCode()).isNotNull(); assertThat(new PropertyDto().setKey("123").setResourceId(123L).hashCode()) .isEqualTo(new PropertyDto().setKey("123").setResourceId(123L).hashCode()); }
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(); } }
@CheckForNull public PropertyDto selectGlobalProperty(DbSession session, String propertyKey) { return getMapper(session).selectByKey(new PropertyDto().setKey(propertyKey)); }
private static List<PropertyDto> getPropertySets(String propertyKey, List<PropertyDto> propertySets, @Nullable Long componentId) { return propertySets.stream() .filter(propertyDto -> Objects.equals(propertyDto.getResourceId(), componentId)) .filter(propertyDto -> propertyDto.getKey().startsWith(propertyKey + ".")) .collect(Collectors.toList()); }
public int delete(DbSession dbSession, PropertyDto dto) { return getMapper(dbSession).delete(dto.getKey(), dto.getUserId(), dto.getResourceId()); }
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 Predicate<PropertyDto> channelAndDispatcherAuthorized() { return prop -> { List<String> key = PROPERTY_KEY_SPLITTER.splitToList(prop.getKey()); return key.size() == 3 && channels.contains(key.get(2)) && isDispatcherAuthorized(prop, key.get(1)); }; }
private static Predicate<PropertyDto> notificationScope(@Nullable ComponentDto project) { return prop -> project == null ? (prop.getResourceId() == null) : (prop.getResourceId() != null); } }
@Test public void deactivate_user_deletes_his_properties() { logInAsSystemAdministrator(); UserDto user = db.users().insertUser(); ComponentDto project = db.components().insertPrivateProject(); db.properties().insertProperty(newUserPropertyDto(user)); db.properties().insertProperty(newUserPropertyDto(user)); db.properties().insertProperty(newUserPropertyDto(user).setResourceId(project.getId())); deactivate(user.getLogin()); assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).build(), dbSession)).isEmpty(); assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).setComponentId(project.getId()).build(), dbSession)).isEmpty(); }
@Test public void user_setting_is_not_updated() { propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my user value").setUserId(42)); propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value")); callForGlobalSetting("my.key", "my new global value"); assertGlobalSetting("my.key", "my new global value"); assertUserSetting("my.key", "my user value", 42); }
private List<PropertyDto> loadDefaultSettings(Optional<String> key) { return propertyDefinitions.getAll().stream() .filter(definition -> !key.isPresent() || key.get().equals(definition.key())) .filter(defaultProperty -> !isEmpty(defaultProperty.defaultValue())) .map(definition -> new PropertyDto().setKey(definition.key()).setValue(definition.defaultValue())) .collect(Collectors.toList()); }
@Test public void return_only_one_setting_when_key_is_provided() { definitions.addComponents(asList( PropertyDefinition.builder("foo").build(), PropertyDefinition.builder("bar").build())); propertyDb.insertProperties( newGlobalPropertyDto().setKey("foo").setValue("one"), newGlobalPropertyDto().setKey("bar").setValue("two")); executeAndVerify(project.getDbKey(), "foo", "return_only_one_setting_when_key_is_provided.json"); executeAndVerify(project.getDbKey(), "unknown", "empty.json"); }
@Test public void testEquals() { assertThat(new PropertyDto().setKey("123").setResourceId(123L)).isEqualTo(new PropertyDto().setKey("123").setResourceId(123L)); assertThat(new PropertyDto().setKey("1234").setResourceId(123L)).isNotEqualTo(new PropertyDto().setKey("123").setResourceId(123L)); assertThat(new PropertyDto().setKey("1234").setResourceId(123L)).isNotEqualTo(null); assertThat(new PropertyDto().setKey("1234").setResourceId(123L)).isNotEqualTo(new Object()); }