Bugfix relation management

This commit is contained in:
Fabio Sinibaldi 2022-09-30 15:34:35 +02:00
parent 3b2ae25034
commit 1aa4a43b95
2 changed files with 14 additions and 7 deletions

View File

@ -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<M extends Project,C extends Projects<M>> 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<RelationshipNavigationObject> it = client.getRelationshipChain(source.getId(),relId,true);
System.out.println("Scanning rel ..");
@ -118,7 +119,7 @@ public class ProfiledDocumentsTest<M extends Project,C extends Projects<M>> exte
target.getId(),null));
assumeTrue(unLinkedSource.getRelationships()==null || unLinkedSource.getRelationships().isEmpty());
assertTrue(unLinkedSource.getRelationships()==null || unLinkedSource.getRelationships().isEmpty());
}

View File

@ -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<Relationship> 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);