diff --git a/CHANGELOG.md b/CHANGELOG.md index 81ef133..d5eaf74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm Mongo integration with Concessione Project interface TempFile management -WorkspaceContent for Concessioni-over-mongo - +WorkspaceContent and publication for Concessioni-over-mongo ## [v1.0.3] 2020-11-11 Fixed HTTP method diff --git a/src/main/java/org/gcube/application/geoportal/service/engine/SDIManager.java b/src/main/java/org/gcube/application/geoportal/service/engine/SDIManager.java index 0dff8c5..fc86bdf 100644 --- a/src/main/java/org/gcube/application/geoportal/service/engine/SDIManager.java +++ b/src/main/java/org/gcube/application/geoportal/service/engine/SDIManager.java @@ -98,6 +98,8 @@ public class SDIManager { WorkspaceManager wsManager=new WorkspaceManager(); + + currentElement.getActualContent().forEach((PersistedContent c)->{ try { if(c instanceof WorkspaceContent) { @@ -160,7 +162,8 @@ public class SDIManager { GeoServerRESTPublisher publisher=gis.getCurrentGeoServer().getPublisher(); log.debug("Trying to create remote workspace : "+workspace); - createWorkspace(workspace); + createWorkspace(workspace); + log.debug("Publishing remote folder "+remoteFolder); URL directoryPath=new URL("file:"+remoteFolder+"/"+completeFileName); diff --git a/src/main/java/org/gcube/application/geoportal/service/engine/StorageClientProvider.java b/src/main/java/org/gcube/application/geoportal/service/engine/StorageClientProvider.java index 6ad3db3..a963a8d 100644 --- a/src/main/java/org/gcube/application/geoportal/service/engine/StorageClientProvider.java +++ b/src/main/java/org/gcube/application/geoportal/service/engine/StorageClientProvider.java @@ -39,6 +39,8 @@ public class StorageClientProvider extends AbstractScopedMap{ protected void dispose(IClient toDispose) { try { toDispose.close(); + }catch (NullPointerException e) { + // expected if closed without uploading }catch(Throwable t) { log.warn(" unable to dispose "+toDispose,t); } diff --git a/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ConcessioniMongoManager.java b/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ConcessioniMongoManager.java index 1432aec..7f0eeb0 100644 --- a/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ConcessioniMongoManager.java +++ b/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ConcessioniMongoManager.java @@ -271,6 +271,7 @@ public class ConcessioniMongoManager extends MongoManager{ log.debug("Registered "+wsContent+" for "+content); content.getActualContent().add(wsContent); } + content.setMongo_id(asString(new ObjectId())); } } diff --git a/src/main/java/org/gcube/application/geoportal/service/rest/ConcessioniOverMongo.java b/src/main/java/org/gcube/application/geoportal/service/rest/ConcessioniOverMongo.java index e6126d0..4e502d5 100644 --- a/src/main/java/org/gcube/application/geoportal/service/rest/ConcessioniOverMongo.java +++ b/src/main/java/org/gcube/application/geoportal/service/rest/ConcessioniOverMongo.java @@ -27,7 +27,7 @@ import org.json.JSONObject; import lombok.extern.slf4j.Slf4j; -@Path("mongo-concessioni") +@Path(InterfaceConstants.Methods.MONGO_CONCESSIONI) @Slf4j public class ConcessioniOverMongo { @@ -137,7 +137,7 @@ public class ConcessioniOverMongo { @PUT @Produces(MediaType.APPLICATION_JSON) - @Path("/publish/{"+InterfaceConstants.Parameters.PROJECT_ID+"}") + @Path("/{"+InterfaceConstants.Methods.PUBLISH_PATH+"}/{"+InterfaceConstants.Parameters.PROJECT_ID+"}") public String publish(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id) { return new GuardedMethod () { @Override @@ -151,7 +151,7 @@ public class ConcessioniOverMongo { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Path("/registerFiles/{"+InterfaceConstants.Parameters.PROJECT_ID+"}") + @Path("/"+InterfaceConstants.Methods.REGISTER_FILES_PATH+"/{"+InterfaceConstants.Parameters.PROJECT_ID+"}") public String registerFile(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id,String jsonRequest) { return new GuardedMethod () { @Override diff --git a/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java b/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java index 554b3fd..4b64d40 100644 --- a/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java +++ b/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java @@ -1,11 +1,11 @@ package org.gcube.application.geoportal.service; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; @@ -16,28 +16,26 @@ import javax.ws.rs.core.Response; import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths; -import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport; +import org.gcube.application.geoportal.common.model.legacy.LayerConcessione; import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus; import org.gcube.application.geoportal.common.rest.AddSectionToConcessioneRequest; +import org.gcube.application.geoportal.common.rest.InterfaceConstants; import org.gcube.application.geoportal.common.rest.TempFile; import org.gcube.application.geoportal.common.utils.Files; import org.gcube.application.geoportal.common.utils.StorageUtils; import org.gcube.application.geoportal.service.legacy.TokenSetter; import org.gcube.application.geoportal.service.utils.Serialization; -import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import com.fasterxml.jackson.core.JsonProcessingException; - public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ - private static final String PATH="mongo-concessioni"; + private static final String PATH=InterfaceConstants.Methods.MONGO_CONCESSIONI; - private static final String PUBLISH_PATH="publish"; - private static final String FILES_PATH="registerFiles"; + private static final String PUBLISH_PATH=InterfaceConstants.Methods.PUBLISH_PATH; + private static final String FILES_PATH=InterfaceConstants.Methods.REGISTER_FILES_PATH; @Before @@ -151,7 +149,7 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ @Test public void publish() throws Exception { WebTarget target=target(PATH); - Concessione c=TestModel.prepareConcessione(); + Concessione c=TestModel.prepareConcessione(1,2); c.setNome("Concessione : publish test"); @@ -164,8 +162,8 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ upload(target,c.getMongo_id(),Paths.RELAZIONE,"relazione.pdf"); upload(target,c.getMongo_id(),Paths.POSIZIONAMENTO,"pos.shp","pos.shx"); - - upload(target,c.getMongo_id(),Paths.piantaByIndex(0),"pos.shp","pos.shx"); + // Clash on workspaces + upload(target,c.getMongo_id(),Paths.piantaByIndex(0),"pianta.shp","pianta.shx"); upload(target,c.getMongo_id(),Paths.imgByIndex(0),"immagine.png"); upload(target,c.getMongo_id(),Paths.imgByIndex(1),"immagine2.png"); @@ -175,8 +173,15 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ Concessione published=publish(target, c); System.out.println("Published : "+published); assertNotNull(published.getReport()); - assertNotEquals(published.getReport().getStatus(),ValidationStatus.ERROR); + assertEquals(published.getReport().getStatus(),ValidationStatus.PASSED); + assertEquals(published.getImmaginiRappresentative().size(),2); + assertEquals(published.getPianteFineScavo().size(),1); + assertNotNull(published.getPosizionamentoScavo().getWmsLink()); + for(LayerConcessione l : published.getPianteFineScavo()) + assertNotNull(l.getWmsLink()); + assertNotNull(published.getCentroidLat()); + assertNotNull(published.getCentroidLong()); } diff --git a/src/test/java/org/gcube/application/geoportal/service/TestModel.java b/src/test/java/org/gcube/application/geoportal/service/TestModel.java index 25aef77..3bfc3c5 100644 --- a/src/test/java/org/gcube/application/geoportal/service/TestModel.java +++ b/src/test/java/org/gcube/application/geoportal/service/TestModel.java @@ -71,8 +71,11 @@ public class TestModel { public static final String rnd() { return new ObjectId().toHexString(); } - public static Concessione prepareConcessione() { + return prepareConcessione(4,2); + } + + public static Concessione prepareConcessione(int pianteCount ,int imgsCount) { Concessione concessione=prepareEmptyConcessione(); @@ -89,7 +92,7 @@ public class TestModel { concessione.setRelazioneScavo(relScavo); //Immagini rappresentative ArrayList imgs=new ArrayList<>(); - for(int i=0;i<5;i++) { + for(int i=0;i piante=new ArrayList(); - for(int i=0;i<4;i++) { + for(int i=0;i