use of com.vaticle.typedb.core.concept.type.RoleType in project grakn by graknlabs.
the class DataExporter method relation.
private DataProto.Item relation(Relation relation) {
status.relationCount.incrementAndGet();
DataProto.Item.Relation.Builder relationBuilder = DataProto.Item.Relation.newBuilder().setId(relation.getIID().toBase64String()).setLabel(relation.getType().getLabel().name());
Map<? extends RoleType, ? extends List<? extends Thing>> playersByRole = relation.getPlayersByRoleType();
for (Map.Entry<? extends RoleType, ? extends List<? extends Thing>> rolePlayers : playersByRole.entrySet()) {
RoleType role = rolePlayers.getKey();
DataProto.Item.Relation.Role.Builder roleBuilder = DataProto.Item.Relation.Role.newBuilder().setLabel(role.getLabel().scopedName());
for (Thing player : rolePlayers.getValue()) {
status.roleCount.incrementAndGet();
roleBuilder.addPlayer(DataProto.Item.Relation.Role.Player.newBuilder().setId(player.getIID().toBase64String()));
}
relationBuilder.addRole(roleBuilder);
}
readOwnerships(relation).forEachRemaining(a -> {
status.ownershipCount.incrementAndGet();
relationBuilder.addAttribute(a);
});
return DataProto.Item.newBuilder().setRelation(relationBuilder).build();
}
use of com.vaticle.typedb.core.concept.type.RoleType in project grakn by graknlabs.
the class DataImporter method importSkippedRelations.
private void importSkippedRelations() {
try (TypeDB.Transaction transaction = session.transaction(Arguments.Transaction.Type.WRITE)) {
skippedRelations.forEach(msg -> {
RelationType relType = transaction.concepts().getRelationType(msg.getLabel());
if (relType == null)
throw TypeDBException.of(TYPE_NOT_FOUND, msg.getLabel());
Relation importedRelation = relType.create();
idMapper.put(msg.getId(), importedRelation.getIID());
int ownershipCount = 0;
for (DataProto.Item.OwnedAttribute ownership : msg.getAttributeList()) {
Thing attribute = transaction.concepts().getThing(idMapper.get(ownership.getId()));
assert attribute != null;
importedRelation.setHas(attribute.asAttribute());
ownershipCount++;
}
status.ownershipCount.addAndGet(ownershipCount);
});
skippedRelations.forEach(msg -> {
RelationType relType = transaction.concepts().getRelationType(msg.getLabel());
Relation relation = transaction.concepts().getThing(idMapper.get(msg.getId())).asRelation();
msg.getRoleList().forEach(roleMsg -> {
RoleType roleType = getRoleType(relType, roleMsg);
for (DataProto.Item.Relation.Role.Player playerMessage : roleMsg.getPlayerList()) {
Thing player = transaction.concepts().getThing(idMapper.get(playerMessage.getId()));
if (player == null)
throw TypeDBException.of(PLAYER_NOT_FOUND, relType.getLabel());
else
relation.addPlayer(roleType, player);
}
});
});
transaction.commit();
}
}
use of com.vaticle.typedb.core.concept.type.RoleType in project grakn by graknlabs.
the class DataImporter method getRoleType.
private RoleType getRoleType(RelationType relationType, DataProto.Item.Relation.Role roleMsg) {
String unscopedRoleLabel;
String roleLabel = roleMsg.getLabel();
if (roleLabel.contains(":"))
unscopedRoleLabel = roleLabel.split(":")[1];
else
unscopedRoleLabel = roleLabel;
RoleType roleType = relationType.getRelates(unscopedRoleLabel);
if (roleType == null) {
throw TypeDBException.of(ROLE_TYPE_NOT_FOUND, roleLabel, relationType.getLabel().name());
} else
return roleType;
}
use of com.vaticle.typedb.core.concept.type.RoleType in project grakn by graknlabs.
the class RelationTypeSteps method relation_type_get_role_type_get_supertype.
@Then("relation\\( ?{type_label} ?) get role\\( ?{type_label} ?) get supertype: {scoped_label}")
public void relation_type_get_role_type_get_supertype(String relationLabel, String roleLabel, Parameters.ScopedLabel superLabel) {
RoleType superType = tx().concepts().getRelationType(superLabel.scope()).getRelates(superLabel.label());
assertEquals(superType, tx().concepts().getRelationType(relationLabel).getRelates(roleLabel).getSupertype());
}
use of com.vaticle.typedb.core.concept.type.RoleType in project grakn by graknlabs.
the class ThingTypeSteps method thing_type_set_plays_role_as_throws_exception.
@When("{root_label}\\( ?{type_label} ?) set plays role: {scoped_label} as {scoped_label}; throws exception")
public void thing_type_set_plays_role_as_throws_exception(RootLabel rootLabel, String typeLabel, Parameters.ScopedLabel roleLabel, Parameters.ScopedLabel overriddenLabel) {
RoleType roleType = tx().concepts().getRelationType(roleLabel.scope()).getRelates(roleLabel.label());
RoleType overriddenType = tx().concepts().getRelationType(overriddenLabel.scope()).getRelates(overriddenLabel.label());
assertThrows(() -> get_thing_type(rootLabel, typeLabel).setPlays(roleType, overriddenType));
}
Aggregations