First integration of LifecycleManager
This commit is contained in:
parent
545b70e022
commit
43e7d6083f
|
@ -1,9 +1,13 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import lombok.Data;
|
||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
|
||||
@Data
|
||||
public class ExecutionReport extends Report{
|
||||
|
||||
StepExecutionRequest request;
|
||||
|
||||
ProfiledDocument result;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.application.geoportal.service.engine.mongo;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.plugins.faults.StepException;
|
||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.DeletionException;
|
||||
|
||||
|
@ -12,10 +13,10 @@ public interface MongoManagerI<T> {
|
|||
|
||||
// create
|
||||
|
||||
public T registerNew(Document toRegister) throws IOException;
|
||||
public T registerNew(Document toRegister) throws IOException, StepException;
|
||||
|
||||
// update
|
||||
public T update(String id,T toSet) throws IOException;
|
||||
public T update(String id,T toSet) throws IOException, StepException;
|
||||
|
||||
// delete
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue