Introduced Profiled Document Interface

This commit is contained in:
Fabio Sinibaldi 2021-12-15 19:10:19 +01:00
parent 98391f8e29
commit 1912bcc1a6
17 changed files with 256 additions and 209 deletions

View File

@ -0,0 +1,39 @@
package org.gcube.application.cms.concessioni.plugins;
import org.gcube.application.cms.plugins.LifecycleManager;
import org.gcube.application.cms.plugins.faults.InitializationException;
import org.gcube.application.cms.plugins.faults.ShutDownException;
import org.gcube.application.cms.plugins.faults.StepException;
import org.gcube.application.cms.plugins.model.PluginDescriptor;
import org.gcube.application.cms.plugins.reports.ExecutionReport;
import org.gcube.application.cms.plugins.reports.InitializationReport;
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
public class ConcessioniLifeCycleManager implements LifecycleManager {
@Override
public InitializationReport initInContext() throws InitializationException {
return null;
}
@Override
public InitializationReport init() throws InitializationException {
return null;
}
@Override
public void shutdown() throws ShutDownException {
}
@Override
public ExecutionReport performStep(StepExecutionRequest request) throws StepException {
return null;
}
@Override
public PluginDescriptor getDescriptor() {
return null;
}
}

View File

@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [v1.0.6-SNAPSHOT] - 2021-09-20
- Changed artifact dependencies
- Default Profiled Documents client
## [v1.0.5] - 2021-09-20
- Refactored repositories

View File

@ -0,0 +1,93 @@
package org.gcube.application.geoportal.client;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest;
import org.gcube.application.geoportal.common.model.rest.Configuration;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import java.util.Iterator;
public class DefaultProfiledConcessioni implements MongoConcessioni {
@Override
public Concessione createNew(Concessione c) throws Exception {
return null;
}
@Override
public void deleteById(String id) throws Exception {
}
@Override
public void deleteById(String id, Boolean force) throws Exception {
}
@Override
public Concessione getById(String id) throws Exception {
return null;
}
@Override
public Iterator<Concessione> getList() throws Exception {
return null;
}
@Override
public Concessione publish(String id) throws Exception {
return null;
}
@Override
public Concessione registerFileSet(String id, AddSectionToConcessioneRequest request) throws Exception {
return null;
}
@Override
public Concessione cleanFileSet(String id, String path) throws Exception {
return null;
}
@Override
public Concessione update(String id, String jsonUpdate) throws Exception {
return null;
}
@Override
public Concessione replace(Concessione replacement) throws Exception {
return null;
}
@Override
public void unPublish(String id) throws Exception {
}
@Override
public Configuration getCurrentConfiguration() throws Exception {
return null;
}
@Override
public Iterator<Concessione> search(String filter) throws Exception {
return null;
}
@Override
public Iterator<Concessione> query(QueryRequest request) throws Exception {
return null;
}
@Override
public String queryForJSON(QueryRequest request) throws Exception {
return null;
}
@Override
public <T> Iterator<T> queryForType(QueryRequest request, Class<T> clazz) throws Exception {
return null;
}
}

View File

@ -0,0 +1,62 @@
package org.gcube.application.geoportal.client;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.bson.Document;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.model.rest.Configuration;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.rest.ProfiledDocumentsI;
import org.gcube.common.clients.delegates.ProxyDelegate;
import javax.ws.rs.client.WebTarget;
import java.rmi.RemoteException;
import java.util.Iterator;
@RequiredArgsConstructor
public class DefaultProfiledDocuments implements ProfiledDocumentsI<ProfiledDocument> {
@NonNull
private final ProxyDelegate<WebTarget> delegate;
@Override
public ProfiledDocument createNew(Document toCreate) throws RemoteException {
return null;
}
@Override
public void deleteById(String id) throws RemoteException {
}
@Override
public void deleteById(String id, Boolean force) throws RemoteException {
}
@Override
public ProfiledDocument getById(String id) throws RemoteException {
return null;
}
@Override
public Configuration getConfiguration() throws RemoteException {
return null;
}
@Override
public Iterator<ProfiledDocument> query(QueryRequest request) throws RemoteException {
return null;
}
@Override
public String querForJSON(QueryRequest request) throws RemoteException {
return null;
}
@Override
public ProfiledDocument performStep(String id, String step, Document request) {
return null;
}
}

View File

@ -1,93 +0,0 @@
package org.gcube.application.geoportal.client;
import java.rmi.RemoteException;
import java.util.Iterator;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import org.gcube.application.geoportal.common.model.project.Project;
import org.gcube.application.geoportal.common.rest.ProjectsI;
import org.gcube.common.clients.Call;
import org.gcube.common.clients.delegates.ProxyDelegate;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public class DefaultProjects implements ProjectsI{
@NonNull
private final ProxyDelegate<WebTarget> delegate;
@Override
public void deleteById(String profileId, String projectId) throws RemoteException {
deleteById(profileId,projectId,false);
}
@Override
public void deleteById(String profileId, String projectId,Boolean force) throws RemoteException {
// Call<WebTarget,String> call= new Call<WebTarget, String>() {
//
// @Override
// public String call(WebTarget endpoint) throws Exception {
// endpoint.path(profileId).path(projectId).request(MediaType.APPLICATION_JSON).delete();
// }
// };
// try{
// delegate.make(call);
// }catch(Exception e) {
//// throw new RemoteException(e);
// }
}
@Override
public Iterator<Project> getAll() throws RemoteException {
Call<WebTarget,Iterator<Project>> call=new Call<WebTarget,Iterator<Project>>(){
@Override
public Iterator<Project> call(WebTarget endpoint) throws Exception {
throw new Exception("Client method not ready");
}
};
try{
return delegate.make(call);
}catch(Exception e) {
throw new RemoteException(e.getMessage());
}
}
@Override
public Iterator<Project> getByFilter(String filter) throws RemoteException {
// TODO Auto-generated method stub
return null;
}
@Override
public Iterator<Project> getByFilter(String filter, String profileId) throws RemoteException {
// TODO Auto-generated method stub
return null;
}
@Override
public Project getById(String profileId, String id) throws RemoteException {
// TODO Auto-generated method stub
return null;
}
@Override
public Iterator<Project> getByProfile(String profileId) throws RemoteException {
// TODO Auto-generated method stub
return null;
}
@Override
public Project registrNew(String profileId, String jsonDocument) throws RemoteException {
// TODO Auto-generated method stub
return null;
}
@Override
public Project update(String profileId, String projectId, String jsonDocument) throws RemoteException {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -6,14 +6,14 @@ import javax.xml.transform.dom.DOMResult;
import javax.xml.ws.EndpointReference;
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.common.rest.ProjectsI;
import org.gcube.application.geoportal.common.rest.ProfiledDocumentsI;
import org.gcube.common.calls.jaxrs.GcubeService;
import org.gcube.common.calls.jaxrs.TargetFactory;
import org.gcube.common.clients.config.ProxyConfig;
import org.gcube.common.clients.delegates.ProxyDelegate;
import org.w3c.dom.Node;
public class ProjectsPlugin extends GeoportalAbstractPlugin<WebTarget, ProjectsI>{
public class ProjectsPlugin extends GeoportalAbstractPlugin<WebTarget, ProfiledDocumentsI>{
@Override
@ -22,8 +22,8 @@ public class ProjectsPlugin extends GeoportalAbstractPlugin<WebTarget, ProjectsI
}
@Override
public ProjectsI newProxy(ProxyDelegate<WebTarget> delegate) {
return new DefaultProjects(delegate);
public ProfiledDocumentsI newProxy(ProxyDelegate<WebTarget> delegate) {
return new DefaultProfiledDocuments(delegate);
}
@Override

View File

@ -1,9 +0,0 @@
package org.gcube.application.geoportal.common.model.project;
public class Centroid {
private Double x;
private Double y;
private Double z;
}

View File

@ -1,10 +0,0 @@
package org.gcube.application.geoportal.common.model.project;
import org.gcube.application.geoportal.common.model.BasicJSONObject;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class Project {
}

View File

@ -1,22 +0,0 @@
package org.gcube.application.geoportal.common.model.project;
import java.time.LocalDateTime;
import lombok.Data;
@Data
public class PublicationDetails {
public static enum Policy{
OPEN,RESTRICTED,EMBARGOED;
}
private LocalDateTime creation_time;
private String creation_user;
private LocalDateTime last_update_time;
private String last_update_user;
private String version;
private String license;
private String policy;
}

View File

@ -1,11 +0,0 @@
package org.gcube.application.geoportal.common.model.project;
import java.util.List;
public class Status {
private StatusPhase phase;
private List<String> messages;
}

View File

@ -1,13 +0,0 @@
package org.gcube.application.geoportal.common.model.project;
public enum StatusPhase {
DRAFT,
UNDER_VALIDATION,
INVALID,
VALID,
UNDER_PUBLICATION,
PUBLICATION_ERROR,
PUBLISHED
}

View File

@ -0,0 +1,28 @@
package org.gcube.application.geoportal.common.rest;
import org.bson.Document;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.model.rest.Configuration;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import java.rmi.RemoteException;
import java.util.Iterator;
public interface ProfiledDocumentsI<P extends ProfiledDocument> {
// CRUD
public P createNew(Document toCreate)throws RemoteException;
public void deleteById(String id) throws RemoteException;
public void deleteById(String id,Boolean force) throws RemoteException;
public P getById(String id) throws RemoteException;
// CONFIG
public Configuration getConfiguration() throws RemoteException;
// QUERY
public Iterator<P> query (QueryRequest request) throws RemoteException;
public String querForJSON(QueryRequest request)throws RemoteException;
//Execution
public P performStep(String id, String step, Document request);
}

View File

@ -1,19 +0,0 @@
package org.gcube.application.geoportal.common.rest;
import org.gcube.application.geoportal.common.model.project.Project;
import java.util.Iterator;
public interface ProjectsI {
public Iterator<Project> getAll() throws Exception;
public Iterator<Project> getByProfile(String profileId) throws Exception;
public Project getById(String profileId,String id) throws Exception;
public Iterator<Project> getByFilter(String filter)throws Exception;
public Iterator<Project> getByFilter(String filter, String profileId)throws Exception;
public Project registrNew(String profileId, String jsonDocument)throws Exception;
public Project update(String profileId, String projectId,String jsonDocument) throws Exception;
public void deleteById(String profileId, String projectId)throws Exception;
public void deleteById(String profileId, String projectId, Boolean force)throws Exception;
}

View File

@ -4,7 +4,8 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.service.rest.ConcessioniOverMongo;
import org.gcube.application.geoportal.service.rest.Projects;
import org.gcube.application.geoportal.service.rest.ProfiledDocuments;
import org.gcube.application.geoportal.service.rest.Sections;
import org.gcube.application.geoportal.service.utils.Serialization;
import org.glassfish.jersey.server.ResourceConfig;
@ -21,7 +22,7 @@ public class GeoPortalService extends ResourceConfig{
//Register interrfaces
// registerClasses(Concessioni.class);
registerClasses(ConcessioniOverMongo.class);
registerClasses(Projects.class);
registerClasses(ProfiledDocuments.class);
registerClasses(Sections.class);

View File

@ -8,6 +8,7 @@ import org.bson.Document;
import org.bson.types.ObjectId;
import org.gcube.application.cms.plugins.LifecycleManager;
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.*;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
@ -67,12 +68,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
UserUtils.AuthenticatedUser u = UserUtils.getCurrent();
updatedDocument.getInfo().setLastEditInfo(u.asInfo());
StepExecutionRequest request=new StepExecutionRequest();
request.setStep(StepExecutionRequest.Steps.ON_UPDATE_DOCUMENT);
request.setProfile(profile);
request.setDocument(updatedDocument);
return lfManager.performStep(request).getResult();
return step(updatedDocument,StepExecutionRequest.Steps.ON_UPDATE_DOCUMENT).getResult();
}
private Document asDocument(ProfiledDocument d) throws JsonProcessingException {
@ -117,20 +113,13 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
toRegister.setProfileVersion(profile.getVersion());
toRegister.setVersion(new ComparableVersion("1.0.0"));
// TODO Apply Lifecycle
// 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();
toRegister=step(toRegister,StepExecutionRequest.Steps.ON_INIT_DOCUMENT).getResult();
log.debug("Going to register {} ",toRegister);
// Insert object
ObjectId id =insert(asDocument(toRegister),getCollectionName());
log.info("Obtained id {} ",id);
@ -140,10 +129,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
@Override
public ProfiledDocument update(String id, ProfiledDocument toSet) throws IOException, StepException {
log.trace("Replacing {} ",toSet);
// DEFAULT ON UPDATE
toSet=onUpdate(toSet);
// TODO SPECIFIC ON UPDATE
return asProfiledDocument(replace(asDocument(toSet),getCollectionName()));
}
@ -229,4 +215,16 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
public ProfiledDocument performStep(String id, String step, Document options) {
throw new RuntimeException("TO IMPLEMENT");
}
private ExecutionReport step(ProfiledDocument theDocument,String step) throws StepException {
log.info("[Profile {} ] Invoking Step {} on " ,profile.getId(),step,lfManager.getDescriptor());
StepExecutionRequest request=new StepExecutionRequest();
request.setDocument(theDocument);
request.setProfile(profile);
request.setStep(StepExecutionRequest.Steps.ON_INIT_DOCUMENT);
log.debug("Requesting Step Execution {} ",request);
return lfManager.performStep(request);
}
}

View File

@ -19,11 +19,11 @@ import javax.ws.rs.core.MediaType;
@Path(InterfaceConstants.Methods.PROJECTS+"/{"+InterfaceConstants.Parameters.PROFILE_ID+"}")
@Slf4j
public class Projects {
public class ProfiledDocuments {
private ProfiledMongoManager manager;
public Projects(@PathParam(InterfaceConstants.Parameters.PROFILE_ID) String profileID) throws ConfigurationException {
public ProfiledDocuments(@PathParam(InterfaceConstants.Parameters.PROFILE_ID) String profileID) throws ConfigurationException {
log.debug("Accessing profiles "+profileID);
manager=new GuardedMethod<ProfiledMongoManager>(){
@Override

12
pom.xml
View File

@ -32,24 +32,26 @@
<modules>
<!-- Main engine -->
<module>geoportal-service</module>
<!-- Common core modules -->
<module>geoportal-common</module>
<module>cms-plugin-framework</module>
<!-- Client library -->
<module>geoportal-client</module>
<module>geoportal-common</module>
<!-- Custom implementations -->
<module>concessioni-use-case</module>
<!-- Utilities & tests -->
<module>cms-test-commons</module>
<module>use-cases</module>
<module>concessioni-use-case</module>
</modules>