/** * Checks if a {@link Relationship} has at least one role player. * @param relationship The {@link Relationship} to check */ static Optional<String> validateRelationshipHasRolePlayers(Relationship relationship) { if(!relationship.rolePlayers().findAny().isPresent()){ return Optional.of(ErrorMessage.VALIDATION_RELATIONSHIP_WITH_NO_ROLE_PLAYERS.getMessage(relationship.id(), relationship.type().label())); } return Optional.empty(); } }
/** * Checks if the {@link Role} of the {@link Casting} has been linked to the {@link RelationshipType} of * the {@link Relationship} which the {@link Casting} connects to. * * @param role the {@link Role} which the {@link Casting} refers to * @param relationshipType the {@link RelationshipType} which should connect to the role * @param relationship the {@link Relationship} which the {@link Casting} refers to * @return an error if one is found */ private static Optional<String> roleNotLinkedToRelationShip(Role role, RelationshipType relationshipType, Relationship relationship){ boolean notFound = role.relationships(). noneMatch(innerRelationType -> innerRelationType.label().equals(relationshipType.label())); if(notFound){ return Optional.of(VALIDATION_RELATION_CASTING_LOOP_FAIL.getMessage(relationship.id(), role.label(), relationshipType.label())); } return Optional.empty(); }
@Override public Collection<PropertyExecutor> insert(Var var) throws GraqlQueryException { PropertyExecutor.Method method = executor -> { Attribute attributeConcept = executor.get(attribute().var()).asAttribute(); Thing thing = executor.get(var).asThing(); ConceptId relationshipId = thing.relhas(attributeConcept).id(); executor.builder(relationship().var()).id(relationshipId); }; PropertyExecutor executor = PropertyExecutor.builder(method) .produces(relationship().var()) .requires(var, attribute().var()) .build(); return ImmutableSet.of(executor); }