[Task 70419] fixed a bug where the RelationshipService creation did not check the max cardinality properly

This commit is contained in:
Raf Ponsaerts
2020-04-20 17:18:27 +02:00
parent 6c91e98f48
commit c7f6a46296
3 changed files with 61 additions and 5 deletions

View File

@@ -202,14 +202,14 @@ public class RelationshipServiceImpl implements RelationshipService {
return false;
}
if (!verifyMaxCardinality(context, relationship.getLeftItem(),
relationshipType.getLeftMaxCardinality(), relationshipType)) {
relationshipType.getLeftMaxCardinality(), relationshipType, true)) {
log.warn("The relationship has been deemed invalid since the left item has more" +
" relationships than the left max cardinality allows after we'd store this relationship");
logRelationshipTypeDetailsForError(relationshipType);
return false;
}
if (!verifyMaxCardinality(context, relationship.getRightItem(),
relationshipType.getRightMaxCardinality(), relationshipType)) {
relationshipType.getRightMaxCardinality(), relationshipType, false)) {
log.warn("The relationship has been deemed invalid since the right item has more" +
" relationships than the right max cardinality allows after we'd store this relationship");
logRelationshipTypeDetailsForError(relationshipType);
@@ -232,9 +232,10 @@ public class RelationshipServiceImpl implements RelationshipService {
private boolean verifyMaxCardinality(Context context, Item itemToProcess,
Integer maxCardinality,
RelationshipType relationshipType) throws SQLException {
RelationshipType relationshipType,
boolean isLeft) throws SQLException {
List<Relationship> rightRelationships = findByItemAndRelationshipType(context, itemToProcess, relationshipType,
false);
isLeft);
if (maxCardinality != null && rightRelationships.size() >= maxCardinality) {
return false;
}