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);
}
}
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();
}
}
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);
}
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));
}
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));
}
}
Aggregations