Bugfix indirect relationship discovery updates

This commit is contained in:
Ben Bosman
2020-12-17 11:24:22 +01:00
parent e3b15bfa92
commit 098b273a85

View File

@@ -375,15 +375,16 @@ public class RelationshipServiceImpl implements RelationshipService {
// authorization system here so that this failure doesn't happen when the items need to be update
context.turnOffAuthorisationSystem();
try {
int max = configurationService.getIntProperty("relationship.update.relateditems.max", 5);
int max = configurationService.getIntProperty("relationship.update.relateditems.max", 10);
int maxDepth = configurationService.getIntProperty("relationship.update.relateditems.maxdepth", 3);
List<Item> itemsToUpdate = new LinkedList<>();
itemsToUpdate.add(relationship.getLeftItem());
itemsToUpdate.add(relationship.getRightItem());
itemsToUpdate = getRelatedItemsForLeftItem(context, relationship.getLeftItem(),
relationship, itemsToUpdate, max);
itemsToUpdate = getRelatedItemsForRightItem(context, relationship.getRightItem(),
relationship, itemsToUpdate, max);
getRelatedItemsForLeftItem(context, relationship.getLeftItem(),
relationship, itemsToUpdate, max, 0, maxDepth);
getRelatedItemsForRightItem(context, relationship.getRightItem(),
relationship, itemsToUpdate, max, 0, maxDepth);
for (Item item : itemsToUpdate) {
if (!item.isMetadataModified()) {
@@ -398,11 +399,14 @@ public class RelationshipServiceImpl implements RelationshipService {
}
private List<Item> getRelatedItemsForRightItem(Context context, Item item, Relationship relationship,
List<Item> itemsToUpdate, int max)
List<Item> itemsToUpdate, int max, int currentDepth, int maxDepth)
throws SQLException {
if (itemsToUpdate.size() >= max) {
return itemsToUpdate;
}
if (currentDepth == maxDepth) {
return itemsToUpdate;
}
List<RelationshipType> relationshipTypes = new LinkedList<>();
EntityType leftType = relationship.getRelationshipType().getLeftType();
String entityTypeStringFromMetadata = relationshipMetadataService.getEntityTypeStringFromMetadata(item);
@@ -420,13 +424,17 @@ public class RelationshipServiceImpl implements RelationshipService {
List<Relationship> list = findByItemAndRelationshipType(context, item, relationshipType, isLeft);
for (Relationship foundRelationship : list) {
if (isLeft) {
if (!itemsToUpdate.contains(foundRelationship.getRightItem())) {
itemsToUpdate.add(foundRelationship.getRightItem());
itemsToUpdate.addAll(getRelatedItemsForRightItem(context, foundRelationship.getRightItem(),
foundRelationship, itemsToUpdate, max));
}
getRelatedItemsForRightItem(context, foundRelationship.getRightItem(),
foundRelationship, itemsToUpdate, max, currentDepth + 1, maxDepth);
} else {
if (!itemsToUpdate.contains(foundRelationship.getLeftItem())) {
itemsToUpdate.add(foundRelationship.getLeftItem());
itemsToUpdate.addAll(getRelatedItemsForLeftItem(context, foundRelationship.getLeftItem(),
foundRelationship, itemsToUpdate, max));
}
getRelatedItemsForLeftItem(context, foundRelationship.getLeftItem(),
foundRelationship, itemsToUpdate, max, currentDepth + 1, maxDepth);
}
}
}
@@ -435,7 +443,7 @@ public class RelationshipServiceImpl implements RelationshipService {
}
private List<Item> getRelatedItemsForLeftItem(Context context, Item item, Relationship relationship,
List<Item> itemsToUpdate, int max)
List<Item> itemsToUpdate, int max, int currentDepth, int maxDepth)
throws SQLException {
if (itemsToUpdate.size() >= max) {
return itemsToUpdate;
@@ -459,11 +467,11 @@ public class RelationshipServiceImpl implements RelationshipService {
if (isLeft) {
itemsToUpdate.add(foundRelationship.getRightItem());
itemsToUpdate.addAll(getRelatedItemsForRightItem(context, foundRelationship.getRightItem(),
foundRelationship, itemsToUpdate, max));
foundRelationship, itemsToUpdate, max, currentDepth + 1, maxDepth));
} else {
itemsToUpdate.add(foundRelationship.getLeftItem());
itemsToUpdate.addAll(getRelatedItemsForLeftItem(context, foundRelationship.getLeftItem(),
foundRelationship, itemsToUpdate, max));
foundRelationship, itemsToUpdate, max, currentDepth + 1, maxDepth));
}
}
}