This commit is contained in:
Fabio Sinibaldi 2021-04-08 16:15:05 +02:00
parent 096165d7f2
commit 13df103c93
12 changed files with 69 additions and 103 deletions

View File

@ -44,6 +44,9 @@
<module>sdi-interface</module>
<module>sdi-test-commons</module>
<!-- INSPIRE Validator -->
<!-- <module>inspire-validator</module> -->
<!-- client -->
<module>sdi-library</module>

View File

@ -20,7 +20,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-smartgears-bom</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>

View File

@ -24,47 +24,6 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GeoNetworkRetriever extends AbstractISModule{
// @Override
// public GeoNetworkDescriptor getObject() throws ConfigurationNotFoundException {
// //TODO skip library
// //TODO use both GCoreEndpoints and ServiceEndpoint
//
//
//// log.info("Gathering geonetwork information under scope {} ",ScopeUtils.getCurrentScope());
//// LocalConfiguration config=LocalConfiguration.get();
//// String category=config.getProperty(LocalConfiguration.GEONETWORK_SE_CATEGORY);
//// String platformName=config.getProperty(LocalConfiguration.GEONETWORK_SE_PLATFORM);
//// String priorityProperty=config.getProperty(LocalConfiguration.GEONETWORK_SE_PRIORITY);
//// String endpointName=config.getProperty(LocalConfiguration.GEONETWORK_SE_ENDPOINT_NAME);
//// ServiceEndpoint se=getTheRightServiceEndpoint(ISUtils.queryForServiceEndpoints(category, platformName), endpointName, priorityProperty);
//// AccessPoint access=getTheRightAccessPoint(se, endpointName, priorityProperty);
////
//
// try{
// //INIT LIB
// GISInterface gis=GISInterface.get();
// GeoNetworkAdministration gnAdmin=(GeoNetworkAdministration) gis.getGeoNewtorkPublisher();
// Configuration config=gnAdmin.getConfiguration();
//
// Version version=config.getGeoNetworkVersion().equals(ServerAccess.Version.TRE)?new Version(3,0,0):new Version(2,6,0);
// String baseEndpoint=config.getGeoNetworkEndpoint();
// ScopeConfiguration scopeConfig=config.getScopeConfiguration();
// List<Credentials> accessibleCredentials=new ArrayList();
// for(Account acc: scopeConfig.getAccounts().values()){
// accessibleCredentials.add(fromGeoNetworkAccount(acc));
// }
//
// Credentials adminCredentials=fromGeoNetworkAccount(config.getAdminAccount());
// // GN Lib doesn't expose ADMIN account type
// adminCredentials.setAccessType(AccessType.ADMIN);
// accessibleCredentials.add(adminCredentials);
// return new GeoNetworkDescriptor(version, baseEndpoint, accessibleCredentials, scopeConfig.getPrivateGroup()+"", scopeConfig.getPublicGroup()+"", "3");
// }catch(Exception e){
// log.warn("Unable to gather geonetwork information",e);
// throw new ConfigurationNotFoundException("Unable to gather information on geonetwork. Please contact administrator.",e);
// }
// }
protected static final Credentials fromGeoNetworkAccount(Account toTranslate){
@ -189,7 +148,7 @@ public class GeoNetworkRetriever extends AbstractISModule{
GeoNetworkServiceDefinition gnDefinition=(GeoNetworkServiceDefinition) definition;
AccessPoint point=new AccessPoint();
point.address("http://"+definition.getHostname()+"/geonetwork");
point.address("https://"+definition.getHostname()+"/geonetwork");
point.credentials(ISUtils.encryptString(definition.getAdminPassword()), "admin");
point.description("Main Access point");
point.name(getServiceEndpointAccessPointName());

View File

@ -164,8 +164,7 @@ public class ThreddsRetriever extends AbstractISModule {
}
}catch(IOException e) {
String msg="Unable to check thredds instance hosted on "+hostname;
log.warn(msg);
log.debug("Exception was ",e);
log.warn(msg,e);
toReturn.add(new Status(msg,Level.WARNING));
// } catch (DataTransferException e) {
// String msg="DataTransfer not found in host "+hostname;

View File

@ -50,6 +50,15 @@ public class MetadataHandler {
}
public String initUUID() throws SAXException, IOException {
return setUUID(UUID.randomUUID().toString());
}
public String setUUID(String uuid) throws SAXException, IOException {
MetadataUtils.addContent("gmd:MD_Metadata",document,String.format(CommonMetadataPieces.fileIdentifier, metaUUID),helper,MetadataUtils.Position.first_child);
return getUUID();
}
public String getUUID() throws SAXException, IOException{
//Set | get meta UUID
if(metaUUID==null){
@ -57,14 +66,11 @@ public class MetadataHandler {
List<String> metaUUIDList=helper.evaluate("//gmd:fileIdentifier/gco:CharacterString/text()");
if(metaUUIDList.isEmpty()){
metaUUID=UUID.randomUUID().toString();
log.debug("Stting uuid {} ",metaUUID);
MetadataUtils.addContent("gmd:MD_Metadata",document,String.format(CommonMetadataPieces.fileIdentifier, metaUUID),helper,MetadataUtils.Position.first_child);
}else {
if(!metaUUIDList.isEmpty()) {
metaUUID=metaUUIDList.get(0);
log.debug("Found meta UUID {} ",metaUUID);
log.debug("Found meta UUID {} ",metaUUID);
}
}
return metaUUID;
}

View File

@ -100,7 +100,7 @@ public class MetadataTemplateManagerImpl implements TemplateManager {
cfg.setLogTemplateExceptions(false);
// availableTemplates.add(new TemplateDescriptor("THREDDS-ONLINE", "Thredds online resources", "Template for online resources exposed by thredds.", "http://sdi-d4s.d4science.org"));
//availableTemplates.add(new TemplateDescriptor("THREDDS-ONLINE", "Thredds online resources", "Template for online resources exposed by thredds.", "..."));
ThreddsOnlineTemplate tpl=new ThreddsOnlineTemplate();

View File

@ -32,7 +32,8 @@ public class ThreddsOnlineTemplate extends AbstractMetadataTemplate<ThreddsOnlin
EXPECTED_PARAMETERS.add(new ParameterType(TemplateInvocationBuilder.THREDDS_ONLINE.FILENAME, "The dataset's file name"));
EXPECTED_PARAMETERS.add(new ParameterType(TemplateInvocationBuilder.THREDDS_ONLINE.HOSTNAME, "Thredds hostname"));
DESCRIPTOR=new TemplateDescriptor(TEMPLATE_ID, TEMPLATE_NAME, "Template for online resources exposed by thredds.", "http://sdi-d4s.d4science.org",EXPECTED_PARAMETERS);
DESCRIPTOR=new TemplateDescriptor(TEMPLATE_ID, TEMPLATE_NAME, "Template for online resources exposed by thredds.",
"https://sdi.d4science.org",EXPECTED_PARAMETERS);
}

View File

@ -110,29 +110,35 @@ public class Metadata {
@QueryParam(ServiceConstants.Metadata.STYLESHEET_PARAMETER) @DefaultValue("_none_") String styleSheet,
@PathParam("gnCategory") String category, @PathParam("uploadedId") String uploadedId){
try{
log.debug("PUBLISHING METADATA. UPLOADED ID {} ",uploadedId);
log.info("PUBLISHING METADATA. UPLOADED ID {} ",uploadedId);
MetadataReport toReturn=new MetadataReport();
File toPublish=persistence.getById(uploadedId);
log.debug("Publishing metadata.. ");
GeoNetworkDescriptor desc=geonetworkManager.getSuggestedInstances().get(0);
GeoNetworkClient client=geonetworkManager.getClient(desc);
log.info("GN IS {} ",client);
String uuid=new MetadataHandler(toPublish).getUUID();
// IF HAS UUID CHECK IF EXISTS OTHERWISE PUSH IT
long id=0;
try {
id=client.insertMetadata(category,styleSheet,validate,Integer.parseInt(desc.getDefaultGroup()),makePublic,toPublish);
}catch(Exception e) {
log.info("INSERT OPERATION FAILED. TRYING TO UPDATE.");
try{
MetadataHandler handler=new MetadataHandler(toPublish);
String uuid=handler.getUUID();
if(uuid!=null) {
log.info("Found UUID {} in upload ID {}. Checking if exists ",uuid,uploadedId);
try {
id=GeoNetworkUtils.getIDByUUID(client, uuid);
log.info("Updateing ID {}, UUID {}",id,uuid);
client.updateMeta(id, toPublish);
}catch(MetadataNotFoundException e1) {
throw new RuntimeException("Insert Operation failed with unexpected reason (Metadata with uuid "+uuid+" has not been found).",e);
}
log.debug("Metadata not found [UUID :{} ]",uuid,e1);
}
}else {
// uuid=handler.initUUID();
}
if(id==0) {
log.info("Inserting UUID {}",uuid);
id=client.insertMetadata(category,styleSheet,validate,Integer.parseInt(desc.getDefaultGroup()),makePublic,toPublish);
}
toReturn.setPublishedID(id);
toReturn.setPublishedUUID(uuid);
return toReturn;

View File

@ -84,7 +84,7 @@
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://${hostname}/thredds/dodsC/${cataloguedPath}</gmd:URL>
<gmd:URL>https://${hostname}/thredds/dodsC/${cataloguedPath}</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gco:CharacterString>WWW:LINK-1.0-http--link</gco:CharacterString>
@ -101,7 +101,7 @@
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://${hostname}/thredds/ncss/${cataloguedPath}</gmd:URL>
<gmd:URL>https://${hostname}/thredds/ncss/${cataloguedPath}</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gco:CharacterString>WWW:LINK-1.0-http--link</gco:CharacterString>
@ -118,7 +118,7 @@
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://${hostname}/thredds/wcs/${cataloguedPath}?service=wcs&amp;version=1.0.0&amp;request=GetCoverage&amp;coverage=${layername}&amp;CRS=EPSG:4326&amp;format=geotiff</gmd:URL>
<gmd:URL>https://${hostname}/thredds/wcs/${cataloguedPath}?service=wcs&amp;version=1.0.0&amp;request=GetCoverage&amp;coverage=${layername}&amp;CRS=EPSG:4326&amp;format=geotiff</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gco:CharacterString>OGC:WCS-1.0.0-http-get-coverage</gco:CharacterString>
@ -135,7 +135,7 @@
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://${hostname}/thredds/wms/${cataloguedPath}</gmd:URL>
<gmd:URL>https://${hostname}/thredds/wms/${cataloguedPath}</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gco:CharacterString>OGC:WMS-1.3.0-http-get-map</gco:CharacterString>
@ -152,7 +152,7 @@
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://${hostname}/thredds/fileServer/${cataloguedPath}</gmd:URL>
<gmd:URL>https://${hostname}/thredds/fileServer/${cataloguedPath}</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gco:CharacterString>WWW:LINK-1.0-http--link</gco:CharacterString>
@ -169,7 +169,7 @@
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://${hostname}/thredds/ncml/${cataloguedPath}</gmd:URL>
<gmd:URL>https://${hostname}/thredds/ncml/${cataloguedPath}</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gco:CharacterString>WWW:LINK-1.0-http--link</gco:CharacterString>
@ -187,7 +187,7 @@
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://${hostname}/thredds/uddc/${cataloguedPath}</gmd:URL>
<gmd:URL>https://${hostname}/thredds/uddc/${cataloguedPath}</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gco:CharacterString>WWW:LINK-1.0-http--link</gco:CharacterString>

View File

@ -2,6 +2,7 @@ package org.gcube.spatial.data.sdi.test;
import static org.junit.Assume.assumeTrue;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Paths;
@ -43,6 +44,18 @@ public class MainTest extends ServiceTest{
path("configuration/"+hostname).request(MediaType.APPLICATION_JSON_TYPE).get(String.class));
}
@Test
public void testHealthReport() {
assumeTrue(isTestInfrastructureEnabled());
System.out.println(target(ServiceConstants.INTERFACE).path("status").request(MediaType.APPLICATION_JSON_TYPE).get(String.class));
System.out.println(target(ServiceConstants.INTERFACE).path("status").request(MediaType.APPLICATION_XML_TYPE).get(String.class));
}
// *********** METADATA
@Test
public void testGetTemplateList(){
assumeTrue(isTestInfrastructureEnabled());
@ -53,27 +66,6 @@ public class MainTest extends ServiceTest{
System.out.println(result);
}
@Test
public void testHealthReport() {
assumeTrue(isTestInfrastructureEnabled());
System.out.println(target(ServiceConstants.INTERFACE).path("status").request(MediaType.APPLICATION_JSON_TYPE).get(String.class));
System.out.println(target(ServiceConstants.INTERFACE).path("status").request(MediaType.APPLICATION_XML_TYPE).get(String.class));
}
@Test
public void publishMetadata() {
assumeTrue(isTestInfrastructureEnabled());
// push
}
// private void publishMetadataFile(File toPublish) {
// TemplateInvocationBuilder builder=new TemplateInvocationBuilder();
// builder.threddsOnlineResources("localhost", "someFileName.sc", "newCatalog");
// TemplateApplicationReport report=manager.applyMetadataTemplates(Paths.get("src/test/resources/xml/toEnrichMetadata.xml").toFile(), builder.get());
// System.out.println(report);
// }
}

View File

@ -3,20 +3,24 @@ package org.gcube.spatial.data.sdi.test;
import static org.junit.Assume.assumeTrue;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Response;
import org.gcube.data.transfer.library.client.AuthorizationFilter;
import org.gcube.sdi.test.GCubeSDITest;
import org.gcube.spatial.data.sdi.SDIService;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.BeforeClass;
public class ServiceTest extends JerseyTest {
// @BeforeClass
// public static void init() throws MalformedURLException {
// LocalConfiguration.init(Paths.get("src/main/webapp/WEB-INF/config.properties").toUri().toURL());
// }
protected static 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)));
}
}
@Override
@ -30,6 +34,7 @@ public class ServiceTest extends JerseyTest {
// TODO Auto-generated method stub
super.configureClient(config);
config.register(MultiPartFeature.class);
config.register(AuthorizationFilter.class);
}

View File

@ -18,12 +18,7 @@ public class TestCreateCatalog {
// ThreddsManager mng=new ThreddsManagerFactory().provide();
/*
* "PUT /sdi-service/gcube/service/Thredds?
* name=Thredds+Root+Catalog&
* path=public/netcdf/syncfolderfrancesco&
* folder=public/netcdf/syncfolderfrancesco HTTP/1.1" 1057 Jersey/2.13 (HttpUrlConnection 1.8.0_131)
*/
String baseName="ThreddsRootCatalog";