Refs #11288: Made resource-registry more RESTful

Task-Url: https://support.d4science.org/issues/11288

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@169103 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2018-06-12 17:42:45 +00:00
parent bb242f83bb
commit 4f42103a1f
1 changed files with 15 additions and 2 deletions

View File

@ -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<String> 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);
}