this.dbClient = dbClient;
}
- public Configuration newProjectConfiguration(String projectUuid, String branchUuid) {
+ public Configuration newProjectConfiguration(String projectUuid) {
Settings projectSettings = new ChildSettings(globalSettings);
addSettings(projectSettings, projectUuid);
- if (!projectUuid.equals(branchUuid)) {
- // TODO not supported?
- addSettings(projectSettings, branchUuid);
- }
return new ConfigurationBridge(projectSettings);
}
private final Supplier<Configuration> configuration;
- public ConfigurationRepositoryImpl(TreeRootHolder treeRootHolder, AnalysisMetadataHolder analysisMetadataHolder, ProjectConfigurationFactory f) {
+ public ConfigurationRepositoryImpl(AnalysisMetadataHolder analysisMetadataHolder, ProjectConfigurationFactory f) {
this.configuration = Suppliers.memoize(() -> {
- String branchUuid = treeRootHolder.getRoot().getUuid();
String projectUuid = analysisMetadataHolder.getProject().getUuid();
- return f.newProjectConfiguration(projectUuid, branchUuid);
+ return f.newProjectConfiguration(projectUuid);
});
}
import org.sonar.api.config.Configuration;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
import org.sonar.db.project.ProjectDto;
import static org.assertj.core.api.Assertions.assertThat;
@Rule
public DbTester db = DbTester.create();
- private MapSettings settings = new MapSettings();
- private ProjectConfigurationFactory underTest = new ProjectConfigurationFactory(settings, db.getDbClient());
+ private final MapSettings settings = new MapSettings();
+ private final ProjectConfigurationFactory underTest = new ProjectConfigurationFactory(settings, db.getDbClient());
@Test
public void return_global_settings() {
settings.setProperty("key", "value");
- Configuration config = underTest.newProjectConfiguration("unknown", "unknown");
+ Configuration config = underTest.newProjectConfiguration("unknown");
assertThat(config.get("key")).hasValue("value");
}
newComponentPropertyDto(project).setKey("2").setValue("val2"),
newComponentPropertyDto(project).setKey("3").setValue("val3"));
- Configuration config = underTest.newProjectConfiguration(project.getUuid(), project.getUuid());
+ Configuration config = underTest.newProjectConfiguration(project.getUuid());
assertThat(config.get("1")).hasValue("val1");
assertThat(config.get("2")).hasValue("val2");
db.properties().insertProperties(null, project.getKey(), project.getName(), project.getQualifier(),
newComponentPropertyDto(project).setKey("key").setValue("value2"));
- Configuration projectConfig = underTest.newProjectConfiguration(project.getUuid(), project.getUuid());
+ Configuration projectConfig = underTest.newProjectConfiguration(project.getUuid());
assertThat(projectConfig.get("key")).hasValue("value2");
}
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
-import org.sonar.ce.task.projectanalysis.analysis.Branch;
import org.sonar.ce.task.projectanalysis.analysis.ProjectConfigurationFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.server.project.Project;
-import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@Rule
public final DbTester db = DbTester.create(System2.INSTANCE);
@Rule
- public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
- @Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
private final DbClient dbClient = db.getDbClient();
private final Component root = mock(Component.class);
private ConfigurationRepository underTest;
-
@Before
public void setUp() {
analysisMetadataHolder.setProject(project);
when(root.getUuid()).thenReturn(project.getUuid());
- treeRootHolder.setRoot(root);
- underTest = new ConfigurationRepositoryImpl(treeRootHolder, analysisMetadataHolder, new ProjectConfigurationFactory(globalSettings, dbClient));
+ underTest = new ConfigurationRepositoryImpl(analysisMetadataHolder, new ProjectConfigurationFactory(globalSettings, dbClient));
}
@Test
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
-import javax.annotation.Nullable;
-import org.assertj.core.api.ListAssert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
assertThat(results)
.extracting(ComponentDto::uuid, ComponentDto::getKey)
- .isEmpty();
+ .isEmpty();
}
@Test
removedFile.uuid());
}
- @Test
- public void selectForIndexing_all() {
- assertSelectForIndexing(null)
- .doesNotContain("DIS7")
- .doesNotContain("COPY8") // copied projects
- .doesNotContain("U2", "U6")// modules
- .doesNotContain("U3")// dir
- .doesNotContain("U4")// file
- .containsExactlyInAnyOrder("U1", "U5", "VW1");
- }
-
- @Test
- public void selectForIndexing_project() {
- assertSelectForIndexing("U1")
- .doesNotContain("DIS7")
- .doesNotContain("COPY8") // copied projects
- .doesNotContain("U6") // other projects
- .doesNotContain("VW1") // view
- .doesNotContain("U2", "U6")// modules
- .doesNotContain("U3")// dir
- .doesNotContain("U4")// file
- .containsExactlyInAnyOrder("U1");
- }
-
- private ListAssert<String> assertSelectForIndexing(@Nullable String projectUuid) {
- ComponentDto project = db.components().insertPrivateProject("U1").getMainBranchComponent();
- ComponentDto removedProject = db.components().insertPrivateProject(p -> p.setEnabled(false)).getMainBranchComponent();
- ComponentDto directory = db.components().insertComponent(newDirectory(project, "U3", "src"));
- ComponentDto removedDirectory = db.components().insertComponent(newDirectory(project, "src2").setEnabled(false));
- ComponentDto file = db.components().insertComponent(newFileDto(project, directory, "U4"));
- ComponentDto removedFile = db.components().insertComponent(newFileDto(project, directory).setEnabled(false));
-
- ComponentDto view = db.components().insertPublicPortfolio("VW1", p -> {
- });
- db.components().insertComponent(newProjectCopy("COPY8", project, view));
-
- ComponentDto project2 = db.components().insertPrivateProject("U5").getMainBranchComponent();
-
- List<ComponentDto> components = new ArrayList<>();
- underTest.scrollForIndexing(dbSession, projectUuid,
- context -> components.add(context.getResultObject()));
- return (ListAssert<String>) assertThat(components).extracting(ComponentDto::uuid);
- }
-
@Test
public void update() {
db.components().insertPrivateProject("U1").getMainBranchComponent();
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.annotation.Nullable;
+import org.apache.ibatis.session.ResultHandler;
import org.assertj.core.api.Assertions;
import org.assertj.core.groups.Tuple;
import org.junit.Rule;
assertThat(projectDao.selectEntityByKey(db.getSession(), "unknown")).isEmpty();
}
+ @Test
+ public void scrollEntitiesForIndexing_shouldReturnAllEntities() {
+ ProjectData application = db.components().insertPrivateApplication();
+ ProjectData project = db.components().insertPrivateProject();
+ PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
+
+ List<EntityDto> result = new LinkedList<>();
+ ResultHandler<EntityDto> handler = resultContext -> result.add(resultContext.getResultObject());
+ projectDao.scrollEntitiesForIndexing(db.getSession(), null, handler);
+
+ assertThat(result).extracting(EntityDto::getUuid)
+ .containsOnly(project.projectUuid(), application.projectUuid(), portfolio.getUuid());
+ }
+
+ @Test
+ public void scrollEntitiesForIndexing_whenEntityUuidSpecified_shouldReturnSpecificEntity() {
+ ProjectData application = db.components().insertPrivateApplication();
+ ProjectData project = db.components().insertPrivateProject();
+ PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
+
+ List<EntityDto> result = new LinkedList<>();
+ ResultHandler<EntityDto> handler = resultContext -> result.add(resultContext.getResultObject());
+ projectDao.scrollEntitiesForIndexing(db.getSession(), project.projectUuid(), handler);
+
+ assertThat(result).extracting(EntityDto::getUuid)
+ .containsOnly(project.projectUuid());
+ }
+
+ @Test
+ public void scrollEntitiesForIndexing_whenNonExistingUuidSpecified_shouldReturnEmpty() {
+ ProjectData application = db.components().insertPrivateApplication();
+ ProjectData project = db.components().insertPrivateProject();
+ PortfolioDto portfolio = db.components().insertPrivatePortfolioDto();
+
+ List<EntityDto> result = new LinkedList<>();
+ ResultHandler<EntityDto> handler = resultContext -> result.add(resultContext.getResultObject());
+ projectDao.scrollEntitiesForIndexing(db.getSession(), "unknown", handler);
+
+ assertThat(result).isEmpty();
+ }
+
private void insertDefaultQualityProfile(String language) {
QProfileDto profile = db.qualityProfiles().insert(qp -> qp.setIsBuiltIn(true).setLanguage(language));
db.qualityProfiles().setAsDefault(profile);
return mapper(session).selectProjectsFromView("%." + escapedViewUuid + ".%", rootViewUuid);
}
- /**
- * Selects all components that are relevant for indexing. The result is not returned (since it is usually too big), but handed over to the <code>handler</code>
- *
- * @param session the database session
- * @param branchUuid the branch uuid, which is selected with all of its children
- * @param handler the action to be applied to every result
- */
- public void scrollForIndexing(DbSession session, @Nullable String branchUuid, ResultHandler<ComponentDto> handler) {
- mapper(session).scrollForIndexing(branchUuid, handler);
- }
-
/**
* Retrieve enabled components keys with given qualifiers
* <p>
*/
List<String> selectProjectsFromView(@Param("viewUuidLikeQuery") String viewUuidLikeQuery, @Param("rootViewUuid") String rootViewUuid);
- void scrollForIndexing(@Param("branchUuid") @Nullable String branchUuid, ResultHandler<ComponentDto> handler);
-
void scrollAllFilesForFileMove(@Param("branchUuid") String branchUuid, ResultHandler<FileMoveRowDto> handler);
void insert(ComponentDto componentDto);
package org.sonar.db.project;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
+import org.apache.ibatis.session.ResultHandler;
import org.sonar.api.utils.System2;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
if (uuids.isEmpty()) {
return emptyList();
}
- return mapper(dbSession).selectEntitiesByUuids(uuids);
+
+ return executeLargeInputs(uuids, partition -> mapper(dbSession).selectEntitiesByUuids(partition));
}
public Optional<EntityDto> selectEntityByKey(DbSession dbSession, String key) {
if (keys.isEmpty()) {
return emptyList();
}
- return mapper(dbSession).selectEntitiesByKeys(keys);
+ return executeLargeInputs(keys, partition -> mapper(dbSession).selectEntitiesByKeys(partition));
}
-
+ public void scrollEntitiesForIndexing(DbSession session, @Nullable String entityUuid, ResultHandler<EntityDto> handler) {
+ mapper(session).scrollEntitiesForIndexing(entityUuid, handler);
+ }
}
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.session.ResultHandler;
import org.sonar.db.entity.EntityDto;
public interface ProjectMapper {
EntityDto selectEntityByKey(String key);
List<EntityDto> selectEntitiesByKeys(@Param("keys") Collection<String> keys);
+
+ void scrollEntitiesForIndexing(@Param("entityUuid") @Nullable String entityUuid, ResultHandler<EntityDto> handler);
}
</choose>
</select>
- <select id="scrollForIndexing" parameterType="map" resultType="Component" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
- select
- <include refid="componentColumns"/>
- from components p
- LEFT JOIN project_branches pb ON pb.uuid = p.branch_uuid
- where
- p.enabled=${_true}
- and p.copy_component_uuid is null
- and <include refid="mainBranchOrPortfolio"/>
- and p.scope = 'PRJ'
- and p.qualifier in ('TRK','VW','SVW','APP')
- <if test="branchUuid != null">
- and p.branch_uuid = #{branchUuid,jdbcType=VARCHAR}
- </if>
- </select>
-
<select id="scrollAllFilesForFileMove" parameterType="map" resultType="org.sonar.db.component.FileMoveRowDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
select
p.uuid as uuid,
where p.kee in
<foreach collection="keys" open="(" close=")" item="kee" separator=",">
#{kee,jdbcType=VARCHAR}
- </foreach>) </select>
+ </foreach>)
+ </select>
+
+ <select id="scrollEntitiesForIndexing" parameterType="map" resultType="Entity" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
+ (select <include refid="entityProjectColumns"/>
+ from projects p
+ <if test="entityUuid != null">
+ where p.uuid = #{entityUuid,jdbcType=VARCHAR}
+ </if>)
+ UNION
+ (select <include refid="entityPortfolioColumns"/>
+ from portfolios p
+ <if test="entityUuid != null">
+ where p.uuid = #{entityUuid,jdbcType=VARCHAR}
+ </if>)
+ </select>
</mapper>
return newPropertyDto(null, user.getUuid());
}
- public static PropertyDto newPropertyDto(String key, String value, ComponentDto component, UserDto user) {
- checkNotNull(component.uuid());
- checkNotNull(user.getUuid());
- return newPropertyDto(key, value, component.uuid(), user.getUuid());
- }
-
- public static PropertyDto newPropertyDto(ComponentDto component, UserDto user) {
- checkNotNull(component.uuid());
- checkNotNull(user.getUuid());
- return newPropertyDto(component.uuid(), user.getUuid());
- }
-
private static PropertyDto newPropertyDto(@Nullable String componentUuid, @Nullable String userUuid) {
String key = String.valueOf(cursor);
cursor++;
ComponentDoc doc = es.getDocuments(TYPE_COMPONENT, ComponentDoc.class).get(0);
assertThat(doc.getId()).isEqualTo(project.uuid());
assertThat(doc.getKey()).isEqualTo(project.getKey());
- assertThat(doc.getProjectUuid()).isEqualTo(project.branchUuid());
assertThat(doc.getName()).isEqualTo(project.name());
}
package org.sonar.server.component.index;
import java.util.HashMap;
-import java.util.Map;
import org.sonar.server.es.BaseDoc;
-import org.sonar.server.permission.index.AuthorizationDoc;
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_KEY;
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_NAME;
-import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_PROJECT_UUID;
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_QUALIFIER;
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_UUID;
import static org.sonar.server.component.index.ComponentIndexDefinition.TYPE_COMPONENT;
super(TYPE_COMPONENT, new HashMap<>(6));
}
- public ComponentDoc(Map<String, Object> fields) {
- super(TYPE_COMPONENT, fields);
- }
-
@Override
public String getId() {
return getField(FIELD_UUID);
return this;
}
- public String getProjectUuid() {
- return getField(FIELD_PROJECT_UUID);
- }
-
- public ComponentDoc setProjectUuid(String s) {
- setField(FIELD_PROJECT_UUID, s);
- setParent(AuthorizationDoc.idOf(s));
- return this;
- }
-
public String getKey() {
return getField(FIELD_KEY);
}
public static final Index DESCRIPTOR = Index.withRelations("components");
public static final IndexType.IndexRelationType TYPE_COMPONENT = IndexType.relation(IndexType.main(DESCRIPTOR, TYPE_AUTHORIZATION), "component");
public static final String FIELD_UUID = "uuid";
- public static final String FIELD_PROJECT_UUID = "project_uuid";
public static final String FIELD_KEY = "key";
public static final String FIELD_NAME = "name";
public static final String FIELD_QUALIFIER = "qualifier";
TypeMapping mapping = index.createTypeMapping(TYPE_COMPONENT);
mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build();
- mapping.keywordFieldBuilder(FIELD_PROJECT_UUID).disableNorms().build();
mapping.keywordFieldBuilder(FIELD_KEY).addSubFields(SORTABLE_ANALYZER).build();
mapping.textFieldBuilder(FIELD_NAME)
.withFieldData()
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDto;
import org.sonar.db.es.EsQueueDto;
import org.sonar.server.es.BaseDoc;
import org.sonar.server.es.BulkIndexer;
return emptyList();
case PROJECT_CREATION, PROJECT_DELETION, PROJECT_KEY_UPDATE:
List<EsQueueDto> items = projectUuids.stream()
- .map(branchUuid -> EsQueueDto.create(TYPE_COMPONENT.format(), branchUuid, null, branchUuid))
+ .map(projectUuid -> EsQueueDto.create(TYPE_COMPONENT.format(), projectUuid, null, projectUuid))
.collect(MoreCollectors.toArrayList(projectUuids.size()));
return dbClient.esQueueDao().insert(dbSession, items);
default:
OneToManyResilientIndexingListener listener = new OneToManyResilientIndexingListener(dbClient, dbSession, items);
BulkIndexer bulkIndexer = new BulkIndexer(esClient, TYPE_COMPONENT, Size.REGULAR, listener);
bulkIndexer.start();
- Set<String> branchUuids = items.stream().map(EsQueueDto::getDocId).collect(MoreCollectors.toHashSet(items.size()));
- Set<String> remaining = new HashSet<>(branchUuids);
+ Set<String> entityUuids = items.stream().map(EsQueueDto::getDocId).collect(MoreCollectors.toHashSet(items.size()));
+ Set<String> remaining = new HashSet<>(entityUuids);
- for (String branchUuid : branchUuids) {
- // TODO allow scrolling multiple projects at the same time
- dbClient.componentDao().scrollForIndexing(dbSession, branchUuid, context -> {
- ComponentDto dto = context.getResultObject();
+ for (String entityUuid : entityUuids) {
+ dbClient.projectDao().scrollEntitiesForIndexing(dbSession, entityUuid, context -> {
+ EntityDto dto = context.getResultObject();
bulkIndexer.add(toDocument(dto).toIndexRequest());
- remaining.remove(dto.branchUuid());
+ remaining.remove(dto.getUuid());
});
}
/**
* @param projectUuid the uuid of the project to analyze, or {@code null} if all content should be indexed.<br/>
- * <b>Warning:</b> only use {@code null} during startup.
+ * <b>Warning:</b> only use {@code null} during startup.
*/
private void doIndexByProjectUuid(@Nullable String projectUuid, Size bulkSize) {
BulkIndexer bulk = new BulkIndexer(esClient, TYPE_COMPONENT, bulkSize);
bulk.start();
try (DbSession dbSession = dbClient.openSession(false)) {
- dbClient.componentDao()
- .scrollForIndexing(dbSession, projectUuid, context -> {
- ComponentDto dto = context.getResultObject();
+ dbClient.projectDao()
+ .scrollEntitiesForIndexing(dbSession, projectUuid, context -> {
+ EntityDto dto = context.getResultObject();
bulk.add(toDocument(dto).toIndexRequest());
});
}
private static void addProjectDeletionToBulkIndexer(BulkIndexer bulkIndexer, String projectUuid) {
SearchRequest searchRequest = EsClient.prepareSearch(TYPE_COMPONENT.getMainType())
- .source(new SearchSourceBuilder().query(QueryBuilders.termQuery(ComponentIndexDefinition.FIELD_PROJECT_UUID, projectUuid)))
+ .source(new SearchSourceBuilder().query(QueryBuilders.termQuery(ComponentIndexDefinition.FIELD_UUID, projectUuid)))
.routing(AuthorizationDoc.idOf(projectUuid));
bulkIndexer.addDeletion(searchRequest);
}
}
@VisibleForTesting
- void index(ComponentDto... docs) {
+ void index(EntityDto... docs) {
BulkIndexer bulk = new BulkIndexer(esClient, TYPE_COMPONENT, Size.REGULAR);
bulk.start();
Arrays.stream(docs)
bulk.stop();
}
- public static ComponentDoc toDocument(ComponentDto component) {
+ public static ComponentDoc toDocument(EntityDto component) {
return new ComponentDoc()
- .setId(component.uuid())
- .setName(component.name())
+ .setId(component.getUuid())
+ .setName(component.getName())
.setKey(component.getKey())
- .setProjectUuid(component.branchUuid())
- .setQualifier(component.qualifier());
+ .setQualifier(component.getQualifier());
}
}
private final DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();
private final FavoriteUpdater favoriteUpdater = new FavoriteUpdater(dbClient);
- private final WsActionTester ws = new WsActionTester(new AddAction(userSession, dbClient, favoriteUpdater, TestComponentFinder.from(db)));
+ private final WsActionTester ws = new WsActionTester(new AddAction(userSession, dbClient, favoriteUpdater));
@Test
public void add_a_project() {
private final DbClient dbClient = db.getDbClient();
private final FavoriteUpdater favoriteUpdater = new FavoriteUpdater(dbClient);
- private final WsActionTester ws = new WsActionTester(new RemoveAction(userSession, dbClient, favoriteUpdater, TestComponentFinder.from(db)));
+ private final WsActionTester ws = new WsActionTester(new RemoveAction(userSession, dbClient, favoriteUpdater));
@Before
public void before() {
@Test
public void fail_if_not_already_a_favorite() {
- ProjectDto componentDto = insertProjectAndPermissions();
+ ProjectDto project = insertProjectAndPermissions();
assertThatThrownBy(() -> call(PROJECT_KEY))
.isInstanceOf(IllegalArgumentException.class)
- .hasMessage("Component '" + PROJECT_KEY + "' (uuid: " + componentDto.getUuid() + ") is not a favorite");
+ .hasMessage("Component '" + PROJECT_KEY + "' (uuid: " + project.getUuid() + ") is not a favorite");
}
@Test
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDbTester;
-import org.sonar.db.component.ComponentDto;
import org.sonar.db.permission.GlobalPermission;
-import org.sonar.server.component.TestComponentFinder;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.tester.UserSessionRule;
public DbTester db = DbTester.create(System2.INSTANCE);
private final DbClient dbClient = db.getDbClient();
- private final ComponentDbTester componentDb = new ComponentDbTester(db);
- private ComponentDto project;
+ private ProjectDto project;
private final PropertyDefinitions propertyDefinitions = new PropertyDefinitions(System2.INSTANCE);
private final SettingsWsSupport support = new SettingsWsSupport(userSession);
- private final WsActionTester ws = new WsActionTester(
- new ListDefinitionsAction(dbClient, TestComponentFinder.from(db), userSession, propertyDefinitions, support));
+ private final WsActionTester ws = new WsActionTester(new ListDefinitionsAction(dbClient, userSession, propertyDefinitions, support));
@Before
public void setUp() {
- project = db.components().insertPrivateProject().getMainBranchComponent();
+ project = db.components().insertPrivateProject().getProjectDto();
}
@Test
private final PropertyDbTester propertyDb = new PropertyDbTester(db);
private final DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();
- private final ComponentFinder componentFinder = TestComponentFinder.from(db);
private final PropertyDefinitions definitions = new PropertyDefinitions(System2.INSTANCE);
private final SettingsUpdater settingsUpdater = new SettingsUpdater(dbClient, definitions);
private final SettingValidations settingValidations = new SettingValidations(definitions, dbClient, i18n);
private ProjectDto project;
- private final ResetAction underTest = new ResetAction(dbClient, componentFinder, settingsUpdater, userSession, definitions, settingValidations);
+ private final ResetAction underTest = new ResetAction(dbClient, settingsUpdater, userSession, definitions, settingValidations);
private final WsActionTester ws = new WsActionTester(underTest);
@Before
assertThat(action.isInternal()).isFalse();
assertThat(action.isPost()).isTrue();
assertThat(action.responseExampleAsString()).isNull();
- assertThat(action.params()).extracting(Param::key).containsExactlyInAnyOrder("keys", "component", "branch", "pullRequest");
+ assertThat(action.params()).extracting(Param::key).containsExactlyInAnyOrder("keys", "component");
}
@Test
import org.sonar.db.property.PropertyQuery;
import org.sonar.process.ProcessProperties;
import org.sonar.scanner.protocol.GsonHelper;
-import org.sonar.server.component.ComponentFinder;
-import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
private PropertyDbTester propertyDb = new PropertyDbTester(db);
private DbClient dbClient = db.getDbClient();
private DbSession dbSession = db.getSession();
- private ComponentFinder componentFinder = TestComponentFinder.from(db);
-
private I18nRule i18n = new I18nRule();
private PropertyDefinitions definitions = new PropertyDefinitions(System2.INSTANCE);
private FakeSettingsNotifier settingsChangeNotifier = new FakeSettingsNotifier(dbClient);
private SettingsUpdater settingsUpdater = new SettingsUpdater(dbClient, definitions);
private SettingValidations validations = new SettingValidations(definitions, dbClient, i18n);
- private SetAction underTest = new SetAction(definitions, dbClient, componentFinder, userSession, settingsUpdater, settingsChangeNotifier, validations);
+ private SetAction underTest = new SetAction(definitions, dbClient, userSession, settingsUpdater, settingsChangeNotifier, validations);
private WsActionTester ws = new WsActionTester(underTest);
private final DbClient dbClient = db.getDbClient();
private final PropertyDefinitions definitions = new PropertyDefinitions(System2.INSTANCE);
private final SettingsWsSupport support = new SettingsWsSupport(userSession);
- private final WsActionTester wsActionTester = new WsActionTester(new ValuesAction(dbClient, TestComponentFinder.from(db), userSession, definitions, support));
+ private final WsActionTester wsActionTester = new WsActionTester(new ValuesAction(dbClient, userSession, definitions, support));
private ProjectDto project;
- private ComponentDto rootComponent;
@Before
public void setUp() {
ProjectData projectData = db.components().insertPrivateProject();
project = projectData.getProjectDto();
- rootComponent = projectData.getMainBranchComponent();
}
@Test
}
/**
- * we are generating suggestions, by using (1) favorites and (2) recently browsed components (without searchin in Elasticsearch)
+ * we are generating suggestions, by using (1) favorites and (2) recently browsed components (without searching in Elasticsearch)
*/
private SuggestionsWsResponse loadSuggestionsWithoutSearch(int skip, int limit, Set<String> recentlyBrowsedKeys, List<String> qualifiers) {
List<EntityDto> favorites = favoriteFinder.list();
.setKey(PROP_FAVORITE_KEY)
.setUserUuid(userSession.getUuid())
.build();
- Set<String> componentUuids = dbClient.propertiesDao().selectByQuery(dbQuery, dbSession).stream().map(PropertyDto::getComponentUuid).collect(Collectors.toSet());
+ Set<String> entitiesUuids = dbClient.propertiesDao().selectByQuery(dbQuery, dbSession).stream().map(PropertyDto::getComponentUuid).collect(Collectors.toSet());
- List<EntityDto> entities = dbClient.projectDao().selectEntitiesByUuids(dbSession, componentUuids);
+ List<EntityDto> entities = dbClient.projectDao().selectEntitiesByUuids(dbSession, entitiesUuids);
return entities.stream()
.sorted(Comparator.comparing(EntityDto::getName))
private final UserSession userSession;
private final DbClient dbClient;
private final FavoriteUpdater favoriteUpdater;
- private final ComponentFinder componentFinder;
- public AddAction(UserSession userSession, DbClient dbClient, FavoriteUpdater favoriteUpdater, ComponentFinder componentFinder) {
+ public AddAction(UserSession userSession, DbClient dbClient, FavoriteUpdater favoriteUpdater) {
this.userSession = userSession;
this.dbClient = dbClient;
this.favoriteUpdater = favoriteUpdater;
- this.componentFinder = componentFinder;
}
@Override
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("add")
- .setDescription("Add a component (project, file etc.) as favorite for the authenticated user.<br>" +
+ .setDescription("Add a component (project, portfolio, etc.) as favorite for the authenticated user.<br>" +
"Only 100 components by qualifier can be added as favorite.<br>" +
- "Requires authentication and the following permission: 'Browse' on the project of the specified component.")
+ "Requires authentication and the following permission: 'Browse' on the component.")
.setSince("6.3")
.setChangelog(
new Change("10.1", String.format("The use of module keys in parameter '%s' is removed", PARAM_COMPONENT)),
private final UserSession userSession;
private final DbClient dbClient;
private final FavoriteUpdater favoriteUpdater;
- private final ComponentFinder componentFinder;
- public RemoveAction(UserSession userSession, DbClient dbClient, FavoriteUpdater favoriteUpdater, ComponentFinder componentFinder) {
+ public RemoveAction(UserSession userSession, DbClient dbClient, FavoriteUpdater favoriteUpdater) {
this.userSession = userSession;
this.dbClient = dbClient;
this.favoriteUpdater = favoriteUpdater;
- this.componentFinder = componentFinder;
}
@Override
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.server.component.ComponentFinder;
+import org.sonar.db.entity.EntityDto;
+import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Settings;
import org.sonarqube.ws.Settings.ListDefinitionsWsResponse;
import static com.google.common.base.Strings.emptyToNull;
+import static java.lang.String.format;
import static java.util.Comparator.comparing;
import static java.util.Optional.ofNullable;
import static org.sonar.api.web.UserRole.USER;
public class ListDefinitionsAction implements SettingsWsAction {
private final DbClient dbClient;
- private final ComponentFinder componentFinder;
private final UserSession userSession;
private final PropertyDefinitions propertyDefinitions;
private final SettingsWsSupport settingsWsSupport;
- public ListDefinitionsAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession, PropertyDefinitions propertyDefinitions,
- SettingsWsSupport settingsWsSupport) {
+ public ListDefinitionsAction(DbClient dbClient, UserSession userSession, PropertyDefinitions propertyDefinitions, SettingsWsSupport settingsWsSupport) {
this.dbClient = dbClient;
- this.componentFinder = componentFinder;
this.userSession = userSession;
this.propertyDefinitions = propertyDefinitions;
this.settingsWsSupport = settingsWsSupport;
private ListDefinitionsWsResponse doHandle(Request request) {
ListDefinitionsRequest wsRequest = toWsRequest(request);
- Optional<ComponentDto> component = loadComponent(wsRequest);
- Optional<String> qualifier = getQualifier(component);
+ Optional<EntityDto> component = loadComponent(wsRequest);
+ Optional<String> qualifier = component.map(EntityDto::getQualifier);
ListDefinitionsWsResponse.Builder wsResponse = ListDefinitionsWsResponse.newBuilder();
propertyDefinitions.getAll().stream()
.filter(definition -> qualifier.map(s -> definition.qualifiers().contains(s)).orElseGet(definition::global))
.setComponent(request.param(PARAM_COMPONENT));
}
- private static Optional<String> getQualifier(Optional<ComponentDto> component) {
- return component.map(ComponentDto::qualifier);
- }
-
- private Optional<ComponentDto> loadComponent(ListDefinitionsRequest request) {
+ private Optional<EntityDto> loadComponent(ListDefinitionsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
- String componentKey = request.getComponent();
- if (componentKey == null) {
+ String entityKey = request.getComponent();
+ if (entityKey == null) {
return Optional.empty();
}
- ComponentDto component = componentFinder.getByKey(dbSession, componentKey);
- userSession.checkComponentPermission(USER, component);
- return Optional.of(component);
+ EntityDto entity = dbClient.projectDao().selectEntityByKey(dbSession, entityKey)
+ .orElseThrow(() -> new NotFoundException(format("Component key '%s' not found", entityKey)));
+ userSession.checkEntityPermission(USER, entity);
+ return Optional.of(entity);
}
}
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDto;
import org.sonar.db.entity.EntityDto;
-import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.setting.ws.SettingValidations.SettingData;
import org.sonar.server.user.UserSession;
import static org.sonar.server.setting.ws.SettingsWsParameters.PARAM_COMPONENT;
import static org.sonar.server.setting.ws.SettingsWsParameters.PARAM_KEYS;
import static org.sonar.server.setting.ws.SettingsWsParameters.PARAM_PULL_REQUEST;
-import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
-import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001;
public class ResetAction implements SettingsWsAction {
private final DbClient dbClient;
- private final ComponentFinder componentFinder;
private final SettingsUpdater settingsUpdater;
private final UserSession userSession;
private final PropertyDefinitions definitions;
private final SettingValidations validations;
- public ResetAction(DbClient dbClient, ComponentFinder componentFinder, SettingsUpdater settingsUpdater, UserSession userSession, PropertyDefinitions definitions,
- SettingValidations validations) {
+ public ResetAction(DbClient dbClient, SettingsUpdater settingsUpdater, UserSession userSession, PropertyDefinitions definitions, SettingValidations validations) {
this.dbClient = dbClient;
this.settingsUpdater = settingsUpdater;
this.userSession = userSession;
- this.componentFinder = componentFinder;
this.definitions = definitions;
this.validations = validations;
}
"</ul>")
.setSince("6.1")
.setChangelog(
+ new Change("10.1", format("Internal parameters '%s' and '%s' were removed", PARAM_BRANCH, PARAM_PULL_REQUEST)),
new Change("8.8", "Deprecated parameter 'componentKey' has been removed"),
- new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)),
+ new Change("7.6", format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)),
new Change("7.1", "The settings defined in conf/sonar.properties are read-only and can't be changed"))
.setPost(true)
.setHandler(this);
action.createParam(PARAM_COMPONENT)
.setDescription("Component key")
.setExampleValue(KEY_PROJECT_EXAMPLE_001);
- action.createParam(PARAM_BRANCH)
- .setDescription("Branch key")
- .setExampleValue(KEY_BRANCH_EXAMPLE_001)
- .setInternal(true)
- .setSince("6.6");
- action.createParam(PARAM_PULL_REQUEST)
- .setDescription("Pull request id")
- .setExampleValue(KEY_PULL_REQUEST_EXAMPLE_001)
- .setInternal(true)
- .setSince("7.1");
}
@Override
resetRequest.getKeys().forEach(key -> {
SettingsWsSupport.validateKey(key);
SettingData data = new SettingData(key, emptyList(), component.orElse(null));
- List.of(validations.scope(), validations.qualifier())
- .forEach(validation -> validation.accept(data));
+ List.of(validations.scope(), validations.qualifier()).forEach(validation -> validation.accept(data));
});
List<String> keys = getKeys(resetRequest);
private static ResetRequest toWsRequest(Request request) {
return new ResetRequest()
.setKeys(request.mandatoryParamAsStrings(PARAM_KEYS))
- .setComponent(request.param(PARAM_COMPONENT))
- .setBranch(request.param(PARAM_BRANCH))
- .setPullRequest(request.param(PARAM_PULL_REQUEST));
+ .setComponent(request.param(PARAM_COMPONENT));
}
private Optional<EntityDto> getComponent(DbSession dbSession, ResetRequest request) {
return Optional.empty();
}
- // TODO this WS should support branches and PRs?
return Optional.of(dbClient.projectDao().selectEntityByKey(dbSession, componentKey)
.orElseThrow(() -> new NotFoundException(format("Component key '%s' not found", componentKey))));
}
}
private static class ResetRequest {
-
- private String branch;
- private String pullRequest;
private String component;
private List<String> keys;
- public ResetRequest setBranch(@Nullable String branch) {
- this.branch = branch;
- return this;
- }
-
- @CheckForNull
- public String getBranch() {
- return branch;
- }
-
- public ResetRequest setPullRequest(@Nullable String pullRequest) {
- this.pullRequest = pullRequest;
- return this;
- }
-
- @CheckForNull
- public String getPullRequest() {
- return pullRequest;
- }
-
public ResetRequest setComponent(@Nullable String component) {
this.component = component;
return this;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDto;
import org.sonar.db.entity.EntityDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.scanner.protocol.GsonHelper;
-import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.setting.SettingsChangeNotifier;
private final PropertyDefinitions propertyDefinitions;
private final DbClient dbClient;
- private final ComponentFinder componentFinder;
private final UserSession userSession;
private final SettingsUpdater settingsUpdater;
private final SettingsChangeNotifier settingsChangeNotifier;
private final SettingValidations validations;
- public SetAction(PropertyDefinitions propertyDefinitions, DbClient dbClient, ComponentFinder componentFinder, UserSession userSession,
+ public SetAction(PropertyDefinitions propertyDefinitions, DbClient dbClient, UserSession userSession,
SettingsUpdater settingsUpdater, SettingsChangeNotifier settingsChangeNotifier, SettingValidations validations) {
this.propertyDefinitions = propertyDefinitions;
this.dbClient = dbClient;
- this.componentFinder = componentFinder;
this.userSession = userSession;
this.settingsUpdater = settingsUpdater;
this.settingsChangeNotifier = settingsChangeNotifier;
import static org.sonar.server.exceptions.BadRequestException.checkRequest;
public class SettingValidations {
- private static final Collection<String> SECURITY_JSON_PROPERTIES = List.of(
+ private static final Set<String> SECURITY_JSON_PROPERTIES = Set.of(
"sonar.security.config.javasecurity",
"sonar.security.config.phpsecurity",
"sonar.security.config.pythonsecurity",
import org.sonar.api.server.ServerSide;
import org.sonar.api.web.UserRole;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDto;
import org.sonar.db.permission.GlobalPermission;
import org.sonar.process.ProcessProperties;
import org.sonar.server.user.UserSession;
});
}
- boolean isVisible(String key, Optional<ComponentDto> component) {
+ boolean isVisible(String key, Optional<EntityDto> component) {
if (isAdmin(component)) {
return true;
}
return hasPermission(GlobalPermission.SCAN, UserRole.SCAN, component) || !isProtected(key);
}
- private boolean isAdmin(Optional<ComponentDto> component) {
+ private boolean isAdmin(Optional<EntityDto> component) {
return userSession.isSystemAdministrator() || hasPermission(GlobalPermission.ADMINISTER, ADMIN, component);
}
return ADMIN_ONLY_SETTINGS.contains(key);
}
- private boolean hasPermission(GlobalPermission orgPermission, String projectPermission, Optional<ComponentDto> component) {
+ private boolean hasPermission(GlobalPermission orgPermission, String projectPermission, Optional<EntityDto> component) {
if (userSession.hasPermission(orgPermission)) {
return true;
}
return component
- .map(c -> userSession.hasComponentPermission(projectPermission, c))
+ .map(c -> userSession.hasEntityPermission(projectPermission, c))
.orElse(false);
}
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Ordering;
-import com.google.common.collect.TreeMultimap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.component.BranchDto;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDto;
import org.sonar.db.permission.GlobalPermission;
import org.sonar.db.property.PropertyDto;
import org.sonar.markdown.Markdown;
-import org.sonar.server.component.ComponentFinder;
+import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Settings;
import org.sonarqube.ws.Settings.ValuesWsResponse;
private static final Set<String> SERVER_SETTING_KEYS = Set.of(SERVER_STARTTIME, SERVER_ID);
private final DbClient dbClient;
- private final ComponentFinder componentFinder;
private final UserSession userSession;
private final PropertyDefinitions propertyDefinitions;
private final SettingsWsSupport settingsWsSupport;
- public ValuesAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession, PropertyDefinitions propertyDefinitions,
- SettingsWsSupport settingsWsSupport) {
+ public ValuesAction(DbClient dbClient, UserSession userSession, PropertyDefinitions propertyDefinitions, SettingsWsSupport settingsWsSupport) {
this.dbClient = dbClient;
- this.componentFinder = componentFinder;
this.userSession = userSession;
this.propertyDefinitions = propertyDefinitions;
this.settingsWsSupport = settingsWsSupport;
private ValuesWsResponse doHandle(Request request) {
try (DbSession dbSession = dbClient.openSession(true)) {
ValuesRequest valuesRequest = ValuesRequest.from(request);
- Optional<ComponentDto> component = loadComponent(dbSession, valuesRequest);
+ Optional<EntityDto> component = loadComponent(dbSession, valuesRequest);
Set<String> keys = loadKeys(valuesRequest);
Map<String, String> keysToDisplayMap = getKeysToDisplayMap(keys);
List<Setting> settings = loadSettings(dbSession, component, keysToDisplayMap.keySet());
return result;
}
- private Optional<ComponentDto> loadComponent(DbSession dbSession, ValuesRequest valuesRequest) {
+ private Optional<EntityDto> loadComponent(DbSession dbSession, ValuesRequest valuesRequest) {
String componentKey = valuesRequest.getComponent();
if (componentKey == null) {
return Optional.empty();
}
- ComponentDto component = componentFinder.getByKey(dbSession, componentKey);
- if (!userSession.hasComponentPermission(USER, component) &&
- !userSession.hasComponentPermission(UserRole.SCAN, component) &&
+ EntityDto component = dbClient.projectDao().selectEntityByKey(dbSession, componentKey)
+ .orElseThrow(() -> new NotFoundException(format("Component key '%s' not found", componentKey)));
+
+ if (!userSession.hasEntityPermission(USER, component) &&
+ !userSession.hasEntityPermission(UserRole.SCAN, component) &&
!userSession.hasPermission(GlobalPermission.SCAN)) {
throw insufficientPrivilegesException();
}
return Optional.of(component);
}
- private List<Setting> loadSettings(DbSession dbSession, Optional<ComponentDto> component, Set<String> keys) {
- // List of settings must be kept in the following orders : default -> global -> component -> branch
+ private List<Setting> loadSettings(DbSession dbSession, Optional<EntityDto> component, Set<String> keys) {
+ // List of settings must be kept in the following orders : default -> global -> component
List<Setting> settings = new ArrayList<>();
settings.addAll(loadDefaultValues(keys));
settings.addAll(loadGlobalSettings(dbSession, keys));
.toList();
}
- private Collection<Setting> loadComponentSettings(DbSession dbSession, ComponentDto componentDto, Set<String> keys) {
- BranchDto branchDto = componentFinder.getBranchByUuid(dbSession, componentDto.branchUuid());
-
- List<String> componentUuids = new LinkedList<>();
- if (!branchDto.isMain()) {
- ComponentDto mainBranchComponent = componentFinder.getByKey(dbSession, componentDto.getKey());
- if (!mainBranchComponent.isRoot()) {
- componentUuids.add(mainBranchComponent.branchUuid());
- }
- componentUuids.add(mainBranchComponent.uuid());
- }
- if (!componentDto.isRoot()) {
- componentUuids.add(componentDto.branchUuid());
- }
- componentUuids.add(componentDto.uuid());
- return loadComponentsSettings(dbSession, keys, componentUuids);
+ private Collection<Setting> loadComponentSettings(DbSession dbSession, EntityDto entity, Set<String> keys) {
+ return loadComponentSettings(dbSession, keys, entity.getUuid());
}
private List<Setting> loadDefaultValues(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), propertyDefinitions.get(property.getKey())))
+ .map(property -> Setting.createFromDto(property, filterPropertySets(property.getKey(), propertySets, null), propertyDefinitions.get(property.getKey())))
.toList();
}
/**
* Return list of settings by component uuids
*/
- private Collection<Setting> loadComponentsSettings(DbSession dbSession, Set<String> keys, List<String> componentUuids) {
- List<PropertyDto> properties = dbClient.propertiesDao().selectPropertiesByKeysAndComponentUuids(dbSession, keys, componentUuids);
- List<PropertyDto> propertySets = dbClient.propertiesDao().selectPropertiesByKeysAndComponentUuids(dbSession, getPropertySetKeys(properties), componentUuids);
+ private Collection<Setting> loadComponentSettings(DbSession dbSession, Set<String> keys, String entityUuid) {
+ List<PropertyDto> properties = dbClient.propertiesDao().selectPropertiesByKeysAndComponentUuids(dbSession, keys, Set.of(entityUuid));
+ List<PropertyDto> propertySets = dbClient.propertiesDao().selectPropertiesByKeysAndComponentUuids(dbSession, getPropertySetKeys(properties), Set.of(entityUuid));
- Multimap<String, Setting> settingsByUuid = TreeMultimap.create(Ordering.explicit(componentUuids), Ordering.arbitrary());
+ List<Setting> settings = new LinkedList<>();
for (PropertyDto propertyDto : properties) {
String componentUuid = propertyDto.getComponentUuid();
String propertyKey = propertyDto.getKey();
- settingsByUuid.put(componentUuid,
- Setting.createFromDto(propertyDto, getPropertySets(propertyKey, propertySets, componentUuid), propertyDefinitions.get(propertyKey)));
+ settings.add(Setting.createFromDto(propertyDto, filterPropertySets(propertyKey, propertySets, componentUuid), propertyDefinitions.get(propertyKey)));
}
- return settingsByUuid.values();
+ return settings;
}
private Set<String> getPropertySetKeys(List<PropertyDto> properties) {
.collect(Collectors.toSet());
}
- private static List<PropertyDto> getPropertySets(String propertyKey, List<PropertyDto> propertySets, @Nullable String componentUuid) {
+ private static List<PropertyDto> filterPropertySets(String propertyKey, List<PropertyDto> propertySets, @Nullable String componentUuid) {
return propertySets.stream()
.filter(propertyDto -> Objects.equals(propertyDto.getComponentUuid(), componentUuid))
.filter(propertyDto -> propertyDto.getKey().startsWith(propertyKey + "."))
private class ValuesResponseBuilder {
private final List<Setting> settings;
- private final Optional<ComponentDto> requestedComponent;
+ private final Optional<EntityDto> requestedComponent;
private final ValuesWsResponse.Builder valuesWsBuilder = ValuesWsResponse.newBuilder();
private final Map<String, Settings.Setting.Builder> settingsBuilderByKey = new HashMap<>();
private final Map<String, Setting> settingsByParentKey = new HashMap<>();
private final Map<String, String> keysToDisplayMap;
- ValuesResponseBuilder(List<Setting> settings, Optional<ComponentDto> requestedComponent, Map<String, String> keysToDisplayMap) {
+ ValuesResponseBuilder(List<Setting> settings, Optional<EntityDto> requestedComponent, Map<String, String> keysToDisplayMap) {
this.settings = settings;
this.requestedComponent = requestedComponent;
this.keysToDisplayMap = keysToDisplayMap;
private void setInherited(Setting setting, Settings.Setting.Builder valueBuilder) {
boolean isDefault = setting.isDefault();
boolean isGlobal = !requestedComponent.isPresent();
- boolean isOnComponent = requestedComponent.isPresent() && Objects.equals(setting.getComponentUuid(), requestedComponent.get().uuid());
+ boolean isOnComponent = requestedComponent.isPresent() && Objects.equals(setting.getComponentUuid(), requestedComponent.get().getUuid());
boolean isSet = isGlobal || isOnComponent;
valueBuilder.setInherited(isDefault || !isSet);
}
import org.sonar.api.web.UserRole;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.permission.GlobalPermission;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.user.UserSession;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.openMocks;
private final boolean hasComponentPermission;
private final boolean expectedIsVisible;
- @Mock
- private ComponentDto componentDto;
- @Mock
- private UserSession userSession;
+ private final ProjectDto componentDto = mock(ProjectDto.class);
+ private final UserSession userSession = mock(UserSession.class);
@InjectMocks
private SettingsWsSupport settingsWsSupport;
openMocks(this);
when(userSession.isSystemAdministrator()).thenReturn(isAdmin);
when(userSession.hasPermission(GlobalPermission.SCAN)).thenReturn(hasGlobalPermission);
- when(userSession.hasComponentPermission(UserRole.SCAN, componentDto)).thenReturn(hasComponentPermission);
+ when(userSession.hasEntityPermission(UserRole.SCAN, componentDto)).thenReturn(hasComponentPermission);
boolean isVisible = settingsWsSupport.isVisible(property, Optional.of(componentDto));
assertThat(isVisible).isEqualTo(expectedIsVisible);
// WS api/components/suggestions
message SuggestionsWsResponse {
- reserved 3; //drop organization
repeated Category results = 1;
optional string warning = 2;
- repeated Project projects = 4;
+ reserved 3; //drop organization
+ reserved 4; //drop projects
message Category {
optional string q = 1;
optional bool isRecentlyBrowsed = 6;
optional bool isFavorite = 7;
}
-
- message Project {
- optional string key = 1;
- optional string name = 2;
- }
}
// WS api/components/search_projects