git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/spatial-data/gis-interface@81693 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3bc82856e8
commit
6dc947cf8a
|
@ -4,7 +4,9 @@ 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;
|
||||
|
@ -67,6 +69,10 @@ 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();
|
||||
}
|
||||
|
||||
|
@ -78,13 +84,18 @@ 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,
|
||||
|
@ -93,9 +104,9 @@ 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);
|
||||
|
@ -130,7 +141,7 @@ public class GISInterface {
|
|||
} catch (Exception e) {
|
||||
// exceptions raised by publishing metadata, need to clean up
|
||||
toReturn.getMetaOperationMessages().add("Unable to publish metadata, cause :"+e.getMessage());
|
||||
DeleteReport delRep=deleteStore(workspace,storeName,null);
|
||||
DeleteReport delRep=deleteStore(workspace,storeName,null,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()+")");
|
||||
|
@ -141,19 +152,102 @@ 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("Using "+desc);
|
||||
try{
|
||||
publisher=getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword()).getPublisher();
|
||||
// Publishing the file to geoserver depends on file type
|
||||
publishResult=publisher.publishDBLayer(workspace, storeName, fte, layerEncoder);
|
||||
|
||||
if(publishResult){
|
||||
toReturn.setDataOperationResult(Report.OperationState.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.getMetaOperationMessages().addAll(enricher.getMessages());
|
||||
if(enricher.getMessages().size()>0)toReturn.setMetaOperationResult(OperationState.WARN);
|
||||
GeoNetworkPublisher pub=getGN();
|
||||
getGN().login(level);
|
||||
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)
|
||||
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 (FileNotFoundException e) {
|
||||
toReturn.getDataOperationMessages().add("Unable to publish data, cause :"+e.getMessage());
|
||||
} catch (Exception e) {
|
||||
// exceptions raised by publishing metadata, need to clean up
|
||||
toReturn.getMetaOperationMessages().add("Unable to publish metadata, cause :"+e.getMessage());
|
||||
DeleteReport delRep=deleteLayer(workspace,fte.getName(),null,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;
|
||||
}
|
||||
|
||||
|
||||
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());
|
||||
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) {
|
||||
// exceptions raised by publishing metadata, need to clean up
|
||||
toReturn.getMetaOperationMessages().add("Unable to publish metadata, cause :"+e.getMessage());
|
||||
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){
|
||||
public DeleteReport deleteStore(String workspace,String storeName,Long metadataUUID,GeoServerDescriptor desc){
|
||||
DeleteReport toReturn=new DeleteReport();
|
||||
GeoServerRESTPublisher publisher=null;
|
||||
try{
|
||||
GeoServerDescriptor desc=getGeoServerSet(false).last();
|
||||
try{
|
||||
publisher=getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword()).getPublisher();
|
||||
boolean removed=publisher.removeDatastore(workspace, storeName,true);
|
||||
if(removed){
|
||||
|
@ -179,6 +273,58 @@ public class GISInterface {
|
|||
return toReturn;
|
||||
}
|
||||
|
||||
public DeleteReport deleteLayer(String workspace,String layerName, Long metadataUUID,GeoServerDescriptor desc){
|
||||
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){
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -25,7 +25,9 @@ public class Range {
|
|||
|
||||
|
||||
|
||||
|
||||
public void setCondition(Condition condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the min
|
||||
|
|
|
@ -135,17 +135,21 @@ 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.less(FF.property(r.getToFilterProperty()), FF.literal(r.getMax())));
|
||||
FF.lessOrEqual(FF.property(r.getToFilterProperty()), FF.literal(r.getMax())));
|
||||
toReturn.setName(r.getToFilterProperty()+" < = "+r.getMin());
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -223,7 +227,7 @@ public class StyleUtils {
|
|||
}
|
||||
|
||||
|
||||
|
||||
toReturn.get(toReturn.size()-1).setCondition(Condition.GREATER_THEN_MIN);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue