Field Definition Checks
This commit is contained in:
parent
7718e91b4e
commit
a6ef5d3547
|
@ -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.plugins.requests.MaterializationRequest;
|
||||||
import org.gcube.application.cms.serialization.Serialization;
|
import org.gcube.application.cms.serialization.Serialization;
|
||||||
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
|
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.ProfiledDocument;
|
||||||
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
|
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
|
||||||
import org.gcube.application.geoportal.common.model.profile.Field;
|
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);
|
log.info("Materializer {} : Performing {} ",this.getDescriptor().getId(),request);
|
||||||
ProfiledDocument profiledDocument=request.getDocument();
|
ProfiledDocument profiledDocument=request.getDocument();
|
||||||
Profile profile = request.getProfile();
|
Profile profile = request.getProfile();
|
||||||
Document configuration=request.getParameters();
|
Document requestArguments=request.getParameters();
|
||||||
Document profileConfiguration =null;
|
Document profileConfiguration =null;
|
||||||
for (HandlerDeclaration h : profile.getHandlers()) {
|
for (HandlerDeclaration h : profile.getHandlers()) {
|
||||||
if (h.getId().equals("SDI-Default-Materializer")) {
|
if (h.getId().equals("SDI-Default-Materializer")) {
|
||||||
|
@ -77,26 +78,34 @@ public class SDIMaterializerPlugin implements MaterializationPlugin {
|
||||||
log.debug("Profile Configuration is {} ",profileConfiguration);
|
log.debug("Profile Configuration is {} ",profileConfiguration);
|
||||||
try{
|
try{
|
||||||
JSONPathWrapper documentNavigator=new JSONPathWrapper(profiledDocument.getTheDocument().toJson());
|
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);
|
log.debug("Managing {} ",fsConfigObj);
|
||||||
MaterializationConfig fsConfig=Serialization.convert(fsConfigObj,MaterializationConfig.class);
|
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
|
// TODO Check if schema points to RegisteredFileSet
|
||||||
|
|
||||||
for(RegisteredFileSet fs : documentNavigator.getByPath(fsConfig.getDocumentPath(),RegisteredFileSet.class)){
|
for(RegisteredFileSet fs : documentNavigator.getByPath(fsConfig.getDocumentPath(),RegisteredFileSet.class)){
|
||||||
log.debug("Found {} ",fs);
|
log.debug("Found {} ",fs);
|
||||||
configuration.putIfAbsent("basePersistencePath",profile.getId());
|
requestArguments.putIfAbsent("basePersistencePath",profile.getId());
|
||||||
configuration.putIfAbsent("documentID",profiledDocument.get_id());
|
requestArguments.putIfAbsent("documentID",profiledDocument.get_id());
|
||||||
if(configuration.containsKey("titleField"))
|
if(requestArguments.containsKey("titleField"))
|
||||||
configuration.putIfAbsent("layerTitle",fs.getString(configuration.getString("titleField")));
|
requestArguments.putIfAbsent("layerTitle",fs.getString(requestArguments.getString("titleField")));
|
||||||
else configuration.putIfAbsent("layerTitle",fs.getUUID());
|
else requestArguments.putIfAbsent("layerTitle",fs.getUUID());
|
||||||
|
|
||||||
RegisteredFileSet obtained = sdiManager.materializeLayer(fs,configuration);
|
RegisteredFileSet obtained = sdiManager.materializeLayer(fs,requestArguments);
|
||||||
log.debug("Obtained {} ",obtained);
|
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
|
@Override
|
||||||
public PluginDescriptor getDescriptor() {
|
public PluginDescriptor getDescriptor() {
|
||||||
return null;
|
return DESCRIPTOR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue