Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
Luca Frosini | 14626cc5b9 | |
Luca Frosini | 3a7649a73c | |
Luca Frosini | c1128dd10b | |
luca.frosini | 46a4ecc5a9 | |
luca.frosini | fea4d597c1 | |
luca.frosini | fa08c93fd8 | |
Luca Frosini | fb19b25664 | |
Luca Frosini | ef7d845903 | |
Luca Frosini | 9933344e63 | |
Luca Frosini | 6510a1dac9 | |
Luca Frosini | 988630d5c0 | |
Luca Frosini | effa972513 | |
Luca Frosini | 99e0725344 |
|
@ -1,3 +1,5 @@
|
||||||
target
|
target
|
||||||
.classpath
|
.classpath
|
||||||
.project
|
.project
|
||||||
|
/.DS_Store
|
||||||
|
/bin/
|
||||||
|
|
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -2,6 +2,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||||
|
|
||||||
# Changelog for Resource Registry Schema Client
|
# Changelog for Resource Registry Schema Client
|
||||||
|
|
||||||
|
## [v4.3.0-SNAPSHOT]
|
||||||
|
|
||||||
|
- Added support for model knowledge [#25922]
|
||||||
|
|
||||||
|
|
||||||
|
## [v4.2.1]
|
||||||
|
|
||||||
|
- Migrated code to reorganized E/R format [#24992]
|
||||||
|
|
||||||
|
|
||||||
## [v4.2.0]
|
## [v4.2.0]
|
||||||
|
|
||||||
- Enhanced gcube-bom version
|
- Enhanced gcube-bom version
|
||||||
|
|
10
pom.xml
10
pom.xml
|
@ -8,7 +8,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.gcube.information-system</groupId>
|
<groupId>org.gcube.information-system</groupId>
|
||||||
<artifactId>resource-registry-schema-client</artifactId>
|
<artifactId>resource-registry-schema-client</artifactId>
|
||||||
<version>4.2.0</version>
|
<version>4.3.0-SNAPSHOT</version>
|
||||||
<name>Resource Registry Schema Client</name>
|
<name>Resource Registry Schema Client</name>
|
||||||
<description>Contains Non Idempotent API to manage Schemas in Resource Registry</description>
|
<description>Contains Non Idempotent API to manage Schemas in Resource Registry</description>
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.distribution</groupId>
|
<groupId>org.gcube.distribution</groupId>
|
||||||
<artifactId>gcube-bom</artifactId>
|
<artifactId>gcube-bom</artifactId>
|
||||||
<version>2.2.0</version>
|
<version>2.4.0</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -49,10 +49,6 @@
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>gxHTTP</artifactId>
|
<artifactId>gxHTTP</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.common</groupId>
|
|
||||||
<artifactId>common-utility-sg3</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
@ -77,7 +73,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>authorization-utils</artifactId>
|
<artifactId>authorization-utils</artifactId>
|
||||||
<version>[2.1.0, 3.0.0-SNAPSHOT)</version>
|
<version>[2.2.0, 3.0.0-SNAPSHOT)</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package org.gcube.informationsystem.resourceregistry.schema;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
|
import org.gcube.informationsystem.model.knowledge.TypesDiscoverer;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.types.reference.Type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
public class RRCCTypesDiscoverer implements TypesDiscoverer<Type> {
|
||||||
|
|
||||||
|
protected ResourceRegistrySchemaClientImpl rrsc;
|
||||||
|
|
||||||
|
public RRCCTypesDiscoverer(ResourceRegistrySchemaClientImpl rrsc) {
|
||||||
|
this.rrsc = rrsc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Type> discover(AccessType accessType) {
|
||||||
|
try {
|
||||||
|
return rrsc.getTypeFromServer(accessType.getTypeClass(), true);
|
||||||
|
} catch (ResourceRegistryException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2,10 +2,13 @@ package org.gcube.informationsystem.resourceregistry.schema;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.informationsystem.base.reference.Element;
|
import org.gcube.informationsystem.model.knowledge.ModelKnowledge;
|
||||||
|
import org.gcube.informationsystem.model.reference.ModelElement;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
|
||||||
|
import org.gcube.informationsystem.tree.Node;
|
||||||
|
import org.gcube.informationsystem.types.knowledge.TypeInformation;
|
||||||
import org.gcube.informationsystem.types.reference.Type;
|
import org.gcube.informationsystem.types.reference.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,19 +16,35 @@ import org.gcube.informationsystem.types.reference.Type;
|
||||||
*/
|
*/
|
||||||
public interface ResourceRegistrySchemaClient {
|
public interface ResourceRegistrySchemaClient {
|
||||||
|
|
||||||
|
public ModelKnowledge<Type, TypeInformation> getModelKnowledge();
|
||||||
|
|
||||||
|
public void renewModelKnowledge();
|
||||||
|
|
||||||
public void addHeader(String name, String value);
|
public void addHeader(String name, String value);
|
||||||
|
|
||||||
public String create(String typeDefinitition) throws SchemaException, ResourceRegistryException;
|
public String create(String typeDefinitition) throws SchemaException, ResourceRegistryException;
|
||||||
|
|
||||||
public <E extends Element> Type create(Class<E> clz) throws SchemaException, ResourceRegistryException;
|
public <ME extends ModelElement> Type create(Class<ME> clz) throws SchemaException, ResourceRegistryException;
|
||||||
|
|
||||||
public boolean exist(String typeName) throws ResourceRegistryException;
|
public boolean exist(String typeName) throws ResourceRegistryException;
|
||||||
|
|
||||||
public <E extends Element> boolean exist(Class<E> clz) throws ResourceRegistryException;
|
public <ME extends ModelElement> boolean exist(Class<ME> clz) throws ResourceRegistryException;
|
||||||
|
|
||||||
public String read(String typeName, Boolean polymorphic) throws SchemaNotFoundException, ResourceRegistryException;
|
public String read(String typeName, Boolean polymorphic) throws SchemaNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
|
public <ME extends ModelElement> List<Type> read(Class<ME> clz, Boolean polymorphic)
|
||||||
|
throws SchemaNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
public <E extends Element> List<Type> read(Class<E> clz, Boolean polymorphic)
|
public String read(String typeName, int level)
|
||||||
|
throws SchemaNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
|
public <ME extends ModelElement> List<Type> read(Class<ME> clz, int level)
|
||||||
|
throws SchemaNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
|
public Node<Type> getTypeTreeNode(String typeName)
|
||||||
|
throws SchemaNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
|
public <ME extends ModelElement> Node<Type> getTypeTreeNode(Class<ME> clz)
|
||||||
throws SchemaNotFoundException, ResourceRegistryException;
|
throws SchemaNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,34 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.schema;
|
package org.gcube.informationsystem.resourceregistry.schema;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.common.gxhttp.reference.GXConnection;
|
import org.gcube.common.gxhttp.reference.GXConnection;
|
||||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||||
import org.gcube.common.http.GXHTTPUtility;
|
import org.gcube.common.http.GXHTTPUtility;
|
||||||
import org.gcube.informationsystem.base.reference.Element;
|
import org.gcube.informationsystem.model.knowledge.ModelKnowledge;
|
||||||
|
import org.gcube.informationsystem.model.reference.ModelElement;
|
||||||
|
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextAlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextAlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
|
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
|
import org.gcube.informationsystem.tree.Node;
|
||||||
import org.gcube.informationsystem.types.TypeMapper;
|
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.types.reference.Type;
|
||||||
|
import org.gcube.informationsystem.utils.TypeUtility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -37,6 +46,44 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
|
|
||||||
protected Map<String, String> headers;
|
protected Map<String, String> headers;
|
||||||
|
|
||||||
|
protected TypesKnowledge typesKnowledge;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Track if the client must request to include {@link Metadata}
|
||||||
|
*/
|
||||||
|
protected boolean includeMeta;
|
||||||
|
|
||||||
|
public boolean includeMeta() {
|
||||||
|
return includeMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIncludeMeta(boolean includeMeta) {
|
||||||
|
this.includeMeta = includeMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addOptionalQueryParameters(Map<String,String> queryParams) throws UnsupportedEncodingException {
|
||||||
|
addIncludeMeta(queryParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{
|
||||||
|
Map<String,String> queryParams = new HashMap<>();
|
||||||
|
return includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
|
||||||
|
if(queryParams==null) {
|
||||||
|
queryParams = new HashMap<>();
|
||||||
|
}
|
||||||
|
addOptionalQueryParameters(queryParams);
|
||||||
|
return gxHTTPStringRequest.queryParams(queryParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addIncludeMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{
|
||||||
|
if(includeMeta) {
|
||||||
|
queryParams.put(AccessPath.INCLUDE_META_QUERY_PARAMETER, Boolean.toString(includeMeta));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addHeader(String name, String value) {
|
public void addHeader(String name, String value) {
|
||||||
headers.put(name, value);
|
headers.put(name, value);
|
||||||
|
@ -52,12 +99,35 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceRegistrySchemaClientImpl(String address) {
|
public ResourceRegistrySchemaClientImpl(String address) {
|
||||||
|
this(address, true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceRegistrySchemaClientImpl(String address, boolean sharedModelKnowledge) {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.headers = new HashMap<>();
|
this.headers = new HashMap<>();
|
||||||
|
this.includeMeta = false;
|
||||||
|
|
||||||
|
if(sharedModelKnowledge) {
|
||||||
|
this.typesKnowledge = TypesKnowledge.getInstance();
|
||||||
|
}else {
|
||||||
|
this.typesKnowledge = new TypesKnowledge();
|
||||||
|
}
|
||||||
|
typesKnowledge.setTypesDiscoverer(new RRCCTypesDiscoverer(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends Element> Type create(Class<E> clz)
|
public ModelKnowledge<Type, TypeInformation> getModelKnowledge() {
|
||||||
|
return typesKnowledge.getModelKnowledge();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renewModelKnowledge() {
|
||||||
|
typesKnowledge.renew();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <ME extends ModelElement> Type create(Class<ME> clz)
|
||||||
throws SchemaException, ResourceRegistryException {
|
throws SchemaException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String typeDefinition = TypeMapper.serializeType(clz);
|
String typeDefinition = TypeMapper.serializeType(clz);
|
||||||
|
@ -83,9 +153,14 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
gxHTTPStringRequest.path(TypePath.TYPES_PATH_PART);
|
gxHTTPStringRequest.path(TypePath.TYPES_PATH_PART);
|
||||||
gxHTTPStringRequest.path(typeDefinitionObj.getName());
|
gxHTTPStringRequest.path(typeDefinitionObj.getName());
|
||||||
|
|
||||||
|
includeAdditionalQueryParameters(gxHTTPStringRequest);
|
||||||
|
|
||||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(typeDefinitition);
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(typeDefinitition);
|
||||||
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
|
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||||
|
|
||||||
|
Type t = TypeMapper.deserializeTypeDefinition(c);
|
||||||
|
typesKnowledge.getModelKnowledge().addType(t);
|
||||||
|
|
||||||
logger.trace("{} successfully created", c);
|
logger.trace("{} successfully created", c);
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
|
@ -97,19 +172,136 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends Element> boolean exist(Class<E> clz) throws ResourceRegistryException {
|
public <ME extends ModelElement> boolean exist(Class<ME> clazz) throws ResourceRegistryException {
|
||||||
|
return exist(TypeUtility.getTypeName(clazz));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean exist(String typeName) throws ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String typeName = Utility.getTypeName(clz);
|
return typesKnowledge.getModelKnowledge().getTypeByName(typeName) != null;
|
||||||
return exist(typeName);
|
}catch (RuntimeException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Type> getTypeFromTypesKnowledge(String typeName, Boolean polymorphic)
|
||||||
|
throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
|
return getTypeFromTypesKnowledge(typeName, polymorphic, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<Type> getTypeFromTypesKnowledge(String typeName, int level)
|
||||||
|
throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
|
return getTypeFromTypesKnowledge(typeName, true, level);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<Type> addChildren(Node<Type> node, List<Type> types, int currentLevel, int maxLevel) {
|
||||||
|
if(maxLevel>=0 && maxLevel <= currentLevel) {
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Node<Type>> children = node.getChildrenNodes();
|
||||||
|
if(children!=null && children.size()>0) {
|
||||||
|
for(Node<Type> child : children) {
|
||||||
|
types.add(child.getNodeElement());
|
||||||
|
types = addChildren(child, types, ++currentLevel, maxLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Type> getTypeFromTypesKnowledge(String typeName, Boolean polymorphic, int level)
|
||||||
|
throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
|
|
||||||
|
Node<Type> node = getTypeTreeNode(typeName);
|
||||||
|
|
||||||
|
List<Type> types = new ArrayList<>();
|
||||||
|
types.add(node.getNodeElement());
|
||||||
|
|
||||||
|
if (polymorphic) {
|
||||||
|
addChildren(node, types, 0, level);
|
||||||
|
}
|
||||||
|
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String read(String typeName, Boolean polymorphic) throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
List<Type> types = getTypeFromTypesKnowledge(typeName, polymorphic);
|
||||||
|
return TypeMapper.serializeTypeDefinitions(types);
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new ResourceRegistryException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <ME extends ModelElement> List<Type> read(Class<ME> clazz, Boolean polymorphic)
|
||||||
|
throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
String typeName = TypeUtility.getTypeName(clazz);
|
||||||
|
return getTypeFromTypesKnowledge(typeName, polymorphic);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean exist(String typeName) throws ResourceRegistryException {
|
public String read(String typeName, int level) throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
List<Type> types = getTypeFromTypesKnowledge(typeName, level);
|
||||||
|
return TypeMapper.serializeTypeDefinitions(types);
|
||||||
|
} catch(ResourceRegistryException e) {
|
||||||
|
throw e;
|
||||||
|
} catch(Exception e) {
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <ME extends ModelElement> List<Type> read(Class<ME> clazz, int level)
|
||||||
|
throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
String typeName = TypeUtility.getTypeName(clazz);
|
||||||
|
return getTypeFromTypesKnowledge(typeName, level);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Node<Type> getTypeTreeNode(String typeName) throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
Node<Type> node = null;
|
||||||
|
try {
|
||||||
|
node = typesKnowledge.getModelKnowledge().getNodeByName(typeName);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
throw new SchemaNotFoundException(e);
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
} catch(ResourceRegistryException e) {
|
||||||
|
throw e;
|
||||||
|
} catch(Exception e) {
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <ME extends ModelElement> Node<Type> getTypeTreeNode(Class<ME> clazz)
|
||||||
|
throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
String typeName = TypeUtility.getTypeName(clazz);
|
||||||
|
return getTypeTreeNode(typeName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean existTypeFromServer(String typeName) throws ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.info("Going to get {} schema", typeName);
|
logger.info("Going to get {} schema", typeName);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
|
@ -134,23 +326,20 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <ME extends ModelElement> List<Type> getTypeFromServer(Class<ME> clz, Boolean polymorphic)
|
||||||
@Override
|
|
||||||
public <E extends Element> List<Type> read(Class<E> clz, Boolean polymorphic)
|
|
||||||
throws SchemaNotFoundException, ResourceRegistryException {
|
throws SchemaNotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String typeName = Utility.getTypeName(clz);
|
String typeName = TypeUtility.getTypeName(clz);
|
||||||
String res = read(typeName, polymorphic);
|
String json = getTypeFromServer(typeName, polymorphic);
|
||||||
return TypeMapper.deserializeTypeDefinitions(res);
|
return TypeMapper.deserializeTypeDefinitions(json);
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public String getTypeFromServer(String typeName, Boolean polymorphic) throws ContextNotFoundException, ResourceRegistryException {
|
||||||
public String read(String typeName, Boolean polymorphic) throws ContextNotFoundException, ResourceRegistryException {
|
|
||||||
try {
|
try {
|
||||||
logger.info("Going to get {} schema", typeName);
|
logger.info("Going to get {} schema", typeName);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
|
@ -162,7 +351,7 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
if(polymorphic != null) {
|
if(polymorphic != null) {
|
||||||
parameters.put(TypePath.POLYMORPHIC_QUERY_PARAMETER, polymorphic.toString());
|
parameters.put(TypePath.POLYMORPHIC_QUERY_PARAMETER, polymorphic.toString());
|
||||||
}
|
}
|
||||||
gxHTTPStringRequest.queryParams(parameters);
|
includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
|
||||||
|
|
||||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||||
String json = HTTPUtility.getResponse(String.class, httpURLConnection);
|
String json = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||||
|
|
|
@ -13,9 +13,9 @@ import org.gcube.common.authorization.utils.secret.JWTSecret;
|
||||||
import org.gcube.common.authorization.utils.secret.Secret;
|
import org.gcube.common.authorization.utils.secret.Secret;
|
||||||
import org.gcube.common.authorization.utils.secret.SecretUtility;
|
import org.gcube.common.authorization.utils.secret.SecretUtility;
|
||||||
import org.gcube.common.keycloak.KeycloakClientFactory;
|
import org.gcube.common.keycloak.KeycloakClientFactory;
|
||||||
|
import org.gcube.common.keycloak.KeycloakClientHelper;
|
||||||
import org.gcube.common.keycloak.model.TokenResponse;
|
import org.gcube.common.keycloak.model.TokenResponse;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -24,7 +24,6 @@ import org.slf4j.LoggerFactory;
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class ContextTest {
|
public class ContextTest {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
||||||
|
@ -40,14 +39,13 @@ public class ContextTest {
|
||||||
public static final String NEXTNEXT;
|
public static final String NEXTNEXT;
|
||||||
public static final String DEVSEC;
|
public static final String DEVSEC;
|
||||||
public static final String DEVVRE;
|
public static final String DEVVRE;
|
||||||
|
|
||||||
protected static final Properties properties;
|
protected static final Properties properties;
|
||||||
|
|
||||||
protected static final String CLIENT_ID_PROPERTY_KEY = "client_id";
|
public static final String TYPE_PROPERTY_KEY = "type";
|
||||||
protected static final String CLIENT_SECRET_PROPERTY_KEY = "client_secret";
|
public static final String USERNAME_PROPERTY_KEY = "username";
|
||||||
|
public static final String PASSWORD_PROPERTY_KEY = "password";
|
||||||
protected static final String clientID;
|
public static final String CLIENT_ID_PROPERTY_KEY = "clientId";
|
||||||
protected static final String clientSecret;
|
|
||||||
|
|
||||||
public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL";
|
public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL";
|
||||||
public static final String RESOURCE_REGISTRY_URL;
|
public static final String RESOURCE_REGISTRY_URL;
|
||||||
|
@ -69,9 +67,6 @@ public class ContextTest {
|
||||||
// load the properties file
|
// load the properties file
|
||||||
properties.load(input);
|
properties.load(input);
|
||||||
|
|
||||||
clientID = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
|
|
||||||
clientSecret = properties.getProperty(CLIENT_SECRET_PROPERTY_KEY);
|
|
||||||
|
|
||||||
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
|
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -80,6 +75,10 @@ public class ContextTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum Type{
|
||||||
|
USER, CLIENT_ID
|
||||||
|
};
|
||||||
|
|
||||||
public static void set(Secret secret) throws Exception {
|
public static void set(Secret secret) throws Exception {
|
||||||
SecretManagerProvider.instance.reset();
|
SecretManagerProvider.instance.reset();
|
||||||
SecretManager secretManager = new SecretManager();
|
SecretManager secretManager = new SecretManager();
|
||||||
|
@ -89,15 +88,56 @@ public class ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setContextByName(String fullContextName) throws Exception {
|
public static void setContextByName(String fullContextName) throws Exception {
|
||||||
|
logger.debug("Going to set credentials for context {}", fullContextName);
|
||||||
Secret secret = getSecretByContextName(fullContextName);
|
Secret secret = getSecretByContextName(fullContextName);
|
||||||
set(secret);
|
set(secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static TokenResponse getJWTAccessToken(String context) throws Exception {
|
private static TokenResponse getJWTAccessToken(String context) throws Exception {
|
||||||
ScopeProvider.instance.set(context);
|
Type type = Type.valueOf(properties.get(TYPE_PROPERTY_KEY).toString());
|
||||||
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, context, null);
|
|
||||||
return tr;
|
TokenResponse tr = null;
|
||||||
|
|
||||||
|
int index = context.indexOf('/', 1);
|
||||||
|
String root = context.substring(0, index == -1 ? context.length() : index);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case CLIENT_ID:
|
||||||
|
String clientId = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
|
||||||
|
String clientSecret = properties.getProperty(root);
|
||||||
|
|
||||||
|
tr = KeycloakClientFactory.newInstance().queryUMAToken(context, clientId, clientSecret, context, null);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case USER:
|
||||||
|
default:
|
||||||
|
String username = properties.getProperty(USERNAME_PROPERTY_KEY);
|
||||||
|
String password = properties.getProperty(PASSWORD_PROPERTY_KEY);
|
||||||
|
|
||||||
|
switch (root) {
|
||||||
|
case "/gcube":
|
||||||
|
default:
|
||||||
|
clientId = "next.d4science.org";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "/pred4s":
|
||||||
|
clientId = "pre.d4science.org";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "/d4science.research-infrastructures.eu":
|
||||||
|
clientId = "services.d4science.org";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
clientSecret = null;
|
||||||
|
|
||||||
|
tr = KeycloakClientHelper.getTokenForUser(context, username, password);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return tr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Secret getSecretByContextName(String context) throws Exception {
|
public static Secret getSecretByContextName(String context) throws Exception {
|
||||||
|
@ -117,7 +157,7 @@ public class ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getUser() {
|
public static String getUser() {
|
||||||
String user = Header.UNKNOWN_USER;
|
String user = Metadata.UNKNOWN_USER;
|
||||||
try {
|
try {
|
||||||
user = SecretManagerProvider.instance.get().getUser().getUsername();
|
user = SecretManagerProvider.instance.get().getUser().getUsername();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
|
|
@ -3,8 +3,12 @@ package org.gcube.informationsystem.resourceregistry.schema;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||||
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||||
|
import org.gcube.informationsystem.model.reference.properties.Property;
|
||||||
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||||
|
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||||
|
import org.gcube.informationsystem.tree.Node;
|
||||||
import org.gcube.informationsystem.types.TypeMapper;
|
import org.gcube.informationsystem.types.TypeMapper;
|
||||||
import org.gcube.informationsystem.types.annotations.Abstract;
|
|
||||||
import org.gcube.informationsystem.types.reference.Type;
|
import org.gcube.informationsystem.types.reference.Type;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -26,19 +30,6 @@ public class ResourceRegistrySchemaClientTest extends ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Abstract
|
|
||||||
interface AuxFacet extends Facet {
|
|
||||||
public static final String NAME = "aux"; //AuxFacet.class.getSimpleName();
|
|
||||||
public static final String DESCRIPTION = "This is AuxFacet used for Test";
|
|
||||||
public static final String VERSION = "1.0.0";
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
public void testCreate() throws Exception {
|
|
||||||
Type td = resourceRegistrySchemaClient.create(AuxFacet.class);
|
|
||||||
logger.debug("{}", td);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRead() throws Exception {
|
public void testRead() throws Exception {
|
||||||
List<Type> types = resourceRegistrySchemaClient.read(Facet.class, true);
|
List<Type> types = resourceRegistrySchemaClient.read(Facet.class, true);
|
||||||
|
@ -54,8 +45,22 @@ public class ResourceRegistrySchemaClientTest extends ContextTest {
|
||||||
|
|
||||||
|
|
||||||
Assert.assertTrue(gotFacetDefinition.getName().compareTo(facetDefinition.getName())==0);
|
Assert.assertTrue(gotFacetDefinition.getName().compareTo(facetDefinition.getName())==0);
|
||||||
// Uncomment when OrientDB team solve bug https://github.com/orientechnologies/orientdb/issues/8730
|
Assert.assertTrue(gotFacetDefinition.getDescription().compareTo(facetDefinition.getDescription())==0);
|
||||||
//Assert.assertTrue(gotFacetDefinition.getDescription().compareTo(facetDefinition.getDescription())==0);
|
|
||||||
|
Node<Type> node = resourceRegistrySchemaClient.getTypeTreeNode(Resource.class);
|
||||||
|
logger.debug("{}",node);
|
||||||
|
|
||||||
|
node = resourceRegistrySchemaClient.getTypeTreeNode(Facet.class);
|
||||||
|
logger.debug("{}",node);
|
||||||
|
|
||||||
|
node = resourceRegistrySchemaClient.getTypeTreeNode(Property.class);
|
||||||
|
logger.debug("{}",node);
|
||||||
|
|
||||||
|
node = resourceRegistrySchemaClient.getTypeTreeNode(IsRelatedTo.class);
|
||||||
|
logger.debug("{}",node);
|
||||||
|
|
||||||
|
node = resourceRegistrySchemaClient.getTypeTreeNode(ConsistsOf.class);
|
||||||
|
logger.debug("{}",node);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue