use of com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace in project grakn by graknlabs.
the class Definer method definePlays.
private void definePlays(ThingType thingType, Set<PlaysConstraint> playsConstraints) {
try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "define_plays")) {
playsConstraints.forEach(plays -> {
define(plays.relation().get());
LabelConstraint roleTypeLabel = plays.role().label().get();
RoleType roleType = getRoleType(roleTypeLabel).asRoleType();
if (plays.overridden().isPresent()) {
String overriddenLabelName = plays.overridden().get().label().get().properLabel().name();
Optional<? extends RoleType> overriddenType = roleType.getSupertypes().filter(rt -> rt.getLabel().name().equals(overriddenLabelName)).first();
if (overriddenType.isPresent()) {
thingType.setPlays(roleType, overriddenType.get());
} else {
throw TypeDBException.of(OVERRIDDEN_NOT_SUPERTYPE, roleTypeLabel.scopedLabel(), overriddenLabelName);
}
} else {
thingType.setPlays(roleType);
}
});
}
}
use of com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace in project grakn by graknlabs.
the class Definer method getRoleType.
private RoleType getRoleType(LabelConstraint label) {
try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "get_role_type")) {
// defined by their Relation Types ahead of time
assert label.scope().isPresent();
ThingType thingType;
RoleType roleType;
if ((thingType = conceptMgr.getThingType(label.scope().get())) == null) {
throw TypeDBException.of(TYPE_NOT_FOUND, label.scope().get());
} else if (!thingType.isRelationType()) {
throw TypeDBException.of(ROLE_TYPE_SCOPE_IS_NOT_RELATION_TYPE, label.scopedLabel(), label.scope().get());
} else if ((roleType = thingType.asRelationType().getRelates(label.label())) == null) {
throw TypeDBException.of(TYPE_NOT_FOUND, label.scopedLabel());
}
return roleType;
}
}
use of com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace in project grakn by graknlabs.
the class Definer method execute.
public void execute() {
try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "execute")) {
validateTypeHierarchyIsNotCyclic(variables);
variables.forEach(variable -> {
if (!defined.contains(variable))
define(variable);
});
rules.forEach(this::define);
}
}
use of com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace in project grakn by graknlabs.
the class Definer method define.
private ThingType define(TypeVariable variable) {
try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "define")) {
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 null;
else if (defined.contains(variable))
return conceptMgr.getThingType(labelConstraint.scopedLabel());
ThingType type = getThingType(labelConstraint);
if (variable.sub().isPresent()) {
type = defineSub(type, variable.sub().get(), variable);
} else if (variable.valueType().isPresent()) {
// && variable.sub().size() == 0
String valueType = variable.valueType().get().valueType().name();
throw TypeDBException.of(ATTRIBUTE_VALUE_TYPE_MODIFIED, valueType, labelConstraint.label());
} else if (type == null) {
throw TypeDBException.of(TYPE_NOT_FOUND, labelConstraint.label());
}
if (variable.valueType().isPresent() && !(type.isAttributeType())) {
throw TypeDBException.of(ATTRIBUTE_VALUE_TYPE_DEFINED_NOT_ON_ATTRIBUTE_TYPE, labelConstraint.label());
}
defined.add(variable);
if (variable.abstractConstraint().isPresent())
defineAbstract(type);
if (variable.regex().isPresent())
defineRegex(type.asAttributeType().asString(), variable.regex().get());
if (!variable.relates().isEmpty())
defineRelates(type.asRelationType(), variable.relates());
if (!variable.owns().isEmpty())
defineOwns(type, variable.owns());
if (!variable.plays().isEmpty())
definePlays(type, variable.plays());
return type;
}
}
use of com.vaticle.factory.tracing.client.FactoryTracingThreadStatic.ThreadTrace in project grakn by graknlabs.
the class Definer method defineOwns.
private void defineOwns(ThingType thingType, Set<OwnsConstraint> ownsConstraints) {
try (ThreadTrace ignored = traceOnThread(TRACE_PREFIX + "define_owns")) {
ownsConstraints.forEach(owns -> {
AttributeType attributeType = define(owns.attribute()).asAttributeType();
if (owns.overridden().isPresent()) {
AttributeType overriddenType = define(owns.overridden().get()).asAttributeType();
thingType.setOwns(attributeType, overriddenType, owns.isKey());
} else {
thingType.setOwns(attributeType, owns.isKey());
}
});
}
}
Aggregations