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 7527fa4..0b8cb5f 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 @@ -11,8 +11,8 @@ import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.gcube.application.geoportal.common.model.legacy.*; +import org.gcube.application.geoportal.common.model.rest.DatabaseConnection; import org.gcube.application.geoportal.common.utils.Files; -import org.gcube.application.geoportal.service.model.internal.db.DatabaseConnection; import org.gcube.application.geoportal.service.model.internal.db.PostgisTable; import org.gcube.application.geoportal.service.model.internal.faults.SDIInteractionException; import org.gcube.common.storagehub.client.dsl.FileContainer; @@ -342,6 +342,22 @@ public class SDIManager { if(!currentGeoserver.getPublisher().publishDBLayer(workspace, storeName, fte, layerEncoder)) throw new SDIInteractionException("Unable to create layer "+name); log.debug("layer "+name+" already exists"); + + + String link=String.format("https://%1$s/geoserver/%2$s/wms?" + +"service=WMS&version=1.1.0&request=GetMap&layers=%2$s:%3$s&" + + "styles=&bbox=%4$f,%5$f,%6$f,%7$f&srs=%8$s&format=application/openlayers&width=%9$d&height=%10$d", + geoserverHostName, + workspace, + name, + "-1563071.166172796", + "4789738.204048398", + "4334926.486925308", + "5828118.072551585", + EPSG_4326, + 400, + 400); + return name; } catch (IllegalArgumentException | MalformedURLException e) { throw new SDIInteractionException("Unable to create layer "+name,e); 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 6cb5efe..010aa7b 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 @@ -9,6 +9,7 @@ import org.bson.types.ObjectId; import org.gcube.application.geoportal.common.model.legacy.*; import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport; import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.common.rest.TempFile; import org.gcube.application.geoportal.common.utils.Files; import org.gcube.application.geoportal.service.engine.ImplementationProvider; @@ -19,7 +20,6 @@ import org.gcube.application.geoportal.service.engine.WorkspaceManager.FolderOpt import org.gcube.application.geoportal.service.engine.postgis.PostgisIndex; import org.gcube.application.geoportal.service.engine.providers.StorageClientProvider; import org.gcube.application.geoportal.service.model.internal.faults.*; -import org.gcube.application.geoportal.service.model.internal.rest.QueryRequest; import org.gcube.application.geoportal.service.utils.Serialization; import org.gcube.common.storagehub.client.dsl.FolderContainer; import org.gcube.data.transfer.library.faults.RemoteServiceException; diff --git a/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManager.java b/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManager.java index 09bdad6..4fa84d6 100644 --- a/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManager.java +++ b/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManager.java @@ -11,9 +11,9 @@ import com.mongodb.client.model.ReturnDocument; import lombok.extern.slf4j.Slf4j; import org.bson.Document; import org.bson.types.ObjectId; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.service.engine.ImplementationProvider; import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException; -import org.gcube.application.geoportal.service.model.internal.rest.QueryRequest; import static com.mongodb.client.model.Filters.eq; import static com.mongodb.client.model.Sorts.ascending; @@ -89,7 +89,7 @@ public abstract class MongoManager { return coll.find(Document.parse(filterString)); } - public FindIterable query(QueryRequest request,String collectionName){ + public FindIterable query(QueryRequest request, String collectionName){ MongoDatabase database=getDatabase(); MongoCollection coll=database.getCollection(collectionName); FindIterable toReturn=iterate(request.getFilter(), collectionName); diff --git a/src/main/java/org/gcube/application/geoportal/service/engine/postgis/PostgisDBManager.java b/src/main/java/org/gcube/application/geoportal/service/engine/postgis/PostgisDBManager.java index 0df70fe..ed67b0b 100644 --- a/src/main/java/org/gcube/application/geoportal/service/engine/postgis/PostgisDBManager.java +++ b/src/main/java/org/gcube/application/geoportal/service/engine/postgis/PostgisDBManager.java @@ -3,10 +3,11 @@ package org.gcube.application.geoportal.service.engine.postgis; import lombok.Synchronized; import lombok.extern.slf4j.Slf4j; import org.gcube.application.geoportal.common.model.legacy.BBOX; -import org.gcube.application.geoportal.service.model.internal.db.DatabaseConnection; +import org.gcube.application.geoportal.common.model.rest.DatabaseConnection; import org.gcube.application.geoportal.service.model.internal.db.PostgisTable; import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException; import org.gcube.application.geoportal.service.model.internal.faults.DataParsingException; +import org.gcube.application.geoportal.service.utils.ISUtils; import java.sql.*; import java.util.regex.Matcher; @@ -19,7 +20,11 @@ public class PostgisDBManager implements PostgisDBManagerI { public static PostgisDBManager get() throws SQLException, ConfigurationException { if(config==null) { log.debug("Looking for Default Configuration.. "); - DatabaseConnection defaultConfiguration= DatabaseConnection.get(DatabaseConnection.TYPE.Concessioni); + + // TODO GENERIC + DatabaseConnection defaultConfiguration= + ISUtils.queryForDB("postgis", "Concessioni"); + log.debug("Found configuration : "+defaultConfiguration); config=defaultConfiguration; } @@ -41,7 +46,9 @@ public class PostgisDBManager implements PostgisDBManagerI { private static Connection getConnection() throws SQLException { Connection toReturn= DriverManager.getConnection(config.getUrl(),config.getUser(),config.getPwd()); - toReturn.setAutoCommit(config.getAutocommit()); + + //TODO configure behaviour + toReturn.setAutoCommit(false); return toReturn; } diff --git a/src/main/java/org/gcube/application/geoportal/service/engine/postgis/PostgisDBManagerI.java b/src/main/java/org/gcube/application/geoportal/service/engine/postgis/PostgisDBManagerI.java index 978f522..bd1cfb4 100644 --- a/src/main/java/org/gcube/application/geoportal/service/engine/postgis/PostgisDBManagerI.java +++ b/src/main/java/org/gcube/application/geoportal/service/engine/postgis/PostgisDBManagerI.java @@ -1,6 +1,6 @@ package org.gcube.application.geoportal.service.engine.postgis; -import org.gcube.application.geoportal.service.model.internal.db.DatabaseConnection; +import org.gcube.application.geoportal.common.model.rest.DatabaseConnection; import org.gcube.application.geoportal.service.model.internal.db.PostgisTable; import org.gcube.application.geoportal.service.model.internal.faults.DataParsingException; diff --git a/src/main/java/org/gcube/application/geoportal/service/engine/postgis/PostgisIndex.java b/src/main/java/org/gcube/application/geoportal/service/engine/postgis/PostgisIndex.java index 235c7da..9ff150f 100644 --- a/src/main/java/org/gcube/application/geoportal/service/engine/postgis/PostgisIndex.java +++ b/src/main/java/org/gcube/application/geoportal/service/engine/postgis/PostgisIndex.java @@ -2,6 +2,8 @@ package org.gcube.application.geoportal.service.engine.postgis; import lombok.extern.slf4j.Slf4j; import org.gcube.application.geoportal.common.model.legacy.Concessione; +import org.gcube.application.geoportal.common.model.rest.DatabaseConnection; +import org.gcube.application.geoportal.common.model.rest.PostgisIndexDescriptor; import org.gcube.application.geoportal.service.engine.ImplementationProvider; import org.gcube.application.geoportal.service.engine.SDIManager; import org.gcube.application.geoportal.service.model.internal.db.DBConstants; @@ -35,7 +37,7 @@ public class PostgisIndex { private SDIManager sdiManager; - + private String wmsLink=null; private static PostgisDBManager getDB() throws ConfigurationException { return ImplementationProvider.get().getDbProvider().getObject(); }; @@ -43,23 +45,27 @@ public class PostgisIndex { public PostgisIndex() throws SDIInteractionException, SQLException, ConfigurationException { super(); this.sdiManager=new SDIManager(); - init(); + this.wmsLink=init(); } + public PostgisIndexDescriptor getInfo() throws ConfigurationException, SDIInteractionException, SQLException { + DatabaseConnection conn=getDB().getConnectionDescriptor(); + return new PostgisIndexDescriptor(conn,wmsLink); + } + protected PostgisTable getCentroidsTable() { return DBConstants.Concessioni.CENTROIDS; } - public void init() throws SQLException, ConfigurationException, SDIInteractionException { + public String init() throws SQLException, ConfigurationException, SDIInteractionException { log.debug("Contacting postgis DB .. "); PostgisDBManagerI db=ImplementationProvider.get().getDbProvider().getObject(); log.debug("Checking if centroids table exists.."); PostgisTable table=getCentroidsTable(); db.create(table); db.commit(); - sdiManager.configureCentroidLayer("centroids_concessioni", "gna", "gna_postgis",table,db.getConnectionDescriptor()); - + return sdiManager.configureCentroidLayer("centroids_concessioni", "gna", "gna_postgis",table,db.getConnectionDescriptor()); } diff --git a/src/main/java/org/gcube/application/geoportal/service/model/internal/Configuration.java b/src/main/java/org/gcube/application/geoportal/service/model/internal/Configuration.java deleted file mode 100644 index a9b7d46..0000000 --- a/src/main/java/org/gcube/application/geoportal/service/model/internal/Configuration.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.gcube.application.geoportal.service.model.internal; - -import lombok.Data; -import org.gcube.application.geoportal.service.model.internal.db.DatabaseConnection; - -import java.util.Map; - -@Data -public class Configuration { - - public DatabaseConnection postgisDBIndex; - public Map details; - -} diff --git a/src/main/java/org/gcube/application/geoportal/service/model/internal/db/DBConstants.java b/src/main/java/org/gcube/application/geoportal/service/model/internal/db/DBConstants.java index 088c4cb..17cd57a 100644 --- a/src/main/java/org/gcube/application/geoportal/service/model/internal/db/DBConstants.java +++ b/src/main/java/org/gcube/application/geoportal/service/model/internal/db/DBConstants.java @@ -8,6 +8,11 @@ import java.util.ArrayList; public class DBConstants { + public static enum TYPE{ + + Concessioni,Mosi,Mopr + } + public static class Defaults{ public static final String DEFAULT_GEOMETRY_COLUMN_NAME="geom"; public static final String INTERNAL_ID="internal_id"; diff --git a/src/main/java/org/gcube/application/geoportal/service/model/internal/db/DatabaseConnection.java b/src/main/java/org/gcube/application/geoportal/service/model/internal/db/DatabaseConnection.java deleted file mode 100644 index 92dfe7c..0000000 --- a/src/main/java/org/gcube/application/geoportal/service/model/internal/db/DatabaseConnection.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.gcube.application.geoportal.service.model.internal.db; - -import lombok.*; -import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException; -import org.gcube.application.geoportal.service.utils.ISUtils; - -@Getter -@Setter -@RequiredArgsConstructor -@ToString -public class DatabaseConnection { - - public static enum TYPE{ - - Concessioni,Mosi,Mopr - } - - public static DatabaseConnection get(TYPE type) throws ConfigurationException { - return ISUtils.queryForDB("postgis", type.toString()); - } - - @NonNull - private String user; - @NonNull - private String pwd; - @NonNull - private String url; - - private Boolean autocommit=false; -} diff --git a/src/main/java/org/gcube/application/geoportal/service/model/internal/rest/AddSectionToConcessioneRequest.java b/src/main/java/org/gcube/application/geoportal/service/model/internal/rest/AddSectionToConcessioneRequest.java deleted file mode 100644 index fc5d4ef..0000000 --- a/src/main/java/org/gcube/application/geoportal/service/model/internal/rest/AddSectionToConcessioneRequest.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.gcube.application.geoportal.service.model.internal.rest; - -import lombok.Data; - -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement -@Data -public class AddSectionToConcessioneRequest { - -// public static enum Section{ -// RELAZIONE,UPLOADED_IMG,PIANTA,POSIZIONAMENTO,OTHER -// } -// -// @XmlRootElement -// @Data -// public static class SHUBFileDescriptor { -// private String filename; -// private String shubID; -// } -// -// -// private Section section; -// @XmlElements({ -// @XmlElement(type=OtherContent.class), -// @XmlElement(type=RelazioneScavo.class), -// @XmlElement(type=SDILayerDescriptor.class), -// @XmlElement(type=LayerConcessione.class), -// @XmlElement(type=UploadedImage.class), -// }) -// private AssociatedContent toRegister; -// private List streams=new ArrayList(); - -} diff --git a/src/main/java/org/gcube/application/geoportal/service/model/internal/rest/QueryRequest.java b/src/main/java/org/gcube/application/geoportal/service/model/internal/rest/QueryRequest.java deleted file mode 100644 index c70df20..0000000 --- a/src/main/java/org/gcube/application/geoportal/service/model/internal/rest/QueryRequest.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.gcube.application.geoportal.service.model.internal.rest; - -import lombok.Data; - -import java.util.List; - -@Data -public class QueryRequest { - - @Data - public static class PagedRequest{ - private int offset; - private int Limit; - } - - @Data - public static class OrderedRequest { - public static enum Direction {ASCENDING,DESCENDING} - private Direction direction; - private String json; - private List fields; - } - private String filter; - private String transformation; - private OrderedRequest ordering; - private PagedRequest paging; -} 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 39f542a..9056bd6 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 @@ -2,13 +2,13 @@ package org.gcube.application.geoportal.service.rest; import lombok.extern.slf4j.Slf4j; import org.gcube.application.geoportal.common.model.legacy.Concessione; -import org.gcube.application.geoportal.common.rest.AddSectionToConcessioneRequest; +import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest; +import org.gcube.application.geoportal.common.model.rest.Configuration; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.common.rest.InterfaceConstants; -import org.gcube.application.geoportal.service.engine.ImplementationProvider; import org.gcube.application.geoportal.service.engine.mongo.ConcessioniMongoManager; -import org.gcube.application.geoportal.service.model.internal.Configuration; +import org.gcube.application.geoportal.service.engine.postgis.PostgisIndex; import org.gcube.application.geoportal.service.model.internal.faults.DeletionException; -import org.gcube.application.geoportal.service.model.internal.rest.QueryRequest; import org.gcube.application.geoportal.service.utils.Serialization; import org.json.JSONArray; import org.json.JSONObject; @@ -22,8 +22,8 @@ import javax.ws.rs.core.Response; public class ConcessioniOverMongo { - @HEAD - @Path("some") + @GET + @Path(InterfaceConstants.Methods.CONFIGURATION_PATH) @Produces(MediaType.APPLICATION_JSON) public String getConfiguration(){ return new GuardedMethod(){ @@ -31,7 +31,8 @@ public class ConcessioniOverMongo { @Override protected String run() throws Exception, WebApplicationException { Configuration toReturn = new Configuration(); - toReturn.setPostgisDBIndex(ImplementationProvider.get().getDbProvider().getObject().getConnectionDescriptor()); + toReturn.setIndex(new PostgisIndex().getInfo()); + log.info("Returning configuration {} ",toReturn); return Serialization.write(toReturn); } }.execute().getResult(); @@ -201,7 +202,7 @@ public class ConcessioniOverMongo { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Path("/"+"search") + @Path("/"+InterfaceConstants.Methods.SEARCH_PATH) public Iterable search(String filter){ return new GuardedMethod>() { @Override @@ -215,7 +216,7 @@ public class ConcessioniOverMongo { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Path("/"+"query") + @Path("/"+InterfaceConstants.Methods.QUERY_PATH) public Iterable search(QueryRequest queryRequest){ return new GuardedMethod>() { @Override diff --git a/src/main/java/org/gcube/application/geoportal/service/utils/ISUtils.java b/src/main/java/org/gcube/application/geoportal/service/utils/ISUtils.java index 0c3e347..75e6baa 100644 --- a/src/main/java/org/gcube/application/geoportal/service/utils/ISUtils.java +++ b/src/main/java/org/gcube/application/geoportal/service/utils/ISUtils.java @@ -1,7 +1,7 @@ package org.gcube.application.geoportal.service.utils; +import org.gcube.application.geoportal.common.model.rest.DatabaseConnection; import org.gcube.application.geoportal.service.ServiceConstants; -import org.gcube.application.geoportal.service.model.internal.db.DatabaseConnection; import org.gcube.application.geoportal.service.model.internal.db.MongoConnection; import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException; import org.gcube.common.encryption.encrypter.StringEncrypter; @@ -29,8 +29,11 @@ public class ISUtils { } AccessPoint point=found.get(0); - - return new DatabaseConnection(point.username(),decryptString(point.password()),point.address()); + DatabaseConnection toReturn=new DatabaseConnection(); + toReturn.setPwd(decryptString(point.password())); + toReturn.setUser(point.username()); + toReturn.setUrl(point.address()); + return toReturn; } 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 33f5cf6..ab84e6b 100644 --- a/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java +++ b/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java @@ -4,7 +4,7 @@ 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.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.model.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; @@ -134,7 +134,7 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ @Test public void getConfiguration() throws Exception { WebTarget target=target(PATH); - System.out.println(check(target.path("some").request(MediaType.APPLICATION_JSON).head(),String.class)); + System.out.println(check(target.path("configuration").request(MediaType.APPLICATION_JSON).get(),String.class)); }