/** * Helper method to check whether implicit or attribute types are included in the query scope * * @return true if they exist, false if they don't */ private boolean scopeIncludesImplicitOrAttributeTypes() { if (!query.in().isPresent()) return false; return query.in().get().stream().anyMatch(label -> { SchemaConcept type = tx.getSchemaConcept(label); return (type != null && (type.isAttributeType() || type.isImplicit())); }); }
@Nullable @Override public <V> AttributeType<V> getAttributeType(String label) { SchemaConcept concept = getSchemaConcept(Label.of(label)); if (concept == null || !concept.isAttributeType()) return null; return concept.asAttributeType(); }
@Override public Set<String> validateOntologically() { SchemaConcept type = getSchemaConcept(); Set<String> errors = new HashSet<>(); if (type == null) return errors; if (!type.isAttributeType()){ errors.add(ErrorMessage.VALIDATION_RULE_INVALID_ATTRIBUTE_TYPE.getMessage(type.label())); return errors; } Type ownerType = getParentQuery().getVarTypeMap().get(getVarName()); if (ownerType != null && ownerType.attributes().noneMatch(rt -> rt.equals(type.asAttributeType()))){ errors.add(ErrorMessage.VALIDATION_RULE_ATTRIBUTE_OWNER_CANNOT_HAVE_ATTRIBUTE.getMessage(type.label(), ownerType.label())); } return errors; }
@Override void checkValidProperty(GraknTx graph, VarPatternAdmin var) { SchemaConcept schemaConcept = graph.getSchemaConcept(type()); if (schemaConcept == null) { throw GraqlQueryException.labelNotFound(type()); } if(!schemaConcept.isAttributeType()) { throw GraqlQueryException.mustBeAttributeType(type()); } }
/** * Map a Type to the Graql string representation * @param schemaConcept type to be mapped * @return Graql var equivalent to the given type */ public static VarPattern map(SchemaConcept schemaConcept) { VarPattern mapped = formatBase(schemaConcept); if (schemaConcept.isRelationshipType()) { mapped = map(mapped, schemaConcept.asRelationshipType()); } else if (schemaConcept.isAttributeType()) { mapped = map(mapped, schemaConcept.asAttributeType()); } return mapped; }
/** * Make the second argument the super of the first argument * * @throws GraqlQueryException if the types are different, or setting the super to be a meta-type */ public static void setSuper(SchemaConcept subConcept, SchemaConcept superConcept) { if (superConcept.isEntityType()) { subConcept.asEntityType().sup(superConcept.asEntityType()); } else if (superConcept.isRelationshipType()) { subConcept.asRelationshipType().sup(superConcept.asRelationshipType()); } else if (superConcept.isRole()) { subConcept.asRole().sup(superConcept.asRole()); } else if (superConcept.isAttributeType()) { subConcept.asAttributeType().sup(superConcept.asAttributeType()); } else if (superConcept.isRule()) { subConcept.asRule().sup(superConcept.asRule()); } else { throw GraqlQueryException.insertMetaType(subConcept.label(), superConcept); } }
/** * Make the second argument the super of the first argument * * @throws GraqlQueryException if the types are different, or setting the super to be a meta-type */ private static void setSuper(SchemaConcept subConcept, SchemaConcept superConcept) { if (superConcept.isEntityType()) { subConcept.asEntityType().sup(superConcept.asEntityType()); } else if (superConcept.isRelationshipType()) { subConcept.asRelationshipType().sup(superConcept.asRelationshipType()); } else if (superConcept.isRole()) { subConcept.asRole().sup(superConcept.asRole()); } else if (superConcept.isAttributeType()) { subConcept.asAttributeType().sup(superConcept.asAttributeType()); } else if (superConcept.isRule()) { subConcept.asRule().sup(superConcept.asRule()); } else { throw GraqlQueryException.insertMetaType(subConcept.getLabel(), superConcept); } } }
private SchemaConcept putSchemaConcept() { SchemaConcept superConcept = use(SUPER_CONCEPT); Label label = use(LABEL); SchemaConcept concept; if (superConcept.isEntityType()) { concept = executor.tx().putEntityType(label); } else if (superConcept.isRelationshipType()) { concept = executor.tx().putRelationshipType(label); } else if (superConcept.isRole()) { concept = executor.tx().putRole(label); } else if (superConcept.isAttributeType()) { AttributeType attributeType = superConcept.asAttributeType(); AttributeType.DataType<?> dataType = useOrDefault(DATA_TYPE, attributeType.dataType()); concept = executor.tx().putAttributeType(label, dataType); } else if (superConcept.isRule()) { concept = executor.tx().putRule(label, use(WHEN), use(THEN)); } else { throw GraqlQueryException.insertMetaType(label, superConcept); } setSuper(concept, superConcept); return concept; }