From 40d9a20bd0378220f5d82e6c3ad8b03ff544106b Mon Sep 17 00:00:00 2001 From: "fabio.sinibaldi" Date: Thu, 23 Jun 2016 13:39:15 +0000 Subject: [PATCH] GIS-Link git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/spatial-data/gis-interface@129360 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 1 + pom.xml | 42 +++++++++---------- .../gcube/spatial/data/gis/GISInterface.java | 21 +++++++++- .../org/gcube/spatial/data/gis/URIUtils.java | 19 +++++++-- .../data/gis/meta/MetadataEnricher.java | 21 +++++++++- .../gcube/spatial/data/gis/PublishTable.java | 3 -- 6 files changed, 76 insertions(+), 31 deletions(-) diff --git a/distro/changelog.xml b/distro/changelog.xml index d832468..a4faf70 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -21,5 +21,6 @@ gCube 4 SDI policies integration + Added GIS link to generated distribution URIS \ No newline at end of file diff --git a/pom.xml b/pom.xml index 76d712e..de267f0 100644 --- a/pom.xml +++ b/pom.xml @@ -30,6 +30,12 @@ geonetwork [3.0.0-SNAPSHOT,4.0.0-SNAPSHOT) + + org.gcube.portlets.user + uri-resolver-manager + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + + it.geosolutions geoserver-manager @@ -41,30 +47,14 @@ - - org.gcube.common - csv4j - [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) - test - + org.gcube.resources.discovery ic-client [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) - - - commons-logging - commons-logging - 1.1.1 - runtime - - - org.slf4j - slf4j-log4j12 - 1.5.11 - test - + + org.gcube.core common-encryption @@ -104,9 +94,19 @@ 4.11 test - - + + org.slf4j + slf4j-log4j12 + 1.6.4 + test + + + org.gcube.common + csv4j + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + test + diff --git a/src/main/java/org/gcube/spatial/data/gis/GISInterface.java b/src/main/java/org/gcube/spatial/data/gis/GISInterface.java index 9ef4d85..758edc0 100644 --- a/src/main/java/org/gcube/spatial/data/gis/GISInterface.java +++ b/src/main/java/org/gcube/spatial/data/gis/GISInterface.java @@ -157,13 +157,21 @@ public class GISInterface { if(publishResult){ toReturn.setDataOperationResult(Report.OperationState.COMPLETE); + MetadataEnricher enricher=new MetadataEnricher(geoNetworkMeta, true); ArrayList distributionUris=new ArrayList(); distributionUris.add(URIUtils.getWmsUrl(desc.getUrl(), coverageName, defaultStyle, new BoundingBox(bbox))); distributionUris.add(URIUtils.getWfsUrl(desc.getUrl(), coverageName)); distributionUris.add(URIUtils.getWcsUrl(desc.getUrl(), coverageName, new BoundingBox(bbox))); + try{ + distributionUris.add(URIUtils.getGisLinkByUUID(enricher.getMetadataIdentifier())); + }catch(Exception e){ + logger.warn("Unabel to get Gis Link ",e); + toReturn.setMetaOperationResult(OperationState.WARN); + toReturn.getMetaOperationMessages().add("Unable to generate GIS link, cause : "+e.getMessage()); + } + - MetadataEnricher enricher=new MetadataEnricher(geoNetworkMeta, true); enricher.addDate(new Date(System.currentTimeMillis()), DateType.CREATION); enricher.addPreview(distributionUris.get(0)); enricher.setdistributionURIs(distributionUris,coverageName); @@ -228,12 +236,21 @@ public class GISInterface { logger.debug("Published data, enriching meta.."); + MetadataEnricher enricher=new MetadataEnricher(geoNetworkMeta, true); + ArrayList distributionUris=new ArrayList(); distributionUris.add(URIUtils.getWmsUrl(desc.getUrl(), fte.getName(), URIUtils.getStyleFromGSLayerEncoder(layerEncoder), null)); distributionUris.add(URIUtils.getWfsUrl(desc.getUrl(), fte.getName())); distributionUris.add(URIUtils.getWcsUrl(desc.getUrl(), fte.getName(), null)); + try{ + distributionUris.add(URIUtils.getGisLinkByUUID(enricher.getMetadataIdentifier())); + }catch(Exception e){ + logger.warn("Unabel to get Gis Link ",e); + toReturn.setMetaOperationResult(OperationState.WARN); + toReturn.getMetaOperationMessages().add("Unable to generate GIS link, cause : "+e.getMessage()); + } + - MetadataEnricher enricher=new MetadataEnricher(geoNetworkMeta, true); enricher.addDate(new Date(System.currentTimeMillis()), DateType.CREATION); enricher.addPreview(distributionUris.get(0)); enricher.setdistributionURIs(distributionUris,fte.getName()); diff --git a/src/main/java/org/gcube/spatial/data/gis/URIUtils.java b/src/main/java/org/gcube/spatial/data/gis/URIUtils.java index 1b64aca..66169fc 100644 --- a/src/main/java/org/gcube/spatial/data/gis/URIUtils.java +++ b/src/main/java/org/gcube/spatial/data/gis/URIUtils.java @@ -1,9 +1,16 @@ package org.gcube.spatial.data.gis; -import org.gcube.spatial.data.gis.model.BoundingBox; - import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; +import java.util.HashMap; +import java.util.Map; + +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.portlets.user.uriresolvermanager.UriResolverManager; +import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException; +import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException; +import org.gcube.spatial.data.gis.model.BoundingBox; + public class URIUtils { @@ -34,7 +41,13 @@ public class URIUtils { layerName + "&CRS=EPSG:4326" + "&bbox=" + bbox + "&width=676&height=330&format=geotiff"; } - + public static String getGisLinkByUUID(String uuid) throws UriResolverMapException, IllegalArgumentException{ + Map params=new HashMap(); + params.put("scope", ScopeProvider.instance.get()); + params.put("gis-UUID", uuid); + UriResolverManager resolver = new UriResolverManager("GIS"); + return resolver.getLink(params, true); + } public static String getStyleFromGSLayerEncoder(GSLayerEncoder encoder){ return encoder.getRoot().getChildText("defaultStyle"); diff --git a/src/main/java/org/gcube/spatial/data/gis/meta/MetadataEnricher.java b/src/main/java/org/gcube/spatial/data/gis/meta/MetadataEnricher.java index 9cfad91..0482948 100644 --- a/src/main/java/org/gcube/spatial/data/gis/meta/MetadataEnricher.java +++ b/src/main/java/org/gcube/spatial/data/gis/meta/MetadataEnricher.java @@ -34,13 +34,19 @@ public class MetadataEnricher { private DefaultMetadata enriched; private ArrayList messages=new ArrayList(); + + private String uuid; + private DefaultDataIdentification ident=null; public MetadataEnricher(Metadata toEnrich,boolean generateUUID) { this.toEnrich=toEnrich; this.enriched=castMeta(toEnrich); if(generateUUID){ - enriched.setFileIdentifier(UUID.randomUUID().toString()); + uuid=UUID.randomUUID().toString(); + enriched.setFileIdentifier(uuid); + }else { + uuid=enriched.getFileIdentifier(); } if(enriched.getIdentificationInfo().isEmpty()){ @@ -50,6 +56,11 @@ public class MetadataEnricher { } + public String getMetadataIdentifier(){ + return uuid; + } + + public void addPreview(String previewURL){ try{ ident.getGraphicOverviews().add(new DefaultBrowseGraphic(new URI(previewURL))); @@ -89,7 +100,13 @@ public class MetadataEnricher { DefaultFormat format3 = new DefaultFormat(); format3.setName(new DefaultInternationalString("WCS")); format3.setVersion(new DefaultInternationalString("1.0.0")); - distribution.setDistributionFormats(new ArrayList(Arrays.asList(format1, format2, format3))); + + //*** GIS-RESOLVER-LINK is HTTP + DefaultFormat format4 = new DefaultFormat(); + format4.setName(new DefaultInternationalString("HTTP")); + format4.setVersion(new DefaultInternationalString("1.1.0")); + + distribution.setDistributionFormats(new ArrayList(Arrays.asList(format1, format2, format3,format4))); distribution.getTransferOptions().add(transferOptions); enriched.setDistributionInfo(distribution); diff --git a/src/test/java/org/gcube/spatial/data/gis/PublishTable.java b/src/test/java/org/gcube/spatial/data/gis/PublishTable.java index 2a6e083..90d7750 100644 --- a/src/test/java/org/gcube/spatial/data/gis/PublishTable.java +++ b/src/test/java/org/gcube/spatial/data/gis/PublishTable.java @@ -1,15 +1,12 @@ package org.gcube.spatial.data.gis; -import it.geosolutions.geonetwork.util.GNInsertConfiguration; import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder; -import java.util.ArrayList; import java.util.Date; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.spatial.data.geonetwork.LoginLevel; -import org.gcube.spatial.data.geonetwork.configuration.Configuration; import org.gcube.spatial.data.geonetwork.iso.GcubeISOMetadata; import org.gcube.spatial.data.geonetwork.iso.Thesaurus; import org.gcube.spatial.data.gis.model.report.PublishResponse;