Adding support for types as tree using ModelKnowledge as cache
This commit is contained in:
parent
29b559a71a
commit
0cc1ead630
|
@ -0,0 +1,26 @@
|
|||
package org.gcube.informationsystem.resourceregistry.client;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.model.knowledge.TypesDiscoverer;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class RRCTypesDiscoverer implements TypesDiscoverer<Type> {
|
||||
|
||||
protected ResourceRegistryClient resourceRegistryClient;
|
||||
|
||||
public RRCTypesDiscoverer(ResourceRegistryClient resourceRegistryClient) {
|
||||
this.resourceRegistryClient = resourceRegistryClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Type> discover(AccessType accessType) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -43,8 +43,10 @@ import org.gcube.informationsystem.resourceregistry.api.rest.QueryTemplatePath;
|
|||
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
import org.gcube.informationsystem.tree.Node;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
import org.gcube.informationsystem.types.knowledge.TypeInformation;
|
||||
import org.gcube.informationsystem.types.knowledge.TypesKnowledge;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.gcube.informationsystem.utils.TypeUtility;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -66,7 +68,7 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou
|
|||
|
||||
protected ContextCache contextCache;
|
||||
|
||||
protected ModelKnowledge<Type, TypeInformation> modelKnowledge;
|
||||
protected TypesKnowledge typesKnowledge;
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
|
@ -148,20 +150,29 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou
|
|||
}
|
||||
|
||||
public ResourceRegistryClientImpl(String address) {
|
||||
this(address, true);
|
||||
this(address, true, true);
|
||||
}
|
||||
|
||||
public ResourceRegistryClientImpl(String address, boolean sharedContextCache) {
|
||||
public ResourceRegistryClientImpl(String address, boolean sharedContextCache, boolean sharedModelKnowledge) {
|
||||
super();
|
||||
this.address = address;
|
||||
this.headers = new HashMap<>();
|
||||
if(sharedContextCache) {
|
||||
contextCache = ContextCache.getInstance();
|
||||
this.contextCache = ContextCache.getInstance();
|
||||
}else {
|
||||
contextCache = new ContextCache();
|
||||
this.contextCache = new ContextCache();
|
||||
}
|
||||
contextCache.setContextCacheRenewal(contextCacheRenewal);
|
||||
this.contextCache.setContextCacheRenewal(contextCacheRenewal);
|
||||
|
||||
if(sharedModelKnowledge) {
|
||||
this.typesKnowledge = TypesKnowledge.getInstance();
|
||||
}else {
|
||||
this.typesKnowledge = new TypesKnowledge();
|
||||
}
|
||||
typesKnowledge.setTypesDiscoverer(new RRCTypesDiscoverer(this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* It reads all the contexts from server.
|
||||
|
@ -210,6 +221,10 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou
|
|||
return contextCache;
|
||||
}
|
||||
|
||||
public ModelKnowledge<Type, TypeInformation> getModelKnowledge() {
|
||||
return typesKnowledge.getModelKnowledge();
|
||||
}
|
||||
|
||||
/**
|
||||
* It reads the context from server.
|
||||
* The cache used for contexts is bypassed and not updated.
|
||||
|
@ -318,6 +333,14 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou
|
|||
|
||||
@Override
|
||||
public boolean existType(String typeName) throws ResourceRegistryException {
|
||||
try {
|
||||
return typesKnowledge.getModelKnowledge().getTypeByName(typeName) != null;
|
||||
}catch (RuntimeException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean existTypeFromServer(String typeName) throws ResourceRegistryException {
|
||||
try {
|
||||
logger.info("Going to get {} schema", typeName);
|
||||
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||
|
@ -344,7 +367,7 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou
|
|||
// logger.trace("Error while getting {}schema for {}", polymorphic ?
|
||||
// AccessPath.POLYMORPHIC_PARAM + " " : "",
|
||||
// type, e);
|
||||
throw new RuntimeException(e);
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -357,10 +380,43 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou
|
|||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public <ERElem extends ERElement> List<Type> getTypeFromServer(Class<ERElem> clazz, Boolean polymorphic)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
String json = getTypeFromServer(TypeUtility.getTypeName(clazz), polymorphic);
|
||||
return TypeMapper.deserializeTypeDefinitions(json);
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public String getType(String typeName, Boolean polymorphic)
|
||||
*/
|
||||
public String getTypeFromKnowledge(String typeName, Boolean polymorphic)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
Node<Type> node = typesKnowledge.getModelKnowledge().getNodeByName(typeName);
|
||||
if(polymorphic) {
|
||||
// TODO
|
||||
}else {
|
||||
// TODO
|
||||
}
|
||||
return null;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// public String getTypeFromServer(String typeName, Boolean polymorphic)
|
||||
@Override
|
||||
public String getType(String typeName, Boolean polymorphic)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
|
|
Loading…
Reference in New Issue