ProfiledConcessione defaults

This commit is contained in:
Fabio Sinibaldi 2022-01-14 12:31:11 +01:00
parent 7fae68c619
commit 6ffa411dfe
20 changed files with 328 additions and 32 deletions

View File

@ -11,7 +11,7 @@ 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_DELETE_DOCUMENT="@@@DELETE_DOCUMENT@@";
public static final String ON_MATERIALIZE_DOCUMENT="@@@MATERIALIZE_DOCUMENT@@";
public static final String ON_DEMATERIALIZE_DOCUMENT="@@@DEMATERIALIZE_DOCUMENT@@";

View File

@ -6,7 +6,7 @@
<artifactId>concessioni-lifecycle</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>GNA Concessioni Use Case</name>
<name>GNA Concessioni Lifecycle</name>
<parent>
@ -40,6 +40,10 @@
<artifactId>cms-test-commons</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.application.cms</groupId>
<artifactId>concessioni-model</artifactId>
</dependency>
</dependencies>

View File

@ -1,6 +1,8 @@
package org.gcube.application.cms.concessioni.plugins;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione;
import org.gcube.application.cms.plugins.LifecycleManager;
import org.gcube.application.cms.plugins.faults.InitializationException;
import org.gcube.application.cms.plugins.faults.ShutDownException;
@ -8,8 +10,11 @@ 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.reports.Report;
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
import org.gcube.application.geoportal.common.model.document.ComparableVersion;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.utils.JSONPathWrapper;
@Slf4j
public class ConcessioniLifeCycleManager implements LifecycleManager {
@ -38,34 +43,60 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
@Override
public ExecutionReport performStep(StepExecutionRequest request) throws StepException {
log.info("Received Request ");
log.info("Serving Request {}",request);
ExecutionReport report=new ExecutionReport();
report.setRequest(request);
report.setStatus(Report.Status.OK);
try {
switch (request.getStep()) {
case StepExecutionRequest.Steps.ON_INIT_DOCUMENT:
// Set Defaults as for on update
case StepExecutionRequest.Steps.ON_UPDATE_DOCUMENT: {
ProfiledDocument doc = request.getDocument();
switch(request.getStep()){
case StepExecutionRequest.Steps.ON_INIT_DOCUMENT:{
break;
}
case StepExecutionRequest.Steps.ON_MATERIALIZE_DOCUMENT:{
case StepExecutionRequest.Steps.ON_MATERIALIZE_DOCUMENT: {
break;
}
case StepExecutionRequest.Steps.ON_DEMATERIALIZE_DOCUMENT:{
case StepExecutionRequest.Steps.ON_DEMATERIALIZE_DOCUMENT: {
break;
}
case StepExecutionRequest.Steps.ON_DEINDEX_DOCUMENT:{
case StepExecutionRequest.Steps.ON_DEINDEX_DOCUMENT: {
break;
}
case StepExecutionRequest.Steps.ON_INDEX_DOCUMENT:{
case StepExecutionRequest.Steps.ON_INDEX_DOCUMENT: {
break;
}
case StepExecutionRequest.Steps.ON_DELETE_DOCUMENT:{
case StepExecutionRequest.Steps.ON_DELETE_DOCUMENT: {
break;
}
default : throw new StepException("Invalid Step "+request.getStep());
default:
throw new StepException("Invalid Step " + request.getStep());
}
throw new StepException("Still to implement");
}catch (StepException e){
throw e;
}catch (Throwable t){
log.error("Unable to perform step "+request.getStep(),t);
report.setStatus(Report.Status.ERROR);
report.getMessages().add("Unable to execute Step "+request.getStep()+". Error was "+t.getMessage());
}
return report;
}
@Override
public PluginDescriptor getDescriptor() {
return DESCRIPTOR;
}
// STATIC ROUTINES
private static final ProfiledDocument setDefaults(ProfiledDocument document){
ProfiledConcessione c =(ProfiledConcessione) document;
c.setDefaults();
return c;
}
}

View File

@ -7,6 +7,8 @@
<groupId>org.gcube.application.cms</groupId>
<artifactId>concessioni-model</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>GNA Concessioni Model</name>
<parent>
<groupId>org.gcube.application.cms</groupId>

View File

@ -0,0 +1,7 @@
package org.gcube.application.cms.custom.gna.concessioni.model;
public interface DefaultLogicHolder {
public void setDefaults();
}

View File

@ -0,0 +1,11 @@
package org.gcube.application.cms.custom.gna.concessioni.model;
import org.bson.Document;
public class DocumentedRelazioneScavo extends Document implements DefaultLogicHolder{
@Override
public void setDefaults() {
}
}

View File

@ -1,8 +1,118 @@
package org.gcube.application.cms.custom.gna.concessioni.model;
import org.bson.BsonDocument;
import org.bson.BsonString;
import org.bson.BsonValue;
import org.bson.Document;
import org.gcube.application.geoportal.common.model.document.Access;
import org.gcube.application.geoportal.common.model.document.AccessPolicy;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.model.document.RegisteredFileSet;
import org.gcube.application.geoportal.common.model.legacy.AbstractRelazione;
import org.gcube.application.geoportal.common.model.legacy.report.Check;
import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck;
import java.util.List;
public class ProfiledConcessione extends ProfiledDocument {
public static final String NOME="nome";
//Introduzione (descrizione del progetto)
public final static String INTRODUZIONE = "introduzione";
//Descrizione del contenuto
public final static String DSCRIZIONE_CONTENUTO ="descrizioneContenuto";
//Autori
public final static String AUTHORS= "authors";
//Soggetto che materialmente invia i dati.
public final static String CONTRIBUTORE ="contributore";
//Indicare il nome del titolare/i dei dati contenuti nel dataset e/o per sue specifiche parti.
public final static String TITOLARI="titolari";
public final static String RESPONSABILE="responsabile";
public final static String EDITORS ="editore";
public final static String FONTI_FINANZIAMENTO="fontiFinanziamento";
//Research Excavation; Archaeology (valori di default)
public final static String SOGGETTO="soggetto";
//Referenze bibliografiche, DOI (se esistenti) di risorse correlate allindagine in oggetto
public final static String RISORSE_CORRELATE="risorseCorrelate";
public final static String DATA_INZIO_PROGETTO="dataInizioProgetto";
public final static String DATA_FINE_PROGETTO="dataFineProgetto";
public final static String TITOLARE_LICENZA="titolareLicenza";
public final static String TITOLARE_COPYRIGHT="titolareCopyright";
public final static String PAROLE_CHIAVE_LIBERE="paroleChiaveLibere";
public final static String PAREOLE_CHIAVE_ICCD="paroleChiaveICCD";
public final static String RELAZIONE_SCAVO="relazioneScavo";
public final static String ABSTRACT_RELAZIONE ="abstractRelazione";
public final static String IMMAGINI_RAPPRESENTATIVE="immaginiRappresentative";
public final static String POSIZIONAMENTO_SCAVO = "posizionamentoScavo";
public final static String PIANTE_FINE_SCAVO = "pianteFineScavo";
public final static String GENERIC_CONTENT= "genericContent";
public static class Sections{
public static final String TITOLO="titolo";
}
public static class Relazione{
public static final String RESPONSABILI= "responsabili";
}
@Override
public void setDefaults() {
Document doc=this.getTheDocument();
doc.putIfAbsent(SOGGETTO,new String[]{"Research Excavation","Archaeology"});
doc.putIfAbsent(DSCRIZIONE_CONTENUTO,"Relazione di fine scavo e relativo abstract; selezione di immagini rappresentative;"
+ " posizionamento topografico dell'area indagata, pianta di fine scavo.");
// Super Section
this.getInfo().getAccess().setLicense(
ConstraintCheck.defaultFor(getInfo().getAccess().getLicense(), "CC0-1.0").evaluate());
//RELAZIONE
doc.putIfAbsent(RELAZIONE_SCAVO,new RegisteredFileSet());
Document rel=doc.get(RELAZIONE_SCAVO,Document.class);
rel.putIfAbsent(Sections.TITOLO,doc.getString(NOME)+" relazione di scavo");
rel.putIfAbsent(SOGGETTO,doc.get(SOGGETTO));
rel.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo());
rel.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess());
Access relAccess=rel.get(RegisteredFileSet.ACCESS,Access.class);
relAccess.setLicense(ConstraintCheck.defaultFor(relAccess.getLicense(),"CC-BY-4.0").evaluate());
relAccess.setPolicy(ConstraintCheck.defaultFor(relAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
//ABSTRACT Relazione
doc.putIfAbsent(ABSTRACT_RELAZIONE,new RegisteredFileSet());
Document abs=doc.get(ABSTRACT_RELAZIONE,Document.class);
abs.putIfAbsent(Sections.TITOLO,doc.getString(NOME)+" abstract relazione di scavo");
abs.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo());
abs.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess());
Access absAccess=rel.get(RegisteredFileSet.ACCESS,Access.class);
absAccess.setLicense(ConstraintCheck.defaultFor(absAccess.getLicense(),"CC-BY-4.0").evaluate());
absAccess.setPolicy(ConstraintCheck.defaultFor(absAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
//IMMAGINI RAPPRESENTATIVE
// if(doc.containsKey(IMMAGINI_RAPPRESENTATIVE)) {
// for (BsonValue bsonValue : doc.toBsonDocument(null, null).
// getArray(IMMAGINI_RAPPRESENTATIVE)) {
// BsonDocument imgDocument = bsonValue.asDocument();
// imgDocument.putIfAbsent(SOGGETTO,new BsonString(doc.getString(SOGGETTO));
// imgDocument.putIfAbsent(RegisteredFileSet.CREATION_INFO,new BsonDocument(this.getInfo().getCreationInfo());
// imgDocument.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess());
// Access absAccess=rel.get(RegisteredFileSet.ACCESS,Access.class);
// absAccess.setLicense(ConstraintCheck.defaultFor(absAccess.getLicense(),"CC-BY-4.0").evaluate());
// absAccess.setPolicy(ConstraintCheck.defaultFor(absAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
// }
// }
}
}

View File

@ -41,6 +41,11 @@
<artifactId>authorization-client</artifactId>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.4.0</version>
</dependency>
<!-- TEST -->
<dependency>

View File

@ -9,6 +9,9 @@ import lombok.*;
@ToString
public class Access {
public static final String POLICY="policy";
public static final String LICENSE="license";
private AccessPolicy policy;
private String license;

View File

@ -11,6 +11,10 @@ import java.time.LocalDateTime;
@ToString
public class AccountingInfo {
public static final String USER="user";
public static final String CONTEXT="context";
public static final String INSTANT="instant";
private User user;
private Context context;
private LocalDateTime instant;

View File

@ -8,6 +8,9 @@ import lombok.*;
@Setter
@ToString
public class Context {
public static final String ID="id";
public static final String NAME = "name";
private String id;
private String name;

View File

@ -11,7 +11,13 @@ import java.util.List;
@ToString
public class LifecycleInformation {
public enum Status{
public static final String PHASE="phase";
public static final String LAST_OPERATION_STATUS="lastOperationStatus";
public static final String ERROR_MESSAGES="errorMessages";
public static final String WARNING_MESSAGES="warningMEssages";
public static final String CHILDREN="children";
public static enum Status{
PASSED,ERROR,WARNING
}

View File

@ -11,17 +11,27 @@ import org.bson.Document;
@Setter
@ToString
public class ProfiledDocument {
public static final String _ID="_id";
public static final String VERSION="version";
public static final String INFO="info";
public static final String PROFILE_ID="profileID";
public static final String PROFILE_VERSION="profileVersion";
public static final String LIFECYCLE_INFORMATION="lifecycleInformation";
public static final String RELATIONSHIPS="relationships";
public static final String SPATIAL_REFERENCE="spatialReference";
public static final String TEMPORAL_REFERENCE="temporalReference";
public static final String THE_DOCUMENT="theDocument";
// CORE METADATA
private String _id;
private ComparableVersion version;
// Publication Info
private PublicationInfo info;
// Profile reference
private String profileID;
private ComparableVersion profileVersion;
@ -35,4 +45,8 @@ public class ProfiledDocument {
private Document theDocument;
public void setDefaults(){
// TODO APPLY DEFAULTS ??
};
}

View File

@ -10,6 +10,11 @@ import org.gcube.application.geoportal.common.model.legacy.AccessPolicy;
@ToString
public class PublicationInfo {
public static final String CREATION_INFO="creationInfo";
public static final String LAST_EDIT_INFO="lastEditInfo";
public static final String ACCESS = "access";
private AccountingInfo creationInfo;
private AccountingInfo lastEditInfo;
private Access access;

View File

@ -0,0 +1,21 @@
package org.gcube.application.geoportal.common.model.document;
import lombok.*;
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
public class RegisteredFile {
public static String MIMETYPE="mimetype";
public static String STORAGE_ID="storageID";
public static String LINK="link";
public static String NAME="NAME";
private String mimetype;
private String storageID;
private String link;
private String name;
}

View File

@ -0,0 +1,25 @@
package org.gcube.application.geoportal.common.model.document;
import lombok.*;
import org.bson.Document;
import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
public class RegisteredFileSet {
public static final String CREATION_INFO="creationInfo";
public static final String ACCESS="access";
public static final String FOLDER_ID="folderID";
public static final String PAYLOADS="payloads";
private AccountingInfo creationInfo;
private Access access;
private String folderID;
private List<RegisteredFile> payloads;
}

View File

@ -9,6 +9,9 @@ import lombok.*;
@ToString
public class Relationship {
public static final String RELATIONSHIP_NAME="relationshipName";
public static final String TARGET_ID="targetID";
private String relationshipName;
private String targetID;

View File

@ -9,6 +9,9 @@ import lombok.*;
@ToString
public class User {
public static final String USERNAME="username";
private String username;
}

View File

@ -0,0 +1,34 @@
package org.gcube.application.geoportal.common.utils;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import lombok.Getter;
import java.util.List;
public class JSONPathWrapper {
public static Configuration JSON_PATH_ALWAYS_LIST_CONFIG=null;
public static Configuration JSON_PATH_PATHS_CONFIGURATION=null;
static {
JSON_PATH_ALWAYS_LIST_CONFIG= Configuration.builder().options(Option.ALWAYS_RETURN_LIST,Option.SUPPRESS_EXCEPTIONS,Option.DEFAULT_PATH_LEAF_TO_NULL).build();
JSON_PATH_PATHS_CONFIGURATION = Configuration.builder().options(Option.AS_PATH_LIST,Option.SUPPRESS_EXCEPTIONS,Option.DEFAULT_PATH_LEAF_TO_NULL).build();
}
@Getter
DocumentContext ctx=null;
public JSONPathWrapper(String json) {
ctx=JsonPath.using(JSON_PATH_ALWAYS_LIST_CONFIG).parse(json);
}
public List<Object> getByPath(String path){
throw new RuntimeException("TO IMPLEMENT");
}
}

View File

@ -46,6 +46,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
public ProfiledMongoManager(String profileId) throws ConfigurationException {
// Check Profile ID
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();
@ -57,20 +58,16 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
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);
//Getting Lifecycle Manager
//Getting Lifecycle Manager declaration from Profile
List<HandlerDeclaration> handlerDeclarations= profile.getHandlersMap().get(PluginDescriptor.BaseTypes.LIFECYCLE_MANAGER);
if(handlerDeclarations==null || handlerDeclarations.isEmpty()) throw new ConfigurationException("No Lifecycle Handler defined for profile ID "+profileId);
if(handlerDeclarations.size()>1) throw new ConfigurationException("Too many Lifecycle Handlers defined ("+handlerDeclarations+") in profile ID "+profileId);
HandlerDeclaration lcHandlerDeclaration=handlerDeclarations.get(0);
// Loading Lifecycle Manager
log.debug("Looking for handler {} ",lcHandlerDeclaration);
try{
lfManager=(LifecycleManager) ImplementationProvider.get().getPluginManager().getObject().get(lcHandlerDeclaration.getId());
@ -79,6 +76,13 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
throw new ConfigurationException("Unable to use "+lcHandlerDeclaration.getId()+" as Lifecycle Manager");
}
// Connect to DB
String toUseDB=super.client.getConnection().getDatabase();
log.info("Connecting to DB {} ",toUseDB);
// TODO MAP OF DATABASES?
db=client.getTheClient().getDatabase(toUseDB);
}
@ -102,6 +106,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
private String getCollectionName(){
// TODO Profile can directly specify, use ID only as default
return profile.getId();
}