use of com.b2international.snowowl.snomed.datastore.StatementFragmentWithDestination in project snow-owl by b2ihealthcare.
the class NormalFormGenerator method relationshipsFromUnionGroup.
private Iterable<StatementFragment> relationshipsFromUnionGroup(final NormalFormUnionGroup unionGroup, final int groupNumber, final int unionGroupNumber) {
return FluentIterable.from(unionGroup.getProperties()).filter(Predicates.or(Predicates.instanceOf(NormalFormRelationship.class), Predicates.instanceOf(NormalFormValue.class))).transform(property -> {
if (property instanceof NormalFormRelationship) {
final NormalFormRelationship r = (NormalFormRelationship) property;
return new StatementFragmentWithDestination(r.getTypeId(), groupNumber, unionGroupNumber, r.isUniversal(), r.getStatementId(), -1L, r.isReleased(), r.getDestinationId(), r.isDestinationNegated());
} else {
final NormalFormValue v = (NormalFormValue) property;
final RelationshipValue relationshipValue = v.getValue();
return new StatementFragmentWithValue(v.getTypeId(), groupNumber, unionGroupNumber, false, v.getStatementId(), -1L, v.isReleased(), relationshipValue.type(), relationshipValue.toRawValue());
}
});
}
use of com.b2international.snowowl.snomed.datastore.StatementFragmentWithDestination in project snow-owl by b2ihealthcare.
the class RelationshipWriter method indexChange.
@Override
public void indexChange(final String conceptId, final StatementFragment fragment, final ChangeNature nature) {
final RelationshipChangeDocument.Builder builder = RelationshipChangeDocument.builder().nature(nature).classificationId(classificationId).sourceId(conceptId);
if (fragment instanceof StatementFragmentWithDestination) {
final long destinationId = ((StatementFragmentWithDestination) fragment).getDestinationId();
builder.destinationId(Long.toString(destinationId));
} else {
final StatementFragmentWithValue fragmentWithValue = (StatementFragmentWithValue) fragment;
final RelationshipValueType valueType = fragmentWithValue.getValueType();
final String rawValue = fragmentWithValue.getRawValue();
builder.valueType(valueType);
builder.rawValue(rawValue);
}
switch(nature) {
case NEW:
builder.group(fragment.getGroup());
builder.unionGroup(fragment.getUnionGroup());
builder.characteristicTypeId(Concepts.INFERRED_RELATIONSHIP);
builder.released(Boolean.FALSE);
if (fragment.getStatementId() != -1L) {
builder.relationshipId(Long.toString(fragment.getStatementId()));
} else {
builder.typeId(Long.toString(fragment.getTypeId()));
}
break;
case UPDATED:
builder.group(fragment.getGroup());
builder.released(fragment.isReleased());
builder.relationshipId(Long.toString(fragment.getStatementId()));
break;
case REDUNDANT:
builder.released(fragment.isReleased());
builder.relationshipId(Long.toString(fragment.getStatementId()));
break;
default:
throw new IllegalStateException(String.format("Unexpected relationship change '%s' found with SCTID '%s'.", nature, fragment.getStatementId()));
}
indexChange(builder.build());
}
use of com.b2international.snowowl.snomed.datastore.StatementFragmentWithDestination in project snow-owl by b2ihealthcare.
the class StatementFragmentOrdering method compare.
@Override
public int compare(final StatementFragment o1, final StatementFragment o2) {
final int classDelta = CLASS_ORDERING.compare(o1.getClass(), o2.getClass());
if (classDelta != 0)
return classDelta;
final int attributeDelta = Longs.compare(o1.getTypeId(), o2.getTypeId());
if (attributeDelta != 0)
return attributeDelta;
final int groupDelta = o1.getGroup() - o2.getGroup();
if (groupDelta != 0)
return groupDelta;
final int unionGroupDelta = o1.getUnionGroup() - o2.getUnionGroup();
if (unionGroupDelta != 0)
return unionGroupDelta;
final int universalDelta = Booleans.compare(o1.isUniversal(), o2.isUniversal());
if (universalDelta != 0)
return universalDelta;
if (o1 instanceof StatementFragmentWithDestination) {
checkState(o2 instanceof StatementFragmentWithDestination);
final StatementFragmentWithDestination d1 = (StatementFragmentWithDestination) o1;
final StatementFragmentWithDestination d2 = (StatementFragmentWithDestination) o2;
final int destinationDelta = Longs.compare(d1.getDestinationId(), d2.getDestinationId());
if (destinationDelta != 0)
return destinationDelta;
final int destinationNegatedDelta = Booleans.compare(d1.isDestinationNegated(), d2.isDestinationNegated());
return destinationNegatedDelta;
}
if (o1 instanceof StatementFragmentWithValue) {
checkState(o2 instanceof StatementFragmentWithValue);
final StatementFragmentWithValue v1 = (StatementFragmentWithValue) o1;
final StatementFragmentWithValue v2 = (StatementFragmentWithValue) o2;
final int valueTypeDelta = v1.getValueType().compareTo(v2.getValueType());
if (valueTypeDelta != 0) {
return valueTypeDelta;
}
final int rawValueDelta = v1.getRawValue().compareTo(v2.getRawValue());
return rawValueDelta;
}
throw new IllegalStateException("Statement fragment ordering is incomplete.");
}
Aggregations