|
|
|
@ -1,5 +1,145 @@
|
|
|
|
|
package org.gcube.application.geoportal.service.engine.mongo;
|
|
|
|
|
|
|
|
|
|
public class ProfiledMongoManager {
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.mongodb.client.MongoDatabase;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.bson.Document;
|
|
|
|
|
import org.bson.types.ObjectId;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
|
|
|
|
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
|
|
|
|
|
import org.gcube.application.geoportal.service.model.internal.faults.DeletionException;
|
|
|
|
|
import org.gcube.application.geoportal.service.utils.Serialization;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
|
|
import static org.gcube.application.geoportal.service.engine.mongo.ConcessioniMongoManager.asConcessione;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class ProfiledMongoManager extends MongoManager implements MongoManagerI<ProfiledDocument>{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ProfiledMongoManager() throws ConfigurationException {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ProfiledDocument onUpdate(ProfiledDocument updatedDocument){
|
|
|
|
|
throw new RuntimeException("Implement Me");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Document asDocument(ProfiledDocument d) throws JsonProcessingException {
|
|
|
|
|
return Document.parse(Serialization.write(d));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ProfiledDocument asProfiledDocument(Document d) throws IOException {
|
|
|
|
|
return Serialization.read(d.toJson(),ProfiledDocument.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getCollectionName(){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected MongoDatabase getDatabase() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ProfiledDocument registerNew(ProfiledDocument toRegister) throws IOException {
|
|
|
|
|
super.insert(asDocument(toRegister),getCollectionName());
|
|
|
|
|
|
|
|
|
|
log.trace("Going to register {} ",toRegister);
|
|
|
|
|
toRegister=onUpdate(toRegister);
|
|
|
|
|
log.trace("Concessione with defaults is {}",toRegister);
|
|
|
|
|
ObjectId id=insert(asDocument(toRegister), getCollectionName());
|
|
|
|
|
|
|
|
|
|
log.trace("Obtained id {}",id);
|
|
|
|
|
ProfiledDocument toReturn=asProfiledDocument(getById(id,getCollectionName()));
|
|
|
|
|
toReturn.setId(asString(id));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toReturn = asProfiledDocument(replace(asDocument(toReturn),getCollectionName()));
|
|
|
|
|
log.debug("Registered {} ",toReturn);
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ProfiledDocument update(String id, ProfiledDocument toSet) throws IOException {
|
|
|
|
|
log.trace("Replacing {} ",toSet);
|
|
|
|
|
toSet=onUpdate(toSet);
|
|
|
|
|
return asProfiledDocument(replace(asDocument(toSet),getCollectionName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void delete(String id,boolean force) throws DeletionException {
|
|
|
|
|
log.debug("Deleting by ID {}, force {}",id,force);
|
|
|
|
|
try{
|
|
|
|
|
ProfiledDocument doc =getByID(id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if(!force&&isPublished(id)) throw new Exception("Cannot delete published documents. Unpublish it or use force = true");
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
// TODO CHECK PHASE AND STATUS
|
|
|
|
|
// DEINDEX
|
|
|
|
|
// DEMATERIALIZE
|
|
|
|
|
// DELETE CONTENT
|
|
|
|
|
// DELETE ENTRY
|
|
|
|
|
throw new DeletionException("IMPLEMENT THIS");
|
|
|
|
|
// delete(asId(id), getCollectionName());
|
|
|
|
|
}catch(DeletionException e) {
|
|
|
|
|
//storing updated - partially deleted
|
|
|
|
|
// concessione=onUpdate(concessione);
|
|
|
|
|
// replace(asDocument(concessione), collectionName);
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}catch(Throwable t){
|
|
|
|
|
throw new DeletionException("Unable to delete "+id,t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ProfiledDocument getByID(String id) throws IOException {
|
|
|
|
|
return asProfiledDocument(super.getById(asId(id),getCollectionName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Iterable<ProfiledDocument> query(QueryRequest queryRequest) {
|
|
|
|
|
log.info("Searching concessione for filter {} ",queryRequest);
|
|
|
|
|
LinkedBlockingQueue queue=new LinkedBlockingQueue<Concessione>();
|
|
|
|
|
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 ProfiledDocument materialize(String id) {
|
|
|
|
|
throw new RuntimeException("TO IMPLEMENT");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ProfiledDocument dematerialize(String id) {
|
|
|
|
|
throw new RuntimeException("TO IMPLEMENT");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ProfiledDocument index(String id) {
|
|
|
|
|
throw new RuntimeException("TO IMPLEMENT");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ProfiledDocument deIndex(String id) {
|
|
|
|
|
throw new RuntimeException("TO IMPLEMENT");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ProfiledDocument performStep(String id, String step, Document options) {
|
|
|
|
|
throw new RuntimeException("TO IMPLEMENT");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|