|
|
|
@ -2,9 +2,11 @@ package org.gcube.application.geoportal.service.engine.mongo;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.mongodb.client.MongoDatabase;
|
|
|
|
|
import lombok.Synchronized;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.bson.Document;
|
|
|
|
|
import org.bson.types.ObjectId;
|
|
|
|
|
import org.gcube.application.cms.plugins.LifecycleManager;
|
|
|
|
|
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;
|
|
|
|
@ -14,6 +16,7 @@ import org.gcube.application.geoportal.service.engine.ImplementationProvider;
|
|
|
|
|
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 org.gcube.application.geoportal.service.utils.UserUtils;
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.WebApplicationException;
|
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
@ -30,16 +33,41 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Profile profile;
|
|
|
|
|
MongoDatabase db=null;
|
|
|
|
|
|
|
|
|
|
LifecycleManager lfManager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ProfiledMongoManager(String profileId) throws ConfigurationException {
|
|
|
|
|
log.info("Loading profile ID {} ",profileId);
|
|
|
|
|
if(profileId==null) throw new InvalidParameterException("Profile ID cannot be null");
|
|
|
|
|
Map<String,Profile> profiles=ImplementationProvider.get().getProfiles().getObject();
|
|
|
|
|
if(!profiles.containsKey(profileId))
|
|
|
|
|
throw new WebApplicationException("Profile "+profileId+" not registered", Response.Status.NOT_FOUND);
|
|
|
|
|
if(!profiles.containsKey(profileId)) {
|
|
|
|
|
log.debug("Asked profile {} not found. Available ones are {} ",profileId,profiles.keySet());
|
|
|
|
|
throw new WebApplicationException("Profile " + profileId + " not registered", Response.Status.NOT_FOUND);
|
|
|
|
|
}
|
|
|
|
|
profile=profiles.get(profileId);
|
|
|
|
|
log.debug("Loaded Profile {} ",profile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String toUseDB=super.client.getConnection().getDatabase();
|
|
|
|
|
log.info("Connecting to DB {} ",toUseDB);
|
|
|
|
|
|
|
|
|
|
// TODO MAP OF DATABASES?
|
|
|
|
|
db=client.getTheClient().getDatabase(toUseDB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ProfiledDocument onUpdate(ProfiledDocument updatedDocument){
|
|
|
|
|
throw new RuntimeException("Implement Me");
|
|
|
|
|
|
|
|
|
|
UserUtils.AuthenticatedUser u = UserUtils.getCurrent();
|
|
|
|
|
updatedDocument.getInfo().setLastEditInfo(u.asInfo());
|
|
|
|
|
|
|
|
|
|
// TODO invoke lifecycle manager
|
|
|
|
|
|
|
|
|
|
return updatedDocument;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Document asDocument(ProfiledDocument d) throws JsonProcessingException {
|
|
|
|
@ -51,12 +79,12 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getCollectionName(){
|
|
|
|
|
return null;
|
|
|
|
|
return profile.getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected MongoDatabase getDatabase() {
|
|
|
|
|
return null;
|
|
|
|
|
public MongoDatabase getDatabase(){
|
|
|
|
|
return db;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -66,27 +94,36 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|
|
|
|
|
|
|
|
|
//TODO initialize ProfiledDocument values
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
// TODO Apply Lifecycle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toReturn = asProfiledDocument(replace(asDocument(toReturn),getCollectionName()));
|
|
|
|
|
log.debug("Registered {} ",toReturn);
|
|
|
|
|
return toReturn;
|
|
|
|
|
|
|
|
|
|
ObjectId id =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 getByID(id.toHexString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ProfiledDocument update(String id, ProfiledDocument toSet) throws IOException {
|
|
|
|
|
log.trace("Replacing {} ",toSet);
|
|
|
|
|
// DEFAULT ON UPDATE
|
|
|
|
|
toSet=onUpdate(toSet);
|
|
|
|
|
// TODO SPECIFIC ON UPDATE
|
|
|
|
|
|
|
|
|
|
return asProfiledDocument(replace(asDocument(toSet),getCollectionName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -96,6 +133,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|
|
|
|
try{
|
|
|
|
|
ProfiledDocument doc =getByID(id);
|
|
|
|
|
|
|
|
|
|
// TODO INVOKE LIFECYCLE
|
|
|
|
|
|
|
|
|
|
//if(!force&&isPublished(id)) throw new Exception("Cannot delete published documents. Unpublish it or use force = true");
|
|
|
|
|
|
|
|
|
|