/** * 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(); }
/** * * @param relationshipType The {@link RelationshipType} to validate * @return An error message if the relationTypes does not have at least 1 role */ static Optional<String> validateHasMinimumRoles(RelationshipType relationshipType) { if(relationshipType.isAbstract() || relationshipType.roles().iterator().hasNext()){ return Optional.empty(); } else { return Optional.of(VALIDATION_RELATION_TYPE.getMessage(relationshipType.label())); } }
@Override public String innerToString(){ StringBuilder description = new StringBuilder(); description.append("ID [").append(id()).append("] Type [").append(type().label()).append("] Roles and Role Players: \n"); for (Map.Entry<Role, Set<Thing>> entry : allRolePlayers().entrySet()) { if(entry.getValue().isEmpty()){ description.append(" Role [").append(entry.getKey().label()).append("] not played by any instance \n"); } else { StringBuilder instancesString = new StringBuilder(); for (Thing thing : entry.getValue()) { instancesString.append(thing.id()).append(","); } description.append(" Role [").append(entry.getKey().label()).append("] played by ["). append(instancesString.toString()).append("] \n"); } } return description.toString(); }
/** * 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(); } }
errorMessages.add(VALIDATION_RELATION_TYPES_ROLES_SCHEMA.getMessage(relate.label(), relationshipType.label(), "super", "super", superRelationType.label())); errorMessages.add(VALIDATION_RELATION_TYPES_ROLES_SCHEMA.getMessage(superRelate.label(), superRelationType.label(), "sub", "sub", relationshipType.label()));
public Pattern pattern(Relationship concept) { VarPattern relationPattern = Graql.var(); Set<Pattern> idPatterns = new HashSet<>(); for (Map.Entry<Role, Set<Thing>> entry : concept.rolePlayersMap().entrySet()) { for (Thing var : entry.getValue()) { Var rolePlayer = Graql.var(); relationPattern = relationPattern.rel(Graql.label(entry.getKey().label()), rolePlayer); idPatterns.add(rolePlayer.asUserDefined().id(var.id())); } } relationPattern = relationPattern.isa(Graql.label(concept.type().label())); Pattern pattern = relationPattern; for (Pattern idPattern : idPatterns) { pattern = pattern.and(idPattern); } return pattern; } }
@Override public String toString(){ return "ID [" + id() + "] Type [" + type().label() + "] Roles and Role Players: \n" + "Role [" + ownerRole().label() + "] played by [" + owner().id() + "] \n" + "Role [" + valueRole().label() + "] played by [" + value().id() + "] \n"; }