|
|
|
@ -6,13 +6,13 @@ import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import org.gcube.informationsystem.model.AccessType;
|
|
|
|
|
import org.gcube.informationsystem.model.ISManageable;
|
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;
|
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.SchemaPath;
|
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall;
|
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall.HTTPMETHOD;
|
|
|
|
@ -46,12 +46,36 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|
|
|
|
return httpCall;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
protected <ISM extends ISManageable> AccessType getType(Class<ISM> clazz) {
|
|
|
|
|
if(ConsistsOf.class.isAssignableFrom(clazz)) {
|
|
|
|
|
return AccessType.CONSISTS_OF;
|
|
|
|
|
} else if(IsRelatedTo.class.isAssignableFrom(clazz)) {
|
|
|
|
|
return AccessType.IS_RELATED_TO;
|
|
|
|
|
} else if(Relation.class.isAssignableFrom(clazz)) {
|
|
|
|
|
return AccessType.RELATION;
|
|
|
|
|
} else if(Resource.class.isAssignableFrom(clazz)) {
|
|
|
|
|
return AccessType.RESOURCE;
|
|
|
|
|
} else if(Facet.class.isAssignableFrom(clazz)) {
|
|
|
|
|
return AccessType.FACET;
|
|
|
|
|
} else if(Embedded.class.isAssignableFrom(clazz)) {
|
|
|
|
|
return AccessType.EMBEDDED;
|
|
|
|
|
} else if(Entity.class.isAssignableFrom(clazz)) {
|
|
|
|
|
return AccessType.ENTITY;
|
|
|
|
|
} else {
|
|
|
|
|
throw new RuntimeException("Type " + clazz.getSimpleName() + " is not an IS base type.") ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <ISM extends ISManageable> TypeDefinition create(Class<ISM> clazz)
|
|
|
|
|
public <ISM extends ISManageable> TypeDefinition create(Class<ISM> clz)
|
|
|
|
|
throws SchemaException, ResourceRegistryException {
|
|
|
|
|
try {
|
|
|
|
|
String typeDefinition = TypeBinder.serializeType(clazz);
|
|
|
|
|
String res = create(typeDefinition);
|
|
|
|
|
String typeDefinition = TypeBinder.serializeType(clz);
|
|
|
|
|
String type = AccessType.getAccessType(clz).getName();
|
|
|
|
|
String res = create(type, typeDefinition);
|
|
|
|
|
return TypeBinder.deserializeTypeDefinition(res);
|
|
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
|
throw e;
|
|
|
|
@ -61,12 +85,14 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String create(String typeDefinitition) throws ContextAlreadyPresentException, ResourceRegistryException {
|
|
|
|
|
public String create(String baseType, String typeDefinitition) throws ContextAlreadyPresentException, ResourceRegistryException {
|
|
|
|
|
try {
|
|
|
|
|
logger.trace("Going to create: {}", typeDefinitition);
|
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
|
stringWriter.append(SchemaPath.SCHEMA_PATH_PART);
|
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
|
stringWriter.append(baseType);
|
|
|
|
|
|
|
|
|
|
HTTPCall httpCall = getHTTPCall();
|
|
|
|
|
String c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, typeDefinitition);
|
|
|
|
@ -81,11 +107,12 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public <ISM extends ISManageable> List<TypeDefinition> read(Class<ISM> clazz, Boolean polymorphic)
|
|
|
|
|
public <ISM extends ISManageable> List<TypeDefinition> read(Class<ISM> clz, Boolean polymorphic)
|
|
|
|
|
throws SchemaNotFoundException, ResourceRegistryException {
|
|
|
|
|
try {
|
|
|
|
|
String type = Utility.getType(clazz);
|
|
|
|
|
String type = Utility.getType(clz);
|
|
|
|
|
String res = read(type, polymorphic);
|
|
|
|
|
return TypeBinder.deserializeTypeDefinitions(res);
|
|
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
@ -104,15 +131,12 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
|
stringWriter.append(SchemaPath.SCHEMA_PATH_PART);
|
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
|
stringWriter.append(AccessPath.SCHEMA_PATH_PART);
|
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
|
stringWriter.append(type);
|
|
|
|
|
|
|
|
|
|
Map<String,String> parameters = new HashMap<>();
|
|
|
|
|
if(polymorphic == null) {
|
|
|
|
|
polymorphic = false;
|
|
|
|
|
if(polymorphic != null) {
|
|
|
|
|
parameters.put(SchemaPath.POLYMORPHIC_PARAM, polymorphic.toString());
|
|
|
|
|
}
|
|
|
|
|
parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString());
|
|
|
|
|
|
|
|
|
|
HTTPCall httpCall = getHTTPCall();
|
|
|
|
|
String json = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.GET, parameters);
|
|
|
|
|