Search in sources :

Example 6 with ThingType

use of com.vaticle.typedb.core.concept.type.ThingType in project grakn by graknlabs.

the class Definer method defineSub.

private ThingType defineSub(ThingType thingType, SubConstraint subConstraint, TypeVariable var) {
    try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "define_sub")) {
        LabelConstraint labelConstraint = var.label().get();
        ThingType supertype = define(subConstraint.type()).asThingType();
        if (supertype.isEntityType()) {
            if (thingType == null)
                thingType = conceptMgr.putEntityType(labelConstraint.label());
            thingType.asEntityType().setSupertype(supertype.asEntityType());
        } else if (supertype.isRelationType()) {
            if (thingType == null)
                thingType = conceptMgr.putRelationType(labelConstraint.label());
            thingType.asRelationType().setSupertype(supertype.asRelationType());
        } else if (supertype.isAttributeType()) {
            ValueType valueType;
            if (var.valueType().isPresent())
                valueType = ValueType.of(var.valueType().get().valueType());
            else if (!supertype.isRoot())
                valueType = supertype.asAttributeType().getValueType();
            else
                throw TypeDBException.of(ATTRIBUTE_VALUE_TYPE_MISSING, labelConstraint.label());
            if (thingType == null)
                thingType = conceptMgr.putAttributeType(labelConstraint.label(), valueType);
            thingType.asAttributeType().setSupertype(supertype.asAttributeType());
        } else {
            throw TypeDBException.of(INVALID_DEFINE_SUB, labelConstraint.scopedLabel(), supertype.getLabel());
        }
        return thingType;
    }
}
Also used : LabelConstraint(com.vaticle.typedb.core.pattern.constraint.type.LabelConstraint) ValueType(com.vaticle.typedb.core.concept.type.AttributeType.ValueType) ThreadTrace(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace) ThingType(com.vaticle.typedb.core.concept.type.ThingType)

Example 7 with ThingType

use of com.vaticle.typedb.core.concept.type.ThingType in project grakn by graknlabs.

the class ThingTypeSteps method thing_type_get_supertype.

@Then("{root_label}\\( ?{type_label} ?) get supertype: {type_label}")
public void thing_type_get_supertype(RootLabel rootLabel, String typeLabel, String superLabel) {
    ThingType supertype = get_thing_type(rootLabel, superLabel);
    assertEquals(supertype, get_thing_type(rootLabel, typeLabel).getSupertype());
}
Also used : ThingType(com.vaticle.typedb.core.concept.type.ThingType) Then(io.cucumber.java.en.Then)

Example 8 with ThingType

use of com.vaticle.typedb.core.concept.type.ThingType in project grakn by graknlabs.

the class AttributeTypeSteps method attribute_type_get_owners_as_key_do_not_contains.

@Then("attribute\\( ?{type_label} ?) get key owners do not contain:")
public void attribute_type_get_owners_as_key_do_not_contains(String typeLabel, List<String> ownerLabels) {
    AttributeType attributeType = tx().concepts().getAttributeType(typeLabel);
    Set<String> actuals = attributeType.getOwners(true).map(ThingType::getLabel).map(Label::toString).toSet();
    for (String ownerLabel : ownerLabels) {
        assertFalse(actuals.contains(ownerLabel));
    }
}
Also used : AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) ThingType(com.vaticle.typedb.core.concept.type.ThingType) Then(io.cucumber.java.en.Then)

Example 9 with ThingType

use of com.vaticle.typedb.core.concept.type.ThingType in project grakn by graknlabs.

the class AttributeTypeSteps method attribute_type_get_owners_as_key_contains.

@Then("attribute\\( ?{type_label} ?) get key owners contain:")
public void attribute_type_get_owners_as_key_contains(String typeLabel, List<String> ownerLabels) {
    AttributeType attributeType = tx().concepts().getAttributeType(typeLabel);
    Set<String> actuals = attributeType.getOwners(true).map(ThingType::getLabel).map(Label::toString).toSet();
    assertTrue(actuals.containsAll(ownerLabels));
}
Also used : AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) ThingType(com.vaticle.typedb.core.concept.type.ThingType) Then(io.cucumber.java.en.Then)

Example 10 with ThingType

use of com.vaticle.typedb.core.concept.type.ThingType in project grakn by graknlabs.

the class ThingSteps method thing_has_type.

@Then("{root_label} {var} has type: {type_label}")
public void thing_has_type(RootLabel rootLabel, String var, String typeLabel) {
    ThingType type = get_thing_type(rootLabel, typeLabel);
    assertEquals(type, get(var).getType());
}
Also used : ThingType(com.vaticle.typedb.core.concept.type.ThingType) Then(io.cucumber.java.en.Then)

Aggregations

ThingType (com.vaticle.typedb.core.concept.type.ThingType)17 AttributeType (com.vaticle.typedb.core.concept.type.AttributeType)11 Then (io.cucumber.java.en.Then)8 ThreadTrace (com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace)6 RoleType (com.vaticle.typedb.core.concept.type.RoleType)6 LabelConstraint (com.vaticle.typedb.core.pattern.constraint.type.LabelConstraint)5 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)3 RelationType (com.vaticle.typedb.core.concept.type.RelationType)3 List (java.util.List)3 FactoryTracingThreadStatic.traceOnThread (com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.traceOnThread)2 TypeDB (com.vaticle.typedb.core.TypeDB)2 TYPE_NOT_FOUND (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_NOT_FOUND)2 OVERRIDDEN_NOT_SUPERTYPE (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OVERRIDDEN_NOT_SUPERTYPE)2 ROLE_DEFINED_OUTSIDE_OF_RELATION (com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROLE_DEFINED_OUTSIDE_OF_RELATION)2 ValueType (com.vaticle.typedb.core.concept.type.AttributeType.ValueType)2 EntityType (com.vaticle.typedb.core.concept.type.EntityType)2 Type (com.vaticle.typedb.core.concept.type.Type)2 Consumer (java.util.function.Consumer)2 UNRECOGNISED_VALUE (com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.UNRECOGNISED_VALUE)1 RULE_NOT_FOUND (com.vaticle.typedb.core.common.exception.ErrorMessage.RuleRead.RULE_NOT_FOUND)1