|
|
|
@ -7,7 +7,9 @@ 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.cms.plugins.faults.StepException;
|
|
|
|
|
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.document.*;
|
|
|
|
|
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.profile.Profile;
|
|
|
|
@ -60,14 +62,17 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ProfiledDocument onUpdate(ProfiledDocument updatedDocument){
|
|
|
|
|
private ProfiledDocument onUpdate(ProfiledDocument updatedDocument) throws StepException {
|
|
|
|
|
|
|
|
|
|
UserUtils.AuthenticatedUser u = UserUtils.getCurrent();
|
|
|
|
|
updatedDocument.getInfo().setLastEditInfo(u.asInfo());
|
|
|
|
|
|
|
|
|
|
// TODO invoke lifecycle manager
|
|
|
|
|
StepExecutionRequest request=new StepExecutionRequest();
|
|
|
|
|
request.setStep(StepExecutionRequest.Steps.ON_UPDATE_DOCUMENT);
|
|
|
|
|
request.setProfile(profile);
|
|
|
|
|
request.setDocument(updatedDocument);
|
|
|
|
|
|
|
|
|
|
return updatedDocument;
|
|
|
|
|
return lfManager.performStep(request).getResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Document asDocument(ProfiledDocument d) throws JsonProcessingException {
|
|
|
|
@ -79,6 +84,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getCollectionName(){
|
|
|
|
|
// TODO Profile can directly specify, use ID only as default
|
|
|
|
|
return profile.getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -88,37 +94,51 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ProfiledDocument registerNew(Document toRegisterDoc) throws IOException {
|
|
|
|
|
public ProfiledDocument registerNew(Document toRegisterDoc) throws IOException, StepException {
|
|
|
|
|
log.info("Registering new document in {} ",profile.getId());
|
|
|
|
|
log.debug("Going to register {}",toRegisterDoc.toJson());
|
|
|
|
|
|
|
|
|
|
ProfiledDocument toRegister = new ProfiledDocument();
|
|
|
|
|
toRegister.setTheDocument(toRegisterDoc);
|
|
|
|
|
|
|
|
|
|
//TODO initialize ProfiledDocument values
|
|
|
|
|
|
|
|
|
|
PublicationInfo pubInfo=new PublicationInfo();
|
|
|
|
|
pubInfo.setCreationInfo(UserUtils.getCurrent().asInfo());
|
|
|
|
|
|
|
|
|
|
// TODO Set Access From Profile
|
|
|
|
|
Access access=new Access();
|
|
|
|
|
access.setLicense("");
|
|
|
|
|
access.setPolicy(AccessPolicy.OPEN);
|
|
|
|
|
pubInfo.setAccess(access);
|
|
|
|
|
|
|
|
|
|
toRegister.setInfo(pubInfo);
|
|
|
|
|
|
|
|
|
|
toRegister.setProfileID(profile.getId());
|
|
|
|
|
toRegister.setProfileVersion(profile.getVersion());
|
|
|
|
|
toRegister.setVersion(new ComparableVersion("1.0.0"));
|
|
|
|
|
|
|
|
|
|
// TODO Apply Lifecycle
|
|
|
|
|
|
|
|
|
|
StepExecutionRequest request=new StepExecutionRequest();
|
|
|
|
|
request.setDocument(toRegister);
|
|
|
|
|
request.setProfile(profile);
|
|
|
|
|
request.setStep(StepExecutionRequest.Steps.ON_INIT_DOCUMENT);
|
|
|
|
|
|
|
|
|
|
log.debug("Delegating init document to LCM. Request is {} ",request);
|
|
|
|
|
|
|
|
|
|
toRegister=lfManager.performStep(request).getResult();
|
|
|
|
|
|
|
|
|
|
log.debug("Going to register {} ",toRegister);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
log.info("Obtained id {} ",id);
|
|
|
|
|
return getByID(id.toHexString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ProfiledDocument update(String id, ProfiledDocument toSet) throws IOException {
|
|
|
|
|
public ProfiledDocument update(String id, ProfiledDocument toSet) throws IOException, StepException {
|
|
|
|
|
log.trace("Replacing {} ",toSet);
|
|
|
|
|
// DEFAULT ON UPDATE
|
|
|
|
|
toSet=onUpdate(toSet);
|
|
|
|
|