Initialization Reports

This commit is contained in:
Fabio Sinibaldi 2022-02-16 17:55:41 +01:00
parent 13fdbffc80
commit c6930f213d
2 changed files with 68 additions and 7 deletions

View File

@ -5,6 +5,9 @@ import org.bson.BsonDocument;
import org.bson.BsonString;
import org.bson.BsonValue;
import org.bson.Document;
import org.gcube.application.cms.concessioni.sdi.SDIManager;
import org.gcube.application.cms.concessioni.sdi.faults.SDIInteractionException;
import org.gcube.application.cms.plugins.InitializablePlugin;
import org.gcube.application.cms.plugins.MaterializationPlugin;
import org.gcube.application.cms.plugins.faults.EventException;
import org.gcube.application.cms.plugins.reports.*;
@ -27,6 +30,7 @@ import org.gcube.application.geoportal.common.model.document.lifecycle.Triggered
import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck;
import org.gcube.application.geoportal.common.model.rest.Configuration;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.utils.ContextUtils;
import org.gcube.application.geoportal.common.utils.Files;
@Slf4j
@ -38,15 +42,59 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
DESCRIPTOR.setVersion(new ComparableVersion("1.0.0"));
}
// TODO DISCOVER
MaterializationPlugin plugin = new SDIMaterializerPlugin();
@Override
public InitializationReport initInContext() throws InitializationException {
return null;
InitializationReport report = new InitializationReport();
try{
InitializationReport matPluginReport = plugin.initInContext();
switch(matPluginReport.getStatus()){
case OK: {
report.setStatus(Report.Status.OK);
report.putMessage("Initialized "+plugin.getDescriptor().getId()+" in current context");
break;
}
default :{
report.setStatus(Report.Status.WARNING);
report.putMessage("Unable to initialize "+plugin.getDescriptor().getId());
matPluginReport.getMessages().forEach(s ->
report.putMessage(plugin.getDescriptor().getId()+" : "+s));
}
}
} catch (InitializationException e) {
log.error("Unable to initialize plugins in {} ",ContextUtils.getCurrentScope(),e);
report.setStatus(Report.Status.WARNING);
report.putMessage("Unable to initialize plugins in "+ ContextUtils.getCurrentScope()+" : "+e.getMessage());
}
return report;
}
@Override
public InitializationReport init() throws InitializationException {
return null;
InitializationReport report = new InitializationReport();
try{
InitializationReport matPluginReport = plugin.init();
switch(matPluginReport.getStatus()){
case OK: {
report.setStatus(Report.Status.OK);
report.putMessage("Initialized "+plugin.getDescriptor().getId());
break;
}
default :{
report.setStatus(Report.Status.WARNING);
report.putMessage("Unable to initialize "+plugin.getDescriptor().getId());
matPluginReport.getMessages().forEach(s ->
report.putMessage(plugin.getDescriptor().getId()+" : "+s));
}
}
} catch (InitializationException e) {
log.error("Unable to initialize plugins ",e);
report.setStatus(Report.Status.WARNING);
report.putMessage("Unable to initialize plugins : "+e.getMessage());
}
return report;
}
@Override

View File

@ -22,6 +22,7 @@ import org.gcube.application.geoportal.common.model.document.filesets.Registered
import org.gcube.application.geoportal.common.model.profile.Field;
import org.gcube.application.geoportal.common.model.profile.HandlerDeclaration;
import org.gcube.application.geoportal.common.model.profile.Profile;
import org.gcube.application.geoportal.common.utils.ContextUtils;
import java.util.List;
@ -38,12 +39,23 @@ public class SDIMaterializerPlugin implements MaterializationPlugin {
@Override
public InitializationReport initInContext() throws InitializationException {
return null;
InitializationReport report = new InitializationReport();
try{
log.info("Initializing in "+ ContextUtils.getCurrentScope());
sdiManager=new SDIManager();
report.setStatus(Report.Status.OK);
report.putMessage("Initialized SDI Manager");
} catch (SDIInteractionException e) {
throw new InitializationException("Unable to initialize SDI Manager ",e);
}
return report;
}
@Override
public InitializationReport init() throws InitializationException {
return null;
InitializationReport report = new InitializationReport();
report.setStatus(Report.Status.OK);
return report;
}
@Override
@ -83,7 +95,7 @@ public class SDIMaterializerPlugin implements MaterializationPlugin {
for(Object fsConfigObj : profileConfiguration.get("registeredFileSetPaths", List.class)){
log.debug("Managing {} ",fsConfigObj);
MaterializationConfig fsConfig=Serialization.convert(fsConfigObj,MaterializationConfig.class);
List<Field> matchingFieldDefinitions =schemaNavigator.getByPath(fsConfig.getSchemaField(), Field.class);
List matchingFieldDefinitions =schemaNavigator.getByPath(fsConfig.getSchemaField());
if(matchingFieldDefinitions==null || matchingFieldDefinitions.isEmpty())
throw new MaterializationException("Invalid Field Definition path in configuration [NO MATCH] : "+
fsConfig.getSchemaField());
@ -91,11 +103,12 @@ public class SDIMaterializerPlugin implements MaterializationPlugin {
throw new MaterializationException("Invalid Field Definition path in configuration [MATCHES "+matchingFieldDefinitions.size()+"] : "+
fsConfig.getSchemaField());
Field f = schemaNavigator.getByPath(fsConfig.getSchemaField(), Field.class).get(0);
Field f = Serialization.convert(matchingFieldDefinitions.get(0),Field.class);
// TODO Check if schema points to RegisteredFileSet
for(RegisteredFileSet fs : documentNavigator.getByPath(fsConfig.getDocumentPath(),RegisteredFileSet.class)){
for(Object fsObject : documentNavigator.getByPath(fsConfig.getDocumentPath())){
RegisteredFileSet fs = Serialization.convert(fsObject,RegisteredFileSet.class);
log.debug("Found {} ",fs);
requestArguments.putIfAbsent("basePersistencePath",profile.getId());
requestArguments.putIfAbsent("documentID",profiledDocument.get_id());