From 1aa4a43b950606315012cb32f0e8b5008acaf212 Mon Sep 17 00:00:00 2001 From: Fabio Sinibaldi Date: Fri, 30 Sep 2022 15:34:35 +0200 Subject: [PATCH] Bugfix relation management --- .../geoportal/clients/ProfiledDocumentsTest.java | 13 +++++++------ .../service/engine/mongo/ProfiledMongoManager.java | 8 +++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledDocumentsTest.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledDocumentsTest.java index 8cec8d5..0376a91 100644 --- a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledDocumentsTest.java +++ b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledDocumentsTest.java @@ -19,6 +19,7 @@ import java.util.Iterator; import java.util.concurrent.atomic.AtomicLong; import static org.gcube.application.geoportal.client.utils.Serialization.write; +import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; @Slf4j @@ -99,11 +100,11 @@ public class ProfiledDocumentsTest> exte new CreateRelationshipRequest(source.getId(),relId, target.getId(), null)); - assumeTrue(linkedSource.getRelationships()!=null); - assumeTrue(!linkedSource.getRelationships().isEmpty()); - assumeTrue(linkedSource.getRelationships().get(0).getRelationshipName().equals(relId)); - assumeTrue(linkedSource.getRelationships().get(0).getTargetID().equals(target.getId())); - assumeTrue(linkedSource.getRelationships().get(0).getTargetUCD().equals(target.getProfileID())); + assertTrue(linkedSource.getRelationships()!=null); + assertTrue(!linkedSource.getRelationships().isEmpty()); + assertTrue(linkedSource.getRelationships().get(0).getRelationshipName().equals(relId)); + assertTrue(linkedSource.getRelationships().get(0).getTargetID().equals(target.getId())); + assertTrue(linkedSource.getRelationships().get(0).getTargetUCD().equals(target.getProfileID())); Iterator it = client.getRelationshipChain(source.getId(),relId,true); System.out.println("Scanning rel .."); @@ -118,7 +119,7 @@ public class ProfiledDocumentsTest> exte target.getId(),null)); - assumeTrue(unLinkedSource.getRelationships()==null || unLinkedSource.getRelationships().isEmpty()); + assertTrue(unLinkedSource.getRelationships()==null || unLinkedSource.getRelationships().isEmpty()); } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java index f1db782..a2d9fff 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java @@ -335,7 +335,9 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI< @Override public Project deleteRelation(String id, String relation, String targetUCD, String targetId) throws IOException, EventException, ProjectLockedException, ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess, RegistrationException, ConfigurationException { + log.debug("Delete relation {}:{}--{}-->{}:{} ",getUseCaseDescriptor().getId(),id,relation,targetUCD,targetId); Project toUpdate=lock(id,"Delete Relation"); + try{ // check if relation existing List relations = toUpdate.getRelationships(); @@ -346,8 +348,12 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI< r.getTargetUCD().equals(targetUCD)&& r.getTargetID().equals(targetId)); // update only if something changed - if(toUpdate.getRelationships().size()!=beforeSize) return unlockAndUpdate(toUpdate); + if(toUpdate.getRelationships().size()!=beforeSize) { + log.debug("Removed {} relations from {} ",(toUpdate.getRelationships().size()!=beforeSize),id); + return unlockAndUpdate(toUpdate); + } } + log.debug("Relationship not found. Unlocking.. "); return unlock(toUpdate); }catch(Throwable t){ log.error("Unexpected exception ",t);