import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_KEY;
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_LANGUAGE;
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_NAME;
+import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_ORGANIZATION_UUID;
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;
setField(FIELD_LANGUAGE, s);
return this;
}
+
+ public String getOrganization() {
+ return getField(FIELD_ORGANIZATION_UUID);
+ }
+
+ public ComponentDoc setOrganization(String s) {
+ setField(FIELD_ORGANIZATION_UUID, s);
+ return this;
+ }
}
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_KEY;
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_LANGUAGE;
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_NAME;
+import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_ORGANIZATION_UUID;
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_QUALIFIER;
import static org.sonar.server.component.index.ComponentIndexDefinition.INDEX_TYPE_COMPONENT;
import static org.sonar.server.component.index.ComponentIndexDefinition.NAME_ANALYZERS;
esQuery.must(ComponentTextSearchQueryFactory.createQuery(componentTextSearchQuery, ComponentTextSearchFeatureRepertoire.values()));
});
setEmptiable(query.getQualifiers(), q -> esQuery.must(termsQuery(FIELD_QUALIFIER, q)));
- setNullable(query.getLanguage(), l -> esQuery.must(termsQuery(FIELD_LANGUAGE, l)));
+ setNullable(query.getLanguage(), l -> esQuery.must(termQuery(FIELD_LANGUAGE, l)));
+ setNullable(query.getOrganizationUuid(), o -> esQuery.must(termQuery(FIELD_ORGANIZATION_UUID, o)));
requestBuilder.setQuery(esQuery);
requestBuilder.addSort(SORTABLE_ANALYZER.subField(FIELD_NAME), SortOrder.ASC);
public static final IndexType INDEX_TYPE_COMPONENT = new IndexType("components", "component");
public static final String FIELD_UUID = "uuid";
public static final String FIELD_PROJECT_UUID = "project_uuid";
+ public static final String FIELD_ORGANIZATION_UUID = "organization_uuid";
public static final String FIELD_KEY = "key";
public static final String FIELD_NAME = "name";
public static final String FIELD_QUALIFIER = "qualifier";
mapping.keywordFieldBuilder(FIELD_QUALIFIER).build();
mapping.keywordFieldBuilder(FIELD_LANGUAGE).disableNorms().build();
+ mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUID).disableNorms().build();
}
}
.setName(component.name())
.setKey(component.getDbKey())
.setProjectUuid(component.projectUuid())
+ .setOrganization(component.getOrganizationUuid())
.setLanguage(component.language())
.setQualifier(component.qualifier());
}
package org.sonar.server.component.index;
import java.util.Collection;
+import javax.annotation.CheckForNull;
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableCollection;
public class ComponentQuery {
+ private final String organizationUuid;
private final String query;
private final Collection<String> qualifiers;
private final String language;
private ComponentQuery(Builder builder) {
+ this.organizationUuid = builder.organizationUuid;
this.query = builder.query;
this.qualifiers = builder.qualifiers;
this.language = builder.language;
}
+ @CheckForNull
+ public String getOrganizationUuid() {
+ return organizationUuid;
+ }
+
+ @CheckForNull
public String getQuery() {
return query;
}
return qualifiers;
}
+ @CheckForNull
public String getLanguage() {
return language;
}
}
public static class Builder {
+ private String organizationUuid;
private String query;
private Collection<String> qualifiers = emptySet();
private String language;
// enforce static factory method
}
+ public Builder setOrganization(String organizationUuid) {
+ this.organizationUuid = organizationUuid;
+ return this;
+ }
+
public Builder setQuery(String query) {
this.query = query;
return this;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.SearchIdResult;
import org.sonar.server.es.SearchOptions;
assertThat(result.getIds()).containsExactlyInAnyOrder(file.uuid());
}
+ @Test
+ public void filter_by_organization() {
+ OrganizationDto organization = db.organizations().insert();
+ OrganizationDto anotherOrganization = db.organizations().insert();
+ ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto anotherProject = db.components().insertPrivateProject(anotherOrganization);
+ index(project, anotherProject);
+
+ SearchIdResult<String> result = underTest.search(ComponentQuery.builder().setOrganization(organization.getUuid()).build(), new SearchOptions());
+
+ assertThat(result.getIds()).containsExactlyInAnyOrder(project.uuid());
+ }
+
@Test
public void order_by_name_case_insensitive() {
ComponentDto project2 = db.components().insertPrivateProject(p -> p.setName("PROJECT 2"));
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentUpdateDto;
import org.sonar.db.es.EsQueueDto;
+import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.IndexingResult;
import org.sonar.server.es.ProjectIndexer;
@Test
public void map_fields() {
- ComponentDto project = db.components().insertPrivateProject(p -> p.setLanguage("java"));
+ OrganizationDto organization = db.organizations().insert();
+ ComponentDto project = db.components().insertPrivateProject(organization, p -> p.setLanguage("java"));
underTest.indexOnStartup(emptySet());
assertThat(doc.getProjectUuid()).isEqualTo(project.projectUuid());
assertThat(doc.getName()).isEqualTo(project.name());
assertThat(doc.getLanguage()).isEqualTo(project.language());
+ assertThat(doc.getOrganization()).isEqualTo(project.getOrganizationUuid());
}
@Test