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>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>gcube-resources</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -13,14 +13,14 @@ import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
|
|||
*/
|
||||
public interface ResourceRegistrySchemaClient {
|
||||
|
||||
public <ISM extends ISManageable> TypeDefinition create(Class<ISM> clazz)
|
||||
public <ISM extends ISManageable> TypeDefinition create(Class<ISM> clz)
|
||||
throws SchemaException, ResourceRegistryException;
|
||||
|
||||
public String create(String typeDefinitition)
|
||||
public String create(String baseType, String typeDefinitition)
|
||||
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;
|
||||
|
||||
public String read(String type, Boolean polymorphic)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
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.LoggerFactory;
|
||||
|
||||
|
@ -7,5 +12,25 @@ public class ResourceRegistrySchemaClientTest extends ScopedTest {
|
|||
|
||||
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