diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/SchemaManager.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/SchemaManager.java index d6b69d8..ce85c4a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/SchemaManager.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/SchemaManager.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; @@ -29,6 +30,7 @@ import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall. import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility; import org.gcube.informationsystem.resourceregistry.schema.SchemaManagement; import org.gcube.informationsystem.resourceregistry.schema.SchemaManagementImpl; +import org.gcube.informationsystem.types.TypeBinder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,11 +76,22 @@ public class SchemaManager { logger.info("Requested {} creation with schema {}", type, json); setCalledMethod(HTTPMETHOD.PUT, type); + AccessType accessType = null; + String firstGotType = null; try { - accessType = ERManagementUtility.getBaseAccessType(type); + Set superClasses = TypeBinder.deserializeTypeDefinition(json).getSuperClasses(); + if(superClasses.size()==0) { + throw new ResourceRegistryException("No superclasses defined"); + } + for(String superClass : superClasses) { + accessType = ERManagementUtility.getBaseAccessType(superClass); + break; + } + } catch (ResourceRegistryException e) { + throw e; } catch(Exception e) { - String error = String.format("Cannot register %s schema", type); + String error = String.format("Cannot register %s schema. Superclass %s not found", type, firstGotType); throw new ResourceRegistryException(error); }