This commit is contained in:
Fabio Sinibaldi 2022-03-04 18:28:45 +01:00
parent 148554d3c9
commit 9a8705183a
32 changed files with 433 additions and 209 deletions

View File

@ -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();
}

View File

@ -13,6 +13,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.extern.slf4j.XSlf4j;
import org.bson.types.ObjectId;
import org.gcube.application.geoportal.common.model.document.accounting.AccountingInfo;
@Data
@ -21,6 +22,7 @@ import org.gcube.application.geoportal.common.model.document.accounting.Accounti
@Slf4j
public class UseCaseDescriptor {
public static final String MONGO_ID="_mongoId";
public static final String ID="_id";
public static final String VERSION="_version";
public static final String NAME="_name";
@ -31,6 +33,8 @@ public class UseCaseDescriptor {
public static final String DATA_ACCESS_POLICIES="_dataAccessPolicies";
@JsonProperty(MONGO_ID)
private ObjectId mongoId;
@JsonProperty(ID)
private String id;
@ -87,4 +91,6 @@ public class UseCaseDescriptor {
return toReturn;
}
}

View File

@ -10,7 +10,7 @@ public class InterfaceConstants {
public static final String SERVICE_NAME="GeoPortal";
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 PROJECTS="projects";
@ -32,12 +32,8 @@ public class InterfaceConstants {
public static final class Parameters{
public static final String PROJECT_ID="project_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";
}

View File

@ -42,11 +42,11 @@ public class ISUtils {
public static List<AccessPoint> performGetAP(String category,String platform,String flagName,String flagValue) {
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/UseCaseDescriptor/Category/text() eq '"+category+"'")
.addCondition("$resource/UseCaseDescriptor/Platform/Name/text() eq '"+platform+"'")
.addCondition("$resource/UseCaseDescriptor/AccessPoint//Property[Name/text() eq '"+
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/UseCaseDescriptor/AccessPoint");
.setResult("$resource/Profile/AccessPoint");
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
return client.submit(query);

View File

@ -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);

View File

@ -1,12 +1,11 @@
package org.gcube.application.geoportal.service;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import jdk.internal.dynalink.linker.LinkerServices;
import lombok.extern.slf4j.Slf4j;
import org.gcube.application.cms.implementations.ISInterface;
import org.gcube.application.cms.implementations.ImplementationProvider;
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
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.providers.*;
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.Sections;
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.glassfish.jersey.server.ResourceConfig;
@ -33,7 +32,8 @@ public class GeoPortalService extends ResourceConfig{
// registerClasses(Concessioni.class);
registerClasses(ConcessioniOverMongo.class);
registerClasses(ProfiledDocuments.class);
registerClasses(Sections.class);
registerClasses(UseCaseDescriptors.class);
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 PluginManager(), PluginManager.PluginMap.class);
ImplementationProvider.get().setEngine(new StorageHubProvider(), StorageHubClient.class);
ImplementationProvider.get().setEngine(new UCDManager(),UCDManagerI.class);
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();

View File

@ -53,7 +53,7 @@ public class WorkspaceManager {
public WorkspaceManager() throws ConfigurationException, StorageHubException {
sgClient= ImplementationProvider.get().getEngineByClass(StorageHubClient.class);
sgClient= ImplementationProvider.get().getEngineByManagedClass(StorageHubClient.class);
appBase=getApplicationBaseFolder(sgClient);
}

View File

@ -258,7 +258,7 @@ public class ConcessioniMongoManager extends MongoManager{
log.info("Persisting {} files for path {} in concessione ",files.size(),destinationPath,id);
try{
Concessione c = getById(id);
StorageUtils storage=ImplementationProvider.get().getEngineByClass(StorageUtils.class);
StorageUtils storage=ImplementationProvider.get().getEngineByManagedClass(StorageUtils.class);
WorkspaceManager ws=new WorkspaceManager();
//Check Init Base folder
FolderContainer baseFolder=null;

View File

@ -34,7 +34,7 @@ public abstract class MongoManager {
protected static final Document asDoc(String json) {return Document.parse(json);}
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.debug("Mongo client is "+client);

View File

@ -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.service.engine.providers.PluginManager;
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.cms.serialization.Serialization;
import org.gcube.application.geoportal.service.model.internal.faults.RegistrationException;
import org.gcube.application.geoportal.service.utils.UserUtils;
import org.gcube.common.storagehub.client.dsl.FolderContainer;
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
log.info("Loading useCaseDescriptor ID {} ",profileId);
if(profileId==null) throw new InvalidParameterException("UseCaseDescriptor ID cannot be null");
Map<String, UseCaseDescriptor> profiles=ImplementationProvider.get().getEngineByClass(ProfileMapCache.ProfileMap.class);
if(!profiles.containsKey(profileId)) {
log.debug("Asked useCaseDescriptor {} not found. Available ones are {} ",profileId,profiles.keySet());
Map<String, UseCaseDescriptor> profiles=ImplementationProvider.get().getEngineByManagedClass(ProfileMapCache.ProfileMap.class);
useCaseDescriptor = ImplementationProvider.get().getEngineByManagedClass(UCDManagerI.class).getById(profileId);
if(useCaseDescriptor == null )
throw new WebApplicationException("UseCaseDescriptor " + profileId + " not registered", Response.Status.NOT_FOUND);
}
useCaseDescriptor =profiles.get(profileId);
log.debug("Loaded UseCaseDescriptor {} ", useCaseDescriptor);
// Connect to DB
@ -105,7 +104,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
// Loading Lifecycle Manager
log.debug("Looking for handler {} ",lcHandlerDeclaration);
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());
return toReturn;
@ -229,7 +228,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
@Override
public Iterable<Document> query(QueryRequest queryRequest) {
log.info("Querying {} ",queryRequest);
LinkedBlockingQueue queue=new LinkedBlockingQueue<Concessione>();
LinkedBlockingQueue queue=new LinkedBlockingQueue<Project>();
query(queryRequest,getCollectionName()).forEach(
(Consumer<? super Document>) (Document d)->{try{
queue.put(d);
@ -241,7 +240,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
@Override
public Iterable<Project> filter(QueryRequest queryRequest) {
log.info("Searching concessione for filter {} ",queryRequest);
LinkedBlockingQueue queue=new LinkedBlockingQueue<Concessione>();
LinkedBlockingQueue queue=new LinkedBlockingQueue<Project>();
query(queryRequest,getCollectionName()).forEach(
(Consumer<? super Document>) (Document d)->{try{
queue.put(d);
@ -299,7 +298,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
doc.getLifecycleInformation().setLastOperationStatus(LifecycleInformation.Status.OK);
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());

View File

@ -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);
}
}

View File

@ -1,18 +1,18 @@
package org.gcube.application.geoportal.service.engine.mongo;
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.rest.QueryRequest;
import org.gcube.application.geoportal.service.model.internal.faults.RegistrationException;
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);
public UseCaseDescriptor getById(String id) throws ConfigurationException, RegistrationException;
}

View File

@ -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;}
}
}

View File

@ -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.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.service.model.internal.faults.DataParsingException;
import org.gcube.application.geoportal.common.utils.ISUtils;
import java.sql.*;
import java.util.regex.Matcher;
@ -25,7 +24,7 @@ public class PostgisDBManager implements PostgisDBManagerI {
// TODO GENERIC
DatabaseConnection defaultConfiguration=
ImplementationProvider.get().getEngineByClass(ISInterface.class)
ImplementationProvider.get().getEngineByManagedClass(ISInterface.class)
.queryForDatabase("Database","postgis", "GNA_DB","Concessioni");
log.debug("Found configuration : "+defaultConfiguration);

View File

@ -39,7 +39,7 @@ public class PostgisIndex {
private SDIManager sdiManager;
private String wmsLink=null;
private static PostgisDBManager getDB() throws ConfigurationException {
return ImplementationProvider.get().getEngineByClass(PostgisDBManager.class);
return ImplementationProvider.get().getEngineByManagedClass(PostgisDBManager.class);
};
public PostgisIndex() throws SDIInteractionException, SQLException, ConfigurationException {

View File

@ -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.common.model.configuration.MongoConnection;
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 java.util.List;
@ -26,7 +25,7 @@ public class MongoClientProvider extends AbstractScopedMap<Mongo> {
@Override
protected Mongo retrieveObject() throws ConfigurationException {
MongoConnection conn=performQueryForMongoDB(ImplementationProvider.get().
getEngineByClass(ISInterface.class),
getEngineByManagedClass(ISInterface.class),
ServiceConstants.SE_GNA_DB_CATEGORY,
ServiceConstants.MONGO_SE_PLATFORM,
ServiceConstants.SE_GNA_DB_FLAG,

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -15,13 +15,13 @@ import org.gcube.application.cms.serialization.Serialization;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@Path(InterfaceConstants.Methods.PROJECTS+"/{"+InterfaceConstants.Parameters.PROFILE_ID+"}")
@Path(InterfaceConstants.Methods.PROJECTS+"/{"+InterfaceConstants.Parameters.UCID +"}")
@Slf4j
public class ProfiledDocuments {
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);
manager=new GuardedMethod<ProfiledMongoManager>(){
@Override

View File

@ -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);
// }
// }
}

View File

@ -1,7 +1,8 @@
package org.gcube.application.geoportal.service.rest;
import lombok.Getter;
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.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
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.core.MediaType;
import javax.ws.rs.core.Response;
@Path(InterfaceConstants.Methods.PROFILES)
@Path(InterfaceConstants.Methods.UCD)
@Slf4j
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
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public UseCaseDescriptor createNew(Document toCreate) {
public UseCaseDescriptor createNew(UseCaseDescriptor toCreate) {
return new GuardedMethod<UseCaseDescriptor>() {
@Override
protected UseCaseDescriptor run() throws Exception, WebApplicationException {
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());
return toReturn;
}
@ -33,15 +47,16 @@ public class UseCaseDescriptors {
}
@PUT
@Path("{"+InterfaceConstants.Parameters.PROFILE_ID+"}")
@Path("{"+InterfaceConstants.Parameters.UCID +"}")
@Consumes(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>() {
@Override
protected UseCaseDescriptor run() throws Exception, WebApplicationException {
log.warn("Updating UseCaseDescriptor ({})",profileId);
return profileEngine.update(profileId,d);
d.setId(profileId);
return getManager().put(d);
}
}.execute().getResult();
}
@ -49,15 +64,15 @@ public class UseCaseDescriptors {
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Path("{"+InterfaceConstants.Parameters.PROFILE_ID+"}")
public Boolean delete(@PathParam(InterfaceConstants.Parameters.PROFILE_ID) String id,
@Path("{"+InterfaceConstants.Parameters.UCID +"}")
public Boolean delete(@PathParam(InterfaceConstants.Parameters.UCID) String id,
@DefaultValue("false")
@QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force) {
return new GuardedMethod<Boolean>() {
@Override
protected Boolean run() throws Exception, WebApplicationException {
log.warn("Deleting UseCaseDescriptor (ID {}). Force is {}",id,force);
profileEngine.deleteById(id,force);
getManager().deleteById(id,force);
return true;
}
}.execute().getResult();
@ -67,12 +82,14 @@ public class UseCaseDescriptors {
// BY ID
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{"+InterfaceConstants.Parameters.PROFILE_ID+"}")
public UseCaseDescriptor getById(@PathParam(InterfaceConstants.Parameters.PROFILE_ID) String id) {
@Path("{"+InterfaceConstants.Parameters.UCID +"}")
public UseCaseDescriptor getById(@PathParam(InterfaceConstants.Parameters.UCID) String id) {
return new GuardedMethod<UseCaseDescriptor>() {
@Override
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();
}
@ -85,7 +102,7 @@ public class UseCaseDescriptors {
return new GuardedMethod<Iterable<?>>() {
@Override
protected Iterable<?> run() throws Exception, WebApplicationException {
return profileEngine.query(Serialization.parseQuery(queryString));
return getManager().query(Serialization.parseQuery(queryString));
}
}.execute().getResult();
}

View File

@ -86,7 +86,7 @@
},
{
"_id" : "org.gcube....geoportal-data-entry-portlet",
"_id" : "org.gcube.geoportal-data-entry-portlet",
"_type" : "DATA_ENTRY_GUI",
"_case" : "",
"_configuration" : {
@ -111,11 +111,11 @@
},
{
"_id" : "org.gcube....geoportal-data-list",
"_id" : "org.gcubegeoportal-data-list",
"_type" : "DATA_LIST_GUI",
"_case" : "smallList",
"_configuration" : {
"projection" : {"nome" : 1, "lifecycleInformation.phase" : 1},
"projection" : "{\"nome\" : 1, \"lifecycleInformation.phase\" : 1}",
"orderPaths":[
{"label" : "author", "path" : "info.creationInfo.user.username"}],
"searchPaths":[
@ -129,7 +129,7 @@
{"id" : "report_backward", "action" : "STEP" , "label" : "Rifiuta"}
]}
],
"implicit_filter":{"nome" : {"$eq" : "ciao" }}
"implicit_filter":"{\"nome\" : {\"$eq\" : \"ciao\" }}"
}
}
]

View File

@ -16,8 +16,7 @@ import static org.junit.Assume.assumeTrue;
@Slf4j
public class BasicServiceTestUnit extends JerseyTest {
@Override
protected Application configure() {
return new GeoPortalService();

View File

@ -12,7 +12,7 @@ public class StorageTests {
public static void main(String[] args) throws ConfigurationException, IOException {
TokenSetter.set("/gcube/devsec/devVRE");
StorageClientProvider storage= ImplementationProvider.get().getEngineByClass(StorageClientProvider.class);
StorageClientProvider storage= ImplementationProvider.get().getEngineByManagedClass(StorageClientProvider.class);
String id="614de23b647cef06aecdfb28";
System.out.println("FROM PROVIDER " + storage.getObject().getURL(id));

View File

@ -113,7 +113,7 @@ public class Caches extends BasicServiceTestUnit {
AtomicLong executed = 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();

View File

@ -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.junit.Test;
public class Profiles {
public class GenericTests {
@Test
@ -18,4 +18,7 @@ public class Profiles {
});
}
}

View File

@ -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);
}
}

View File

@ -1,6 +1,5 @@
package org.gcube.application.cms.sdi.plugins;
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
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.faults.InitializationException;
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.Report;
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.application.geoportal.common.utils.ContextUtils;
import org.gcube.data.transfer.model.ServiceConstants;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalUnit;
@Slf4j
public abstract class SDIAbstractPlugin extends AbstractPlugin implements InitializablePlugin {
@ -53,7 +47,7 @@ public abstract class SDIAbstractPlugin extends AbstractPlugin implements Initia
@Override
protected DatabaseConnection retrieveObject() throws ConfigurationException {
try {
DatabaseConnection db = ImplementationProvider.get().getEngineByClass(ISInterface.class).
DatabaseConnection db = ImplementationProvider.get().getEngineByManagedClass(ISInterface.class).
queryForDatabase("Database","postgis", "GNA_DB","Concessioni");
log.debug("Postgis Connection in {} is {} ", ContextUtils.getCurrentScope(),db);
return db;