From 8bccea574fc9bc0fd1d11fe0a30080802949993f Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 24 Jan 2024 16:10:42 +0100 Subject: [PATCH] Fixed API interface --- .../client/ResourceRegistryClient.java | 15 +++++---- .../client/ResourceRegistryClientImpl.java | 32 +++++++++---------- .../client/ResourceRegistryClientTest.java | 17 ++++++++-- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java index 0700aca..83eaf6c 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClient.java @@ -9,6 +9,7 @@ import org.gcube.informationsystem.base.reference.Direction; import org.gcube.informationsystem.contexts.reference.entities.Context; import org.gcube.informationsystem.model.knowledge.ModelKnowledge; import org.gcube.informationsystem.model.reference.ERElement; +import org.gcube.informationsystem.model.reference.ModelElement; import org.gcube.informationsystem.model.reference.entities.Entity; import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Resource; @@ -72,24 +73,24 @@ public interface ResourceRegistryClient extends RequestInfo { public boolean existType(String typeName) throws ResourceRegistryException; - public boolean existType(Class clazz) throws ResourceRegistryException; + public boolean existType(Class clazz) throws ResourceRegistryException; public String getType(String typeName, Boolean polymorphic) throws SchemaNotFoundException, ResourceRegistryException; - - public List getType(Class clazz, Boolean polymorphic) - throws SchemaNotFoundException, ResourceRegistryException; public String getType(String typeName, int level) throws SchemaNotFoundException, ResourceRegistryException; - public List getType(Class clazz, int level) + public List getType(Class clazz, Boolean polymorphic) throws SchemaNotFoundException, ResourceRegistryException; - public Node getTypeTreeNode(String typeName) + public List getType(Class clazz, int level) throws SchemaNotFoundException, ResourceRegistryException; - public Node getTypeTreeNode(Class clazz) + public Node getTypeTreeNode(Class clazz) + throws SchemaNotFoundException, ResourceRegistryException; + + public Node getTypeTreeNode(String typeName) throws SchemaNotFoundException, ResourceRegistryException; /* ---------------------------------------------------------------------- */ diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java index 57a0053..8bcac2a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java @@ -19,6 +19,7 @@ import org.gcube.informationsystem.base.reference.Direction; import org.gcube.informationsystem.contexts.reference.entities.Context; import org.gcube.informationsystem.model.knowledge.ModelKnowledge; import org.gcube.informationsystem.model.reference.ERElement; +import org.gcube.informationsystem.model.reference.ModelElement; import org.gcube.informationsystem.model.reference.entities.Entity; import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Resource; @@ -362,7 +363,7 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou } @Override - public boolean existType(Class clazz) throws ResourceRegistryException { + public boolean existType(Class clazz) throws ResourceRegistryException { return existType(TypeUtility.getTypeName(clazz)); } @@ -460,18 +461,6 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou } } - @Override - public List getType(Class clazz, Boolean polymorphic) - throws SchemaNotFoundException, ResourceRegistryException { - try { - String typeName = TypeUtility.getTypeName(clazz); - return getTypeFromTypesKnowledge(typeName, polymorphic); - } catch (Exception e) { - throw new ResourceRegistryException(e); - } - } - - @Override public String getType(String typeName, int level) throws SchemaNotFoundException, ResourceRegistryException { try { @@ -483,9 +472,20 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou throw new ResourceRegistryException(e); } } + + @Override + public List getType(Class clazz, Boolean polymorphic) + throws SchemaNotFoundException, ResourceRegistryException { + try { + String typeName = TypeUtility.getTypeName(clazz); + return getTypeFromTypesKnowledge(typeName, polymorphic); + } catch (Exception e) { + throw new ResourceRegistryException(e); + } + } @Override - public List getType(Class clazz, int level) + public List getType(Class clazz, int level) throws SchemaNotFoundException, ResourceRegistryException { try { String typeName = TypeUtility.getTypeName(clazz); @@ -513,7 +513,7 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou } @Override - public Node getTypeTreeNode(Class clazz) + public Node getTypeTreeNode(Class clazz) throws SchemaNotFoundException, ResourceRegistryException { try { String typeName = TypeUtility.getTypeName(clazz); @@ -523,7 +523,7 @@ public class ResourceRegistryClientImpl extends BaseRequestInfo implements Resou } } - public List getTypeFromServer(Class clazz, Boolean polymorphic) + public List getTypeFromServer(Class clazz, Boolean polymorphic) throws SchemaNotFoundException, ResourceRegistryException { try { String json = getTypeFromServer(TypeUtility.getTypeName(clazz), polymorphic); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTest.java index f6538f2..069ce80 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTest.java @@ -16,7 +16,7 @@ import org.gcube.informationsystem.contexts.reference.entities.Context; import org.gcube.informationsystem.contexts.reference.relations.IsParentOf; import org.gcube.informationsystem.model.impl.properties.MetadataImpl; import org.gcube.informationsystem.model.knowledge.ModelKnowledge; -import org.gcube.informationsystem.model.reference.ERElement; +import org.gcube.informationsystem.model.reference.ModelElement; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.properties.Metadata; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; @@ -76,7 +76,7 @@ public class ResourceRegistryClientTest extends ContextTest { return list; } - protected void getTypesFromKnowledge(Class clazz) throws SchemaNotFoundException, ResourceRegistryException { + protected void getTypesFromKnowledge(Class clazz) throws SchemaNotFoundException, ResourceRegistryException { List types = resourceRegistryClient.getType(clazz, true); logger.trace("List size {}\n{}", types.size(), getTypeNames(types)); } @@ -299,4 +299,17 @@ public class ResourceRegistryClientTest extends ContextTest { Assert.assertTrue(contexts.get(0).getMetadata()==null); } + + @Test + public void testRunQueryTemplates() throws Exception { + String ret = resourceRegistryClient.runQueryTemplate("IS-Monitoring-All-HostingNode"); + logger.trace(ret); + ret = resourceRegistryClient.runQueryTemplate("IS-Monitoring-All-EService"); + logger.trace(ret); + ret = resourceRegistryClient.runQueryTemplate("IS-Monitoring-All-HostingNode", "{}"); + logger.trace(ret); + ret = resourceRegistryClient.runQueryTemplate("IS-Monitoring-All-EService", "{}"); + logger.trace(ret); + } + }