public List<PropertyDto> selectProjectProperties(String resourceKey) { try (DbSession session = mybatis.openSession(false)) { return selectProjectProperties(session, resourceKey); } }
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(); })); }
@Test public void loads_configuration_of_any_given_component_only_once() { String mainBranch1DbKey = randomAlphanumeric(4); String mainBranch1Uuid = randomAlphanumeric(5); String branch1DbKey = mainBranch1DbKey + ComponentDto.BRANCH_KEY_SEPARATOR + randomAlphabetic(5); String branch1Uuid = randomAlphanumeric(6); String branch2DbKey = mainBranch1DbKey + ComponentDto.BRANCH_KEY_SEPARATOR + randomAlphabetic(7); String branch2Uuid = randomAlphanumeric(8); String mainBranch2DbKey = randomAlphanumeric(14); String mainBranch2Uuid = randomAlphanumeric(15); String branch3DbKey = mainBranch2DbKey + ComponentDto.BRANCH_KEY_SEPARATOR + randomAlphabetic(5); String branch3Uuid = randomAlphanumeric(16); ComponentDto mainBranch1 = newComponentDto(mainBranch1DbKey, mainBranch1Uuid); ComponentDto branch1 = newComponentDto(branch1DbKey, branch1Uuid); ComponentDto branch2 = newComponentDto(branch2DbKey, branch2Uuid); ComponentDto mainBranch2 = newComponentDto(mainBranch2DbKey, mainBranch2Uuid); ComponentDto branch3 = newComponentDto(branch3DbKey, branch3Uuid); underTest.loadProjectConfigurations(dbSession, ImmutableSet.of(mainBranch1, mainBranch2, branch1, branch2, branch3)); verify(propertiesDao, times(1)).selectProjectProperties(dbSession, mainBranch1DbKey); verify(propertiesDao, times(1)).selectProjectProperties(dbSession, mainBranch2DbKey); verify(propertiesDao, times(1)).selectProjectProperties(dbSession, branch1DbKey); verify(propertiesDao, times(1)).selectProjectProperties(dbSession, branch2DbKey); verify(propertiesDao, times(1)).selectProjectProperties(dbSession, branch3DbKey); verifyNoMoreInteractions(propertiesDao); }
@Test public void return_configuration_with_just_global_settings_when_no_component_settings() { String key = randomAlphanumeric(3); String value = randomAlphanumeric(4); String componentDbKey = randomAlphanumeric(5); String componentUuid = randomAlphanumeric(6); globalSettings.setProperty(key, value); when(propertiesDao.selectProjectProperties(dbSession, componentDbKey)) .thenReturn(emptyList()); ComponentDto component = newComponentDto(componentDbKey, componentUuid); Map<String, Configuration> configurations = underTest.loadProjectConfigurations(dbSession, singleton(component)); assertThat(configurations) .containsOnlyKeys(componentUuid); assertThat(configurations.get(componentUuid).get(key)).contains(value); }
@Test @UseDataProvider("allValuesForSelect") public void selectProjectProperties_supports_all_values(String dbValue, String expected) { ComponentDto projectDto = insertPrivateProject("A"); insertProperty("project.one", dbValue, projectDto.getId(), null); List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey()); assertThat(dtos).hasSize(1); assertThatDto(dtos.iterator().next()) .hasKey("project.one") .hasResourceId(projectDto.getId()) .hasValue(expected); }
@Test public void return_configuration_with_global_settings_main_branch_settings_and_branch_settings() { String globalKey = randomAlphanumeric(3); String globalValue = randomAlphanumeric(4); String mainBranchDbKey = randomAlphanumeric(5); String branchDbKey = mainBranchDbKey + ComponentDto.BRANCH_KEY_SEPARATOR + randomAlphabetic(5); String branchUuid = randomAlphanumeric(6); String mainBranchPropKey = randomAlphanumeric(7); String mainBranchPropValue = randomAlphanumeric(8); String branchPropKey = randomAlphanumeric(9); String branchPropValue = randomAlphanumeric(10); globalSettings.setProperty(globalKey, globalValue); when(propertiesDao.selectProjectProperties(dbSession, mainBranchDbKey)) .thenReturn(ImmutableList.of(newPropertyDto(mainBranchPropKey, mainBranchPropValue))); when(propertiesDao.selectProjectProperties(dbSession, branchDbKey)) .thenReturn(ImmutableList.of(newPropertyDto(branchPropKey, branchPropValue))); ComponentDto component = newComponentDto(branchDbKey, branchUuid); Map<String, Configuration> configurations = underTest.loadProjectConfigurations(dbSession, singleton(component)); assertThat(configurations) .containsOnlyKeys(branchUuid); assertThat(configurations.get(branchUuid).get(globalKey)).contains(globalValue); assertThat(configurations.get(branchUuid).get(mainBranchPropKey)).contains(mainBranchPropValue); assertThat(configurations.get(branchUuid).get(branchPropKey)).contains(branchPropValue); }
@Test public void return_configuration_with_global_settings_and_component_settings() { String globalKey = randomAlphanumeric(3); String globalValue = randomAlphanumeric(4); String componentDbKey = randomAlphanumeric(5); String componentUuid = randomAlphanumeric(6); String projectPropKey1 = randomAlphanumeric(7); String projectPropValue1 = randomAlphanumeric(8); String projectPropKey2 = randomAlphanumeric(9); String projectPropValue2 = randomAlphanumeric(10); globalSettings.setProperty(globalKey, globalValue); when(propertiesDao.selectProjectProperties(dbSession, componentDbKey)) .thenReturn(ImmutableList.of(newPropertyDto(projectPropKey1, projectPropValue1), newPropertyDto(projectPropKey2, projectPropValue2))); ComponentDto component = newComponentDto(componentDbKey, componentUuid); Map<String, Configuration> configurations = underTest.loadProjectConfigurations(dbSession, singleton(component)); assertThat(configurations) .containsOnlyKeys(componentUuid); assertThat(configurations.get(componentUuid).get(globalKey)).contains(globalValue); assertThat(configurations.get(componentUuid).get(projectPropKey1)).contains(projectPropValue1); assertThat(configurations.get(componentUuid).get(projectPropKey2)).contains(projectPropValue2); }
@Test public void delete_quality_gate_and_any_association_to_any_project() { OrganizationDto organization = db.organizations().insert(); db.qualityGates().createDefaultQualityGate(organization); QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization); ComponentDto prj1 = db.components().insertPublicProject(organization); ComponentDto prj2 = db.components().insertPublicProject(organization); db.qualityGates().associateProjectToQualityGate(prj1, qualityGate); db.qualityGates().associateProjectToQualityGate(prj2, qualityGate); userSession.addPermission(ADMINISTER_QUALITY_GATES, organization); ws.newRequest() .setParam(PARAM_ID, valueOf(qualityGate.getId())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute(); assertThat(db.getDbClient().qualityGateDao().selectByOrganizationAndId(dbSession, organization, qualityGate.getId())) .isNull(); assertThat(db.getDbClient().propertiesDao().selectProjectProperties(prj1.getDbKey())) .isEmpty(); assertThat(db.getDbClient().propertiesDao().selectProjectProperties(prj2.getDbKey())) .isEmpty(); }
assertThat(dbClient.propertiesDao().selectProjectProperties(dbSession, project.getDbKey())).hasSize(5); assertGlobalSetting("my.key", "1"); assertGlobalSetting("my.key.1.firstField", "oldFirstValue");
@Test public void selectProjectProperties() { ComponentDto projectDto = insertPrivateProject("A"); long projectId = projectDto.getId(); // global insertProperty("global.one", "one", null, null); insertProperty("global.two", "two", null, null); // project insertProperty("project.one", "Pone", projectId, null); insertProperty("project.two", "Ptwo", projectId, null); List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey()); assertThat(dtos) .hasSize(2); assertThatDto(findByKey(dtos, "project.one")) .hasKey("project.one") .hasResourceId(projectId) .hasValue("Pone"); assertThatDto(findByKey(dtos, "project.two")) .hasKey("project.two") .hasResourceId(projectId) .hasValue("Ptwo"); }
public List<PropertyDto> selectProjectProperties(String resourceKey) { try (DbSession session = mybatis.openSession(false)) { return selectProjectProperties(session, resourceKey); } }
private Map<String, String> getSettingsFromParents(ComponentDto module, boolean hasScanPerm, DbSession session) { List<ComponentDto> parents = newArrayList(); aggregateParentModules(module, parents, session); Collections.reverse(parents); Map<String, String> parentProperties = newHashMap(); for (ComponentDto parent : parents) { parentProperties.putAll(getPropertiesMap(dbClient.propertiesDao().selectProjectProperties(session, parent.getKey()), hasScanPerm)); } return parentProperties; }
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(); })); }