Refs #10248: Create Resource Registry Schema Client
Task-Url: https://support.d4science.org/issues/10248 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-schema-client@160674 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
97c810e126
commit
e1a53c3da8
5
pom.xml
5
pom.xml
|
@ -78,6 +78,11 @@
|
||||||
<version>1.0.13</version>
|
<version>1.0.13</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.information-system</groupId>
|
||||||
|
<artifactId>gcube-resources</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
|
@ -13,14 +13,14 @@ import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
|
||||||
*/
|
*/
|
||||||
public interface ResourceRegistrySchemaClient {
|
public interface ResourceRegistrySchemaClient {
|
||||||
|
|
||||||
public <ISM extends ISManageable> TypeDefinition create(Class<ISM> clazz)
|
public <ISM extends ISManageable> TypeDefinition create(Class<ISM> clz)
|
||||||
throws SchemaException, ResourceRegistryException;
|
throws SchemaException, ResourceRegistryException;
|
||||||
|
|
||||||
public String create(String typeDefinitition)
|
public String create(String baseType, String typeDefinitition)
|
||||||
throws SchemaException, ResourceRegistryException;
|
throws SchemaException, ResourceRegistryException;
|
||||||
|
|
||||||
|
|
||||||
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;
|
throws SchemaNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
public String read(String type, Boolean polymorphic)
|
public String read(String type, Boolean polymorphic)
|
||||||
|
|
|
@ -6,13 +6,13 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.model.AccessType;
|
||||||
import org.gcube.informationsystem.model.ISManageable;
|
import org.gcube.informationsystem.model.ISManageable;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
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.ContextAlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
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.SchemaException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
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.SchemaPath;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall;
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall.HTTPMETHOD;
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall.HTTPMETHOD;
|
||||||
|
@ -46,12 +46,36 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
return httpCall;
|
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
|
@Override
|
||||||
public <ISM extends ISManageable> TypeDefinition create(Class<ISM> clazz)
|
public <ISM extends ISManageable> TypeDefinition create(Class<ISM> clz)
|
||||||
throws SchemaException, ResourceRegistryException {
|
throws SchemaException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String typeDefinition = TypeBinder.serializeType(clazz);
|
String typeDefinition = TypeBinder.serializeType(clz);
|
||||||
String res = create(typeDefinition);
|
String type = AccessType.getAccessType(clz).getName();
|
||||||
|
String res = create(type, typeDefinition);
|
||||||
return TypeBinder.deserializeTypeDefinition(res);
|
return TypeBinder.deserializeTypeDefinition(res);
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -61,12 +85,14 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String create(String typeDefinitition) throws ContextAlreadyPresentException, ResourceRegistryException {
|
public String create(String baseType, String typeDefinitition) throws ContextAlreadyPresentException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.trace("Going to create: {}", typeDefinitition);
|
logger.trace("Going to create: {}", typeDefinitition);
|
||||||
StringWriter stringWriter = new StringWriter();
|
StringWriter stringWriter = new StringWriter();
|
||||||
stringWriter.append(PATH_SEPARATOR);
|
stringWriter.append(PATH_SEPARATOR);
|
||||||
stringWriter.append(SchemaPath.SCHEMA_PATH_PART);
|
stringWriter.append(SchemaPath.SCHEMA_PATH_PART);
|
||||||
|
stringWriter.append(PATH_SEPARATOR);
|
||||||
|
stringWriter.append(baseType);
|
||||||
|
|
||||||
HTTPCall httpCall = getHTTPCall();
|
HTTPCall httpCall = getHTTPCall();
|
||||||
String c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, typeDefinitition);
|
String c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, typeDefinitition);
|
||||||
|
@ -81,11 +107,12 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@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 {
|
throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String type = Utility.getType(clazz);
|
String type = Utility.getType(clz);
|
||||||
String res = read(type, polymorphic);
|
String res = read(type, polymorphic);
|
||||||
return TypeBinder.deserializeTypeDefinitions(res);
|
return TypeBinder.deserializeTypeDefinitions(res);
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
|
@ -104,15 +131,12 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
stringWriter.append(PATH_SEPARATOR);
|
stringWriter.append(PATH_SEPARATOR);
|
||||||
stringWriter.append(SchemaPath.SCHEMA_PATH_PART);
|
stringWriter.append(SchemaPath.SCHEMA_PATH_PART);
|
||||||
stringWriter.append(PATH_SEPARATOR);
|
stringWriter.append(PATH_SEPARATOR);
|
||||||
stringWriter.append(AccessPath.SCHEMA_PATH_PART);
|
|
||||||
stringWriter.append(PATH_SEPARATOR);
|
|
||||||
stringWriter.append(type);
|
stringWriter.append(type);
|
||||||
|
|
||||||
Map<String,String> parameters = new HashMap<>();
|
Map<String,String> parameters = new HashMap<>();
|
||||||
if(polymorphic == null) {
|
if(polymorphic != null) {
|
||||||
polymorphic = false;
|
parameters.put(SchemaPath.POLYMORPHIC_PARAM, polymorphic.toString());
|
||||||
}
|
}
|
||||||
parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString());
|
|
||||||
|
|
||||||
HTTPCall httpCall = getHTTPCall();
|
HTTPCall httpCall = getHTTPCall();
|
||||||
String json = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.GET, parameters);
|
String json = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.GET, parameters);
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.schema;
|
package org.gcube.informationsystem.resourceregistry.schema;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.model.entity.Facet;
|
||||||
|
import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
|
||||||
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -7,5 +12,25 @@ public class ResourceRegistrySchemaClientTest extends ScopedTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(ResourceRegistrySchemaClientTest.class);
|
private static Logger logger = LoggerFactory.getLogger(ResourceRegistrySchemaClientTest.class);
|
||||||
|
|
||||||
|
interface Aux extends Facet {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreate() throws Exception {
|
||||||
|
ResourceRegistrySchemaClient resourceRegistrySchemaClient = ResourceRegistrySchemaClientFactory.create();
|
||||||
|
TypeDefinition td = resourceRegistrySchemaClient.create(Aux.class);
|
||||||
|
logger.debug("{}", td);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRead() throws Exception {
|
||||||
|
ResourceRegistrySchemaClient resourceRegistrySchemaClient = ResourceRegistrySchemaClientFactory.create();
|
||||||
|
List<TypeDefinition> types = resourceRegistrySchemaClient.read(Facet.class, true);
|
||||||
|
for(TypeDefinition td : types) {
|
||||||
|
logger.debug("{}", td);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue