82 lines
2.8 KiB
Java
82 lines
2.8 KiB
Java
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);
|
|
}
|
|
}
|