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.DatabaseConnection;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -29,5 +29,10 @@ public class ImplementationProvider {
|
|||
public <T> void setEngine(Engine<T> engine, Class<T> clazz){
|
||||
implementationsRegistry.put(clazz,engine);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ImplementationProvider(){
|
||||
//Defaults
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,32 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import lombok.Getter;
|
||||
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.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 TemporalReference toSetTemporalReference;
|
||||
public SpatialReference toSetSpatialReference;
|
||||
|
||||
|
||||
public IndexDocumentReport(@NonNull IndexDocumentRequest 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;
|
||||
|
||||
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.MaterializationPlugin;
|
||||
import org.gcube.application.cms.plugins.Plugin;
|
||||
import org.gcube.application.cms.plugins.PluginsReflections;
|
||||
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.junit.Assert;
|
||||
import org.junit.Before;
|
||||
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.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BasicPluginTest {
|
||||
|
||||
protected String context;
|
||||
|
||||
|
||||
static List<Plugin> plugins=new ArrayList<>();
|
||||
|
||||
protected static Map<String,Plugin> plugins=new HashMap<>();
|
||||
|
||||
@BeforeClass
|
||||
public static void checkPluginRegistration() {
|
||||
plugins.addAll(PluginsReflections.load().values());
|
||||
plugins.forEach(plugin -> System.out.println());
|
||||
plugins.putAll(PluginsReflections.load());
|
||||
plugins.forEach((s,p) -> System.out.println(s+" "+p.getDescriptor()));
|
||||
|
||||
Assert.assertFalse(plugins.isEmpty());
|
||||
System.out.println("Plugin Loading OK");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void init(){
|
||||
plugins.forEach(p->{
|
||||
plugins.forEach((s,p)->{
|
||||
System.out.println("INIT Plugin "+p.getClass());
|
||||
Assert.assertNotNull(p.getDescriptor());
|
||||
Assert.assertNotNull(p.getDescriptor().getId());
|
||||
|
@ -53,35 +38,24 @@ public class BasicPluginTest {
|
|||
InitializablePlugin ip=(InitializablePlugin)p;
|
||||
try {
|
||||
ip.init();
|
||||
|
||||
if(GCubeTest.isTestInfrastructureEnabled()){
|
||||
TokenSetter.set(GCubeTest.getContext());
|
||||
ip.initInContext();
|
||||
}
|
||||
} catch (InitializationException e) {
|
||||
e.printStackTrace(System.err);
|
||||
Assert.fail("Unable to Init "+p.getDescriptor().getId());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void initInContext(){
|
||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
plugins.forEach(p->{
|
||||
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());
|
||||
}
|
||||
}
|
||||
});
|
||||
System.out.println("Plugin Loading OK");
|
||||
|
||||
if(GCubeTest.isTestInfrastructureEnabled()){
|
||||
ImplementationProvider.get().setEngine(new ISProvider(), ISInterface.class);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()){
|
||||
try {
|
||||
profiles.put(f.getName(), Serialization.read(
|
||||
Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset()),Profile.class));
|
||||
Profile p =Serialization.read(
|
||||
Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset()),Profile.class);
|
||||
profiles.put(p.getId(), p);
|
||||
} catch (IOException 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;
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
package org.gcube.application.geoportal.common.model.document;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.mongodb.client.model.geojson.GeoJsonObjectType;
|
||||
import com.vdurmont.semver4j.Semver;
|
||||
import lombok.*;
|
||||
import org.bson.Document;
|
||||
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.spatial.SpatialReference;
|
||||
import org.gcube.application.geoportal.common.model.document.temporal.TemporalReference;
|
||||
|
||||
|
||||
@NoArgsConstructor
|
||||
|
@ -52,7 +53,7 @@ public class ProfiledDocument {
|
|||
|
||||
// Expected GEOJSON
|
||||
@JsonProperty(SPATIAL_REFERENCE)
|
||||
private Document spatialReference;
|
||||
private SpatialReference spatialReference;
|
||||
|
||||
@JsonProperty(TEMPORAL_REFERENCE)
|
||||
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 .. ");
|
||||
|
||||
ImplementationProvider.get().setEngine(new ISProvider(),ISInterface.class);
|
||||
ImplementationProvider.get().setEngine(new MongoClientProvider(), Mongo.class);
|
||||
ImplementationProvider.get().setEngine(new StorageClientProvider(), StorageUtils.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.common.model.rest.ConfigurationException;
|
||||
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.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.cms.implementations.ImplementationProvider;
|
||||
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.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
|
||||
public class MongoClientProvider extends AbstractScopedMap<Mongo> {
|
||||
|
@ -21,10 +25,12 @@ public class MongoClientProvider extends AbstractScopedMap<Mongo> {
|
|||
|
||||
@Override
|
||||
protected Mongo retrieveObject() throws ConfigurationException {
|
||||
MongoConnection conn=((ISUtils)ImplementationProvider.get().
|
||||
getEngineByClass(ISInterface.class)).
|
||||
queryForMongoDB(
|
||||
ServiceConstants.MONGO_SE_PLATFORM, ServiceConstants.MONGO_SE_GNA_FLAG);
|
||||
MongoConnection conn=performQueryForMongoDB(ImplementationProvider.get().
|
||||
getEngineByClass(ISInterface.class),
|
||||
ServiceConstants.SE_GNA_DB_CATEGORY,
|
||||
ServiceConstants.MONGO_SE_PLATFORM,
|
||||
ServiceConstants.SE_GNA_DB_FLAG,
|
||||
ServiceConstants.MONGO_SE_GNA_FLAG);
|
||||
|
||||
log.debug("Connecting to "+conn);
|
||||
return new Mongo(conn);
|
||||
|
@ -39,4 +45,32 @@ public class MongoClientProvider extends AbstractScopedMap<Mongo> {
|
|||
public void init() {
|
||||
// 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.ToString;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.geoportal.common.model.configuration.MongoConnection;
|
||||
|
||||
@Slf4j
|
||||
@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.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.model.rest.DatabaseConnection;
|
||||
import org.gcube.data.transfer.model.ServiceConstants;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
@ -52,7 +53,7 @@ public abstract class SDIAbstractPlugin extends AbstractPlugin implements Initia
|
|||
protected DatabaseConnection retrieveObject() throws ConfigurationException {
|
||||
try {
|
||||
return ImplementationProvider.get().getEngineByClass(ISInterface.class).
|
||||
queryForDatabase("postgis", "Concessioni");
|
||||
queryForDatabase("Database","postgis", "GNA_DB","Concessioni");
|
||||
} catch (Exception 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);
|
||||
|
||||
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