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 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)); }
@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 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; })); } }
@Override public void onGlobalPropertyChange(String key, @Nullable String value) { wasCalled = true; PropertyDto property = dbClient.propertiesDao().selectGlobalProperty(key); assertThat(property.getValue()).isEqualTo(value); }
private void dissociateProject(DbSession dbSession, OrganizationDto organization, ComponentDto project) { wsSupport.checkCanAdminProject(organization, project); dbClient.propertiesDao().deleteProjectProperty(SONAR_QUALITYGATE_PROPERTY, project.getId(), dbSession); dbSession.commit(); }
@Before public void setUp() throws Exception { when(dbClient.openSession(anyBoolean())) .thenThrow(new IllegalStateException("ProjectConfigurationLoaderImpl should not open DB session")); when(dbClient.propertiesDao()).thenReturn(propertiesDao); }
@Before public void setUp() { when(dispatcher.getKey()).thenReturn("NewViolations"); when(emailChannel.getKey()).thenReturn("Email"); when(twitterChannel.getKey()).thenReturn("Twitter"); when(dbClient.openSession(anyBoolean())).thenReturn(dbSession); when(dbClient.propertiesDao()).thenReturn(propertiesDao); when(dbClient.notificationQueueDao()).thenReturn(notificationQueueDao); when(dbClient.authorizationDao()).thenReturn(authorizationDao); underTest = new DefaultNotificationManager(new NotificationChannel[] {emailChannel, twitterChannel}, dbClient); }
public PropertyDto insertProperty(PropertyDto property) { dbClient.propertiesDao().saveProperty(dbSession, property); db.commit(); return property; }
public void insertProperties(List<PropertyDto> properties) { for (PropertyDto propertyDto : properties) { dbClient.propertiesDao().saveProperty(dbSession, propertyDto); } dbSession.commit(); }
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 assertFavorite() { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setUserId(USER_ID) .setComponentId(COMPONENT_ID) .build(), dbSession)).hasSize(1); }
private void assertNoFavorite() { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setUserId(USER_ID) .setComponentId(COMPONENT_ID) .build(), dbSession)).isEmpty(); } }
@Test public void delete_property_from_database_and_notify_extensions() { underTest.saveProperty("foo", "bar"); underTest.saveProperty("foo", null); assertThat(underTest.getString("foo")).isNull(); assertThat(dbTester.getDbClient().propertiesDao().selectGlobalProperty("foo")).isNull(); verify(changeNotifier).onGlobalPropertyChange("foo", null); }
public boolean hasNoFavorite(ComponentDto componentDto) { List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(PROP_FAVORITE_KEY) .setComponentId(componentDto.getId()) .build(), dbSession); return result.isEmpty(); } }
private void assertUserPropertyExists(String key, UserDto user) { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(key) .setUserId(user.getId()) .build(), dbSession)).isNotEmpty(); }
public boolean hasFavorite(ComponentDto componentDto, int userId) { List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(PROP_FAVORITE_KEY) .setComponentId(componentDto.getId()) .setUserId(userId) .build(), dbSession); return !result.isEmpty(); }
public void add(ComponentDto componentDto, int userId) { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey(PROP_FAVORITE_KEY) .setUserId(userId) .setResourceId(componentDto.getId())); dbSession.commit(); }
private void insertProperty(String key, String value) { PropertyDto dto = new PropertyDto().setKey(key).setValue(value); db.getDbClient().propertiesDao().saveProperty(db.getSession(), dto); db.commit(); }
@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(); }