Implements #22907
This commit is contained in:
parent
148554d3c9
commit
9a8705183a
|
@ -20,7 +20,7 @@ public class ImplementationProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public <T> T getEngineByClass(Class<T> clazz) throws ConfigurationException {
|
public <T> T getEngineByManagedClass(Class<T> clazz) throws ConfigurationException {
|
||||||
return (T) implementationsRegistry.get(clazz).getObject();
|
return (T) implementationsRegistry.get(clazz).getObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import lombok.extern.slf4j.XSlf4j;
|
import lombok.extern.slf4j.XSlf4j;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
import org.gcube.application.geoportal.common.model.document.accounting.AccountingInfo;
|
import org.gcube.application.geoportal.common.model.document.accounting.AccountingInfo;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -21,6 +22,7 @@ import org.gcube.application.geoportal.common.model.document.accounting.Accounti
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class UseCaseDescriptor {
|
public class UseCaseDescriptor {
|
||||||
|
|
||||||
|
public static final String MONGO_ID="_mongoId";
|
||||||
public static final String ID="_id";
|
public static final String ID="_id";
|
||||||
public static final String VERSION="_version";
|
public static final String VERSION="_version";
|
||||||
public static final String NAME="_name";
|
public static final String NAME="_name";
|
||||||
|
@ -31,6 +33,8 @@ public class UseCaseDescriptor {
|
||||||
public static final String DATA_ACCESS_POLICIES="_dataAccessPolicies";
|
public static final String DATA_ACCESS_POLICIES="_dataAccessPolicies";
|
||||||
|
|
||||||
|
|
||||||
|
@JsonProperty(MONGO_ID)
|
||||||
|
private ObjectId mongoId;
|
||||||
|
|
||||||
@JsonProperty(ID)
|
@JsonProperty(ID)
|
||||||
private String id;
|
private String id;
|
||||||
|
@ -87,4 +91,6 @@ public class UseCaseDescriptor {
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -10,7 +10,7 @@ public class InterfaceConstants {
|
||||||
public static final String SERVICE_NAME="GeoPortal";
|
public static final String SERVICE_NAME="GeoPortal";
|
||||||
|
|
||||||
public static final class Methods{
|
public static final class Methods{
|
||||||
public static final String PROFILES="profiles";
|
public static final String UCD ="ucd";
|
||||||
public static final String SECTIONS="sections";
|
public static final String SECTIONS="sections";
|
||||||
public static final String PROJECTS="projects";
|
public static final String PROJECTS="projects";
|
||||||
|
|
||||||
|
@ -32,12 +32,8 @@ public class InterfaceConstants {
|
||||||
public static final class Parameters{
|
public static final class Parameters{
|
||||||
public static final String PROJECT_ID="project_id";
|
public static final String PROJECT_ID="project_id";
|
||||||
public static final String SECTION_ID="section_id";
|
public static final String SECTION_ID="section_id";
|
||||||
public static final String PROFILE_ID="profile_id";
|
public static final String UCID ="usecase_id";
|
||||||
|
|
||||||
// //INVESTIGATE CAPABILITIES
|
|
||||||
// public static final String ORDER_BY="order_by";
|
|
||||||
// public static final String LIMIT="limit";
|
|
||||||
// public static final String OFFSET="offset";
|
|
||||||
public static final String FORCE="force";
|
public static final String FORCE="force";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,11 @@ public class ISUtils {
|
||||||
public static List<AccessPoint> performGetAP(String category,String platform,String flagName,String flagValue) {
|
public static List<AccessPoint> performGetAP(String category,String platform,String flagName,String flagValue) {
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
|
|
||||||
query.addCondition("$resource/UseCaseDescriptor/Category/text() eq '"+category+"'")
|
query.addCondition("$resource/Profile/Category/text() eq '"+category+"'")
|
||||||
.addCondition("$resource/UseCaseDescriptor/Platform/Name/text() eq '"+platform+"'")
|
.addCondition("$resource/Profile/Platform/Name/text() eq '"+platform+"'")
|
||||||
.addCondition("$resource/UseCaseDescriptor/AccessPoint//Property[Name/text() eq '"+
|
.addCondition("$resource/Profile/AccessPoint//Property[Name/text() eq '"+
|
||||||
flagName+"'][Value/text() eq '"+flagValue+"']")
|
flagName+"'][Value/text() eq '"+flagValue+"']")
|
||||||
.setResult("$resource/UseCaseDescriptor/AccessPoint");
|
.setResult("$resource/Profile/AccessPoint");
|
||||||
|
|
||||||
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
||||||
return client.submit(query);
|
return client.submit(query);
|
||||||
|
|
|
@ -11,8 +11,8 @@ public class GCubeTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
testContext = "/pred4s/preprod/preVRE";
|
// testContext = "/pred4s/preprod/preVRE";
|
||||||
|
testContext = "/gcube/devsec/devVRE";
|
||||||
|
|
||||||
|
|
||||||
System.out.println("TEST CONTEXT = "+testContext);
|
System.out.println("TEST CONTEXT = "+testContext);
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package org.gcube.application.geoportal.service;
|
package org.gcube.application.geoportal.service;
|
||||||
|
|
||||||
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
|
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
|
||||||
import jdk.internal.dynalink.linker.LinkerServices;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.gcube.application.cms.implementations.ISInterface;
|
|
||||||
import org.gcube.application.cms.implementations.ImplementationProvider;
|
import org.gcube.application.cms.implementations.ImplementationProvider;
|
||||||
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
||||||
import org.gcube.application.geoportal.common.utils.StorageUtils;
|
import org.gcube.application.geoportal.common.utils.StorageUtils;
|
||||||
|
import org.gcube.application.geoportal.service.engine.mongo.UCDManagerI;
|
||||||
import org.gcube.application.geoportal.service.engine.postgis.PostgisDBManager;
|
import org.gcube.application.geoportal.service.engine.postgis.PostgisDBManager;
|
||||||
import org.gcube.application.geoportal.service.engine.providers.*;
|
import org.gcube.application.geoportal.service.engine.providers.*;
|
||||||
import org.gcube.application.geoportal.service.model.internal.db.Mongo;
|
import org.gcube.application.geoportal.service.model.internal.db.Mongo;
|
||||||
|
@ -14,8 +13,8 @@ import org.gcube.application.geoportal.service.rest.ConcessioniOverMongo;
|
||||||
|
|
||||||
|
|
||||||
import org.gcube.application.geoportal.service.rest.ProfiledDocuments;
|
import org.gcube.application.geoportal.service.rest.ProfiledDocuments;
|
||||||
import org.gcube.application.geoportal.service.rest.Sections;
|
|
||||||
import org.gcube.application.cms.serialization.Serialization;
|
import org.gcube.application.cms.serialization.Serialization;
|
||||||
|
import org.gcube.application.geoportal.service.rest.UseCaseDescriptors;
|
||||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||||
import org.glassfish.jersey.server.ResourceConfig;
|
import org.glassfish.jersey.server.ResourceConfig;
|
||||||
|
|
||||||
|
@ -33,7 +32,8 @@ public class GeoPortalService extends ResourceConfig{
|
||||||
// registerClasses(Concessioni.class);
|
// registerClasses(Concessioni.class);
|
||||||
registerClasses(ConcessioniOverMongo.class);
|
registerClasses(ConcessioniOverMongo.class);
|
||||||
registerClasses(ProfiledDocuments.class);
|
registerClasses(ProfiledDocuments.class);
|
||||||
registerClasses(Sections.class);
|
|
||||||
|
registerClasses(UseCaseDescriptors.class);
|
||||||
|
|
||||||
log.info("Setting implementations .. ");
|
log.info("Setting implementations .. ");
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ public class GeoPortalService extends ResourceConfig{
|
||||||
ImplementationProvider.get().setEngine(new ProfileMapCache(), ProfileMapCache.ProfileMap.class);
|
ImplementationProvider.get().setEngine(new ProfileMapCache(), ProfileMapCache.ProfileMap.class);
|
||||||
ImplementationProvider.get().setEngine(new PluginManager(), PluginManager.PluginMap.class);
|
ImplementationProvider.get().setEngine(new PluginManager(), PluginManager.PluginMap.class);
|
||||||
ImplementationProvider.get().setEngine(new StorageHubProvider(), StorageHubClient.class);
|
ImplementationProvider.get().setEngine(new StorageHubProvider(), StorageHubClient.class);
|
||||||
|
ImplementationProvider.get().setEngine(new UCDManager(),UCDManagerI.class);
|
||||||
|
|
||||||
|
|
||||||
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
|
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class WorkspaceManager {
|
||||||
|
|
||||||
|
|
||||||
public WorkspaceManager() throws ConfigurationException, StorageHubException {
|
public WorkspaceManager() throws ConfigurationException, StorageHubException {
|
||||||
sgClient= ImplementationProvider.get().getEngineByClass(StorageHubClient.class);
|
sgClient= ImplementationProvider.get().getEngineByManagedClass(StorageHubClient.class);
|
||||||
appBase=getApplicationBaseFolder(sgClient);
|
appBase=getApplicationBaseFolder(sgClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -258,7 +258,7 @@ public class ConcessioniMongoManager extends MongoManager{
|
||||||
log.info("Persisting {} files for path {} in concessione ",files.size(),destinationPath,id);
|
log.info("Persisting {} files for path {} in concessione ",files.size(),destinationPath,id);
|
||||||
try{
|
try{
|
||||||
Concessione c = getById(id);
|
Concessione c = getById(id);
|
||||||
StorageUtils storage=ImplementationProvider.get().getEngineByClass(StorageUtils.class);
|
StorageUtils storage=ImplementationProvider.get().getEngineByManagedClass(StorageUtils.class);
|
||||||
WorkspaceManager ws=new WorkspaceManager();
|
WorkspaceManager ws=new WorkspaceManager();
|
||||||
//Check Init Base folder
|
//Check Init Base folder
|
||||||
FolderContainer baseFolder=null;
|
FolderContainer baseFolder=null;
|
||||||
|
|
|
@ -34,7 +34,7 @@ public abstract class MongoManager {
|
||||||
protected static final Document asDoc(String json) {return Document.parse(json);}
|
protected static final Document asDoc(String json) {return Document.parse(json);}
|
||||||
|
|
||||||
public MongoManager() throws ConfigurationException {
|
public MongoManager() throws ConfigurationException {
|
||||||
client=ImplementationProvider.get().getEngineByClass(Mongo.class);
|
client=ImplementationProvider.get().getEngineByManagedClass(Mongo.class);
|
||||||
|
|
||||||
log.info("Got Mongo Client at "+client.getConnection());
|
log.info("Got Mongo Client at "+client.getConnection());
|
||||||
log.debug("Mongo client is "+client);
|
log.debug("Mongo client is "+client);
|
||||||
|
|
|
@ -40,8 +40,10 @@ import org.gcube.application.geoportal.service.engine.WorkspaceManager;
|
||||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
import org.gcube.application.geoportal.service.engine.providers.PluginManager;
|
import org.gcube.application.geoportal.service.engine.providers.PluginManager;
|
||||||
import org.gcube.application.geoportal.service.engine.providers.ProfileMapCache;
|
import org.gcube.application.geoportal.service.engine.providers.ProfileMapCache;
|
||||||
|
import org.gcube.application.geoportal.service.engine.providers.UCDManager;
|
||||||
import org.gcube.application.geoportal.service.model.internal.faults.DeletionException;
|
import org.gcube.application.geoportal.service.model.internal.faults.DeletionException;
|
||||||
import org.gcube.application.cms.serialization.Serialization;
|
import org.gcube.application.cms.serialization.Serialization;
|
||||||
|
import org.gcube.application.geoportal.service.model.internal.faults.RegistrationException;
|
||||||
import org.gcube.application.geoportal.service.utils.UserUtils;
|
import org.gcube.application.geoportal.service.utils.UserUtils;
|
||||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
|
@ -68,17 +70,14 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ProfiledMongoManager(String profileId) throws ConfigurationException {
|
public ProfiledMongoManager(String profileId) throws ConfigurationException, RegistrationException {
|
||||||
// Check UseCaseDescriptor ID
|
// Check UseCaseDescriptor ID
|
||||||
log.info("Loading useCaseDescriptor ID {} ",profileId);
|
log.info("Loading useCaseDescriptor ID {} ",profileId);
|
||||||
if(profileId==null) throw new InvalidParameterException("UseCaseDescriptor ID cannot be null");
|
if(profileId==null) throw new InvalidParameterException("UseCaseDescriptor ID cannot be null");
|
||||||
Map<String, UseCaseDescriptor> profiles=ImplementationProvider.get().getEngineByClass(ProfileMapCache.ProfileMap.class);
|
Map<String, UseCaseDescriptor> profiles=ImplementationProvider.get().getEngineByManagedClass(ProfileMapCache.ProfileMap.class);
|
||||||
if(!profiles.containsKey(profileId)) {
|
useCaseDescriptor = ImplementationProvider.get().getEngineByManagedClass(UCDManagerI.class).getById(profileId);
|
||||||
log.debug("Asked useCaseDescriptor {} not found. Available ones are {} ",profileId,profiles.keySet());
|
if(useCaseDescriptor == null )
|
||||||
throw new WebApplicationException("UseCaseDescriptor " + profileId + " not registered", Response.Status.NOT_FOUND);
|
throw new WebApplicationException("UseCaseDescriptor " + profileId + " not registered", Response.Status.NOT_FOUND);
|
||||||
}
|
|
||||||
useCaseDescriptor =profiles.get(profileId);
|
|
||||||
log.debug("Loaded UseCaseDescriptor {} ", useCaseDescriptor);
|
|
||||||
|
|
||||||
|
|
||||||
// Connect to DB
|
// Connect to DB
|
||||||
|
@ -105,7 +104,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
// Loading Lifecycle Manager
|
// Loading Lifecycle Manager
|
||||||
log.debug("Looking for handler {} ",lcHandlerDeclaration);
|
log.debug("Looking for handler {} ",lcHandlerDeclaration);
|
||||||
toReturn=(LifecycleManager) ImplementationProvider.get().
|
toReturn=(LifecycleManager) ImplementationProvider.get().
|
||||||
getEngineByClass(PluginManager.PluginMap.class).get(lcHandlerDeclaration.getId());
|
getEngineByManagedClass(PluginManager.PluginMap.class).get(lcHandlerDeclaration.getId());
|
||||||
if(toReturn==null) throw new ConfigurationException("Unable to find Lifecycle Manager Plugin. ID "+lcHandlerDeclaration.getId());
|
if(toReturn==null) throw new ConfigurationException("Unable to find Lifecycle Manager Plugin. ID "+lcHandlerDeclaration.getId());
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
|
@ -229,7 +228,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
@Override
|
@Override
|
||||||
public Iterable<Document> query(QueryRequest queryRequest) {
|
public Iterable<Document> query(QueryRequest queryRequest) {
|
||||||
log.info("Querying {} ",queryRequest);
|
log.info("Querying {} ",queryRequest);
|
||||||
LinkedBlockingQueue queue=new LinkedBlockingQueue<Concessione>();
|
LinkedBlockingQueue queue=new LinkedBlockingQueue<Project>();
|
||||||
query(queryRequest,getCollectionName()).forEach(
|
query(queryRequest,getCollectionName()).forEach(
|
||||||
(Consumer<? super Document>) (Document d)->{try{
|
(Consumer<? super Document>) (Document d)->{try{
|
||||||
queue.put(d);
|
queue.put(d);
|
||||||
|
@ -241,7 +240,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
@Override
|
@Override
|
||||||
public Iterable<Project> filter(QueryRequest queryRequest) {
|
public Iterable<Project> filter(QueryRequest queryRequest) {
|
||||||
log.info("Searching concessione for filter {} ",queryRequest);
|
log.info("Searching concessione for filter {} ",queryRequest);
|
||||||
LinkedBlockingQueue queue=new LinkedBlockingQueue<Concessione>();
|
LinkedBlockingQueue queue=new LinkedBlockingQueue<Project>();
|
||||||
query(queryRequest,getCollectionName()).forEach(
|
query(queryRequest,getCollectionName()).forEach(
|
||||||
(Consumer<? super Document>) (Document d)->{try{
|
(Consumer<? super Document>) (Document d)->{try{
|
||||||
queue.put(d);
|
queue.put(d);
|
||||||
|
@ -299,7 +298,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
doc.getLifecycleInformation().setLastOperationStatus(LifecycleInformation.Status.OK);
|
doc.getLifecycleInformation().setLastOperationStatus(LifecycleInformation.Status.OK);
|
||||||
|
|
||||||
WorkspaceManager ws=new WorkspaceManager();
|
WorkspaceManager ws=new WorkspaceManager();
|
||||||
StorageUtils storage=ImplementationProvider.get().getEngineByClass(StorageUtils.class);
|
StorageUtils storage=ImplementationProvider.get().getEngineByManagedClass(StorageUtils.class);
|
||||||
|
|
||||||
|
|
||||||
log.debug("Checking field {} definition in {}",request.getFieldDefinitionPath(), useCaseDescriptor.getId());
|
log.debug("Checking field {} definition in {}",request.getFieldDefinitionPath(), useCaseDescriptor.getId());
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
package org.gcube.application.geoportal.service.engine.mongo;
|
|
||||||
|
|
||||||
import com.mongodb.client.MongoDatabase;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.bson.Document;
|
|
||||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
|
||||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
|
||||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
|
||||||
import org.gcube.application.geoportal.common.utils.ContextUtils;
|
|
||||||
|
|
||||||
import javax.ws.rs.WebApplicationException;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class UCDManager extends MongoManager implements UCDManagerI {
|
|
||||||
|
|
||||||
MongoDatabase db=null;
|
|
||||||
|
|
||||||
public UCDManager() throws ConfigurationException {
|
|
||||||
log.info("Init useCaseDescriptor Manager");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MongoDatabase getDatabase(){
|
|
||||||
if(db == null) {
|
|
||||||
log.debug("Getting client for {}",getCollectionName());
|
|
||||||
db = client.getTheClient().getDatabase(getCollectionName());
|
|
||||||
}
|
|
||||||
return db;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getCollectionName(){
|
|
||||||
return "profiles_"+ContextUtils.getCurrentScope();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UseCaseDescriptor create(Document toCreate) {
|
|
||||||
// Validate
|
|
||||||
// NB Check for existing ID
|
|
||||||
// INSERT
|
|
||||||
// force update cache
|
|
||||||
throw new WebApplicationException("TO BE IMPLEMENTED", Response.Status.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<UseCaseDescriptor> query(QueryRequest queryRequest) {
|
|
||||||
log.info("Querying {} ",queryRequest);
|
|
||||||
LinkedBlockingQueue queue=new LinkedBlockingQueue<UseCaseDescriptor>();
|
|
||||||
query(queryRequest,getCollectionName()).forEach(
|
|
||||||
(Consumer<? super Document>) (Document d)->{try{
|
|
||||||
queue.put(d);
|
|
||||||
}catch(Throwable t){log.warn("Unable to translate "+d);}});
|
|
||||||
log.info("Returned {} elements ",queue.size());
|
|
||||||
return queue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteById(String id, boolean force) {
|
|
||||||
// NB Check for existing ID
|
|
||||||
// Check Force (existing documents)
|
|
||||||
throw new WebApplicationException("TO BE IMPLEMENTED", Response.Status.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UseCaseDescriptor update(String ID, Document toSet) {
|
|
||||||
// NB Check for existing ID
|
|
||||||
// Validate
|
|
||||||
// INSERT
|
|
||||||
// force update cache
|
|
||||||
throw new WebApplicationException("TO BE IMPLEMENTED", Response.Status.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UseCaseDescriptor getById(String id) {
|
|
||||||
// GET from mongo cache
|
|
||||||
// IF void try from ProfileEngine
|
|
||||||
throw new WebApplicationException("TO BE IMPLEMENTED", Response.Status.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +1,18 @@
|
||||||
package org.gcube.application.geoportal.service.engine.mongo;
|
package org.gcube.application.geoportal.service.engine.mongo;
|
||||||
|
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||||
|
import org.gcube.application.geoportal.service.model.internal.faults.RegistrationException;
|
||||||
|
|
||||||
public interface UCDManagerI {
|
public interface UCDManagerI {
|
||||||
|
|
||||||
public UseCaseDescriptor create(Document toCreate);
|
public Iterable<UseCaseDescriptor> query(QueryRequest request) throws ConfigurationException;
|
||||||
|
|
||||||
public Iterable<UseCaseDescriptor> query(QueryRequest request);
|
public void deleteById(String id,boolean force) throws RegistrationException, ConfigurationException;
|
||||||
|
|
||||||
public void deleteById(String id,boolean force);
|
public UseCaseDescriptor put(UseCaseDescriptor descriptor) throws RegistrationException, ConfigurationException;
|
||||||
|
|
||||||
public UseCaseDescriptor update(String ID, Document toSet);
|
public UseCaseDescriptor getById(String id) throws ConfigurationException, RegistrationException;
|
||||||
|
|
||||||
public UseCaseDescriptor getById(String id);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,138 @@
|
||||||
|
package org.gcube.application.geoportal.service.engine.mongo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.mongodb.client.FindIterable;
|
||||||
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
import com.mongodb.client.model.FindOneAndReplaceOptions;
|
||||||
|
import com.mongodb.client.model.ReturnDocument;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
import org.gcube.application.cms.caches.Engine;
|
||||||
|
import org.gcube.application.cms.implementations.ImplementationProvider;
|
||||||
|
import org.gcube.application.cms.serialization.Serialization;
|
||||||
|
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
||||||
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||||
|
import org.gcube.application.geoportal.common.utils.ContextUtils;
|
||||||
|
import org.gcube.application.geoportal.service.engine.providers.ProfileMapCache;
|
||||||
|
import org.gcube.application.geoportal.service.model.internal.faults.RegistrationException;
|
||||||
|
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class UCDMongoManager extends MongoManager implements UCDManagerI{
|
||||||
|
|
||||||
|
|
||||||
|
MongoDatabase db=null;
|
||||||
|
|
||||||
|
public UCDMongoManager() throws ConfigurationException {
|
||||||
|
String toUseDB=super.client.getConnection().getDatabase();
|
||||||
|
log.info("Connecting to DB {} ",toUseDB);
|
||||||
|
|
||||||
|
|
||||||
|
db=client.getTheClient().getDatabase(toUseDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MongoDatabase getDatabase(){
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCollectionName(){
|
||||||
|
return "profiles_"+ContextUtils.getCurrentScope();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public UseCaseDescriptor insert(UseCaseDescriptor desc) throws RegistrationException {
|
||||||
|
try {
|
||||||
|
if (desc.getMongoId() != null)
|
||||||
|
throw new RegistrationException("UCD has already a mongo ID");
|
||||||
|
|
||||||
|
//TODO validate
|
||||||
|
|
||||||
|
ObjectId id = super.insert(Serialization.asDocument(desc), mongoCollectionName());
|
||||||
|
desc.setMongoId(id);
|
||||||
|
return Serialization.convert(super.getById(id, mongoCollectionName()), UseCaseDescriptor.class);
|
||||||
|
}catch(JsonProcessingException e){
|
||||||
|
log.error("Unexpected serialization exception ",e);
|
||||||
|
throw new WebApplicationException("Unexpected exception ",e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UseCaseDescriptor put(UseCaseDescriptor desc) throws RegistrationException, ConfigurationException {
|
||||||
|
log.debug("PUT UCD ID {} MONGO ID ",desc.getId(),desc.getMongoId());
|
||||||
|
FindOneAndReplaceOptions opts = new FindOneAndReplaceOptions();
|
||||||
|
Document filter = new Document(UseCaseDescriptor.ID,desc.getId());
|
||||||
|
if(desc.getMongoId()!=null)
|
||||||
|
// MONGO ID SHOULD MATCH IF PROVIDED
|
||||||
|
filter.put(UseCaseDescriptor.MONGO_ID,desc.getMongoId());
|
||||||
|
try {
|
||||||
|
UseCaseDescriptor toReturn = Serialization.convert(getDatabase().getCollection(mongoCollectionName()).findOneAndReplace(
|
||||||
|
filter, Serialization.asDocument(desc),
|
||||||
|
new FindOneAndReplaceOptions().returnDocument(ReturnDocument.BEFORE)), UseCaseDescriptor.class);
|
||||||
|
log.trace("Matching is {} ", toReturn);
|
||||||
|
|
||||||
|
// NOT FOUND
|
||||||
|
if (toReturn == null) {
|
||||||
|
if (desc.getMongoId() != null) {
|
||||||
|
// illegal update check
|
||||||
|
if (getById(desc.getId()) != null)
|
||||||
|
throw new RegistrationException("Illegal attempt to write to " + desc.getId() + " with unmatching mongo ID ");
|
||||||
|
}
|
||||||
|
toReturn = insert(desc);
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}catch (RegistrationException | ConfigurationException e){
|
||||||
|
throw e;
|
||||||
|
}catch(Throwable e){
|
||||||
|
log.error("Unable to update ",e);
|
||||||
|
throw new RegistrationException("Invalid UCD provided "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private String mongoCollectionName(){
|
||||||
|
return "_UCD"+ ContextUtils.getCurrentScope().replaceAll("/","_");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<UseCaseDescriptor> query(QueryRequest queryRequest) {
|
||||||
|
|
||||||
|
log.info("Searching UCD for {} ",queryRequest);
|
||||||
|
LinkedBlockingQueue queue=new LinkedBlockingQueue<UseCaseDescriptor>();
|
||||||
|
|
||||||
|
query(queryRequest,getCollectionName()).forEach(
|
||||||
|
(Consumer<? super Document>) d ->{try{
|
||||||
|
queue.put(Serialization.convert(d,UseCaseDescriptor.class));
|
||||||
|
}catch(Throwable t){log.warn("Unable to translate "+d);}});
|
||||||
|
|
||||||
|
log.info("Returned {} elements ",queue.size());
|
||||||
|
return queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteById(String id, boolean force) throws ConfigurationException {
|
||||||
|
delete(getById(id).getMongoId(),mongoCollectionName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UseCaseDescriptor getById(String id) throws ConfigurationException {
|
||||||
|
log.info("Getting UC by ID {} ",id);
|
||||||
|
QueryRequest request=new QueryRequest();
|
||||||
|
request.setFilter(new Document(UseCaseDescriptor.ID,id));
|
||||||
|
try {
|
||||||
|
return this.query(request).iterator().next();
|
||||||
|
}catch (NoSuchElementException e){return null;}
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,6 @@ 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.common.utils.ISUtils;
|
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -25,7 +24,7 @@ public class PostgisDBManager implements PostgisDBManagerI {
|
||||||
|
|
||||||
// TODO GENERIC
|
// TODO GENERIC
|
||||||
DatabaseConnection defaultConfiguration=
|
DatabaseConnection defaultConfiguration=
|
||||||
ImplementationProvider.get().getEngineByClass(ISInterface.class)
|
ImplementationProvider.get().getEngineByManagedClass(ISInterface.class)
|
||||||
.queryForDatabase("Database","postgis", "GNA_DB","Concessioni");
|
.queryForDatabase("Database","postgis", "GNA_DB","Concessioni");
|
||||||
|
|
||||||
log.debug("Found configuration : "+defaultConfiguration);
|
log.debug("Found configuration : "+defaultConfiguration);
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class PostgisIndex {
|
||||||
private SDIManager sdiManager;
|
private SDIManager sdiManager;
|
||||||
private String wmsLink=null;
|
private String wmsLink=null;
|
||||||
private static PostgisDBManager getDB() throws ConfigurationException {
|
private static PostgisDBManager getDB() throws ConfigurationException {
|
||||||
return ImplementationProvider.get().getEngineByClass(PostgisDBManager.class);
|
return ImplementationProvider.get().getEngineByManagedClass(PostgisDBManager.class);
|
||||||
};
|
};
|
||||||
|
|
||||||
public PostgisIndex() throws SDIInteractionException, SQLException, ConfigurationException {
|
public PostgisIndex() throws SDIInteractionException, SQLException, ConfigurationException {
|
||||||
|
|
|
@ -8,7 +8,6 @@ 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.common.model.configuration.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.common.utils.ISUtils;
|
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -26,7 +25,7 @@ public class MongoClientProvider extends AbstractScopedMap<Mongo> {
|
||||||
@Override
|
@Override
|
||||||
protected Mongo retrieveObject() throws ConfigurationException {
|
protected Mongo retrieveObject() throws ConfigurationException {
|
||||||
MongoConnection conn=performQueryForMongoDB(ImplementationProvider.get().
|
MongoConnection conn=performQueryForMongoDB(ImplementationProvider.get().
|
||||||
getEngineByClass(ISInterface.class),
|
getEngineByManagedClass(ISInterface.class),
|
||||||
ServiceConstants.SE_GNA_DB_CATEGORY,
|
ServiceConstants.SE_GNA_DB_CATEGORY,
|
||||||
ServiceConstants.MONGO_SE_PLATFORM,
|
ServiceConstants.MONGO_SE_PLATFORM,
|
||||||
ServiceConstants.SE_GNA_DB_FLAG,
|
ServiceConstants.SE_GNA_DB_FLAG,
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
package org.gcube.application.geoportal.service.engine.providers;
|
||||||
|
|
||||||
|
import com.mongodb.client.FindIterable;
|
||||||
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.gcube.application.cms.caches.AbstractScopedMap;
|
||||||
|
import org.gcube.application.cms.implementations.ImplementationProvider;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||||
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||||
|
import org.gcube.application.geoportal.common.utils.ContextUtils;
|
||||||
|
import org.gcube.application.geoportal.service.engine.mongo.MongoManager;
|
||||||
|
import org.gcube.application.geoportal.service.engine.mongo.UCDManagerI;
|
||||||
|
import org.gcube.application.geoportal.service.engine.mongo.UCDMongoManager;
|
||||||
|
import org.gcube.application.geoportal.service.model.internal.faults.RegistrationException;
|
||||||
|
|
||||||
|
import javax.jws.soap.SOAPBinding;
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class UCDManager extends AbstractScopedMap<UCDManagerI> implements UCDManagerI {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public UCDManager() {
|
||||||
|
super("UCD MANAGER");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<UseCaseDescriptor> query(QueryRequest queryRequest) throws ConfigurationException {
|
||||||
|
return getMongoManager().query(queryRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteById(String id, boolean force) throws RegistrationException, ConfigurationException {
|
||||||
|
log.warn("Trying to delete {} [force : {}]",id,force);
|
||||||
|
// NB Check for existing ID
|
||||||
|
UseCaseDescriptor found = getById(id);
|
||||||
|
if(found!=null) {
|
||||||
|
// TODO validate DELETE REQUEST
|
||||||
|
// TODO STORE UCD
|
||||||
|
// forceUpdateCache();
|
||||||
|
throw new WebApplicationException("TO IMPLEMENT ", Response.Status.INTERNAL_SERVER_ERROR);
|
||||||
|
} else
|
||||||
|
throw new WebApplicationException("No Matching UCD with ID "+id, Response.Status.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UseCaseDescriptor put(UseCaseDescriptor desc) throws ConfigurationException, RegistrationException {
|
||||||
|
log.debug("Update {} ",desc.getId());
|
||||||
|
// NB Check for existing ID
|
||||||
|
UseCaseDescriptor found = getById(desc.getId());
|
||||||
|
if(found!=null) {
|
||||||
|
// TODO validate UPDATE
|
||||||
|
// TODO STORE UCD
|
||||||
|
// forceUpdateCache();
|
||||||
|
throw new WebApplicationException("TO IMPLEMENT ", Response.Status.INTERNAL_SERVER_ERROR);
|
||||||
|
} else
|
||||||
|
throw new WebApplicationException("No Matching UCD with ID "+desc.getId(), Response.Status.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UseCaseDescriptor getById(String id) throws ConfigurationException, RegistrationException {
|
||||||
|
// GET from mongo cache
|
||||||
|
UCDMongoManager mongo=getMongoManager();
|
||||||
|
UseCaseDescriptor toReturn=mongo.getById(id);
|
||||||
|
log.debug("UCD ID : {} from mongo is {} ",id,toReturn);
|
||||||
|
if(toReturn == null) {
|
||||||
|
// IF void try from ProfileEngine
|
||||||
|
toReturn =getLiveMap().get(id);
|
||||||
|
if(toReturn != null ){
|
||||||
|
log.debug("Force update of live map {} from live map ",id);
|
||||||
|
toReturn = mongo.put(toReturn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ProfileMapCache.ProfileMap getLiveMap() throws ConfigurationException {
|
||||||
|
return ImplementationProvider.get().getEngineByManagedClass(ProfileMapCache.ProfileMap.class);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
private UCDMongoManager getMongoManager() throws ConfigurationException {
|
||||||
|
return new UCDMongoManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected UCDManagerI retrieveObject() throws ConfigurationException {
|
||||||
|
forceUpdateCache();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void forceUpdateCache() throws ConfigurationException {
|
||||||
|
log.trace("UPDATING PROFILE CACHE..");
|
||||||
|
final UCDMongoManager manager = getMongoManager();
|
||||||
|
final AtomicLong counter= new AtomicLong(0l);
|
||||||
|
for (Map.Entry<String, UseCaseDescriptor> entry : getLiveMap().entrySet()) {
|
||||||
|
String s = entry.getKey();
|
||||||
|
UseCaseDescriptor useCaseDescriptor = entry.getValue();
|
||||||
|
try {
|
||||||
|
log.info("Updateing cache with {} ", useCaseDescriptor.getId());
|
||||||
|
// insert/update into DB
|
||||||
|
manager.put(useCaseDescriptor);
|
||||||
|
|
||||||
|
} catch (RegistrationException e) {
|
||||||
|
log.warn("Unable to cache UCD {}",entry.getKey(),e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("Cached : {} UCDs in {} ",counter.get(),ContextUtils.getCurrentScope());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package org.gcube.application.geoportal.service.model.internal.faults;
|
||||||
|
|
||||||
|
public class RegistrationException extends Exception {
|
||||||
|
|
||||||
|
public RegistrationException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegistrationException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegistrationException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegistrationException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegistrationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||||
|
super(message, cause, enableSuppression, writableStackTrace);
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,13 +15,13 @@ import org.gcube.application.cms.serialization.Serialization;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
@Path(InterfaceConstants.Methods.PROJECTS+"/{"+InterfaceConstants.Parameters.PROFILE_ID+"}")
|
@Path(InterfaceConstants.Methods.PROJECTS+"/{"+InterfaceConstants.Parameters.UCID +"}")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ProfiledDocuments {
|
public class ProfiledDocuments {
|
||||||
|
|
||||||
private ProfiledMongoManager manager;
|
private ProfiledMongoManager manager;
|
||||||
|
|
||||||
public ProfiledDocuments(@PathParam(InterfaceConstants.Parameters.PROFILE_ID) String profileID) throws ConfigurationException {
|
public ProfiledDocuments(@PathParam(InterfaceConstants.Parameters.UCID) String profileID) throws ConfigurationException {
|
||||||
log.info("Accessing profiles "+profileID);
|
log.info("Accessing profiles "+profileID);
|
||||||
manager=new GuardedMethod<ProfiledMongoManager>(){
|
manager=new GuardedMethod<ProfiledMongoManager>(){
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
package org.gcube.application.geoportal.service.rest;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
|
||||||
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Path(InterfaceConstants.Methods.SECTIONS+"/{"+InterfaceConstants.Parameters.PROJECT_ID+"}")
|
|
||||||
public class Sections {
|
|
||||||
|
|
||||||
@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String projectID;
|
|
||||||
|
|
||||||
|
|
||||||
// Add Section to Project Document
|
|
||||||
// @PUT
|
|
||||||
// @Produces(MediaType.APPLICATION_JSON)
|
|
||||||
// @Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
// public Section registerNewSection(Section toRegister) {
|
|
||||||
// try {
|
|
||||||
// log.info("Creating new Section [PROJECT_ID:{}]",projectID);
|
|
||||||
// throw new RuntimeException("Feature not yet available");
|
|
||||||
// }catch(WebApplicationException e){
|
|
||||||
// log.warn("Unable to serve request",e);
|
|
||||||
// throw e;
|
|
||||||
// }catch(Throwable e){
|
|
||||||
// log.warn("Unable to serve request",e);
|
|
||||||
// throw new WebApplicationException("Unable to serve request", e);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// // Remove Section to Project Document
|
|
||||||
// @DELETE
|
|
||||||
// @Produces(MediaType.APPLICATION_JSON)
|
|
||||||
// @Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
// @Path("{"+InterfaceConstants.Parameters.SECTION_ID+"}")
|
|
||||||
// public Project deleteSection(@QueryParam(InterfaceConstants.Parameters.SECTION_ID) String sectionID) {
|
|
||||||
// try {
|
|
||||||
// log.info("Deleting Section [ID : {}, PROJECT_ID:{}]",projectID,sectionID);
|
|
||||||
// throw new RuntimeException("Feature not yet available");
|
|
||||||
// }catch(WebApplicationException e){
|
|
||||||
// log.warn("Unable to serve request",e);
|
|
||||||
// throw e;
|
|
||||||
// }catch(Throwable e){
|
|
||||||
// log.warn("Unable to serve request",e);
|
|
||||||
// throw new WebApplicationException("Unable to serve request", e);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
|
@ -1,7 +1,8 @@
|
||||||
package org.gcube.application.geoportal.service.rest;
|
package org.gcube.application.geoportal.service.rest;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.bson.Document;
|
import org.gcube.application.cms.implementations.ImplementationProvider;
|
||||||
import org.gcube.application.cms.serialization.Serialization;
|
import org.gcube.application.cms.serialization.Serialization;
|
||||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||||
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
||||||
|
@ -9,23 +10,36 @@ import org.gcube.application.geoportal.service.engine.mongo.UCDManagerI;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
@Path(InterfaceConstants.Methods.PROFILES)
|
@Path(InterfaceConstants.Methods.UCD)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class UseCaseDescriptors {
|
public class UseCaseDescriptors {
|
||||||
|
|
||||||
private UCDManagerI profileEngine;
|
|
||||||
|
private UCDManagerI getManager(){
|
||||||
|
try{
|
||||||
|
return ImplementationProvider.get().getEngineByManagedClass(UCDManagerI.class);
|
||||||
|
}catch(Throwable t){
|
||||||
|
log.error("Unable to get UCD Engine",t);
|
||||||
|
throw new WebApplicationException("Unable to access UC Engine", Response.Status.INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public UseCaseDescriptor createNew(Document toCreate) {
|
public UseCaseDescriptor createNew(UseCaseDescriptor toCreate) {
|
||||||
return new GuardedMethod<UseCaseDescriptor>() {
|
return new GuardedMethod<UseCaseDescriptor>() {
|
||||||
@Override
|
@Override
|
||||||
protected UseCaseDescriptor run() throws Exception, WebApplicationException {
|
protected UseCaseDescriptor run() throws Exception, WebApplicationException {
|
||||||
log.info("Creating new UseCaseDescriptor ({})",toCreate);
|
log.info("Creating new UseCaseDescriptor ({})",toCreate);
|
||||||
UseCaseDescriptor toReturn= profileEngine.create(toCreate);
|
if(toCreate.getMongoId()!=null) throw new WebApplicationException("Cannot register Use Case Descriptor with mongo ID", Response.Status.BAD_REQUEST);
|
||||||
|
if(toCreate.getId()==null) throw new WebApplicationException("Missing mandatory field ID", Response.Status.BAD_REQUEST);
|
||||||
|
UseCaseDescriptor toReturn = getManager().put(toCreate);
|
||||||
log.info("Created new UseCaseDescriptor (ID {})",toReturn.getId());
|
log.info("Created new UseCaseDescriptor (ID {})",toReturn.getId());
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
@ -33,15 +47,16 @@ public class UseCaseDescriptors {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{"+InterfaceConstants.Parameters.PROFILE_ID+"}")
|
@Path("{"+InterfaceConstants.Parameters.UCID +"}")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public UseCaseDescriptor update(@PathParam(InterfaceConstants.Parameters.PROFILE_ID) String profileId, Document d) {
|
public UseCaseDescriptor update(@PathParam(InterfaceConstants.Parameters.UCID) String profileId, UseCaseDescriptor d) {
|
||||||
return new GuardedMethod<UseCaseDescriptor>() {
|
return new GuardedMethod<UseCaseDescriptor>() {
|
||||||
@Override
|
@Override
|
||||||
protected UseCaseDescriptor run() throws Exception, WebApplicationException {
|
protected UseCaseDescriptor run() throws Exception, WebApplicationException {
|
||||||
log.warn("Updating UseCaseDescriptor ({})",profileId);
|
log.warn("Updating UseCaseDescriptor ({})",profileId);
|
||||||
return profileEngine.update(profileId,d);
|
d.setId(profileId);
|
||||||
|
return getManager().put(d);
|
||||||
}
|
}
|
||||||
}.execute().getResult();
|
}.execute().getResult();
|
||||||
}
|
}
|
||||||
|
@ -49,15 +64,15 @@ public class UseCaseDescriptors {
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("{"+InterfaceConstants.Parameters.PROFILE_ID+"}")
|
@Path("{"+InterfaceConstants.Parameters.UCID +"}")
|
||||||
public Boolean delete(@PathParam(InterfaceConstants.Parameters.PROFILE_ID) String id,
|
public Boolean delete(@PathParam(InterfaceConstants.Parameters.UCID) String id,
|
||||||
@DefaultValue("false")
|
@DefaultValue("false")
|
||||||
@QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force) {
|
@QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force) {
|
||||||
return new GuardedMethod<Boolean>() {
|
return new GuardedMethod<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
protected Boolean run() throws Exception, WebApplicationException {
|
protected Boolean run() throws Exception, WebApplicationException {
|
||||||
log.warn("Deleting UseCaseDescriptor (ID {}). Force is {}",id,force);
|
log.warn("Deleting UseCaseDescriptor (ID {}). Force is {}",id,force);
|
||||||
profileEngine.deleteById(id,force);
|
getManager().deleteById(id,force);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}.execute().getResult();
|
}.execute().getResult();
|
||||||
|
@ -67,12 +82,14 @@ public class UseCaseDescriptors {
|
||||||
// BY ID
|
// BY ID
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("{"+InterfaceConstants.Parameters.PROFILE_ID+"}")
|
@Path("{"+InterfaceConstants.Parameters.UCID +"}")
|
||||||
public UseCaseDescriptor getById(@PathParam(InterfaceConstants.Parameters.PROFILE_ID) String id) {
|
public UseCaseDescriptor getById(@PathParam(InterfaceConstants.Parameters.UCID) String id) {
|
||||||
return new GuardedMethod<UseCaseDescriptor>() {
|
return new GuardedMethod<UseCaseDescriptor>() {
|
||||||
@Override
|
@Override
|
||||||
protected UseCaseDescriptor run() throws Exception, WebApplicationException {
|
protected UseCaseDescriptor run() throws Exception, WebApplicationException {
|
||||||
return profileEngine.getById(id);
|
UseCaseDescriptor toReturn = getManager().getById(id);
|
||||||
|
if(toReturn == null ) throw new WebApplicationException("No UCD Matching ID "+id, Response.Status.NOT_FOUND);
|
||||||
|
else return toReturn;
|
||||||
}
|
}
|
||||||
}.execute().getResult();
|
}.execute().getResult();
|
||||||
}
|
}
|
||||||
|
@ -85,7 +102,7 @@ public class UseCaseDescriptors {
|
||||||
return new GuardedMethod<Iterable<?>>() {
|
return new GuardedMethod<Iterable<?>>() {
|
||||||
@Override
|
@Override
|
||||||
protected Iterable<?> run() throws Exception, WebApplicationException {
|
protected Iterable<?> run() throws Exception, WebApplicationException {
|
||||||
return profileEngine.query(Serialization.parseQuery(queryString));
|
return getManager().query(Serialization.parseQuery(queryString));
|
||||||
}
|
}
|
||||||
}.execute().getResult();
|
}.execute().getResult();
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"_id" : "org.gcube....geoportal-data-entry-portlet",
|
"_id" : "org.gcube.geoportal-data-entry-portlet",
|
||||||
"_type" : "DATA_ENTRY_GUI",
|
"_type" : "DATA_ENTRY_GUI",
|
||||||
"_case" : "",
|
"_case" : "",
|
||||||
"_configuration" : {
|
"_configuration" : {
|
||||||
|
@ -111,11 +111,11 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"_id" : "org.gcube....geoportal-data-list",
|
"_id" : "org.gcubegeoportal-data-list",
|
||||||
"_type" : "DATA_LIST_GUI",
|
"_type" : "DATA_LIST_GUI",
|
||||||
"_case" : "smallList",
|
"_case" : "smallList",
|
||||||
"_configuration" : {
|
"_configuration" : {
|
||||||
"projection" : {"nome" : 1, "lifecycleInformation.phase" : 1},
|
"projection" : "{\"nome\" : 1, \"lifecycleInformation.phase\" : 1}",
|
||||||
"orderPaths":[
|
"orderPaths":[
|
||||||
{"label" : "author", "path" : "info.creationInfo.user.username"}],
|
{"label" : "author", "path" : "info.creationInfo.user.username"}],
|
||||||
"searchPaths":[
|
"searchPaths":[
|
||||||
|
@ -129,7 +129,7 @@
|
||||||
{"id" : "report_backward", "action" : "STEP" , "label" : "Rifiuta"}
|
{"id" : "report_backward", "action" : "STEP" , "label" : "Rifiuta"}
|
||||||
]}
|
]}
|
||||||
],
|
],
|
||||||
"implicit_filter":{"nome" : {"$eq" : "ciao" }}
|
"implicit_filter":"{\"nome\" : {\"$eq\" : \"ciao\" }}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -16,8 +16,7 @@ import static org.junit.Assume.assumeTrue;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class BasicServiceTestUnit extends JerseyTest {
|
public class BasicServiceTestUnit extends JerseyTest {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Application configure() {
|
protected Application configure() {
|
||||||
return new GeoPortalService();
|
return new GeoPortalService();
|
||||||
|
|
|
@ -12,7 +12,7 @@ public class StorageTests {
|
||||||
|
|
||||||
public static void main(String[] args) throws ConfigurationException, IOException {
|
public static void main(String[] args) throws ConfigurationException, IOException {
|
||||||
TokenSetter.set("/gcube/devsec/devVRE");
|
TokenSetter.set("/gcube/devsec/devVRE");
|
||||||
StorageClientProvider storage= ImplementationProvider.get().getEngineByClass(StorageClientProvider.class);
|
StorageClientProvider storage= ImplementationProvider.get().getEngineByManagedClass(StorageClientProvider.class);
|
||||||
|
|
||||||
String id="614de23b647cef06aecdfb28";
|
String id="614de23b647cef06aecdfb28";
|
||||||
System.out.println("FROM PROVIDER " + storage.getObject().getURL(id));
|
System.out.println("FROM PROVIDER " + storage.getObject().getURL(id));
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class Caches extends BasicServiceTestUnit {
|
||||||
AtomicLong executed = new AtomicLong(0);
|
AtomicLong executed = new AtomicLong(0);
|
||||||
AtomicLong launched = new AtomicLong(0);
|
AtomicLong launched = new AtomicLong(0);
|
||||||
|
|
||||||
final StorageUtils storage=ImplementationProvider.get().getEngineByClass(StorageUtils.class);
|
final StorageUtils storage=ImplementationProvider.get().getEngineByManagedClass(StorageUtils.class);
|
||||||
|
|
||||||
String id =storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"))[0].getId();
|
String id =storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"))[0].getId();
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package org.gcube.application.geoportal.service.profiledDocuments;
|
package org.gcube.application.geoportal.service.engine.profiles;
|
||||||
|
|
||||||
import org.gcube.application.cms.tests.TestProfiles;
|
import org.gcube.application.cms.tests.TestProfiles;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Profiles {
|
public class GenericTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -18,4 +18,7 @@ public class Profiles {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package org.gcube.application.geoportal.service.engine.profiles;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.gcube.application.cms.serialization.Serialization;
|
||||||
|
import org.gcube.application.cms.tests.TokenSetter;
|
||||||
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||||
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||||
|
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
||||||
|
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||||
|
import org.gcube.application.geoportal.service.BasicServiceTestUnit;
|
||||||
|
import org.gcube.common.storagehub.model.query.Queries;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.ws.rs.client.Entity;
|
||||||
|
import javax.ws.rs.client.WebTarget;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertEquals;
|
||||||
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
|
public class UCDCalls extends BasicServiceTestUnit {
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setContext(){
|
||||||
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
|
TokenSetter.set(GCubeTest.getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected WebTarget baseTarget() {
|
||||||
|
return target(InterfaceConstants.Methods.UCD);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void queryByHandlerId() throws Exception {
|
||||||
|
|
||||||
|
QueryRequest req = new QueryRequest();
|
||||||
|
req.setFilter(Document.parse("{\"_handlers._id\" : {\"$eq\" : \"org.gcube....geoportal-data-entry-portlet\"}}"));
|
||||||
|
check(baseTarget().path(InterfaceConstants.Methods.QUERY_PATH).request(MediaType.APPLICATION_JSON_TYPE).
|
||||||
|
post(Entity.entity(Serialization.write(req),MediaType.APPLICATION_JSON)), List.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getById() throws Exception {
|
||||||
|
String testProfileId="profiledConcessioni";
|
||||||
|
check(baseTarget().path(testProfileId).request(MediaType.APPLICATION_JSON_TYPE).get(), UseCaseDescriptor.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
|
||||||
|
public void getByWrongID() throws Exception {
|
||||||
|
String testProfileId="gnegne";
|
||||||
|
assertEquals(baseTarget().path(testProfileId).request(MediaType.APPLICATION_JSON_TYPE).get().getStatus(), Response.Status.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package org.gcube.application.cms.sdi.plugins;
|
package org.gcube.application.cms.sdi.plugins;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
|
|
||||||
import lombok.Synchronized;
|
import lombok.Synchronized;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.gcube.application.cms.caches.AbstractScopedMap;
|
import org.gcube.application.cms.caches.AbstractScopedMap;
|
||||||
|
@ -10,20 +9,15 @@ import org.gcube.application.cms.plugins.AbstractPlugin;
|
||||||
import org.gcube.application.cms.plugins.InitializablePlugin;
|
import org.gcube.application.cms.plugins.InitializablePlugin;
|
||||||
import org.gcube.application.cms.plugins.faults.InitializationException;
|
import org.gcube.application.cms.plugins.faults.InitializationException;
|
||||||
import org.gcube.application.cms.plugins.faults.ShutDownException;
|
import org.gcube.application.cms.plugins.faults.ShutDownException;
|
||||||
import org.gcube.application.cms.plugins.model.PluginDescriptor;
|
|
||||||
import org.gcube.application.cms.plugins.reports.InitializationReport;
|
import org.gcube.application.cms.plugins.reports.InitializationReport;
|
||||||
import org.gcube.application.cms.plugins.reports.Report;
|
import org.gcube.application.cms.plugins.reports.Report;
|
||||||
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.application.geoportal.common.utils.ContextUtils;
|
import org.gcube.application.geoportal.common.utils.ContextUtils;
|
||||||
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;
|
||||||
import java.time.temporal.TemporalAmount;
|
|
||||||
import java.time.temporal.TemporalUnit;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class SDIAbstractPlugin extends AbstractPlugin implements InitializablePlugin {
|
public abstract class SDIAbstractPlugin extends AbstractPlugin implements InitializablePlugin {
|
||||||
|
@ -53,7 +47,7 @@ public abstract class SDIAbstractPlugin extends AbstractPlugin implements Initia
|
||||||
@Override
|
@Override
|
||||||
protected DatabaseConnection retrieveObject() throws ConfigurationException {
|
protected DatabaseConnection retrieveObject() throws ConfigurationException {
|
||||||
try {
|
try {
|
||||||
DatabaseConnection db = ImplementationProvider.get().getEngineByClass(ISInterface.class).
|
DatabaseConnection db = ImplementationProvider.get().getEngineByManagedClass(ISInterface.class).
|
||||||
queryForDatabase("Database","postgis", "GNA_DB","Concessioni");
|
queryForDatabase("Database","postgis", "GNA_DB","Concessioni");
|
||||||
log.debug("Postgis Connection in {} is {} ", ContextUtils.getCurrentScope(),db);
|
log.debug("Postgis Connection in {} is {} ", ContextUtils.getCurrentScope(),db);
|
||||||
return db;
|
return db;
|
||||||
|
|
Loading…
Reference in New Issue