git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/spatial-data/sdi-library@181731 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Fabio Sinibaldi 2019-09-18 15:00:05 +00:00
parent 5c3010d4a1
commit e08dab963e
7 changed files with 290 additions and 28 deletions

14
pom.xml
View File

@ -3,11 +3,11 @@
<parent>
<groupId>org.gcube.tools</groupId>
<artifactId>maven-parent</artifactId>
<version>LATEST</version>
<version>1.1.0-SNAPSHOT</version>
</parent>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>sdi-library</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.2-SNAPSHOT</version>
<name>SDI Library</name>
<description>Client library to interact with gCube SDI Service</description>
@ -66,15 +66,21 @@
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.22.2</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22.2</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>

View File

@ -10,15 +10,16 @@ import org.gcube.common.clients.delegates.ProxyDelegate;
import org.gcube.spatial.data.sdi.interfaces.Metadata;
import org.gcube.spatial.data.sdi.model.metadata.MetadataPublishOptions;
import org.gcube.spatial.data.sdi.model.metadata.MetadataReport;
import org.gcube.spatial.data.sdi.model.metadata.TemplateCollection;
import org.gcube.spatial.data.sdi.model.metadata.TemplateDescriptor;
public class SDIClient implements Metadata{
@Override
public Set<TemplateDescriptor> getAvailableTemplates() {
// TODO Auto-generated method stub
return null;
}
// @Override
// public Set<TemplateDescriptor> getAvailableTemplates() {
// // TODO Auto-generated method stub
// return null;
// }
@Override
public MetadataReport pushMetadata(File toPublish) {
@ -38,4 +39,10 @@ public class SDIClient implements Metadata{
this.delegate = new AsyncProxyDelegate<WebTarget>(config);
}
@Override
public TemplateCollection getAvailableTemplates() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -36,7 +36,9 @@ public class MetadataPlugin extends SDIAbstractPlugin<WebTarget, Metadata>{
Node node =result.getNode();
Node child=node.getFirstChild();
String address = child.getTextContent();
GcubeService service = GcubeService.service().withName(new QName(ServiceConstants.NAMESPACE,ServiceConstants.Metadata.INTERFACE)).andPath(ServiceConstants.Metadata.INTERFACE);
GcubeService service = GcubeService.service().
withName(new QName(ServiceConstants.NAMESPACE,ServiceConstants.Metadata.INTERFACE)).
andPath(ServiceConstants.Metadata.INTERFACE);
return TargetFactory.stubFor(service).at(address);
}

View File

@ -1,9 +1,10 @@
package org.gcube.spatial.data.sdi.proxies;
import java.io.File;
import java.lang.reflect.GenericArrayType;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
@ -15,43 +16,130 @@ import org.gcube.spatial.data.sdi.interfaces.Metadata;
import org.gcube.spatial.data.sdi.model.ServiceConstants;
import org.gcube.spatial.data.sdi.model.metadata.MetadataPublishOptions;
import org.gcube.spatial.data.sdi.model.metadata.MetadataReport;
import org.gcube.spatial.data.sdi.model.metadata.SetWrapper;
import org.gcube.spatial.data.sdi.model.metadata.TemplateCollection;
import org.gcube.spatial.data.sdi.model.metadata.TemplateDescriptor;
import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocation;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
public class DefaultMetadata implements Metadata{
private final ProxyDelegate<WebTarget> delegate;
public DefaultMetadata(ProxyDelegate<WebTarget> config){
this.delegate = config;
}
@Override
public Set<TemplateDescriptor> getAvailableTemplates() {
public TemplateCollection getAvailableTemplates() {
Call<WebTarget, Set<TemplateDescriptor>> call = new Call<WebTarget, Set<TemplateDescriptor>>() {
@Override
public Set<TemplateDescriptor> call(WebTarget templates) throws Exception {
return templates.path(ServiceConstants.Metadata.LIST_METHOD).request(MediaType.APPLICATION_JSON).get(SetWrapper.class).getSet();
GenericType<Set<TemplateDescriptor>> generic=new GenericType<Set<TemplateDescriptor>>() {
};
return templates.path(ServiceConstants.Metadata.LIST_METHOD).request(MediaType.APPLICATION_JSON).get(generic);
}
};
try {
return delegate.make(call);
return new TemplateCollection(new HashSet<TemplateDescriptor>(delegate.make(call)));
}catch(Exception e) {
throw new RuntimeException(e);
}
}
@Override
public MetadataReport pushMetadata(File toPublish) {
// TODO Auto-generated method stub
return null;
return pushMetadata(toPublish, new MetadataPublishOptions());
}
@Override
public MetadataReport pushMetadata(File toPublish, MetadataPublishOptions options) {
// TODO Auto-generated method stub
return null;
public MetadataReport pushMetadata(final File toPublish, final MetadataPublishOptions options) {
// upload Meta
Call<WebTarget,MetadataReport> applyTemplatesCall=null; //needs uploaded id
Call<WebTarget,MetadataReport> publishCall=null; //needs uploaded id
try{
Call<WebTarget,String> uploadCall=new Call<WebTarget, String>() {
@Override
public String call(WebTarget endpoint) throws Exception {
endpoint.register(MultiPartFeature.class);
FormDataMultiPart multi=new FormDataMultiPart();
// multi.field("file",toPublish,MediaType.APPLICATION_OCTET_STREAM_TYPE);
FileDataBodyPart fileDataBodyPart = new FileDataBodyPart(ServiceConstants.Metadata.UPLOADED_FILE_PARAMETER,
toPublish,MediaType.APPLICATION_OCTET_STREAM_TYPE);
multi.bodyPart(fileDataBodyPart);
Response resp= endpoint.request().post(Entity.entity(multi, multi.getMediaType()));
checkResponse(resp);
return resp.readEntity(String.class);
}
};
final String id=delegate.make(uploadCall);
applyTemplatesCall=new Call<WebTarget, MetadataReport>() {
@Override
public MetadataReport call(WebTarget endpoint) throws Exception {
Response resp= endpoint.path(id).
request(MediaType.APPLICATION_JSON).put(Entity.entity(
new HashSet<TemplateInvocation>(options.getTemplateInvocations()),MediaType.APPLICATION_JSON));
checkResponse(resp);
return resp.readEntity(MetadataReport.class);
}
};
publishCall=new Call<WebTarget,MetadataReport>(){
@Override
public MetadataReport call(WebTarget endpoint) throws Exception {
Response resp= endpoint.path(ServiceConstants.Metadata.PUBLISH_METHOD).path(id).path(options.getGeonetworkCategory()).
queryParam(ServiceConstants.Metadata.VALIDATE_PARAMETER, options.isValidate()).
queryParam(ServiceConstants.Metadata.PUBLIC_PARAMETER, options.isMakePublic()).
queryParam(ServiceConstants.Metadata.STYLESHEET_PARAMETER, options.getGeonetworkStyleSheet()).
request(MediaType.APPLICATION_JSON).get();
checkResponse(resp);
return resp.readEntity(MetadataReport.class);
}
};
}catch(Throwable t){
throw new RuntimeException("Unable to upload file.",t);
}
//APPLY TEMPLATES
MetadataReport templateReport =null;
try{
if(!options.getTemplateInvocations().isEmpty())
templateReport=delegate.make(applyTemplatesCall);
}catch(Throwable t){
throw new RuntimeException("Unable to apply templates",t);
}
//PUBLISH
try{
MetadataReport publishReport=delegate.make(publishCall);
if(templateReport!=null) publishReport.setAppliedTemplates(templateReport.getAppliedTemplates());
return publishReport;
}catch(Throwable t){
throw new RuntimeException("Unable to publish metadata. ",t);
}
}
protected void checkResponse(Response toCheck) throws Exception{
switch(toCheck.getStatusInfo().getFamily()){
case SUCCESSFUL : break;
default : throw new Exception("Unexpected Response code : "+toCheck.getStatus(),new Exception(toCheck.readEntity(String.class)));
}
}
}

View File

@ -1,16 +1,46 @@
package org.gcube.spatial.data.sdi;
import org.gcube.spatial.data.sdi.interfaces.*;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import org.gcube.spatial.data.sdi.interfaces.Metadata;
import org.gcube.spatial.data.sdi.model.metadata.MetadataPublishOptions;
import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocationBuilder;
import org.gcube.spatial.data.sdi.plugins.SDIAbstractPlugin;
import org.junit.Before;
import org.junit.Test;
public class MetadataTests {
@Test
public void getAvailableTemplatesTest(){
@Before
public void setScope(){
// TokenSetter.set("/pred4s/preprod/preVRE");
TokenSetter.set("/gcube/devsec/devVRE");
Metadata meta=SDIAbstractPlugin.metadata().build();
System.out.println(meta.getAvailableTemplates());
}
@Test
public void getAvailableTemplatesTest() throws IllegalArgumentException, URISyntaxException{
Metadata meta=SDIAbstractPlugin.metadata().at(new URI("http://sdi-d-d4s.d4science.org/sdi-service/gcube/service")).build();
System.out.println(meta.getAvailableTemplates());
}
@Test
public void pushMetadata() throws IllegalArgumentException, URISyntaxException{
File toPubilsh=Paths.get("src/test/resources/toEnrichMeta.xml").toFile();
Metadata meta=SDIAbstractPlugin.metadata().at(new URI("http://sdi-d-d4s.d4science.org/sdi-service/gcube/service")).build();
System.out.println(meta.pushMetadata(toPubilsh));
MetadataPublishOptions opts=new MetadataPublishOptions(new TemplateInvocationBuilder().threddsOnlineResources("my_hostname", "some_dataset.nc", "myPersonalCatalog").get());
opts.setGeonetworkCategory("service");
opts.setValidate(false);
System.out.println(meta.pushMetadata(toPubilsh, opts));
}
}

View File

@ -0,0 +1,10 @@
package org.gcube.spatial.data.sdi.utils;
public class RegisterGN {
public static void main(String[] args) {
// Get definition
// push to service
}
}

View File

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gmd:MD_Metadata xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmi="http://www.isotc211.org/2005/gmi" xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:xlink="http://www.w3.org/1999/xlink">
<gmd:hierarchyLevel>
<gmd:MD_ScopeCode codeList="http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#MD_ScopeCode" codeListValue="dataset">Dataset</gmd:MD_ScopeCode>
</gmd:hierarchyLevel>
<gmd:contact>
<gmd:CI_ResponsibleParty>
<gmd:organisationName>
<gco:CharacterString>CNR</gco:CharacterString>
</gmd:organisationName>
<gmd:role>
<gmd:CI_RoleCode codeList="http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#CI_RoleCode" codeListValue="pointOfContact">Point of contact</gmd:CI_RoleCode>
</gmd:role>
</gmd:CI_ResponsibleParty>
</gmd:contact>
<gmd:metadataStandardName>
<gco:CharacterString>Geographic Information — Metadata Part 1: Fundamentals</gco:CharacterString>
</gmd:metadataStandardName>
<gmd:metadataStandardVersion>
<gco:CharacterString>ISO 19115-1:2014(E)</gco:CharacterString>
</gmd:metadataStandardVersion>
<gmd:spatialRepresentationInfo>
<gmd:MD_GridSpatialRepresentation>
<gmd:numberOfDimensions>
<gco:Integer>4</gco:Integer>
</gmd:numberOfDimensions>
<gmd:axisDimensionProperties>
<gmd:MD_Dimension>
<gmd:dimensionSize>
<gco:Integer>721</gco:Integer>
</gmd:dimensionSize>
</gmd:MD_Dimension>
</gmd:axisDimensionProperties>
<gmd:axisDimensionProperties>
<gmd:MD_Dimension>
<gmd:dimensionSize>
<gco:Integer>361</gco:Integer>
</gmd:dimensionSize>
</gmd:MD_Dimension>
</gmd:axisDimensionProperties>
<gmd:axisDimensionProperties>
<gmd:MD_Dimension>
<gmd:dimensionSize>
<gco:Integer>11</gco:Integer>
</gmd:dimensionSize>
</gmd:MD_Dimension>
</gmd:axisDimensionProperties>
<gmd:axisDimensionProperties>
<gmd:MD_Dimension>
<gmd:dimensionSize>
<gco:Integer>1</gco:Integer>
</gmd:dimensionSize>
</gmd:MD_Dimension>
</gmd:axisDimensionProperties>
<gmd:cellGeometry>
<gmd:MD_CellGeometryCode codeList="http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#MD_CellGeometryCode" codeListValue="area">Area</gmd:MD_CellGeometryCode>
</gmd:cellGeometry>
<gmd:transformationParameterAvailability>
<gco:Boolean>false</gco:Boolean>
</gmd:transformationParameterAvailability>
</gmd:MD_GridSpatialRepresentation>
</gmd:spatialRepresentationInfo>
<gmd:identificationInfo>
<gmd:MD_DataIdentification>
<gmd:citation>
<gmd:CI_Citation>
<gmd:title>
<gco:CharacterString>NetCDF of ARGO data aggregated at .25 degrees - produced by D4Science through the DataMiner platform</gco:CharacterString>
</gmd:title>
<gmd:citedResponsibleParty>
<gmd:CI_ResponsibleParty>
<gmd:organisationName>
<gco:CharacterString>CNR</gco:CharacterString>
</gmd:organisationName>
<gmd:role>
<gmd:CI_RoleCode codeList="http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#CI_RoleCode" codeListValue="originator">Originator</gmd:CI_RoleCode>
</gmd:role>
</gmd:CI_ResponsibleParty>
</gmd:citedResponsibleParty>
<gmd:otherCitationDetails>
<gco:CharacterString>Paolo Scarponi - scarponi@isti.cnr.it; Gianpaolo Coro - coro@isti.cnr.it</gco:CharacterString>
</gmd:otherCitationDetails>
</gmd:CI_Citation>
</gmd:citation>
<gmd:pointOfContact>
<gmd:CI_ResponsibleParty>
<gmd:organisationName>
<gco:CharacterString>CNR</gco:CharacterString>
</gmd:organisationName>
<gmd:role>
<gmd:CI_RoleCode codeList="http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#CI_RoleCode" codeListValue="pointOfContact">Point of contact</gmd:CI_RoleCode>
</gmd:role>
</gmd:CI_ResponsibleParty>
</gmd:pointOfContact>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
<gmd:contentInfo>
<gmd:MD_CoverageDescription>
<gmd:dimension>
<gmd:MD_Band>
<gmd:sequenceIdentifier>
<gco:MemberName>
<gco:aName>
<gco:CharacterString>Backscattering</gco:CharacterString>
</gco:aName>
<gco:attributeType>
<gco:TypeName>
<gco:aName>
<gco:CharacterString>double[721][361][11][1]</gco:CharacterString>
</gco:aName>
</gco:TypeName>
</gco:attributeType>
</gco:MemberName>
</gmd:sequenceIdentifier>
</gmd:MD_Band>
</gmd:dimension>
</gmd:MD_CoverageDescription>
</gmd:contentInfo>
</gmd:MD_Metadata>