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());
}
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());
}
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());
}
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");
}
Aggregations