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 b5f23a8..fb0d5f5 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 @@ -737,7 +737,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI< throw new WebApplicationException("Multiple Fileset (" + matchingPaths.size() + ") matching " + path, Response.Status.BAD_REQUEST); - RegisteredFileSet fs = Serialization.convert(wrapper.getByPath(path), RegisteredFileSet.class); + RegisteredFileSet fs = Serialization.convert(wrapper.getByPath(path).get(0), RegisteredFileSet.class); log.debug("Going to delete {}", fs); doc = triggerEvent(doc,EventExecutionRequest.Events.ON_DELETE_FILESET,new Document("force",force).append("path",path)); diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/DummyProjectTest.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/DummyProjectTest.java index 05899f3..52ab1eb 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/DummyProjectTest.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/DummyProjectTest.java @@ -26,6 +26,15 @@ import static org.junit.Assume.assumeTrue; public class DummyProjectTest extends AbstractProfiledDocumentsTests{ + + // Try set releazione scavo + String parentPath="section"; + String fieldName="fileset"; + String fieldDefinition="section."+Field.CHILDREN+"[?(@.fileset)]"; + + String filename = "sample.tif"; + + @Override protected WebTarget baseTarget() { String testProfileId="basic"; @@ -69,6 +78,23 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{ RegisteredFileSet fs = Serialization.convert(wrapper.getByPath("section.fileset").get(0),RegisteredFileSet.class); assertTrue(fs.getPayloads().size()==1); assertTrue(fs.getString("customField").equals("customFieldValue")); + + // test replace + doc = upload( + new StorageUtils(), + doc.getId(), + parentPath,fieldName, + fieldDefinition, + new Document("customField","customFieldValue"), + RegisterFileSetRequest.ClashOptions.REPLACE_EXISTING, + filename); + + wrapper = new JSONPathWrapper(doc.getTheDocument().toJson()); + assertTrue("Relazione exists",wrapper.getMatchingPaths("section").size()==1); + fs = Serialization.convert(wrapper.getByPath("section.fileset").get(0),RegisteredFileSet.class); + assertTrue(fs.getPayloads().size()==1); + assertTrue(fs.getString("customField").equals("customFieldValue")); + } @@ -85,12 +111,6 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{ Project doc = createNew(baseDoc); - // Try set releazione scavo - String parentPath="section"; - String fieldName="fileset"; - String fieldDefinition="section."+Field.CHILDREN+"[?(@.fileset)]"; - - String filename = "sample.tif"; @@ -103,6 +123,7 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{ new Document("customField","customFieldValue"), RegisterFileSetRequest.ClashOptions.REPLACE_EXISTING, filename); + return doc; }