merged
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/spatial-data/gis-interface@99355 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0ed5d6ae4f
commit
fdbda47be8
|
@ -4,9 +4,7 @@ import it.geosolutions.geonetwork.util.GNInsertConfiguration;
|
|||
import it.geosolutions.geoserver.rest.GeoServerRESTManager;
|
||||
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
|
||||
import it.geosolutions.geoserver.rest.GeoServerRESTReader;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -26,7 +24,6 @@ import org.gcube.spatial.data.geonetwork.LoginLevel;
|
|||
import org.gcube.spatial.data.gis.is.GeoServerDescriptor;
|
||||
import org.gcube.spatial.data.gis.is.InfrastructureCrawler;
|
||||
import org.gcube.spatial.data.gis.meta.MetadataEnricher;
|
||||
import org.gcube.spatial.data.gis.model.BoundingBox;
|
||||
import org.gcube.spatial.data.gis.model.report.DeleteReport;
|
||||
import org.gcube.spatial.data.gis.model.report.PublishResponse;
|
||||
import org.gcube.spatial.data.gis.model.report.Report;
|
||||
|
@ -70,10 +67,6 @@ public class GISInterface {
|
|||
|
||||
public GeoServerRESTReader getGeoServerReader(ResearchMethod method,boolean forceRefresh) throws Exception{
|
||||
GeoServerDescriptor desc=getGeoServerSet(forceRefresh).last();
|
||||
return getGeoServerReader(desc);
|
||||
}
|
||||
|
||||
public GeoServerRESTReader getGeoServerReader(GeoServerDescriptor desc)throws Exception{
|
||||
return getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword()).getReader();
|
||||
}
|
||||
|
||||
|
@ -85,18 +78,13 @@ public class GISInterface {
|
|||
return new GeoServerRESTReader(url);
|
||||
}
|
||||
|
||||
public GeoServerDescriptor getCurrentGeoServerDescriptor(){
|
||||
return getGeoServerSet(false).last();
|
||||
}
|
||||
|
||||
public SortedSet<GeoServerDescriptor> getGeoServerDescriptorSet(boolean forceRefresh){
|
||||
return getGeoServerSet(forceRefresh);
|
||||
}
|
||||
|
||||
//******************* Create logic
|
||||
/**
|
||||
* @see it.geosolutions.geoserver.rest.GeoServerRESTPublisher#publishGeoTIFF(String, String, String, File, String, ProjectionPolicy, String, double[])
|
||||
*
|
||||
* @param geoNetworkMeta
|
||||
* @param config
|
||||
* @return
|
||||
*/
|
||||
public PublishResponse addGeoTIFF(String workspace, String storeName, String coverageName,
|
||||
File toPublishFile,String srs,
|
||||
|
@ -105,59 +93,44 @@ public class GISInterface {
|
|||
boolean publishResult = false;
|
||||
PublishResponse toReturn=new PublishResponse(geoNetworkMeta);
|
||||
GeoServerRESTPublisher publisher=null;
|
||||
GeoServerDescriptor desc=getGeoServerSet(false).last();
|
||||
logger.debug("Using "+desc);
|
||||
try{
|
||||
GeoServerDescriptor desc=getGeoServerSet(false).last();
|
||||
logger.debug("Using "+desc);
|
||||
publisher=getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword()).getPublisher();
|
||||
// Publishing the file to geoserver depends on file type
|
||||
publishResult=publisher.publishGeoTIFF(workspace, storeName, coverageName, toPublishFile, srs, policy, defaultStyle, bbox);
|
||||
|
||||
if(publishResult){
|
||||
toReturn.setDataOperationResult(Report.OperationState.COMPLETE);
|
||||
|
||||
|
||||
ArrayList<String> distributionUris=new ArrayList<String>();
|
||||
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)));
|
||||
// distributionUris.add(desc.getUrl()+"gwc/service/wms")
|
||||
|
||||
MetadataEnricher enricher=new MetadataEnricher(geoNetworkMeta, true);
|
||||
enricher.addDate(new Date(System.currentTimeMillis()), DateType.CREATION);
|
||||
enricher.addPreview(distributionUris.get(0));
|
||||
enricher.setdistributionURIs(distributionUris,coverageName);
|
||||
enricher.setdistributionURIs(distributionUris);
|
||||
toReturn.getMetaOperationMessages().addAll(enricher.getMessages());
|
||||
if(enricher.getMessages().size()>0)toReturn.setMetaOperationResult(OperationState.WARN);
|
||||
GeoNetworkPublisher pub=getGN();
|
||||
getGN().login(level);
|
||||
|
||||
Metadata enriched=enricher.getEnriched();
|
||||
toReturn.setPublishedMetadata(enriched);
|
||||
long returnedId=pub.insertMetadata(config,enriched);
|
||||
|
||||
long returnedId=pub.insertMetadata(config,enricher.getEnriched());
|
||||
toReturn.setReturnedMetaId(returnedId);
|
||||
toReturn.setMetaOperationResult(OperationState.COMPLETE);
|
||||
}else toReturn.getDataOperationMessages().add("Publish operation returned false, unable to publish data");
|
||||
}catch(NoSuchElementException e){
|
||||
toReturn.getDataOperationMessages().add("No GeoServer Found under scope "+ScopeProvider.instance.get());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if(publisher==null){
|
||||
if(publisher==null)
|
||||
toReturn.getDataOperationMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
|
||||
logger.debug("Unable to instatiate GeoServerRESTPublisher",e);
|
||||
}else {
|
||||
toReturn.getDataOperationMessages().add("Unable to publish data, cause :"+e.getMessage());
|
||||
logger.debug("Unable to publish data",e);
|
||||
}
|
||||
else toReturn.getDataOperationMessages().add("Unable to publish data, cause :"+e.getMessage());
|
||||
} catch (MalformedURLException e) {
|
||||
toReturn.getDataOperationMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
|
||||
logger.debug("Unable to instatiate GeoServerRESTPublisher",e);
|
||||
} catch (FileNotFoundException e) {
|
||||
toReturn.getDataOperationMessages().add("Unable to publish data, cause :"+e.getMessage());
|
||||
logger.debug("Unable to publish data",e);
|
||||
} catch (Exception e) {
|
||||
// exceptions raised by publishing metadata, need to clean up
|
||||
toReturn.getMetaOperationMessages().add("Unable to publish metadata, cause :"+e.getMessage());
|
||||
logger.debug("Unable to publish metadata",e);
|
||||
DeleteReport delRep=deleteStore(workspace,storeName,null,desc);
|
||||
DeleteReport delRep=deleteStore(workspace,storeName,null);
|
||||
if(!delRep.getDataOperationResult().equals(OperationState.COMPLETE)){
|
||||
toReturn.setDataOperationResult(OperationState.WARN);
|
||||
toReturn.getDataOperationMessages().add("Unable to rollback data publishing, following messages from delete operation (state : "+delRep.getDataOperationResult()+")");
|
||||
|
@ -168,130 +141,19 @@ public class GISInterface {
|
|||
}
|
||||
|
||||
|
||||
public PublishResponse publishDBTable(String workspace, String storeName, GSFeatureTypeEncoder fte,GSLayerEncoder layerEncoder,Metadata geoNetworkMeta, GNInsertConfiguration config,LoginLevel level){
|
||||
boolean publishResult = false;
|
||||
PublishResponse toReturn=new PublishResponse(geoNetworkMeta);
|
||||
GeoServerRESTPublisher publisher=null;
|
||||
GeoServerDescriptor desc=getGeoServerSet(false).last();
|
||||
logger.debug("Publish db table : "+storeName+" under ws : "+workspace+", using geoserver "+desc);
|
||||
logger.debug("Using "+desc);
|
||||
try{
|
||||
GeoServerRESTManager mng=getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword());
|
||||
publisher=mng.getPublisher();
|
||||
// Publishing the file to geoserver depends on file type
|
||||
publishResult=publisher.publishDBLayer(workspace, storeName, fte, layerEncoder);
|
||||
|
||||
if(publishResult){
|
||||
toReturn.setDataOperationResult(Report.OperationState.COMPLETE);
|
||||
|
||||
|
||||
logger.debug("Published data, enriching meta..");
|
||||
ArrayList<String> distributionUris=new ArrayList<String>();
|
||||
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));
|
||||
|
||||
MetadataEnricher enricher=new MetadataEnricher(geoNetworkMeta, true);
|
||||
enricher.addDate(new Date(System.currentTimeMillis()), DateType.CREATION);
|
||||
enricher.addPreview(distributionUris.get(0));
|
||||
enricher.setdistributionURIs(distributionUris,fte.getName());
|
||||
|
||||
toReturn.getMetaOperationMessages().addAll(enricher.getMessages());
|
||||
if(enricher.getMessages().size()>0)toReturn.setMetaOperationResult(OperationState.WARN);
|
||||
|
||||
|
||||
GeoNetworkPublisher pub=getGN();
|
||||
getGN().login(level);
|
||||
Metadata enriched=enricher.getEnriched();
|
||||
toReturn.setPublishedMetadata(enriched);
|
||||
long returnedId=pub.insertMetadata(config,enriched);
|
||||
toReturn.setReturnedMetaId(returnedId);
|
||||
toReturn.setMetaOperationResult(OperationState.COMPLETE);
|
||||
}else {
|
||||
toReturn.getDataOperationMessages().add("Publish operation returned false, unable to publish data");
|
||||
|
||||
}
|
||||
}catch(NoSuchElementException e){
|
||||
toReturn.getDataOperationMessages().add("No GeoServer Found under scope "+ScopeProvider.instance.get());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if(publisher==null){
|
||||
toReturn.getDataOperationMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
|
||||
logger.debug("Unable to instatiate GeoServerRESTPublisher",e);
|
||||
}else {
|
||||
toReturn.getDataOperationMessages().add("Unable to publish data, cause :"+e.getMessage());
|
||||
logger.debug("Unable to publish data",e);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
toReturn.getDataOperationMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
|
||||
logger.debug("Unable to instatiate GeoServerRESTPublisher",e);
|
||||
} catch (FileNotFoundException e) {
|
||||
toReturn.getDataOperationMessages().add("Unable to publish data, cause :"+e.getMessage());
|
||||
logger.debug("Unable to publish data",e);
|
||||
} catch (Exception e) {
|
||||
// exceptions raised by publishing metadata, need to clean up
|
||||
toReturn.getMetaOperationMessages().add("Unable to publish metadata, cause :"+e.getMessage());
|
||||
logger.debug("Unable to publish metadata",e);
|
||||
DeleteReport delRep=deleteLayer(workspace,fte.getName(),null,desc,level);
|
||||
if(!delRep.getDataOperationResult().equals(OperationState.COMPLETE)){
|
||||
toReturn.setDataOperationResult(OperationState.WARN);
|
||||
toReturn.getDataOperationMessages().add("Unable to rollback data publishing, following messages from delete operation (state : "+delRep.getDataOperationResult()+")");
|
||||
toReturn.getDataOperationMessages().addAll(delRep.getDataOperationMessages());
|
||||
}
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
public PublishResponse publishStyle(String sldBody,String styleName){
|
||||
boolean publishResult = false;
|
||||
PublishResponse toReturn=new PublishResponse();
|
||||
GeoServerRESTPublisher publisher=null;
|
||||
GeoServerDescriptor desc=getGeoServerSet(false).last();
|
||||
logger.debug("Using "+desc);
|
||||
try{
|
||||
publisher=getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword()).getPublisher();
|
||||
// Publishing the file to geoserver depends on file type
|
||||
publishResult=publisher.publishStyle(sldBody, styleName);
|
||||
|
||||
if(publishResult){
|
||||
toReturn.setDataOperationResult(Report.OperationState.COMPLETE);
|
||||
}else toReturn.getDataOperationMessages().add("Publish operation returned false, unable to publish data");
|
||||
}catch(NoSuchElementException e){
|
||||
toReturn.getDataOperationMessages().add("No GeoServer Found under scope "+ScopeProvider.instance.get());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if(publisher==null){
|
||||
toReturn.getDataOperationMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
|
||||
logger.debug("Unable to instatiate GeoServerRESTPublisher",e);
|
||||
}else {
|
||||
toReturn.getDataOperationMessages().add("Unable to publish data, cause :"+e.getMessage());
|
||||
logger.debug("Unable to publish data",e);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
toReturn.getDataOperationMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
|
||||
logger.debug("Unable to instatiate GeoServerRESTPublisher",e);
|
||||
} catch (Exception e) {
|
||||
// exceptions raised by publishing metadata, need to clean up
|
||||
toReturn.getMetaOperationMessages().add("Unable to publish metadata, cause :"+e.getMessage());
|
||||
logger.debug("Unable to publish metadata",e);
|
||||
DeleteReport delRep=deleteStyle(styleName,desc);
|
||||
if(!delRep.getDataOperationResult().equals(OperationState.COMPLETE)){
|
||||
toReturn.setDataOperationResult(OperationState.WARN);
|
||||
toReturn.getDataOperationMessages().add("Unable to rollback data publishing, following messages from delete operation (state : "+delRep.getDataOperationResult()+")");
|
||||
toReturn.getDataOperationMessages().addAll(delRep.getDataOperationMessages());
|
||||
}
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
// ********************* DELETE Logic
|
||||
/**
|
||||
* @see it.geosolutions.geoserver.rest.GeoServerRESTPublisher#removeDatastore(String, String, boolean)
|
||||
*
|
||||
*/
|
||||
public DeleteReport deleteStore(String workspace,String storeName,Long metadataUUID,GeoServerDescriptor desc){
|
||||
public DeleteReport deleteStore(String workspace,String storeName,Long metadataUUID){
|
||||
DeleteReport toReturn=new DeleteReport();
|
||||
GeoServerRESTPublisher publisher=null;
|
||||
try{
|
||||
try{
|
||||
GeoServerDescriptor desc=getGeoServerSet(false).last();
|
||||
publisher=getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword()).getPublisher();
|
||||
boolean removed=publisher.removeDatastore(workspace, storeName,true);
|
||||
if(removed){
|
||||
|
@ -317,60 +179,6 @@ public class GISInterface {
|
|||
return toReturn;
|
||||
}
|
||||
|
||||
public DeleteReport deleteLayer(String workspace,String layerName, Long metadataUUID,GeoServerDescriptor desc,LoginLevel gnLoginLevel){
|
||||
DeleteReport toReturn=new DeleteReport();
|
||||
GeoServerRESTPublisher publisher=null;
|
||||
try{
|
||||
publisher=getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword()).getPublisher();
|
||||
boolean removed=publisher.removeLayer(workspace, layerName);
|
||||
if(removed){
|
||||
toReturn.setDataOperationResult(Report.OperationState.COMPLETE);
|
||||
if(metadataUUID!=null){
|
||||
GeoNetworkPublisher gnPub=getGN();
|
||||
gnPub.login(gnLoginLevel);
|
||||
gnPub.deleteMetadata(metadataUUID);
|
||||
}else {
|
||||
toReturn.setMetaOperationResult(OperationState.WARN);
|
||||
toReturn.getMetaOperationMessages().add("Passed meta UUID is null, no metadata deleted");
|
||||
}
|
||||
}else toReturn.getDataOperationMessages().add("Remove data operation returned false, unable to delete Store");
|
||||
}catch(NoSuchElementException e){
|
||||
toReturn.getDataOperationMessages().add("No GeoServer Found under scope "+ScopeProvider.instance.get());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if(publisher==null)
|
||||
toReturn.getDataOperationMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
|
||||
else toReturn.getDataOperationMessages().add("Unable to publish data, cause :"+e.getMessage());
|
||||
} catch (MalformedURLException e) {
|
||||
toReturn.getDataOperationMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
|
||||
} catch (Exception e) {
|
||||
toReturn.getMetaOperationMessages().add("Unable to delete metadata, cause :"+e.getMessage());
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public DeleteReport deleteStyle(String styleName,GeoServerDescriptor desc){
|
||||
DeleteReport toReturn=new DeleteReport();
|
||||
GeoServerRESTPublisher publisher=null;
|
||||
try{
|
||||
publisher=getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword()).getPublisher();
|
||||
boolean removed=publisher.removeStyle(styleName, true);
|
||||
if(removed){
|
||||
toReturn.setDataOperationResult(Report.OperationState.COMPLETE);
|
||||
}else toReturn.getDataOperationMessages().add("Remove data operation returned false, unable to delete Store");
|
||||
}catch(NoSuchElementException e){
|
||||
toReturn.getDataOperationMessages().add("No GeoServer Found under scope "+ScopeProvider.instance.get());
|
||||
} catch (IllegalArgumentException e) {
|
||||
if(publisher==null)
|
||||
toReturn.getDataOperationMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
|
||||
else toReturn.getDataOperationMessages().add("Unable to publish data, cause :"+e.getMessage());
|
||||
} catch (MalformedURLException e) {
|
||||
toReturn.getDataOperationMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
|
||||
} catch (Exception e) {
|
||||
toReturn.getMetaOperationMessages().add("Unable to delete metadata, cause :"+e.getMessage());
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
//************ PRIVATE
|
||||
|
||||
private GeoNetworkPublisher geoNetwork=null;
|
||||
|
@ -397,6 +205,9 @@ public class GISInterface {
|
|||
|
||||
|
||||
|
||||
//********************* PRIVATE PUBLISH BY FILE TYPE
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
package org.gcube.spatial.data.gis;
|
||||
|
||||
import org.gcube.spatial.data.gis.model.BoundingBox;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||
|
||||
public class URIUtils {
|
||||
|
||||
|
||||
public static final String CRS="EPSG:4326";
|
||||
public static final String WMS_PROTOCOL="OGC:WMS-1.3.0-http-get-map";
|
||||
public static final String WFS_PROTOCOL="OGC:WFS-1.0.0-http-get-feature";
|
||||
public static final String HTTP_PROTOCOL="WWW:LINK-1.0-http--link";
|
||||
|
||||
|
||||
public static String getWmsUrl(String geoServerUrl, String layerName,String style, BoundingBox bbox) {
|
||||
if(bbox==null) bbox=BoundingBox.WORLD_EXTENT;
|
||||
return geoServerUrl +
|
||||
"/wms?service=wms&version=1.1.0"
|
||||
+ "&request=GetMap&layers=" + layerName
|
||||
+ "&styles=" + (style == null ? "" : style)
|
||||
+ "&bbox=" + bbox + "&width=676&height=330" +
|
||||
"&srs=EPSG:4326&crs="+CRS+"&format=application/openlayers";
|
||||
}
|
||||
public static String getWfsUrl(String geoServerUrl, String layerName) {
|
||||
return geoServerUrl +
|
||||
"/ows?service=wfs&version=1.0.0"
|
||||
+ "&request=GetFeature&typeName=" + layerName
|
||||
+"&format=json";
|
||||
}
|
||||
public static String getWcsUrl(String geoServerUrl, String layerName,BoundingBox bbox) {
|
||||
if(bbox==null) bbox=BoundingBox.WORLD_EXTENT;
|
||||
return geoServerUrl + "/wcs?service=wcs&version=1.0.0" + "&request=GetCoverage&coverage=" +
|
||||
layerName + "&CRS=EPSG:4326" + "&bbox=" + bbox + "&width=676&height=330&format=geotiff";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getStyleFromGSLayerEncoder(GSLayerEncoder encoder){
|
||||
return encoder.getRoot().getChildText("defaultStyle");
|
||||
}
|
||||
|
||||
public static final String getProtocol(String uri){
|
||||
uri=uri.toLowerCase();
|
||||
if(uri.contains(("service=wms"))) return WMS_PROTOCOL;
|
||||
else if(uri.contains("service=wfs")) return WFS_PROTOCOL;
|
||||
else return HTTP_PROTOCOL;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,23 +3,20 @@ package org.gcube.spatial.data.gis.meta;
|
|||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.spatial.data.gis.URIUtils;
|
||||
import org.gcube.spatial.data.gis.model.report.Report.OperationState;
|
||||
import org.geotoolkit.metadata.iso.DefaultMetadata;
|
||||
import org.geotoolkit.metadata.iso.citation.DefaultCitation;
|
||||
import org.geotoolkit.metadata.iso.citation.DefaultCitationDate;
|
||||
import org.geotoolkit.metadata.iso.citation.DefaultOnlineResource;
|
||||
import org.geotoolkit.metadata.iso.distribution.DefaultDigitalTransferOptions;
|
||||
import org.geotoolkit.metadata.iso.distribution.DefaultDistribution;
|
||||
import org.geotoolkit.metadata.iso.distribution.DefaultFormat;
|
||||
import org.geotoolkit.metadata.iso.identification.DefaultBrowseGraphic;
|
||||
import org.geotoolkit.metadata.iso.identification.DefaultDataIdentification;
|
||||
import org.geotoolkit.util.DefaultInternationalString;
|
||||
import org.opengis.metadata.Metadata;
|
||||
import org.opengis.metadata.citation.CitationDate;
|
||||
import org.opengis.metadata.citation.DateType;
|
||||
|
@ -60,37 +57,18 @@ public class MetadataEnricher {
|
|||
}
|
||||
}
|
||||
|
||||
public void setdistributionURIs(List<String> uris,String layerName){
|
||||
public void setdistributionURIs(List<String> uris){
|
||||
DefaultDistribution distribution=new DefaultDistribution();
|
||||
|
||||
DefaultDigitalTransferOptions transferOptions=new DefaultDigitalTransferOptions();
|
||||
for(String uriString:uris)
|
||||
for(String uri:uris)
|
||||
try{
|
||||
URI uri=new URI(uriString);
|
||||
DefaultOnlineResource resource=new DefaultOnlineResource(uri);
|
||||
String protocol=URIUtils.getProtocol(uriString);
|
||||
resource.setName(layerName);
|
||||
resource.setProtocol(protocol);
|
||||
transferOptions.getOnLines().add(resource);
|
||||
|
||||
transferOptions.getOnLines().add(new DefaultOnlineResource(new URI(uri)));
|
||||
}catch(URISyntaxException e){
|
||||
String msg="Unable to set transfer option, passed URI is "+uriString+", cause : "+e.getMessage();
|
||||
String msg="Unable to set transfer option, passed URI is "+uri+", cause : "+e.getMessage();
|
||||
logger.warn(msg);
|
||||
messages.add(msg);
|
||||
}
|
||||
|
||||
//******* Assuming all formats available
|
||||
DefaultFormat format1 = new DefaultFormat();
|
||||
format1.setName(new DefaultInternationalString("WMS"));
|
||||
format1.setVersion(new DefaultInternationalString("1.1.0"));
|
||||
DefaultFormat format2 = new DefaultFormat();
|
||||
format2.setName(new DefaultInternationalString("WFS"));
|
||||
format2.setVersion(new DefaultInternationalString("1.1.0"));
|
||||
DefaultFormat format3 = new DefaultFormat();
|
||||
format3.setName(new DefaultInternationalString("WCS"));
|
||||
format3.setVersion(new DefaultInternationalString("1.0.0"));
|
||||
distribution.setDistributionFormats(new ArrayList<DefaultFormat>(Arrays.asList(format1, format2, format3)));
|
||||
|
||||
distribution.getTransferOptions().add(transferOptions);
|
||||
enriched.setDistributionInfo(distribution);
|
||||
}
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
package org.gcube.spatial.data.gis.model;
|
||||
|
||||
public class BoundingBox {
|
||||
|
||||
public static final BoundingBox WORLD_EXTENT=new BoundingBox(90, -90, 180, -180);
|
||||
|
||||
private double N=90;
|
||||
private double S=-90;
|
||||
private double W=180;
|
||||
private double E=-180;
|
||||
|
||||
public BoundingBox(double n, double s, double w, double e) {
|
||||
super();
|
||||
N = n;
|
||||
S = s;
|
||||
W = w;
|
||||
E = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumed order is E, S, W, N
|
||||
*
|
||||
* @param bbox
|
||||
*/
|
||||
public BoundingBox(double[] bbox) {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
public double getN() {
|
||||
return N;
|
||||
}
|
||||
|
||||
public void setN(double n) {
|
||||
N = n;
|
||||
}
|
||||
|
||||
public double getS() {
|
||||
return S;
|
||||
}
|
||||
|
||||
public void setS(double s) {
|
||||
S = s;
|
||||
}
|
||||
|
||||
public double getW() {
|
||||
return W;
|
||||
}
|
||||
|
||||
public void setW(double w) {
|
||||
W = w;
|
||||
}
|
||||
|
||||
public double getE() {
|
||||
return E;
|
||||
}
|
||||
|
||||
public void setE(double e) {
|
||||
E = e;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return E, S, W, N
|
||||
*/
|
||||
public double[] toArray(){
|
||||
return new double[]{
|
||||
E,S,W,N
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return E, S, W, N
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return E+","+S+","+W+","+N;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -25,9 +25,7 @@ public class Range {
|
|||
|
||||
|
||||
|
||||
public void setCondition(Condition condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the min
|
||||
|
|
|
@ -135,21 +135,17 @@ public class StyleUtils {
|
|||
|
||||
private static MutableRule makeRule(Range r){
|
||||
MutableRule toReturn=SF.rule();
|
||||
toReturn.setName(r.getToFilterProperty()+" in ["+r.getMin()+" , "+r.getMax()+")");
|
||||
switch(r.getCondition()){
|
||||
case BETWEEN : toReturn.setFilter(FF.and( // property => min AND property < max
|
||||
FF.greaterOrEqual(FF.property(r.getToFilterProperty()), FF.literal(r.getMin())),
|
||||
FF.less(FF.property(r.getToFilterProperty()), FF.literal(r.getMax()))));
|
||||
toReturn.setName(r.getToFilterProperty()+" in ["+r.getMin()+" , "+r.getMax()+")");
|
||||
break;
|
||||
|
||||
case GREATER_THEN_MIN : toReturn.setFilter(// property => min
|
||||
FF.greaterOrEqual(FF.property(r.getToFilterProperty()), FF.literal(r.getMin())));
|
||||
toReturn.setName(r.getToFilterProperty()+" = > "+r.getMin());
|
||||
break;
|
||||
|
||||
case UP_TO_MAX : toReturn.setFilter(// property < max
|
||||
FF.lessOrEqual(FF.property(r.getToFilterProperty()), FF.literal(r.getMax())));
|
||||
toReturn.setName(r.getToFilterProperty()+" < = "+r.getMin());
|
||||
FF.less(FF.property(r.getToFilterProperty()), FF.literal(r.getMax())));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -227,7 +223,7 @@ public class StyleUtils {
|
|||
}
|
||||
|
||||
|
||||
toReturn.get(toReturn.size()-1).setCondition(Condition.GREATER_THEN_MIN);
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
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;
|
||||
import org.geotoolkit.metadata.iso.extent.DefaultExtent;
|
||||
import org.opengis.metadata.citation.PresentationForm;
|
||||
import org.opengis.metadata.identification.TopicCategory;
|
||||
import org.opengis.metadata.spatial.GeometricObjectType;
|
||||
import org.opengis.metadata.spatial.TopologyLevel;
|
||||
|
||||
public class PublishTable {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
|
||||
|
||||
|
||||
private static final String crs="GEOGCS[\"WGS 84\", DATUM[\"World Geodetic System 1984\", SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]],"+
|
||||
"AUTHORITY[\"EPSG\",\"6326\"]], PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.017453292519943295],"+
|
||||
"AXIS[\"Geodetic longitude\", EAST], AXIS[\"Geodetic latitude\", NORTH], AUTHORITY[\"EPSG\",\"4326\"]]";
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
String scope="/gcube";
|
||||
String toPublishTable="mytable";
|
||||
String datastore="mydatastore";
|
||||
|
||||
|
||||
String defaultStyle="defaultStyle";
|
||||
String workspace="myworkspace";
|
||||
|
||||
|
||||
|
||||
GSFeatureTypeEncoder fte=new GSFeatureTypeEncoder();
|
||||
fte.setEnabled(true);
|
||||
fte.setLatLonBoundingBox(-180.0, -90.0, 180.0, 90.0, crs);
|
||||
fte.setName(toPublishTable);
|
||||
fte.setNativeCRS(crs);
|
||||
|
||||
GSLayerEncoder le=new GSLayerEncoder();
|
||||
le.setDefaultStyle(defaultStyle);
|
||||
le.setEnabled(true);
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
GcubeISOMetadata meta=fillMeta();
|
||||
|
||||
|
||||
GISInterface gis=GISInterface.get();
|
||||
Configuration gnConfig=gis.getGeoNetworkReader().getConfiguration();
|
||||
|
||||
PublishResponse resp=gis.publishDBTable(workspace, datastore, fte, le, meta.getMetadata(), new GNInsertConfiguration(gnConfig.getScopeGroup()+"", "datasets", "_none_", true), LoginLevel.DEFAULT);
|
||||
System.out.println(resp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static GcubeISOMetadata fillMeta() throws Exception{
|
||||
GcubeISOMetadata meta=new GcubeISOMetadata();
|
||||
meta.setAbstractField("This metadata is just a test");
|
||||
meta.setCreationDate(new Date(System.currentTimeMillis()));
|
||||
meta.setExtent((DefaultExtent) DefaultExtent.WORLD);
|
||||
meta.setGeometricObjectType(GeometricObjectType.SURFACE);
|
||||
meta.setPresentationForm(PresentationForm.MAP_DIGITAL);
|
||||
meta.setPurpose("Purpose of this layer is to test the library");
|
||||
meta.setResolution(0.5d);
|
||||
meta.setTitle("My Test Layer");
|
||||
meta.setTopologyLevel(TopologyLevel.GEOMETRY_ONLY);
|
||||
meta.setUser("fabio.sinibaldi");
|
||||
|
||||
|
||||
meta.addCredits("Thanks to me");
|
||||
meta.addGraphicOverview("http://www.d4science.org/D4ScienceOrg-Social-theme/images/custom/D4ScienceInfrastructure.png");
|
||||
|
||||
Thesaurus generalThesaurus=meta.getConfig().getThesauri().get("General");
|
||||
meta.addKeyword("TEST", generalThesaurus);
|
||||
meta.addKeyword("Geoserverinterface", generalThesaurus);
|
||||
|
||||
meta.addTopicCategory(TopicCategory.BIOTA);
|
||||
return meta;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,14 +5,12 @@ import it.geosolutions.geoserver.rest.GeoServerRESTReader;
|
|||
import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList.RESTShortWorkspace;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.spatial.data.geonetwork.LoginLevel;
|
||||
import org.gcube.spatial.data.gis.model.Costants;
|
||||
import org.gcube.spatial.data.gis.symbology.StyleUtils;
|
||||
import org.geotoolkit.metadata.iso.DefaultMetadata;
|
||||
import org.opengis.metadata.Metadata;
|
||||
|
||||
|
@ -37,38 +35,18 @@ public class PublishTest {
|
|||
}
|
||||
|
||||
|
||||
// String geoTiffPath = "/home/fabio/Downloads/aquamaps-lprognathodesfalcifer20121207161043540cet.geotiff";
|
||||
// File geoTiff=new File(geoTiffPath);
|
||||
// String workspace="aquamaps";
|
||||
// String storeName=geoTiff.getName()+"_store";
|
||||
// String coverageName="";
|
||||
// String srs="EPSG:4326";
|
||||
// ProjectionPolicy policy=ProjectionPolicy.REPROJECT_TO_DECLARED;
|
||||
// String defaultStyle="raster";
|
||||
// double[] bbox=Costants.WORLD_BOUNDING_BOX;
|
||||
// Metadata theMeta=new DefaultMetadata();
|
||||
// GNInsertConfiguration config=new GNInsertConfiguration("view-group", "datasets", "_none_", true);
|
||||
// gisInterface.addGeoTIFF(workspace, storeName, coverageName, geoTiff, srs, policy, defaultStyle, bbox, theMeta, config,LoginLevel.DEFAULT);
|
||||
|
||||
|
||||
//*************** publish Style
|
||||
|
||||
String nameStyle="TestStyle"+System.currentTimeMillis();
|
||||
String attributeName="probability";
|
||||
Integer maxClasses=5;
|
||||
Color c1= Color.YELLOW;
|
||||
Color c2= Color.RED;
|
||||
Class typeValue =Double.class;
|
||||
Double maxValue=1d;
|
||||
Double minValue=0d;
|
||||
String sldStyle=StyleUtils.createStyle(nameStyle, attributeName, maxClasses, c1, c2, typeValue, maxValue, minValue);
|
||||
System.out.println("Generated Style is : ");
|
||||
System.out.println(sldStyle);
|
||||
// System.out.println(gisInterface.publishStyle(, nameStyle));
|
||||
|
||||
|
||||
//**************
|
||||
|
||||
String geoTiffPath = "/home/fabio/Downloads/aquamaps-lprognathodesfalcifer20121207161043540cet.geotiff";
|
||||
File geoTiff=new File(geoTiffPath);
|
||||
String workspace="aquamaps";
|
||||
String storeName=geoTiff.getName()+"_store";
|
||||
String coverageName="";
|
||||
String srs="EPSG:4326";
|
||||
ProjectionPolicy policy=ProjectionPolicy.REPROJECT_TO_DECLARED;
|
||||
String defaultStyle="raster";
|
||||
double[] bbox=Costants.WORLD_BOUNDING_BOX;
|
||||
Metadata theMeta=new DefaultMetadata();
|
||||
GNInsertConfiguration config=new GNInsertConfiguration("view-group", "datasets", "_none_", true);
|
||||
gisInterface.addGeoTIFF(workspace, storeName, coverageName, geoTiff, srs, policy, defaultStyle, bbox, theMeta, config,LoginLevel.DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package org.gcube.spatial.data.gis;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||
|
||||
|
||||
public class StringTest {
|
||||
|
||||
|
||||
public static void main (String[] args){
|
||||
String style="myDefaultStyle09";
|
||||
GSLayerEncoder lenc=new GSLayerEncoder();
|
||||
lenc.setDefaultStyle(style);
|
||||
lenc.setEnabled(true);
|
||||
lenc.setQueryable(true);
|
||||
|
||||
|
||||
String res=URIUtils.getStyleFromGSLayerEncoder(lenc);
|
||||
System.out.println(style+(style.equals(res)?" = ":" != ")+res);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,12 @@
|
|||
log4j.rootLogger=DEBUG, stdout
|
||||
log4j.rootLogger=DEBUG, A1, stdout
|
||||
log4j.appender.A1=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.A1.File=log.txt
|
||||
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
|
||||
# ***** Max file size is set to 100KB
|
||||
log4j.appender.A1.MaxFileSize=100MB
|
||||
# ***** Keep one backup file
|
||||
log4j.appender.A1.MaxBackupIndex=1
|
||||
|
||||
#CONSOLE
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
|
|
Loading…
Reference in New Issue