Default IS Provider
This commit is contained in:
parent
7c0e615429
commit
3249c7be04
|
@ -0,0 +1,32 @@
|
||||||
|
package org.gcube.application.cms.implementations;
|
||||||
|
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.DatabaseConnection;
|
||||||
|
import org.gcube.application.geoportal.common.utils.ISUtils;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DefaultISProvider implements ISInterface{
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnection queryForDatabase(String category, String platform, String flagName, String flagValue) throws ConfigurationException {
|
||||||
|
return ISUtils.performQueryForDB(category, platform, flagName, flagValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ServiceEndpoint.AccessPoint> performGetAP(String category, String platform, String flagName, String flagValue) {
|
||||||
|
return ISUtils.performGetAP(category, platform, flagName, flagValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String decryptString(String toDecrypt) {
|
||||||
|
return ISUtils.decryptString(toDecrypt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String encryptString(String toEncrypt) {
|
||||||
|
return ISUtils.encryptString(toEncrypt);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,9 +2,14 @@ package org.gcube.application.cms.implementations;
|
||||||
|
|
||||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
import org.gcube.application.geoportal.common.model.rest.DatabaseConnection;
|
import org.gcube.application.geoportal.common.model.rest.DatabaseConnection;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface ISInterface {
|
public interface ISInterface {
|
||||||
|
|
||||||
public DatabaseConnection queryForDatabase(String platform, String flag) throws ConfigurationException;
|
public DatabaseConnection queryForDatabase(String category, String platform,String flagName, String flagValue) throws ConfigurationException;
|
||||||
|
public List<ServiceEndpoint.AccessPoint> performGetAP(String category, String platform, String flagName, String flagValue);
|
||||||
|
public String decryptString(String toDecrypt);
|
||||||
|
public String encryptString(String toEncrypt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,4 +30,9 @@ public class ImplementationProvider {
|
||||||
implementationsRegistry.put(clazz,engine);
|
implementationsRegistry.put(clazz,engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ImplementationProvider(){
|
||||||
|
//Defaults
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,32 @@
|
||||||
package org.gcube.application.cms.plugins.reports;
|
package org.gcube.application.cms.plugins.reports;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.gcube.application.cms.plugins.requests.BaseExecutionRequest;
|
import lombok.Setter;
|
||||||
|
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
|
||||||
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
|
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.spatial.SpatialReference;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.temporal.TemporalReference;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public class IndexDocumentReport extends DocumentHandlingReport<IndexDocumentRequest> {
|
public class IndexDocumentReport extends DocumentHandlingReport<IndexDocumentRequest> {
|
||||||
|
|
||||||
|
public TemporalReference toSetTemporalReference;
|
||||||
|
public SpatialReference toSetSpatialReference;
|
||||||
|
|
||||||
|
|
||||||
public IndexDocumentReport(@NonNull IndexDocumentRequest theRequest) {
|
public IndexDocumentReport(@NonNull IndexDocumentRequest theRequest) {
|
||||||
super(theRequest);
|
super(theRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProfiledDocument prepareResult() throws JsonProcessingException, PluginExecutionException {
|
||||||
|
ProfiledDocument toReturn= super.prepareResult();
|
||||||
|
if(toSetSpatialReference != null) toReturn.setSpatialReference(toSetSpatialReference);
|
||||||
|
if(toSetTemporalReference != null) toReturn.setTemporalReference(toSetTemporalReference);
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,49 +1,34 @@
|
||||||
package org.gcube.application.cms.tests;
|
package org.gcube.application.cms.tests;
|
||||||
|
|
||||||
import ch.qos.logback.core.net.SyslogOutputStream;
|
import org.gcube.application.cms.implementations.ISInterface;
|
||||||
|
import org.gcube.application.cms.implementations.ImplementationProvider;
|
||||||
import org.gcube.application.cms.plugins.InitializablePlugin;
|
import org.gcube.application.cms.plugins.InitializablePlugin;
|
||||||
import org.gcube.application.cms.plugins.MaterializationPlugin;
|
|
||||||
import org.gcube.application.cms.plugins.Plugin;
|
import org.gcube.application.cms.plugins.Plugin;
|
||||||
import org.gcube.application.cms.plugins.PluginsReflections;
|
import org.gcube.application.cms.plugins.PluginsReflections;
|
||||||
import org.gcube.application.cms.plugins.faults.InitializationException;
|
import org.gcube.application.cms.plugins.faults.InitializationException;
|
||||||
import org.gcube.application.cms.plugins.requests.MaterializationRequest;
|
|
||||||
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
|
||||||
import org.reflections.Reflections;
|
|
||||||
import org.reflections.util.ConfigurationBuilder;
|
|
||||||
import org.reflections.util.FilterBuilder;
|
|
||||||
|
|
||||||
import java.rmi.ServerError;
|
import java.util.HashMap;
|
||||||
import java.util.ArrayList;
|
import java.util.Map;
|
||||||
import java.util.List;
|
|
||||||
import java.util.ServiceLoader;
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
|
|
||||||
import static org.junit.Assume.assumeTrue;
|
|
||||||
|
|
||||||
public class BasicPluginTest {
|
public class BasicPluginTest {
|
||||||
|
|
||||||
protected String context;
|
|
||||||
|
|
||||||
|
|
||||||
static List<Plugin> plugins=new ArrayList<>();
|
|
||||||
|
protected static Map<String,Plugin> plugins=new HashMap<>();
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void checkPluginRegistration() {
|
public static void checkPluginRegistration() {
|
||||||
plugins.addAll(PluginsReflections.load().values());
|
plugins.putAll(PluginsReflections.load());
|
||||||
plugins.forEach(plugin -> System.out.println());
|
plugins.forEach((s,p) -> System.out.println(s+" "+p.getDescriptor()));
|
||||||
|
|
||||||
Assert.assertFalse(plugins.isEmpty());
|
Assert.assertFalse(plugins.isEmpty());
|
||||||
System.out.println("Plugin Loading OK");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
plugins.forEach((s,p)->{
|
||||||
public void init(){
|
|
||||||
plugins.forEach(p->{
|
|
||||||
System.out.println("INIT Plugin "+p.getClass());
|
System.out.println("INIT Plugin "+p.getClass());
|
||||||
Assert.assertNotNull(p.getDescriptor());
|
Assert.assertNotNull(p.getDescriptor());
|
||||||
Assert.assertNotNull(p.getDescriptor().getId());
|
Assert.assertNotNull(p.getDescriptor().getId());
|
||||||
|
@ -53,35 +38,24 @@ public class BasicPluginTest {
|
||||||
InitializablePlugin ip=(InitializablePlugin)p;
|
InitializablePlugin ip=(InitializablePlugin)p;
|
||||||
try {
|
try {
|
||||||
ip.init();
|
ip.init();
|
||||||
|
|
||||||
|
if(GCubeTest.isTestInfrastructureEnabled()){
|
||||||
|
TokenSetter.set(GCubeTest.getContext());
|
||||||
|
ip.initInContext();
|
||||||
|
}
|
||||||
} catch (InitializationException e) {
|
} catch (InitializationException e) {
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
Assert.fail("Unable to Init "+p.getDescriptor().getId());
|
Assert.fail("Unable to Init "+p.getDescriptor().getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
System.out.println("Plugin Loading OK");
|
||||||
public void initInContext(){
|
|
||||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
if(GCubeTest.isTestInfrastructureEnabled()){
|
||||||
plugins.forEach(p->{
|
ImplementationProvider.get().setEngine(new ISProvider(), ISInterface.class);
|
||||||
TokenSetter.set(context);
|
}
|
||||||
System.out.println("INIT Plugin "+p.getClass()+" in "+context);
|
|
||||||
Assert.assertNotNull(p.getDescriptor());
|
|
||||||
Assert.assertNotNull(p.getDescriptor().getId());
|
|
||||||
Assert.assertNotNull(p.getDescriptor().getType());
|
|
||||||
Assert.assertNotNull(p.getDescriptor().getVersion());
|
|
||||||
if(p instanceof InitializablePlugin){
|
|
||||||
InitializablePlugin ip=(InitializablePlugin)p;
|
|
||||||
try {
|
|
||||||
ip.initInContext();
|
|
||||||
} catch (InitializationException e) {
|
|
||||||
e.printStackTrace(System.err);
|
|
||||||
Assert.fail("Unable to Init "+p.getDescriptor().getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.gcube.application.cms.tests;
|
||||||
|
|
||||||
|
import org.gcube.application.cms.serialization.Serialization;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||||
|
import org.gcube.application.geoportal.common.model.profile.Profile;
|
||||||
|
import org.gcube.application.geoportal.common.utils.Files;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class TestDocuments {
|
||||||
|
public static File BASE_FOLDER =new File("../test-data/profiledDocuments");
|
||||||
|
public static final HashMap<String, ProfiledDocument> documentMap =new HashMap<>();
|
||||||
|
|
||||||
|
static{
|
||||||
|
|
||||||
|
for(File f:BASE_FOLDER.listFiles()){
|
||||||
|
try {
|
||||||
|
if(!f.isDirectory()) {
|
||||||
|
ProfiledDocument p = Serialization.read(
|
||||||
|
Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset()), ProfiledDocument.class);
|
||||||
|
documentMap.put(f.getName(), p);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Unable to read "+f.getAbsolutePath(),e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -19,8 +19,9 @@ public class TestProfiles {
|
||||||
|
|
||||||
for(File f:BASE_FOLDER.listFiles()){
|
for(File f:BASE_FOLDER.listFiles()){
|
||||||
try {
|
try {
|
||||||
profiles.put(f.getName(), Serialization.read(
|
Profile p =Serialization.read(
|
||||||
Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset()),Profile.class));
|
Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset()),Profile.class);
|
||||||
|
profiles.put(p.getId(), p);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Unable to read "+f.getAbsolutePath(),e);
|
throw new RuntimeException("Unable to read "+f.getAbsolutePath(),e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.gcube.application.geoportal.service.model.internal.db;
|
package org.gcube.application.geoportal.common.model.configuration;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package org.gcube.application.geoportal.common.model.document;
|
package org.gcube.application.geoportal.common.model.document;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.mongodb.client.model.geojson.GeoJsonObjectType;
|
|
||||||
import com.vdurmont.semver4j.Semver;
|
import com.vdurmont.semver4j.Semver;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.gcube.application.geoportal.common.model.document.accounting.PublicationInfo;
|
import org.gcube.application.geoportal.common.model.document.accounting.PublicationInfo;
|
||||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.spatial.SpatialReference;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.temporal.TemporalReference;
|
||||||
|
|
||||||
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@ -52,7 +53,7 @@ public class ProfiledDocument {
|
||||||
|
|
||||||
// Expected GEOJSON
|
// Expected GEOJSON
|
||||||
@JsonProperty(SPATIAL_REFERENCE)
|
@JsonProperty(SPATIAL_REFERENCE)
|
||||||
private Document spatialReference;
|
private SpatialReference spatialReference;
|
||||||
|
|
||||||
@JsonProperty(TEMPORAL_REFERENCE)
|
@JsonProperty(TEMPORAL_REFERENCE)
|
||||||
private TemporalReference temporalReference;
|
private TemporalReference temporalReference;
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
package org.gcube.application.geoportal.common.model.document;
|
|
||||||
|
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@ToString
|
|
||||||
public class TemporalReference {
|
|
||||||
|
|
||||||
private String field;
|
|
||||||
}
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package org.gcube.application.geoportal.common.model.document.spatial;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
|
||||||
|
public class SpatialReference extends Document {
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package org.gcube.application.geoportal.common.model.document.temporal;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import org.bson.Document;
|
||||||
|
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public class TemporalReference extends Document {
|
||||||
|
|
||||||
|
private String field;
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package org.gcube.application.geoportal.common.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import org.gcube.application.geoportal.common.model.configuration.MongoConnection;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.DatabaseConnection;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
|
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||||
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||||
|
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||||
|
|
||||||
|
public class ISUtils {
|
||||||
|
|
||||||
|
|
||||||
|
public static DatabaseConnection performQueryForDB(String category, String platform,String flagName, String flag) throws ConfigurationException {
|
||||||
|
|
||||||
|
List<AccessPoint> found=performGetAP(category,platform, flagName,flag);
|
||||||
|
if(found.size()>1) {
|
||||||
|
throw new ConfigurationException("Multiple SE found ["+found.size()+"] for platform : "+platform+" flag : "+flag);
|
||||||
|
}else if (found.isEmpty()){
|
||||||
|
throw new ConfigurationException("No SE found for platform : "+platform+" flag : "+flag);
|
||||||
|
}
|
||||||
|
AccessPoint point=found.get(0);
|
||||||
|
|
||||||
|
DatabaseConnection toReturn=new DatabaseConnection();
|
||||||
|
toReturn.setPwd(decryptString(point.password()));
|
||||||
|
toReturn.setUser(point.username());
|
||||||
|
toReturn.setUrl(point.address());
|
||||||
|
return toReturn;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static List<AccessPoint> performGetAP(String category,String platform,String flagName,String flagValue) {
|
||||||
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
|
|
||||||
|
query.addCondition("$resource/Profile/Category/text() eq '"+category+"'")
|
||||||
|
.addCondition("$resource/Profile/Platform/Name/text() eq '"+platform+"'")
|
||||||
|
.addCondition("$resource/Profile/AccessPoint//Property[Name/text() eq '"+
|
||||||
|
flagName+"'][Value/text() eq '"+flagValue+"']")
|
||||||
|
.setResult("$resource/Profile/AccessPoint");
|
||||||
|
|
||||||
|
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
||||||
|
return client.submit(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String decryptString(String toDecrypt){
|
||||||
|
try{
|
||||||
|
return StringEncrypter.getEncrypter().decrypt(toDecrypt);
|
||||||
|
}catch(Exception e) {
|
||||||
|
throw new RuntimeException("Unable to decrypt : "+toDecrypt,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String encryptString(String toEncrypt){
|
||||||
|
try{
|
||||||
|
return StringEncrypter.getEncrypter().encrypt(toEncrypt);
|
||||||
|
}catch(Exception e) {
|
||||||
|
throw new RuntimeException("Unable to decrypt : "+toEncrypt,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,7 +37,6 @@ public class GeoPortalService extends ResourceConfig{
|
||||||
|
|
||||||
log.info("Setting implementations .. ");
|
log.info("Setting implementations .. ");
|
||||||
|
|
||||||
ImplementationProvider.get().setEngine(new ISProvider(),ISInterface.class);
|
|
||||||
ImplementationProvider.get().setEngine(new MongoClientProvider(), Mongo.class);
|
ImplementationProvider.get().setEngine(new MongoClientProvider(), Mongo.class);
|
||||||
ImplementationProvider.get().setEngine(new StorageClientProvider(), StorageUtils.class);
|
ImplementationProvider.get().setEngine(new StorageClientProvider(), StorageUtils.class);
|
||||||
ImplementationProvider.get().setEngine(new PostgisConnectionProvider(), PostgisDBManager.class);
|
ImplementationProvider.get().setEngine(new PostgisConnectionProvider(), PostgisDBManager.class);
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.gcube.application.cms.implementations.ImplementationProvider;
|
||||||
import org.gcube.application.geoportal.service.model.internal.db.PostgisTable;
|
import org.gcube.application.geoportal.service.model.internal.db.PostgisTable;
|
||||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
import org.gcube.application.geoportal.service.model.internal.faults.DataParsingException;
|
import org.gcube.application.geoportal.service.model.internal.faults.DataParsingException;
|
||||||
import org.gcube.application.geoportal.service.utils.ISUtils;
|
import org.gcube.application.geoportal.common.utils.ISUtils;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
package org.gcube.application.geoportal.service.engine.providers;
|
|
||||||
|
|
||||||
import org.gcube.application.cms.caches.Engine;
|
|
||||||
import org.gcube.application.cms.implementations.ISInterface;
|
|
||||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
|
||||||
import org.gcube.application.geoportal.service.utils.ISUtils;
|
|
||||||
|
|
||||||
public class ISProvider implements Engine<ISInterface> {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init() { }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void shutdown() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ISInterface getObject() throws ConfigurationException {
|
|
||||||
return new ISUtils();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,9 +6,13 @@ import org.gcube.application.cms.implementations.ISInterface;
|
||||||
import org.gcube.application.geoportal.service.ServiceConstants;
|
import org.gcube.application.geoportal.service.ServiceConstants;
|
||||||
import org.gcube.application.cms.implementations.ImplementationProvider;
|
import org.gcube.application.cms.implementations.ImplementationProvider;
|
||||||
import org.gcube.application.geoportal.service.model.internal.db.Mongo;
|
import org.gcube.application.geoportal.service.model.internal.db.Mongo;
|
||||||
import org.gcube.application.geoportal.service.model.internal.db.MongoConnection;
|
import org.gcube.application.geoportal.common.model.configuration.MongoConnection;
|
||||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
import org.gcube.application.geoportal.service.utils.ISUtils;
|
import org.gcube.application.geoportal.common.utils.ISUtils;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class MongoClientProvider extends AbstractScopedMap<Mongo> {
|
public class MongoClientProvider extends AbstractScopedMap<Mongo> {
|
||||||
|
@ -21,10 +25,12 @@ public class MongoClientProvider extends AbstractScopedMap<Mongo> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Mongo retrieveObject() throws ConfigurationException {
|
protected Mongo retrieveObject() throws ConfigurationException {
|
||||||
MongoConnection conn=((ISUtils)ImplementationProvider.get().
|
MongoConnection conn=performQueryForMongoDB(ImplementationProvider.get().
|
||||||
getEngineByClass(ISInterface.class)).
|
getEngineByClass(ISInterface.class),
|
||||||
queryForMongoDB(
|
ServiceConstants.SE_GNA_DB_CATEGORY,
|
||||||
ServiceConstants.MONGO_SE_PLATFORM, ServiceConstants.MONGO_SE_GNA_FLAG);
|
ServiceConstants.MONGO_SE_PLATFORM,
|
||||||
|
ServiceConstants.SE_GNA_DB_FLAG,
|
||||||
|
ServiceConstants.MONGO_SE_GNA_FLAG);
|
||||||
|
|
||||||
log.debug("Connecting to "+conn);
|
log.debug("Connecting to "+conn);
|
||||||
return new Mongo(conn);
|
return new Mongo(conn);
|
||||||
|
@ -39,4 +45,32 @@ public class MongoClientProvider extends AbstractScopedMap<Mongo> {
|
||||||
public void init() {
|
public void init() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static MongoConnection performQueryForMongoDB(ISInterface is,String category, String platform,String flagName, String flagValue) throws ConfigurationException {
|
||||||
|
|
||||||
|
List<ServiceEndpoint.AccessPoint> found=is.performGetAP(category,platform,flagName, flagValue);
|
||||||
|
if(found.size()>1) {
|
||||||
|
throw new ConfigurationException("Multiple SE found ["+found.size()+"] for platform : "+platform+" flag : "+flagValue);
|
||||||
|
}else if (found.isEmpty()){
|
||||||
|
throw new ConfigurationException("No SE found for platform : "+platform+" flag : "+flagValue);
|
||||||
|
}
|
||||||
|
ServiceEndpoint.AccessPoint point=found.get(0);
|
||||||
|
MongoConnection toReturn=new MongoConnection();
|
||||||
|
for(ServiceEndpoint.Property prop:point.properties()) {
|
||||||
|
switch(prop.name()) {
|
||||||
|
case "host" : {
|
||||||
|
toReturn.getHosts().add(prop.value());
|
||||||
|
break;}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toReturn.getHosts().add(point.address());
|
||||||
|
Map<String, ServiceEndpoint.Property> props=point.propertyMap();
|
||||||
|
toReturn.setDatabase(props.get("database").value());
|
||||||
|
toReturn.setPassword(is.decryptString(point.password()));
|
||||||
|
toReturn.setPort(Integer.parseInt(props.get("port").value()));
|
||||||
|
toReturn.setUser(point.username());
|
||||||
|
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.mongodb.ServerAddress;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.gcube.application.geoportal.common.model.configuration.MongoConnection;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ToString
|
@ToString
|
||||||
|
|
|
@ -1,148 +0,0 @@
|
||||||
package org.gcube.application.geoportal.service.utils;
|
|
||||||
|
|
||||||
import org.gcube.application.cms.implementations.ISInterface;
|
|
||||||
import org.gcube.application.geoportal.common.model.rest.DatabaseConnection;
|
|
||||||
import org.gcube.application.geoportal.service.ServiceConstants;
|
|
||||||
import org.gcube.application.geoportal.service.model.internal.db.MongoConnection;
|
|
||||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
|
||||||
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
|
||||||
|
|
||||||
public class ISUtils implements ISInterface {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public DatabaseConnection queryForDB(String platform, String flag) throws ConfigurationException {
|
|
||||||
return ISUtils.performQueryForDB(platform,flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
// public List<AccessPoint> GetAP(String platform,String flag) {
|
|
||||||
// return performGetAP(platform,flag);
|
|
||||||
// }
|
|
||||||
|
|
||||||
private static DatabaseConnection performQueryForDB(String platform, String flag) throws ConfigurationException {
|
|
||||||
|
|
||||||
List<AccessPoint> found=performGetAP(platform, flag);
|
|
||||||
if(found.size()>1) {
|
|
||||||
throw new ConfigurationException("Multiple SE found ["+found.size()+"] for platform : "+platform+" flag : "+flag);
|
|
||||||
}else if (found.isEmpty()){
|
|
||||||
throw new ConfigurationException("No SE found for platform : "+platform+" flag : "+flag);
|
|
||||||
}
|
|
||||||
AccessPoint point=found.get(0);
|
|
||||||
|
|
||||||
DatabaseConnection toReturn=new DatabaseConnection();
|
|
||||||
toReturn.setPwd(decryptString(point.password()));
|
|
||||||
toReturn.setUser(point.username());
|
|
||||||
toReturn.setUrl(point.address());
|
|
||||||
return toReturn;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static List<AccessPoint> performGetAP(String platform,String flag) {
|
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
|
||||||
|
|
||||||
query.addCondition("$resource/Profile/Category/text() eq '"+ServiceConstants.SE_GNA_DB_CATEGORY+"'")
|
|
||||||
.addCondition("$resource/Profile/Platform/Name/text() eq '"+platform+"'")
|
|
||||||
.addCondition("$resource/Profile/AccessPoint//Property[Name/text() eq '"+
|
|
||||||
ServiceConstants.SE_GNA_DB_FLAG+"'][Value/text() eq '"+flag+"']")
|
|
||||||
.setResult("$resource/Profile/AccessPoint");
|
|
||||||
|
|
||||||
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
|
||||||
return client.submit(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MongoConnection queryForMongoDB(String platform,String flag) throws ConfigurationException {
|
|
||||||
return performQueryForMongoDB(platform,flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MongoConnection performQueryForMongoDB(String platform,String flag) throws ConfigurationException {
|
|
||||||
|
|
||||||
List<AccessPoint> found=performGetAP(platform, flag);
|
|
||||||
if(found.size()>1) {
|
|
||||||
throw new ConfigurationException("Multiple SE found ["+found.size()+"] for platform : "+platform+" flag : "+flag);
|
|
||||||
}else if (found.isEmpty()){
|
|
||||||
throw new ConfigurationException("No SE found for platform : "+platform+" flag : "+flag);
|
|
||||||
}
|
|
||||||
AccessPoint point=found.get(0);
|
|
||||||
MongoConnection toReturn=new MongoConnection();
|
|
||||||
for(Property prop:point.properties()) {
|
|
||||||
switch(prop.name()) {
|
|
||||||
case "host" : {
|
|
||||||
toReturn.getHosts().add(prop.value());
|
|
||||||
break;}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
toReturn.getHosts().add(point.address());
|
|
||||||
Map<String, Property> props=point.propertyMap();
|
|
||||||
toReturn.setDatabase(props.get("database").value());
|
|
||||||
toReturn.setPassword(decryptString(point.password()));
|
|
||||||
toReturn.setPort(Integer.parseInt(props.get("port").value()));
|
|
||||||
toReturn.setUser(point.username());
|
|
||||||
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// private static String getToken() throws ConfigurationException {
|
|
||||||
// SimpleQuery query = queryFor(ServiceEndpoint.class);
|
|
||||||
//
|
|
||||||
// query.addCondition("$resource/Profile/Category/text() eq 'Application'")
|
|
||||||
// .addCondition("$resource/Profile/Name/text() eq 'GNA-APP'")
|
|
||||||
// .setResult("$resource/Profile/AccessPoint");
|
|
||||||
//
|
|
||||||
// DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
|
||||||
//
|
|
||||||
// List<AccessPoint> found= client.submit(query);
|
|
||||||
// if(found.size()>1) {
|
|
||||||
// throw new ConfigurationException("Multiple Token SE found ["+found.size()+"] for Category : Application name : GNA-APP");
|
|
||||||
// }else if (found.isEmpty()){
|
|
||||||
// throw new ConfigurationException("No Token SE found ["+found.size()+"] for Category : Application name : GNA-APP");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// AccessPoint point=found.get(0);
|
|
||||||
// return decryptString(point.password());
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
private static String decryptString(String toDecrypt){
|
|
||||||
try{
|
|
||||||
return StringEncrypter.getEncrypter().decrypt(toDecrypt);
|
|
||||||
}catch(Exception e) {
|
|
||||||
throw new RuntimeException("Unable to decrypt : "+toDecrypt,e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DatabaseConnection queryForDatabase(String platform, String flag) throws ConfigurationException {
|
|
||||||
return queryForDB(platform,flag);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// private static String getgCubeBaseEndpoint(String category,String name) {
|
|
||||||
//
|
|
||||||
// SimpleQuery query = queryFor(ServiceEndpoint.class);
|
|
||||||
//
|
|
||||||
// query.addCondition("$resource/Profile/Category/text() eq '"+category+"'")
|
|
||||||
// .addCondition("$resource/Profile/Name/text() eq '"+name+"'");
|
|
||||||
// DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
|
||||||
//
|
|
||||||
// AccessPoint point=client.submit(query).get(0).profile().accessPoints().asCollection().iterator().next();
|
|
||||||
//
|
|
||||||
// return point.address();
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
|
@ -17,6 +17,7 @@ import org.gcube.application.cms.sdi.engine.SDIManager;
|
||||||
import org.gcube.application.cms.sdi.engine.SDIManagerWrapper;
|
import org.gcube.application.cms.sdi.engine.SDIManagerWrapper;
|
||||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
import org.gcube.application.geoportal.common.model.rest.DatabaseConnection;
|
import org.gcube.application.geoportal.common.model.rest.DatabaseConnection;
|
||||||
|
import org.gcube.data.transfer.model.ServiceConstants;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
@ -52,7 +53,7 @@ public abstract class SDIAbstractPlugin extends AbstractPlugin implements Initia
|
||||||
protected DatabaseConnection retrieveObject() throws ConfigurationException {
|
protected DatabaseConnection retrieveObject() throws ConfigurationException {
|
||||||
try {
|
try {
|
||||||
return ImplementationProvider.get().getEngineByClass(ISInterface.class).
|
return ImplementationProvider.get().getEngineByClass(ISInterface.class).
|
||||||
queryForDatabase("postgis", "Concessioni");
|
queryForDatabase("Database","postgis", "GNA_DB","Concessioni");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ConfigurationException(e);
|
throw new ConfigurationException(e);
|
||||||
}
|
}
|
|
@ -42,7 +42,7 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static final PluginDescriptor DESCRIPTOR=new PluginDescriptor("SDI-Indexer-Plugin",
|
static final PluginDescriptor DESCRIPTOR=new PluginDescriptor("SDI-Indexer-Plugin",
|
||||||
PluginDescriptor.BaseTypes.INDEXER);
|
PluginDescriptor.BaseTypes.INDEXER);
|
||||||
|
|
||||||
static {
|
static {
|
|
@ -0,0 +1,47 @@
|
||||||
|
package org.gcube.application.cms.sdi.plugins;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.gcube.application.cms.plugins.IndexerPluginInterface;
|
||||||
|
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
|
||||||
|
import org.gcube.application.cms.plugins.reports.IndexDocumentReport;
|
||||||
|
import org.gcube.application.cms.plugins.reports.Report;
|
||||||
|
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
|
||||||
|
import org.gcube.application.cms.sdi.plugins.SDIIndexerPlugin;
|
||||||
|
import org.gcube.application.cms.serialization.Serialization;
|
||||||
|
import org.gcube.application.cms.tests.BasicPluginTest;
|
||||||
|
import org.gcube.application.cms.tests.TestDocuments;
|
||||||
|
import org.gcube.application.cms.tests.TestProfiles;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||||
|
import org.gcube.application.geoportal.common.utils.Files;
|
||||||
|
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
|
public class IndexerTest extends BasicPluginTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIndexRequest() throws PluginExecutionException, JsonProcessingException {
|
||||||
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
|
IndexDocumentRequest request=new IndexDocumentRequest();
|
||||||
|
|
||||||
|
ProfiledDocument doc= TestDocuments.documentMap.get("profiledConcessioniExample.json");
|
||||||
|
request.setProfile(TestProfiles.profiles.get(doc.getProfileID()));
|
||||||
|
request.setDocument(doc);
|
||||||
|
Document parameters = new Document();
|
||||||
|
parameters.put("workspace", "testing_workspace");
|
||||||
|
parameters.put("indexName", "unique_index"+System.currentTimeMillis());
|
||||||
|
request.setCallParameters(parameters);
|
||||||
|
|
||||||
|
IndexerPluginInterface plugin = (IndexerPluginInterface) plugins.get(SDIIndexerPlugin.DESCRIPTOR.getId());
|
||||||
|
|
||||||
|
IndexDocumentReport response = plugin.index(request);
|
||||||
|
assumeTrue(response!=null);
|
||||||
|
response.validate();
|
||||||
|
|
||||||
|
assumeTrue(response.getStatus().equals(Report.Status.OK));
|
||||||
|
assumeTrue(response.prepareResult().getSpatialReference()!=null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue