git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/spatial-data/gis-interface@72863 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1d3be8a750
commit
374e7951fb
|
@ -1,28 +1,45 @@
|
|||
package org.gcube.spatial.data.gis;
|
||||
|
||||
import it.geosolutions.geonetwork.exception.GNException;
|
||||
import it.geosolutions.geonetwork.exception.GNServerException;
|
||||
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.GSResourceEncoder.ProjectionPolicy;
|
||||
|
||||
import org.opengis.metadata.Metadata;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.SortedSet;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetworkReader;
|
||||
import org.gcube.spatial.data.geonetwork.configuration.AuthorizationException;
|
||||
import org.gcube.spatial.data.gis.meta.MetadataEnricher;
|
||||
import org.gcube.spatial.data.gis.model.GeoServerDescriptor;
|
||||
import org.gcube.spatial.data.gis.model.InfrastructureCrawler;
|
||||
import org.gcube.spatial.data.gis.model.PublishResponse;
|
||||
import org.gcube.spatial.data.gis.model.PublishResponse.PublishedState;
|
||||
import org.opengis.metadata.Metadata;
|
||||
import org.opengis.metadata.citation.DateType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class GISInterface {
|
||||
|
||||
final static Logger logger= LoggerFactory.getLogger(GISInterface.class);
|
||||
|
||||
private static final long MAX_GEOSERVER_CACHE_TIME=2*60*1000;
|
||||
|
||||
public static GISInterface get() throws Exception{
|
||||
|
@ -39,73 +56,7 @@ public class GISInterface {
|
|||
|
||||
}
|
||||
|
||||
//***************** GEONETWORK READ METHODS
|
||||
|
||||
// public GNSearchResponse query(GNSearchRequest request)
|
||||
// throws GNLibException, GNServerException, Exception{
|
||||
// return getGN().query(request);
|
||||
// }
|
||||
//
|
||||
// public GNSearchResponse query(File request)
|
||||
// throws GNLibException, GNServerException, Exception{
|
||||
// return getGN().query(request);
|
||||
// }
|
||||
//
|
||||
// public Metadata getById(long id) throws GNLibException,
|
||||
// GNServerException, JAXBException, Exception {
|
||||
// return getGN().getById(id);
|
||||
// }
|
||||
//
|
||||
// public Metadata getById(String UUID) throws GNLibException,
|
||||
// GNServerException, JAXBException, Exception {
|
||||
// return getGN().getById(UUID);
|
||||
// }
|
||||
|
||||
//****************** GEONETWORK WRITE METHODS
|
||||
|
||||
// public void deleteMetadata(long id) throws GNLibException,
|
||||
// GNServerException, AuthorizationException, Exception {
|
||||
// getGN().deleteMetadata(id);
|
||||
// }
|
||||
//
|
||||
// public void setPrivileges(long metadataId, GNPrivConfiguration cfg)
|
||||
// throws GNLibException, GNServerException, AuthorizationException,Exception{
|
||||
// getGN().setPrivileges(metadataId, cfg);
|
||||
// }
|
||||
//
|
||||
// public long insertMetadata(GNInsertConfiguration configuration,
|
||||
// File metadataFile) throws GNLibException, GNServerException,
|
||||
// AuthorizationException,Exception{
|
||||
// return getGN().insertMetadata(configuration, metadataFile);
|
||||
// }
|
||||
//
|
||||
// public long insertMetadata(GNInsertConfiguration configuration,
|
||||
// Metadata meta) throws GNLibException, GNServerException,
|
||||
// AuthorizationException, IOException, JAXBException,Exception{
|
||||
// return getGN().insertMetadata(configuration, meta);
|
||||
// }
|
||||
//
|
||||
// public long insertMetadata(File requestFile) throws GNLibException,
|
||||
// GNServerException, AuthorizationException,Exception{
|
||||
// return getGN().insertMetadata(requestFile);
|
||||
// }
|
||||
//
|
||||
// public long insertMetadata(Metadata meta) throws GNLibException,
|
||||
// GNServerException, AuthorizationException, IOException,
|
||||
// JAXBException,Exception{
|
||||
// return getGN().insertMetadata(meta);
|
||||
// }
|
||||
//
|
||||
// public void updateMetadata(long id, File metadataFile)
|
||||
// throws GNLibException, GNServerException, AuthorizationException,Exception{
|
||||
// getGN().updateMetadata(id, metadataFile);
|
||||
// }
|
||||
//
|
||||
// public void updateMetadata(long id, Metadata meta) throws GNLibException,
|
||||
// GNServerException, AuthorizationException, IOException,
|
||||
// JAXBException,Exception{
|
||||
// getGN().updateMetadata(id, meta);
|
||||
// }
|
||||
|
||||
|
||||
//*******************READER getter METHODS
|
||||
|
||||
|
@ -130,29 +81,50 @@ public class GISInterface {
|
|||
return new GeoServerRESTReader(url);
|
||||
}
|
||||
|
||||
//******************* Complex logic
|
||||
//******************* Create logic
|
||||
|
||||
public void addGeoTIFF(String workspace, String storeName, String coverageName,
|
||||
public PublishResponse addGeoTIFF(String workspace, String storeName, String coverageName,
|
||||
File geotiff,String srs,
|
||||
ProjectionPolicy policy,String defaultStyle, double[] bbox,
|
||||
Metadata geoNetworkMeta) throws FileNotFoundException, IllegalArgumentException, MalformedURLException,AuthorizationException,Exception{
|
||||
Metadata geoNetworkMeta, GNInsertConfiguration config){
|
||||
boolean publishResult = false;
|
||||
PublishResponse toReturn=new PublishResponse(geoNetworkMeta);
|
||||
GeoServerRESTPublisher publisher=null;
|
||||
try{
|
||||
GeoServerDescriptor desc=getGeoServerSet(false).last();
|
||||
GeoServerRESTPublisher publisher=getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword()).getPublisher();
|
||||
publishResult=publisher.publishGeoTIFF(workspace, storeName, coverageName, geotiff, srs, policy, defaultStyle, bbox);
|
||||
if(publishResult){
|
||||
getGN().insertMetadata(geoNetworkMeta);
|
||||
}
|
||||
}catch(Exception e){
|
||||
publisher=getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword()).getPublisher();
|
||||
publishResult=publisher.publishGeoTIFF(workspace, storeName, coverageName, geotiff, srs, policy, defaultStyle, bbox);
|
||||
if(publishResult){
|
||||
toReturn.setDataPublishResult(PublishedState.COMPLETE);
|
||||
ArrayList<String> distributionUris=new ArrayList<String>();
|
||||
// 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);
|
||||
toReturn.getMetaPublishMessages().addAll(enricher.getMessages());
|
||||
long returnedId=getGN().insertMetadata(config,enricher.getEnriched());
|
||||
toReturn.setReturnedMetaId(returnedId);
|
||||
}
|
||||
}
|
||||
}catch(NoSuchElementException e){
|
||||
toReturn.getDataPublishMessages().add("No GeoServer Found under scope "+ScopeProvider.instance.get());
|
||||
} catch (IllegalArgumentException e) {
|
||||
toReturn.getDataPublishMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
|
||||
} catch (MalformedURLException e) {
|
||||
toReturn.getDataPublishMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
|
||||
} catch (FileNotFoundException e) {
|
||||
toReturn.getDataPublishMessages().add("Unable to publish data GeoServerRESTPublisher, cause :"+e.getMessage());
|
||||
} catch (Exception e) {
|
||||
// exceptions raised by publishing metadata, need to clean up
|
||||
toReturn.getMetaPublishMessages().add("Unable to publish metadata, cause :"+e.getMessage());
|
||||
//TODO rollback
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ********************* DELETE Logic
|
||||
|
||||
//************ PRIVATE
|
||||
|
||||
|
@ -160,7 +132,7 @@ public class GISInterface {
|
|||
private ConcurrentSkipListSet<GeoServerDescriptor> geoservers=new ConcurrentSkipListSet<GeoServerDescriptor>();
|
||||
private long lastAccessedTime=0l;
|
||||
|
||||
private synchronized SortedSet<GeoServerDescriptor> getGeoServerSet(boolean forceRefresh) throws Exception{
|
||||
private synchronized SortedSet<GeoServerDescriptor> getGeoServerSet(boolean forceRefresh){
|
||||
if(forceRefresh||geoservers.size()==0||System.currentTimeMillis()-lastAccessedTime>MAX_GEOSERVER_CACHE_TIME){
|
||||
geoservers.clear();
|
||||
geoservers.addAll(InfrastructureCrawler.queryforGeoServer());
|
||||
|
@ -180,4 +152,5 @@ public class GISInterface {
|
|||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
package org.gcube.spatial.data.gis.meta;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.spatial.data.gis.model.PublishResponse.PublishedState;
|
||||
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.identification.DefaultBrowseGraphic;
|
||||
import org.geotoolkit.metadata.iso.identification.DefaultDataIdentification;
|
||||
import org.opengis.metadata.Metadata;
|
||||
import org.opengis.metadata.citation.CitationDate;
|
||||
import org.opengis.metadata.citation.DateType;
|
||||
import org.opengis.metadata.identification.DataIdentification;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MetadataEnricher {
|
||||
final static Logger logger= LoggerFactory.getLogger(MetadataEnricher.class);
|
||||
|
||||
private Metadata toEnrich;
|
||||
private DefaultMetadata enriched;
|
||||
private ArrayList<String> messages=new ArrayList<String>();
|
||||
|
||||
private DefaultDataIdentification ident=null;
|
||||
|
||||
public MetadataEnricher(Metadata toEnrich,boolean generateUUID) {
|
||||
this.toEnrich=toEnrich;
|
||||
this.enriched=castMeta(toEnrich);
|
||||
if(generateUUID){
|
||||
enriched.setFileIdentifier(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
if(enriched.getIdentificationInfo().isEmpty()){
|
||||
ident=new DefaultDataIdentification();
|
||||
enriched.getIdentificationInfo().add(ident);
|
||||
}else ident=new DefaultDataIdentification((DataIdentification)enriched.getIdentificationInfo().iterator().next());
|
||||
|
||||
}
|
||||
|
||||
public void addPreview(String previewURL){
|
||||
try{
|
||||
ident.getGraphicOverviews().add(new DefaultBrowseGraphic(new URI(previewURL)));
|
||||
}catch(URISyntaxException e){
|
||||
String msg="Unable to set preview, passed URI is "+previewURL+", cause : "+e.getMessage();
|
||||
logger.warn(msg);
|
||||
messages.add(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void setdistributionURIs(List<String> uris){
|
||||
DefaultDistribution distribution=new DefaultDistribution();
|
||||
|
||||
DefaultDigitalTransferOptions transferOptions=new DefaultDigitalTransferOptions();
|
||||
for(String uri:uris)
|
||||
try{
|
||||
transferOptions.getOnLines().add(new DefaultOnlineResource(new URI(uri)));
|
||||
}catch(URISyntaxException e){
|
||||
String msg="Unable to set transfer option, passed URI is "+uri+", cause : "+e.getMessage();
|
||||
logger.warn(msg);
|
||||
messages.add(msg);
|
||||
}
|
||||
distribution.getTransferOptions().add(transferOptions);
|
||||
enriched.setDistributionInfo(distribution);
|
||||
}
|
||||
|
||||
public void addDate(Date toAdd,DateType type){
|
||||
DefaultCitationDate publishDate=new DefaultCitationDate(toAdd, type);
|
||||
if(ident.getCitation()==null){
|
||||
DefaultCitation citation=new DefaultCitation();
|
||||
citation.getDates().add(publishDate);
|
||||
}else ((Collection<CitationDate>)ident.getCitation().getDates()).add((CitationDate)publishDate);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public DefaultMetadata getEnriched() {
|
||||
return enriched;
|
||||
}
|
||||
public Metadata getToEnrich() {
|
||||
return toEnrich;
|
||||
}
|
||||
public ArrayList<String> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
private static final DefaultMetadata castMeta(Metadata meta){
|
||||
if(meta.getClass().isAssignableFrom(DefaultMetadata.class))
|
||||
return (DefaultMetadata)meta;
|
||||
else return new DefaultMetadata(meta);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.gcube.spatial.data.gis.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.geotoolkit.metadata.iso.DefaultMetadata;
|
||||
|
||||
public class EnrichmentResponse {
|
||||
|
||||
private DefaultMetadata enrichedMeta;
|
||||
private DefaultMetadata passedMeta;
|
||||
private ArrayList<String> warnMessages=new ArrayList<String>();
|
||||
|
||||
public EnrichmentResponse(DefaultMetadata passed) {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public DefaultMetadata getEnrichedMeta() {
|
||||
return enrichedMeta;
|
||||
}
|
||||
public void setEnrichedMeta(DefaultMetadata enrichedMeta) {
|
||||
this.enrichedMeta = enrichedMeta;
|
||||
}
|
||||
public DefaultMetadata getPassedMeta() {
|
||||
return passedMeta;
|
||||
}
|
||||
public ArrayList<String> getWarnMessages() {
|
||||
return warnMessages;
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|||
public class InfrastructureCrawler {
|
||||
|
||||
|
||||
public static List<GeoServerDescriptor> queryforGeoServer() throws Exception{
|
||||
public static List<GeoServerDescriptor> queryforGeoServer(){
|
||||
List<GeoServerDescriptor> toReturn=new ArrayList<GeoServerDescriptor>();
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
package org.gcube.spatial.data.gis.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.geotoolkit.metadata.iso.DefaultMetadata;
|
||||
import org.opengis.metadata.Metadata;
|
||||
|
||||
public class PublishResponse {
|
||||
|
||||
public static enum PublishedState{
|
||||
COMPLETE,ERROR,WARN
|
||||
}
|
||||
|
||||
private Metadata passedMetadata;
|
||||
private Metadata publishedMetadata;
|
||||
private PublishedState dataPublishResult=PublishedState.ERROR;
|
||||
private PublishedState metaPublishResult=PublishedState.ERROR;
|
||||
private ArrayList<String> dataPublishMessages=new ArrayList<String>();
|
||||
private ArrayList<String> metaPublishMessages=new ArrayList<String>();
|
||||
private long returnedMetaId;
|
||||
|
||||
public PublishResponse() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public PublishResponse(Metadata passedMetadata){
|
||||
setPassedMetadata(passedMetadata);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the passedMetadata
|
||||
*/
|
||||
public Metadata getPassedMetadata() {
|
||||
return passedMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param passedMetadata the passedMetadata to set
|
||||
*/
|
||||
public void setPassedMetadata(Metadata passedMetadata) {
|
||||
this.passedMetadata = new DefaultMetadata(passedMetadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the publishedMetadata
|
||||
*/
|
||||
public Metadata getPublishedMetadata() {
|
||||
return publishedMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param publishedMetadata the publishedMetadata to set
|
||||
*/
|
||||
public void setPublishedMetadata(Metadata publishedMetadata) {
|
||||
this.publishedMetadata = publishedMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dataPublishResult
|
||||
*/
|
||||
public PublishedState getDataPublishResult() {
|
||||
return dataPublishResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataPublishResult the dataPublishResult to set
|
||||
*/
|
||||
public void setDataPublishResult(PublishedState dataPublishResult) {
|
||||
this.dataPublishResult = dataPublishResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the metaPublishResult
|
||||
*/
|
||||
public PublishedState getMetaPublishResult() {
|
||||
return metaPublishResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param metaPublishResult the metaPublishResult to set
|
||||
*/
|
||||
public void setMetaPublishResult(PublishedState metaPublishResult) {
|
||||
this.metaPublishResult = metaPublishResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dataPublishMessages
|
||||
*/
|
||||
public ArrayList<String> getDataPublishMessages() {
|
||||
return dataPublishMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataPublishMessages the dataPublishMessages to set
|
||||
*/
|
||||
public void setDataPublishMessages(ArrayList<String> dataPublishMessages) {
|
||||
this.dataPublishMessages = dataPublishMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the metaPublishMessages
|
||||
*/
|
||||
public ArrayList<String> getMetaPublishMessages() {
|
||||
return metaPublishMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param metaPublishMessages the metaPublishMessages to set
|
||||
*/
|
||||
public void setMetaPublishMessages(ArrayList<String> metaPublishMessages) {
|
||||
this.metaPublishMessages = metaPublishMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the returnedMetaId
|
||||
*/
|
||||
public long getReturnedMetaId() {
|
||||
return returnedMetaId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param returnedMetaId the returnedMetaId to set
|
||||
*/
|
||||
public void setReturnedMetaId(long returnedMetaId) {
|
||||
this.returnedMetaId = returnedMetaId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue