#22461 #1

Merged
fabio.sinibaldi merged 27 commits from #22461 into master 2022-01-14 12:43:19 +01:00
10 changed files with 123 additions and 23 deletions
Showing only changes of commit 545b70e022 - Show all commits

View File

@ -3,10 +3,12 @@ package org.gcube.application.cms.plugins;
import org.gcube.application.cms.plugins.faults.StepException;
import org.gcube.application.cms.plugins.reports.ExecutionReport;
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
public interface LifecycleManager extends InitializablePlugin{
// Lifecycle operations
public ExecutionReport performStep(StepExecutionRequest request)throws StepException;
}

View File

@ -12,7 +12,7 @@ import org.gcube.application.geoportal.common.model.document.ComparableVersion;
public class PluginDescriptor {
@NonNull
private String ID;
private String id;
@NonNull
private String type;
private String label;

View File

@ -8,6 +8,19 @@ import org.gcube.application.geoportal.common.model.profile.Profile;
@Data
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;
ProfiledDocument document;
String step;

View File

@ -13,7 +13,7 @@ import org.bson.Document;
public class ProfiledDocument {
// CORE METADATA
private String id;
private String _id;
private ComparableVersion version;
// Publication Info

View File

@ -87,6 +87,11 @@
<artifactId>geoportal-common</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.application</groupId>
<artifactId>cms-plugin-framework</artifactId>
</dependency>
<!-- SDI -->
<dependency>

View File

@ -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));
toReturn = asProfiledDocument(replace(asDocument(toReturn),getCollectionName()));
log.debug("Registered {} ",toReturn);
return toReturn;
// TODO Apply Lifecycle
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");

View File

@ -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;
}
}

View File

@ -3,12 +3,17 @@ package org.gcube.application.geoportal.service.utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
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.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import java.time.LocalDateTime;
@Slf4j
public class UserUtils {
@ -58,7 +63,19 @@ public class UserUtils {
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;
}
}
}

View File

@ -1,5 +1,5 @@
{
"id" : "concessione",
"id" : "legacyConcessioni",
"version" : "1.0.0",
"name" : "Concessione",
"description" : "Embedded profile for concessioni [mibac] management",

View File

@ -17,7 +17,7 @@ import static org.junit.Assert.assertEquals;
public class ProjectTests extends BasicServiceTestUnit{
String testProfileId="concessione";
String testProfileId="legacyConcessioni";
@Before
public void setContext(){