Field Definition Checks

This commit is contained in:
Fabio Sinibaldi 2022-02-16 17:12:23 +01:00
parent 7718e91b4e
commit a6ef5d3547
1 changed files with 28 additions and 12 deletions

View File

@ -16,6 +16,7 @@ import org.gcube.application.cms.plugins.reports.Report;
import org.gcube.application.cms.plugins.requests.MaterializationRequest;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
import org.gcube.application.geoportal.common.model.document.ComparableVersion;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
import org.gcube.application.geoportal.common.model.profile.Field;
@ -64,7 +65,7 @@ public class SDIMaterializerPlugin implements MaterializationPlugin {
log.info("Materializer {} : Performing {} ",this.getDescriptor().getId(),request);
ProfiledDocument profiledDocument=request.getDocument();
Profile profile = request.getProfile();
Document configuration=request.getParameters();
Document requestArguments=request.getParameters();
Document profileConfiguration =null;
for (HandlerDeclaration h : profile.getHandlers()) {
if (h.getId().equals("SDI-Default-Materializer")) {
@ -77,26 +78,34 @@ public class SDIMaterializerPlugin implements MaterializationPlugin {
log.debug("Profile Configuration is {} ",profileConfiguration);
try{
JSONPathWrapper documentNavigator=new JSONPathWrapper(profiledDocument.getTheDocument().toJson());
JSONPathWrapper profileNavigator=new JSONPathWrapper(profile.getSchema().toJson());
JSONPathWrapper schemaNavigator=new JSONPathWrapper(profile.getSchema().toJson());
for(Object fsConfigObj : configuration.get("registeredFileSetPaths", List.class)){
for(Object fsConfigObj : profileConfiguration.get("registeredFileSetPaths", List.class)){
log.debug("Managing {} ",fsConfigObj);
MaterializationConfig fsConfig=Serialization.convert(fsConfigObj,MaterializationConfig.class);
Field f = profileNavigator.getByPath(fsConfig.getSchemaField(), Field.class).get(0);
List<Field> matchingFieldDefinitions =schemaNavigator.getByPath(fsConfig.getSchemaField(), Field.class);
if(matchingFieldDefinitions==null || matchingFieldDefinitions.isEmpty())
throw new MaterializationException("Invalid Field Definition path in configuration [NO MATCH] : "+
fsConfig.getSchemaField());
if(matchingFieldDefinitions.size()>1)
throw new MaterializationException("Invalid Field Definition path in configuration [MATCHES "+matchingFieldDefinitions.size()+"] : "+
fsConfig.getSchemaField());
Field f = schemaNavigator.getByPath(fsConfig.getSchemaField(), Field.class).get(0);
// TODO Check if schema points to RegisteredFileSet
for(RegisteredFileSet fs : documentNavigator.getByPath(fsConfig.getDocumentPath(),RegisteredFileSet.class)){
log.debug("Found {} ",fs);
configuration.putIfAbsent("basePersistencePath",profile.getId());
configuration.putIfAbsent("documentID",profiledDocument.get_id());
if(configuration.containsKey("titleField"))
configuration.putIfAbsent("layerTitle",fs.getString(configuration.getString("titleField")));
else configuration.putIfAbsent("layerTitle",fs.getUUID());
requestArguments.putIfAbsent("basePersistencePath",profile.getId());
requestArguments.putIfAbsent("documentID",profiledDocument.get_id());
if(requestArguments.containsKey("titleField"))
requestArguments.putIfAbsent("layerTitle",fs.getString(requestArguments.getString("titleField")));
else requestArguments.putIfAbsent("layerTitle",fs.getUUID());
RegisteredFileSet obtained = sdiManager.materializeLayer(fs,configuration);
RegisteredFileSet obtained = sdiManager.materializeLayer(fs,requestArguments);
log.debug("Obtained {} ",obtained);
documentNavigator.set("$..[?(@.uuid == "+fs.getUUID()+")]",obtained);
documentNavigator.setElement("$..[?(@.uuid == "+fs.getUUID()+")]",obtained);
}
}
@ -116,8 +125,15 @@ public class SDIMaterializerPlugin implements MaterializationPlugin {
}
}
private static final PluginDescriptor DESCRIPTOR=new PluginDescriptor("SDI-Default-Materializer", PluginDescriptor.BaseTypes.MATERIALIZER);
static {
DESCRIPTOR.setDescription("SDI Materializer. " +
"This plugin materialize FileSets in gCube SDI.");
DESCRIPTOR.setVersion(new ComparableVersion("1.0.0"));
}
@Override
public PluginDescriptor getDescriptor() {
return null;
return DESCRIPTOR;
}
}