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