First integration of LifecycleManager
This commit is contained in:
parent
5ced0095d6
commit
545b70e022
|
@ -3,10 +3,12 @@ package org.gcube.application.cms.plugins;
|
||||||
import org.gcube.application.cms.plugins.faults.StepException;
|
import org.gcube.application.cms.plugins.faults.StepException;
|
||||||
import org.gcube.application.cms.plugins.reports.ExecutionReport;
|
import org.gcube.application.cms.plugins.reports.ExecutionReport;
|
||||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||||
|
|
||||||
public interface LifecycleManager extends InitializablePlugin{
|
public interface LifecycleManager extends InitializablePlugin{
|
||||||
|
|
||||||
// Lifecycle operations
|
// Lifecycle operations
|
||||||
|
|
||||||
public ExecutionReport performStep(StepExecutionRequest request)throws StepException;
|
public ExecutionReport performStep(StepExecutionRequest request)throws StepException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.gcube.application.geoportal.common.model.document.ComparableVersion;
|
||||||
public class PluginDescriptor {
|
public class PluginDescriptor {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private String ID;
|
private String id;
|
||||||
@NonNull
|
@NonNull
|
||||||
private String type;
|
private String type;
|
||||||
private String label;
|
private String label;
|
||||||
|
|
|
@ -8,6 +8,19 @@ import org.gcube.application.geoportal.common.model.profile.Profile;
|
||||||
@Data
|
@Data
|
||||||
public class StepExecutionRequest {
|
public class StepExecutionRequest {
|
||||||
|
|
||||||
|
public static class Steps{
|
||||||
|
public static final String ON_INIT_DOCUMENT="@@@INIT_DOCUMENT@@";
|
||||||
|
public static final String ON_UPDATE_DOCUMENT="@@@UPDATE_DOCUMENT@@";
|
||||||
|
public static final String ON_DELETE_DOCUMENT="@@@UPDATE_DOCUMENT@@";
|
||||||
|
|
||||||
|
public static final String ON_MATERIALIZE_DOCUMENT="@@@MATERIALIZE_DOCUMENT@@";
|
||||||
|
public static final String ON_DEMATERIALIZE_DOCUMENT="@@@DEMATERIALIZE_DOCUMENT@@";
|
||||||
|
|
||||||
|
public static final String ON_INDEX_DOCUMENT="@@@INDEX_DOCUMENT@@";
|
||||||
|
public static final String ON_DEINDEX_DOCUMENT="@@@DEINDEX_DOCUMENT@@";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Profile profile;
|
Profile profile;
|
||||||
ProfiledDocument document;
|
ProfiledDocument document;
|
||||||
String step;
|
String step;
|
||||||
|
|
|
@ -13,7 +13,7 @@ import org.bson.Document;
|
||||||
public class ProfiledDocument {
|
public class ProfiledDocument {
|
||||||
// CORE METADATA
|
// CORE METADATA
|
||||||
|
|
||||||
private String id;
|
private String _id;
|
||||||
private ComparableVersion version;
|
private ComparableVersion version;
|
||||||
|
|
||||||
// Publication Info
|
// Publication Info
|
||||||
|
|
|
@ -87,6 +87,11 @@
|
||||||
<artifactId>geoportal-common</artifactId>
|
<artifactId>geoportal-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.application</groupId>
|
||||||
|
<artifactId>cms-plugin-framework</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- SDI -->
|
<!-- SDI -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -2,9 +2,11 @@ package org.gcube.application.geoportal.service.engine.mongo;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.mongodb.client.MongoDatabase;
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
import lombok.Synchronized;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.bson.types.ObjectId;
|
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.document.ProfiledDocument;
|
||||||
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
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.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.ConfigurationException;
|
||||||
import org.gcube.application.geoportal.service.model.internal.faults.DeletionException;
|
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.Serialization;
|
||||||
|
import org.gcube.application.geoportal.service.utils.UserUtils;
|
||||||
|
|
||||||
import javax.ws.rs.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
@ -30,16 +33,41 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
|
|
||||||
|
|
||||||
Profile profile;
|
Profile profile;
|
||||||
|
MongoDatabase db=null;
|
||||||
|
|
||||||
|
LifecycleManager lfManager;
|
||||||
|
|
||||||
|
|
||||||
public ProfiledMongoManager(String profileId) throws ConfigurationException {
|
public ProfiledMongoManager(String profileId) throws ConfigurationException {
|
||||||
|
log.info("Loading profile ID {} ",profileId);
|
||||||
if(profileId==null) throw new InvalidParameterException("Profile ID cannot be null");
|
if(profileId==null) throw new InvalidParameterException("Profile ID cannot be null");
|
||||||
Map<String,Profile> profiles=ImplementationProvider.get().getProfiles().getObject();
|
Map<String,Profile> profiles=ImplementationProvider.get().getProfiles().getObject();
|
||||||
if(!profiles.containsKey(profileId))
|
if(!profiles.containsKey(profileId)) {
|
||||||
throw new WebApplicationException("Profile "+profileId+" not registered", Response.Status.NOT_FOUND);
|
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){
|
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 {
|
private Document asDocument(ProfiledDocument d) throws JsonProcessingException {
|
||||||
|
@ -51,12 +79,12 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCollectionName(){
|
private String getCollectionName(){
|
||||||
return null;
|
return profile.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected MongoDatabase getDatabase() {
|
public MongoDatabase getDatabase(){
|
||||||
return null;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,27 +94,36 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
|
|
||||||
//TODO initialize ProfiledDocument values
|
//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));
|
|
||||||
|
|
||||||
|
|
||||||
toReturn = asProfiledDocument(replace(asDocument(toReturn),getCollectionName()));
|
// TODO Apply Lifecycle
|
||||||
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
|
@Override
|
||||||
public ProfiledDocument update(String id, ProfiledDocument toSet) throws IOException {
|
public ProfiledDocument update(String id, ProfiledDocument toSet) throws IOException {
|
||||||
log.trace("Replacing {} ",toSet);
|
log.trace("Replacing {} ",toSet);
|
||||||
|
// DEFAULT ON UPDATE
|
||||||
toSet=onUpdate(toSet);
|
toSet=onUpdate(toSet);
|
||||||
|
// TODO SPECIFIC ON UPDATE
|
||||||
|
|
||||||
return asProfiledDocument(replace(asDocument(toSet),getCollectionName()));
|
return asProfiledDocument(replace(asDocument(toSet),getCollectionName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +133,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
try{
|
try{
|
||||||
ProfiledDocument doc =getByID(id);
|
ProfiledDocument doc =getByID(id);
|
||||||
|
|
||||||
|
// TODO INVOKE LIFECYCLE
|
||||||
|
|
||||||
//if(!force&&isPublished(id)) throw new Exception("Cannot delete published documents. Unpublish it or use force = true");
|
//if(!force&&isPublished(id)) throw new Exception("Cannot delete published documents. Unpublish it or use force = true");
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package org.gcube.application.geoportal.service.engine.providers;
|
||||||
|
|
||||||
|
import org.gcube.application.cms.plugins.Plugin;
|
||||||
|
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PluginManager implements Engine<Map<String, Plugin>>{
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shutdown() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Plugin> getObject() throws ConfigurationException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,12 +3,17 @@ package org.gcube.application.geoportal.service.utils;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.AccountingInfo;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.Context;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.User;
|
||||||
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class UserUtils {
|
public class UserUtils {
|
||||||
|
|
||||||
|
@ -58,7 +63,19 @@ public class UserUtils {
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AccountingInfo asInfo(){
|
||||||
|
AccountingInfo info=new AccountingInfo();
|
||||||
|
User user = new User();
|
||||||
|
user.setUsername(this.getUser().getId());
|
||||||
|
|
||||||
|
info.setUser(user);
|
||||||
|
info.setInstant(LocalDateTime.now());
|
||||||
|
Context c=new Context();
|
||||||
|
c.setId(this.context);
|
||||||
|
c.setName(context.contains("/")?context.substring(context.lastIndexOf("/")):context);
|
||||||
|
info.setContext(c);
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"id" : "concessione",
|
"id" : "legacyConcessioni",
|
||||||
"version" : "1.0.0",
|
"version" : "1.0.0",
|
||||||
"name" : "Concessione",
|
"name" : "Concessione",
|
||||||
"description" : "Embedded profile for concessioni [mibac] management",
|
"description" : "Embedded profile for concessioni [mibac] management",
|
||||||
|
|
|
@ -17,7 +17,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class ProjectTests extends BasicServiceTestUnit{
|
public class ProjectTests extends BasicServiceTestUnit{
|
||||||
|
|
||||||
String testProfileId="concessione";
|
String testProfileId="legacyConcessioni";
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setContext(){
|
public void setContext(){
|
||||||
|
|
Loading…
Reference in New Issue