Search in sources :

Example 1 with IndexRelationType

use of org.sonar.server.es.IndexType.IndexRelationType in project sonarqube by SonarSource.

the class MetadataIndexImpl method initializedId.

private static String initializedId(IndexType indexType) {
    if (indexType instanceof IndexMainType) {
        IndexMainType mainType = (IndexMainType) indexType;
        return mainType.getIndex().getName() + "." + mainType.getType() + ".initialized";
    }
    if (indexType instanceof IndexRelationType) {
        IndexRelationType relationType = (IndexRelationType) indexType;
        IndexMainType mainType = relationType.getMainType();
        return mainType.getIndex().getName() + "." + mainType.getType() + "." + relationType.getName() + ".initialized";
    }
    throw new IllegalArgumentException("Unsupported IndexType " + indexType.getClass());
}
Also used : IndexRelationType(org.sonar.server.es.IndexType.IndexRelationType) IndexMainType(org.sonar.server.es.IndexType.IndexMainType)

Example 2 with IndexRelationType

use of org.sonar.server.es.IndexType.IndexRelationType in project sonarqube by SonarSource.

the class IndexTypeTest method IndexRelationType_equals_and_hashCode.

@Test
public void IndexRelationType_equals_and_hashCode() {
    IndexMainType mainType1 = IndexType.main(Index.withRelations("foo"), "bar");
    IndexMainType mainType2 = IndexType.main(Index.withRelations("foo"), "baz");
    IndexRelationType type1 = IndexType.relation(mainType1, "donut");
    IndexRelationType type1b = IndexType.relation(mainType1, "donut");
    IndexRelationType type2 = IndexType.relation(mainType1, "donuz");
    IndexRelationType type3 = IndexType.relation(mainType2, "donut");
    assertThat(type1).isEqualTo(type1).isEqualTo(type1b).isNotEqualTo(type2).isNotEqualTo(type3).hasSameHashCodeAs(type1).hasSameHashCodeAs(type1b);
    assertThat(type2.hashCode()).isNotEqualTo(type1.hashCode());
    assertThat(type3.hashCode()).isNotEqualTo(type2.hashCode()).isNotEqualTo(type1.hashCode());
}
Also used : IndexRelationType(org.sonar.server.es.IndexType.IndexRelationType) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) SimpleIndexMainType(org.sonar.server.es.IndexType.SimpleIndexMainType) Test(org.junit.Test)

Example 3 with IndexRelationType

use of org.sonar.server.es.IndexType.IndexRelationType in project sonarqube by SonarSource.

the class BaseDoc method setParent.

protected void setParent(String parentId) {
    checkState(this.indexType instanceof IndexRelationType, "Doc must be associated to a IndexRelationType to set a parent");
    checkArgument(parentId != null && !parentId.isEmpty(), "parentId can't be null nor empty");
    this.parentId = parentId;
    IndexRelationType indexRelationType = (IndexRelationType) this.indexType;
    setField(indexRelationType.getMainType().getIndex().getJoinField(), ImmutableMap.of("name", indexRelationType.getName(), "parent", parentId));
    setField(FIELD_INDEX_TYPE, indexRelationType.getName());
}
Also used : IndexRelationType(org.sonar.server.es.IndexType.IndexRelationType)

Example 4 with IndexRelationType

use of org.sonar.server.es.IndexType.IndexRelationType in project sonarqube by SonarSource.

the class IndexTypeTest method parseMainType_from_relationtype.

@Test
public void parseMainType_from_relationtype() {
    IndexMainType mainType = IndexType.main(Index.withRelations("foo"), "bar");
    IndexRelationType type1 = IndexType.relation(mainType, "donut");
    assertThat(type1.format()).isEqualTo("foo/bar/donut");
    SimpleIndexMainType type2 = IndexType.parseMainType(type1.format());
    assertThat(type2).extracting(SimpleIndexMainType::getIndex, SimpleIndexMainType::getType).containsExactly("foo", "bar");
}
Also used : IndexRelationType(org.sonar.server.es.IndexType.IndexRelationType) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) SimpleIndexMainType(org.sonar.server.es.IndexType.SimpleIndexMainType) SimpleIndexMainType(org.sonar.server.es.IndexType.SimpleIndexMainType) Test(org.junit.Test)

Aggregations

IndexRelationType (org.sonar.server.es.IndexType.IndexRelationType)4 IndexMainType (org.sonar.server.es.IndexType.IndexMainType)3 Test (org.junit.Test)2 SimpleIndexMainType (org.sonar.server.es.IndexType.SimpleIndexMainType)2