This commit is contained in:
Fabio Sinibaldi 2013-04-04 14:41:58 +00:00
parent 374e7951fb
commit c85edb4b8c
10 changed files with 256 additions and 186 deletions

View File

@ -1,7 +1,5 @@
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;
@ -10,7 +8,6 @@ import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@ -19,18 +16,17 @@ 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.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.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.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;
import org.gcube.spatial.data.gis.model.report.Report.OperationState;
import org.opengis.metadata.Metadata;
import org.opengis.metadata.citation.DateType;
import org.slf4j.Logger;
@ -92,10 +88,11 @@ public class GISInterface {
GeoServerRESTPublisher publisher=null;
try{
GeoServerDescriptor desc=getGeoServerSet(false).last();
logger.debug("Using "+desc);
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);
toReturn.setDataOperationResult(Report.OperationState.COMPLETE);
ArrayList<String> distributionUris=new ArrayList<String>();
// distributionUris.add(desc.getUrl()+"gwc/service/wms")
@ -103,29 +100,68 @@ public class GISInterface {
enricher.addDate(new Date(System.currentTimeMillis()), DateType.CREATION);
enricher.addPreview(distributionUris.get(0));
enricher.setdistributionURIs(distributionUris);
toReturn.getMetaPublishMessages().addAll(enricher.getMessages());
toReturn.getMetaOperationMessages().addAll(enricher.getMessages());
if(enricher.getMessages().size()>0)toReturn.setMetaOperationResult(OperationState.WARN);
long returnedId=getGN().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.getDataPublishMessages().add("No GeoServer Found under scope "+ScopeProvider.instance.get());
toReturn.getDataOperationMessages().add("No GeoServer Found under scope "+ScopeProvider.instance.get());
} catch (IllegalArgumentException e) {
toReturn.getDataPublishMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
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.getDataPublishMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
toReturn.getDataOperationMessages().add("Unable to instatiate GeoServerRESTPublisher, cause :"+e.getMessage());
} catch (FileNotFoundException e) {
toReturn.getDataPublishMessages().add("Unable to publish data GeoServerRESTPublisher, cause :"+e.getMessage());
toReturn.getDataOperationMessages().add("Unable to publish data, 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
}
toReturn.getMetaOperationMessages().add("Unable to publish metadata, cause :"+e.getMessage());
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()+")");
toReturn.getDataOperationMessages().addAll(delRep.getDataOperationMessages());
}
}
return toReturn;
}
// ********************* DELETE Logic
public DeleteReport deleteStore(String workspace,String storeName,Long metadataUUID){
DeleteReport toReturn=new DeleteReport();
GeoServerRESTPublisher publisher=null;
try{
GeoServerDescriptor desc=getGeoServerSet(false).last();
publisher=getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword()).getPublisher();
boolean removed=publisher.removeDatastore(workspace, storeName,true);
if(removed){
toReturn.setDataOperationResult(Report.OperationState.COMPLETE);
if(metadataUUID!=null){
getGN().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;
}
//************ PRIVATE
private GeoNetworkPublisher geoNetwork=null;

View File

@ -1,4 +1,4 @@
package org.gcube.spatial.data.gis.model;
package org.gcube.spatial.data.gis.is;
public class GeoServerDescriptor implements Comparable<GeoServerDescriptor>{

View File

@ -1,4 +1,4 @@
package org.gcube.spatial.data.gis.model;
package org.gcube.spatial.data.gis.is;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
@ -8,18 +8,23 @@ import java.util.List;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.utils.encryption.StringEncrypter;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.spatial.data.gis.GISInterface;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class InfrastructureCrawler {
final static Logger logger= LoggerFactory.getLogger(InfrastructureCrawler.class);
public static List<GeoServerDescriptor> queryforGeoServer(){
List<GeoServerDescriptor> toReturn=new ArrayList<GeoServerDescriptor>();
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Category/text() eq 'Gis'")
.addCondition("$resource/Profile/Platform/Name/text() eq 'geonetwork'")
.addCondition("$resource/Profile/Platform/Name/text() eq 'GeoServer'")
.setResult("$resource/Profile/AccessPoint");
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
@ -27,7 +32,11 @@ public class InfrastructureCrawler {
List<AccessPoint> accesspoints = client.submit(query);
// if(accesspoints.size()==0) throw new Exception("No Resource found under current scope "+ScopeProvider.instance.get());
for (AccessPoint point : accesspoints) {
toReturn.add(new GeoServerDescriptor(point.address(),point.username(),point.password(),0l));
try{
toReturn.add(new GeoServerDescriptor(point.address(),point.username(),StringEncrypter.getEncrypter().decrypt(point.password()),0l));
}catch(Exception e){
logger.warn("Unable to decript password for "+point.username()+" in access point "+point.address()+", access to modify methods may fail");
}
// url=point.address();
// user=point.username();
// pwd=point.password();

View File

@ -8,7 +8,7 @@ import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.gcube.spatial.data.gis.model.PublishResponse.PublishedState;
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;

View File

@ -0,0 +1,9 @@
package org.gcube.spatial.data.gis.model;
public class Costants {
public static final double[] WORLD_BOUNDING_BOX=new double[]{
-180.0,-90.0,180.0,90.0
};
}

View File

@ -1,29 +0,0 @@
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;
}
}

View File

@ -1,132 +0,0 @@
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;
}
}

View File

@ -0,0 +1,8 @@
package org.gcube.spatial.data.gis.model.report;
public class DeleteReport extends Report {
private String metadataUUID;
}

View File

@ -0,0 +1,86 @@
package org.gcube.spatial.data.gis.model.report;
import org.geotoolkit.metadata.iso.DefaultMetadata;
import org.opengis.metadata.Metadata;
public class PublishResponse extends Report{
private Metadata passedMetadata;
private Metadata publishedMetadata;
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 returnedMetaId
*/
public long getReturnedMetaId() {
return returnedMetaId;
}
/**
* @param returnedMetaId the returnedMetaId to set
*/
public void setReturnedMetaId(long returnedMetaId) {
this.returnedMetaId = returnedMetaId;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("PublishResponse [passedMetadata=");
builder.append(passedMetadata);
builder.append(", publishedMetadata=");
builder.append(publishedMetadata);
builder.append(", returnedMetaId=");
builder.append(returnedMetaId);
builder.append(", report=");
builder.append(super.toString());
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,83 @@
package org.gcube.spatial.data.gis.model.report;
import java.util.ArrayList;
public class Report {
public static enum OperationState{
COMPLETE,ERROR,WARN
}
private Report.OperationState dataOperationResult = Report.OperationState.ERROR;
private Report.OperationState metaOperationResult = Report.OperationState.ERROR;
private ArrayList<String> dataOperationMessages = new ArrayList<String>();
private ArrayList<String> metaOperationMessages = new ArrayList<String>();
/**
* @return the dataOperationResult
*/
public Report.OperationState getDataOperationResult() {
return dataOperationResult;
}
/**
* @param dataOperationResult the dataOperationResult to set
*/
public void setDataOperationResult(Report.OperationState dataOperationResult) {
this.dataOperationResult = dataOperationResult;
}
/**
* @return the metaOperationResult
*/
public Report.OperationState getMetaOperationResult() {
return metaOperationResult;
}
/**
* @param metaOperationResult the metaOperationResult to set
*/
public void setMetaOperationResult(Report.OperationState metaOperationResult) {
this.metaOperationResult = metaOperationResult;
}
/**
* @return the dataOperationMessages
*/
public ArrayList<String> getDataOperationMessages() {
return dataOperationMessages;
}
/**
* @param dataOperationMessages the dataOperationMessages to set
*/
public void setDataOperationMessages(ArrayList<String> dataOperationMessages) {
this.dataOperationMessages = dataOperationMessages;
}
/**
* @return the metaOperationMessages
*/
public ArrayList<String> getMetaOperationMessages() {
return metaOperationMessages;
}
/**
* @param metaOperationMessages the metaOperationMessages to set
*/
public void setMetaOperationMessages(ArrayList<String> metaOperationMessages) {
this.metaOperationMessages = metaOperationMessages;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Report [dataOperationResult=");
builder.append(dataOperationResult);
builder.append(", metaOperationResult=");
builder.append(metaOperationResult);
builder.append(", dataOperationMessages=");
builder.append(dataOperationMessages);
builder.append(", metaOperationMessages=");
builder.append(metaOperationMessages);
builder.append("]");
return builder.toString();
}
}