use of com.vaticle.typedb.core.concept.type.AttributeType in project grakn by graknlabs.
the class ThingTypeSteps method thing_type_set_owns_attribute_type_as.
@When("{root_label}\\( ?{type_label} ?) set owns attribute type: {type_label} as {type_label}")
public void thing_type_set_owns_attribute_type_as(RootLabel rootLabel, String typeLabel, String attributeLabel, String overriddenLabel) {
AttributeType attributeType = tx().concepts().getAttributeType(attributeLabel);
AttributeType overriddenType = tx().concepts().getAttributeType(overriddenLabel);
get_thing_type(rootLabel, typeLabel).setOwns(attributeType, overriddenType);
}
use of com.vaticle.typedb.core.concept.type.AttributeType in project grakn by graknlabs.
the class ThingTypeSteps method thing_type_set_supertype_throws_exception.
@Then("{root_label}\\( ?{type_label} ?) set supertype: {type_label}; throws exception")
public void thing_type_set_supertype_throws_exception(RootLabel rootLabel, String typeLabel, String superLabel) {
switch(rootLabel) {
case ENTITY:
EntityType entitySuperType = tx().concepts().getEntityType(superLabel);
assertThrows(() -> tx().concepts().getEntityType(typeLabel).setSupertype(entitySuperType));
break;
case ATTRIBUTE:
AttributeType attributeSuperType = tx().concepts().getAttributeType(superLabel);
assertThrows(() -> tx().concepts().getAttributeType(typeLabel).setSupertype(attributeSuperType));
break;
case RELATION:
RelationType relationSuperType = tx().concepts().getRelationType(superLabel);
assertThrows(() -> tx().concepts().getRelationType(typeLabel).setSupertype(relationSuperType));
break;
}
}
use of com.vaticle.typedb.core.concept.type.AttributeType in project grakn by graknlabs.
the class ThingTypeImpl method ownsKey.
private void ownsKey(AttributeTypeImpl attributeType) {
validateIsNotDeleted();
TypeVertex attVertex = attributeType.vertex;
TypeEdge ownsEdge, ownsKeyEdge;
if (vertex.outs().edge(OWNS_KEY, attVertex) != null)
return;
if (!attributeType.isKeyable()) {
throw exception(TypeDBException.of(OWNS_KEY_VALUE_TYPE, attributeType.getLabel(), attributeType.getValueType().name()));
} else if (link(getSupertype().getOwns(attributeType.getValueType(), true), getSupertype().overriddenOwns(false, true)).anyMatch(a -> a.equals(attributeType))) {
throw exception(TypeDBException.of(OWNS_KEY_NOT_AVAILABLE, attributeType.getLabel()));
}
if ((ownsEdge = vertex.outs().edge(OWNS, attVertex)) != null) {
// TODO: These ownership and uniqueness checks should be parallelised to scale better
getInstances().forEachRemaining(thing -> {
FunctionalIterator<? extends Attribute> attrs = thing.getHas(attributeType);
if (!attrs.hasNext())
throw exception(TypeDBException.of(OWS_KEY_PRECONDITION_OWNERSHIP_KEY_TOO_MANY, vertex.label(), attVertex.label()));
Attribute attr = attrs.next();
if (attrs.hasNext())
throw exception(TypeDBException.of(OWS_KEY_PRECONDITION_OWNERSHIP_KEY_MISSING, vertex.label(), attVertex.label()));
else if (compareSize(attr.getOwners(this), 1) != 0) {
throw exception(TypeDBException.of(OWNS_KEY_PRECONDITION_UNIQUENESS, attVertex.label(), vertex.label()));
}
});
ownsEdge.delete();
} else if (getInstances().first().isPresent()) {
throw exception(TypeDBException.of(OWNS_KEY_PRECONDITION_NO_INSTANCES, vertex.label(), attVertex.label()));
}
ownsKeyEdge = vertex.outs().put(OWNS_KEY, attVertex);
if (getSupertype().declaredOwns(false).findFirst(attributeType).isPresent())
ownsKeyEdge.overridden(attVertex);
}
use of com.vaticle.typedb.core.concept.type.AttributeType in project grakn by graknlabs.
the class ThingTypeImpl method ownsAttribute.
private void ownsAttribute(AttributeTypeImpl attributeType) {
validateIsNotDeleted();
Forwardable<AttributeType, Order.Asc> owns = getSupertypes().filter(t -> !t.equals(this)).mergeMap(ThingType::getOwns, ASC);
if (owns.findFirst(attributeType).isPresent()) {
throw exception(TypeDBException.of(OWNS_ATT_NOT_AVAILABLE, attributeType.getLabel()));
}
TypeVertex attVertex = attributeType.vertex;
TypeEdge keyEdge;
if ((keyEdge = vertex.outs().edge(OWNS_KEY, attVertex)) != null)
keyEdge.delete();
vertex.outs().put(OWNS, attVertex);
}
use of com.vaticle.typedb.core.concept.type.AttributeType in project grakn by graknlabs.
the class ConceptService method putAttributeType.
private void putAttributeType(ConceptProto.ConceptManager.PutAttributeType.Req attributeTypeReq, UUID reqID) {
ConceptProto.AttributeType.ValueType valueTypeProto = attributeTypeReq.getValueType();
AttributeType.ValueType valueType;
switch(valueTypeProto) {
case STRING:
valueType = AttributeType.ValueType.STRING;
break;
case BOOLEAN:
valueType = AttributeType.ValueType.BOOLEAN;
break;
case LONG:
valueType = AttributeType.ValueType.LONG;
break;
case DOUBLE:
valueType = AttributeType.ValueType.DOUBLE;
break;
case DATETIME:
valueType = AttributeType.ValueType.DATETIME;
break;
case OBJECT:
case UNRECOGNIZED:
default:
throw TypeDBException.of(BAD_VALUE_TYPE, valueTypeProto);
}
AttributeType attributeType = conceptMgr.putAttributeType(attributeTypeReq.getLabel(), valueType);
transactionSvc.respond(putAttributeTypeRes(reqID, attributeType));
}
Aggregations