private List<PropertyDto> loadGlobalSettings(DbSession dbSession, Optional<String> key) { if (key.isPresent()) { return dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, Collections.singleton(key.get())); } return dbClient.propertiesDao().selectGlobalProperties(dbSession); }
private List<Setting> loadGlobalSettings(DbSession dbSession, Set<String> keys) { Set<String> allowedKeys; if (isSonarCloud && !userSession.isSystemAdministrator()) { // remove the global settings that require admin permission allowedKeys = keys.stream().filter(k -> !isSecured(k)).collect(Collectors.toSet()); } else { allowedKeys = keys; } List<PropertyDto> properties = dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, allowedKeys); List<PropertyDto> propertySets = dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, getPropertySetKeys(properties)); return properties.stream() .map(property -> Setting.createFromDto(property, getPropertySets(property.getKey(), propertySets, null), propertyDefinitions.get(property.getKey()))) .collect(MoreCollectors.toList(properties.size())); }
@Test public void select_global_properties_by_keys() { insertPrivateProject("A"); int userId = db.users().insertUser(u -> u.setLogin("B")).getId(); String key = "key"; String anotherKey = "anotherKey"; insertProperty(key, "value", null, null); insertProperty(key, "value", 10L, null); insertProperty(key, "value", null, userId); insertProperty(anotherKey, "value", null, null); assertThat(underTest.selectGlobalPropertiesByKeys(session, newHashSet(key))) .extracting("key") .containsOnly(key); assertThat(underTest.selectGlobalPropertiesByKeys(session, newHashSet(key, anotherKey))) .extracting("key") .containsOnly(key, anotherKey); assertThat(underTest.selectGlobalPropertiesByKeys(session, newHashSet(key, anotherKey, "unknown"))) .extracting("key") .containsOnly(key, anotherKey); assertThat(underTest.selectGlobalPropertiesByKeys(session, newHashSet("unknown"))) .isEmpty(); }
private List<PropertyDto> loadGlobalSettings(DbSession dbSession, Optional<String> key) { if (key.isPresent()) { return dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, Collections.singleton(key.get())); } return dbClient.propertiesDao().selectGlobalProperties(dbSession); }
public List<Setting> loadGlobalSettings(DbSession dbSession, Set<String> keys) { List<PropertyDto> properties = dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, keys); List<PropertyDto> propertySets = dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, getPropertySetKeys(properties)); return properties.stream() .map(property -> Setting.createFromDto(property, getPropertySets(property.getKey(), propertySets, null), definitions.get(property.getKey()))) .collect(Collectors.toList()); }