Search in sources :

Example 11 with ThingType

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

the class Undefiner method undefine.

private void undefine(TypeVariable variable) {
    try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "undefine")) {
        assert variable.label().isPresent();
        LabelConstraint labelConstraint = variable.label().get();
        if (labelConstraint.scope().isPresent() && variable.constraints().size() > 1) {
            throw TypeDBException.of(ROLE_DEFINED_OUTSIDE_OF_RELATION, labelConstraint.scopedLabel());
        } else if (!variable.is().isEmpty()) {
            throw TypeDBException.of(TYPE_CONSTRAINT_UNACCEPTED, IS);
        } else if (// do nothing
        labelConstraint.scope().isPresent())
            // do nothing
            return;
        else // do nothing
        if (undefined.contains(variable))
            return;
        ThingType type = getThingType(labelConstraint);
        if (!variable.plays().isEmpty())
            undefinePlays(type, variable.plays());
        if (!variable.owns().isEmpty())
            undefineOwns(type, variable.owns());
        if (!variable.relates().isEmpty())
            undefineRelates(type.asRelationType(), variable.relates());
        if (variable.regex().isPresent())
            undefineRegex(type.asAttributeType().asString(), variable.regex().get());
        if (variable.abstractConstraint().isPresent())
            undefineAbstract(type);
        if (variable.sub().isPresent())
            undefineSub(type, variable.sub().get());
        else if (variable.valueType().isPresent()) {
            throw TypeDBException.of(ATTRIBUTE_VALUE_TYPE_UNDEFINED, variable.valueType().get().valueType().name(), variable.label().get().label());
        }
        undefined.add(variable);
    }
}
Also used : LabelConstraint(com.vaticle.typedb.core.pattern.constraint.type.LabelConstraint) ThreadTrace(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace) ThingType(com.vaticle.typedb.core.concept.type.ThingType)

Example 12 with ThingType

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

the class Undefiner method undefineSub.

private void undefineSub(ThingType thingType, SubConstraint subConstraint) {
    try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "undefine_sub")) {
        if (thingType.isRoleType()) {
            throw TypeDBException.of(ROLE_DEFINED_OUTSIDE_OF_RELATION, thingType.getLabel());
        }
        ThingType supertype = getThingType(subConstraint.type().label().get());
        if (supertype == null) {
            throw TypeDBException.of(TYPE_NOT_FOUND, subConstraint.type().label().get());
        } else if (thingType.getSupertypes().noneMatch(t -> t.equals(supertype))) {
            throw TypeDBException.of(INVALID_UNDEFINE_SUB, thingType.getLabel(), supertype.getLabel());
        }
        if (thingType.isRelationType()) {
            variables.stream().filter(v -> v.label().isPresent() && v.label().get().scope().isPresent() && v.label().get().scope().get().equals(thingType.getLabel().name())).forEach(undefined::add);
        }
        thingType.delete();
    }
}
Also used : ConceptManager(com.vaticle.typedb.core.concept.ConceptManager) Context(com.vaticle.typedb.core.common.parameters.Context) LabelConstraint(com.vaticle.typedb.core.pattern.constraint.type.LabelConstraint) TypeQLUndefine(com.vaticle.typeql.lang.query.TypeQLUndefine) RelationType(com.vaticle.typedb.core.concept.type.RelationType) INVALID_UNDEFINE_SUB(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_SUB) LogicManager(com.vaticle.typedb.core.logic.LogicManager) HashSet(java.util.HashSet) PlaysConstraint(com.vaticle.typedb.core.pattern.constraint.type.PlaysConstraint) TYPE_CONSTRAINT_UNACCEPTED(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_CONSTRAINT_UNACCEPTED) INVALID_UNDEFINE_OWNS_KEY(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_OWNS_KEY) ThingType(com.vaticle.typedb.core.concept.type.ThingType) RelatesConstraint(com.vaticle.typedb.core.pattern.constraint.type.RelatesConstraint) TYPE_NOT_FOUND(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeRead.TYPE_NOT_FOUND) INVALID_UNDEFINE_RELATES_OVERRIDE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_RELATES_OVERRIDE) OwnsConstraint(com.vaticle.typedb.core.pattern.constraint.type.OwnsConstraint) LinkedList(java.util.LinkedList) IS(com.vaticle.typeql.lang.common.TypeQLToken.Constraint.IS) ROLE_DEFINED_OUTSIDE_OF_RELATION(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROLE_DEFINED_OUTSIDE_OF_RELATION) SubConstraint(com.vaticle.typedb.core.pattern.constraint.type.SubConstraint) Set(java.util.Set) RegexConstraint(com.vaticle.typedb.core.pattern.constraint.type.RegexConstraint) ATTRIBUTE_VALUE_TYPE_UNDEFINED(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ATTRIBUTE_VALUE_TYPE_UNDEFINED) RoleType(com.vaticle.typedb.core.concept.type.RoleType) FactoryTracingThreadStatic.traceOnThread(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.traceOnThread) RULE_NOT_FOUND(com.vaticle.typedb.core.common.exception.ErrorMessage.RuleRead.RULE_NOT_FOUND) INVALID_UNDEFINE_OWNS_OVERRIDE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_OWNS_OVERRIDE) INVALID_UNDEFINE_RULE_BODY(com.vaticle.typedb.core.common.exception.ErrorMessage.RuleWrite.INVALID_UNDEFINE_RULE_BODY) List(java.util.List) TypeVariable(com.vaticle.typedb.core.pattern.variable.TypeVariable) VariableRegistry(com.vaticle.typedb.core.pattern.variable.VariableRegistry) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) ThreadTrace(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace) INVALID_UNDEFINE_PLAYS_OVERRIDE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_PLAYS_OVERRIDE) Type(com.vaticle.typedb.core.concept.type.Type) ThreadTrace(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace) ThingType(com.vaticle.typedb.core.concept.type.ThingType)

Example 13 with ThingType

use of com.vaticle.typedb.core.concept.type.ThingType 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);
}
Also used : TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) INVALID_UNDEFINE_NONEXISTENT_OWNS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_NONEXISTENT_OWNS) RelationImpl(com.vaticle.typedb.core.concept.thing.impl.RelationImpl) ASC(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.ASC) ThingType(com.vaticle.typedb.core.concept.type.ThingType) Iterators.loop(com.vaticle.typedb.core.common.iterator.Iterators.loop) OWNS_KEY_PRECONDITION_UNIQUENESS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_PRECONDITION_UNIQUENESS) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) OWNS_KEY_PRECONDITION_NO_INSTANCES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_PRECONDITION_NO_INSTANCES) OWNS_KEY_VALUE_TYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_VALUE_TYPE) SUB(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.SUB) EntityImpl(com.vaticle.typedb.core.concept.thing.impl.EntityImpl) INVALID_UNDEFINE_NONEXISTENT_PLAYS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_NONEXISTENT_PLAYS) Forwardable(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Forwardable) INVALID_UNDEFINE_PLAYS_HAS_INSTANCES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_PLAYS_HAS_INSTANCES) ThingVertex(com.vaticle.typedb.core.graph.vertex.ThingVertex) Objects(java.util.Objects) List(java.util.List) ThingImpl(com.vaticle.typedb.core.concept.thing.impl.ThingImpl) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) PLAYS_ROLE_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.PLAYS_ROLE_NOT_AVAILABLE) OVERRIDDEN_NOT_SUPERTYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OVERRIDDEN_NOT_SUPERTYPE) Iterators.link(com.vaticle.typedb.core.common.iterator.Iterators.link) INVALID_UNDEFINE_INHERITED_OWNS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_INHERITED_OWNS) Order(com.vaticle.typedb.core.common.iterator.sorted.SortedIterator.Order) Function(java.util.function.Function) Forwardable.iterateSorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.iterateSorted) INVALID_UNDEFINE_OWNS_HAS_INSTANCES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_OWNS_HAS_INSTANCES) OWNS_ABSTRACT_ATT_TYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_ABSTRACT_ATT_TYPE) Forwardable.emptySorted(com.vaticle.typedb.core.common.iterator.sorted.SortedIterators.Forwardable.emptySorted) OWNS_ATT_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_ATT_NOT_AVAILABLE) OWS_KEY_PRECONDITION_OWNERSHIP_KEY_TOO_MANY(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWS_KEY_PRECONDITION_OWNERSHIP_KEY_TOO_MANY) TYPE_HAS_SUBTYPES(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_SUBTYPES) INVALID_UNDEFINE_INHERITED_PLAYS(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.INVALID_UNDEFINE_INHERITED_PLAYS) TYPE_HAS_INSTANCES_DELETE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_INSTANCES_DELETE) Encoding(com.vaticle.typedb.core.graph.common.Encoding) Nullable(javax.annotation.Nullable) PLAYS(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.PLAYS) GraphManager(com.vaticle.typedb.core.graph.GraphManager) UNRECOGNISED_VALUE(com.vaticle.typedb.core.common.exception.ErrorMessage.Internal.UNRECOGNISED_VALUE) OWS_KEY_PRECONDITION_OWNERSHIP_KEY_MISSING(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWS_KEY_PRECONDITION_OWNERSHIP_KEY_MISSING) Iterators(com.vaticle.typedb.core.common.iterator.Iterators) OWNS_KEY(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS_KEY) AttributeImpl(com.vaticle.typedb.core.concept.thing.impl.AttributeImpl) RoleType(com.vaticle.typedb.core.concept.type.RoleType) OWNS_KEY_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OWNS_KEY_NOT_AVAILABLE) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) Iterators.compareSize(com.vaticle.typedb.core.common.iterator.Iterators.compareSize) PLAYS_ABSTRACT_ROLE_TYPE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.PLAYS_ABSTRACT_ROLE_TYPE) ROOT_TYPE_MUTATION(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.ROOT_TYPE_MUTATION) OWNS(com.vaticle.typedb.core.graph.common.Encoding.Edge.Type.OWNS) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex) Collections(java.util.Collections) TYPE_HAS_INSTANCES_SET_ABSTRACT(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.TYPE_HAS_INSTANCES_SET_ABSTRACT) Type(com.vaticle.typedb.core.concept.type.Type) OVERRIDE_NOT_AVAILABLE(com.vaticle.typedb.core.common.exception.ErrorMessage.TypeWrite.OVERRIDE_NOT_AVAILABLE) TypeEdge(com.vaticle.typedb.core.graph.edge.TypeEdge) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) ThingType(com.vaticle.typedb.core.concept.type.ThingType) TypeVertex(com.vaticle.typedb.core.graph.vertex.TypeVertex)

Example 14 with ThingType

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

the class AttributeTypeSteps method attribute_type_as_value_type_get_subtypes_contain.

@Then("attribute\\( ?{type_label} ?) as\\( ?{value_type} ?) get subtypes contain:")
public void attribute_type_as_value_type_get_subtypes_contain(String typeLabel, AttributeType.ValueType valueType, List<String> subLabels) {
    AttributeType attributeType = attribute_type_as_value_type(typeLabel, valueType);
    Set<String> actuals = attributeType.getSubtypes().map(ThingType::getLabel).map(Label::toString).toSet();
    assertTrue(actuals.containsAll(subLabels));
}
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 15 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_attribute_do_not_contains.

@Then("attribute\\( ?{type_label} ?) get attribute owners do not contain:")
public void attribute_type_get_owners_as_attribute_do_not_contains(String typeLabel, List<String> ownerLabels) {
    AttributeType attributeType = tx().concepts().getAttributeType(typeLabel);
    Set<String> actuals = attributeType.getOwners(false).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)

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