Compare commits
41 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 | |
Luca Frosini | eb60093daf | |
Luca Frosini | 0bd6be8c3f | |
Luca Frosini | 1a55e93ebe | |
Luca Frosini | 76873d9787 | |
Luca Frosini | 9be6bfa8ec | |
Luca Frosini | 5f3bcda570 | |
Luca Frosini | c84c4e4c78 | |
Luca Frosini | b1541f1671 | |
Luca Frosini | 926812df1d | |
Luca Frosini | 00c275d22f | |
Luca Frosini | 9ea7640867 | |
Luca Frosini | 26e2eb5e6d | |
Luca Frosini | 66506cb5e5 | |
Luca Frosini | 31c19f3c49 | |
Luca Frosini | 7a0eb867fe | |
Luca Frosini | f56b983b2e | |
Luca Frosini | 73560578ea | |
Luca Frosini | adbda6559e | |
Luca Frosini | 73de846d82 | |
Luca Frosini | 58e80626a7 | |
Luca Frosini | dde4d011d2 | |
Luca Frosini | 9577ba0b13 | |
Luca Frosini | 76d1a81b9f | |
Luca Frosini | 847dc36fab | |
Luca Frosini | 9fa32fa7c3 | |
Luca Frosini | edc51232a5 | |
Luca Frosini | 4b58c94bc5 | |
Luca Frosini | 47ba494ec3 |
|
@ -1,3 +1,5 @@
|
|||
target
|
||||
.classpath
|
||||
.project
|
||||
/.DS_Store
|
||||
/bin/
|
||||
|
|
25
CHANGELOG.md
25
CHANGELOG.md
|
@ -2,8 +2,31 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for Resource Registry Schema Client
|
||||
|
||||
## [v4.3.0-SNAPSHOT]
|
||||
|
||||
## [v4.0.0] [r5.0.0] -
|
||||
- Added support for model knowledge [#25922]
|
||||
|
||||
|
||||
## [v4.2.1]
|
||||
|
||||
- Migrated code to reorganized E/R format [#24992]
|
||||
|
||||
|
||||
## [v4.2.0]
|
||||
|
||||
- Enhanced gcube-bom version
|
||||
- Added usage of common-utility to overcome issues with different Smartgears version (i.e. 3 and 4)
|
||||
- Added the possibility for a client to add additional HTTP headers
|
||||
- Added the possibility to create a client instance by specifying context
|
||||
|
||||
|
||||
## [v4.1.0]
|
||||
|
||||
- Restrict the interface to accept ERElement classes and not all the Element classes [#21973]
|
||||
- Client gets service URL using resource-registry-api lib utility [#23658]
|
||||
|
||||
|
||||
## [v4.0.0] [r5.0.0]
|
||||
|
||||
- Switched JSON management to gcube-jackson [#19116]
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
# Acknowledgments
|
||||
|
||||
The projects leading to this software have received funding from a series of European Union programmes including:
|
||||
|
||||
- the Sixth Framework Programme for Research and Technological Development
|
||||
- [DILIGENT](https://cordis.europa.eu/project/id/004260) (grant no. 004260).
|
||||
- the Seventh Framework Programme for research, technological development and demonstration
|
||||
- [D4Science](https://cordis.europa.eu/project/id/212488) (grant no. 212488);
|
||||
- [D4Science-II](https://cordis.europa.eu/project/id/239019) (grant no.239019);
|
||||
- [ENVRI](https://cordis.europa.eu/project/id/283465) (grant no. 283465);
|
||||
- [iMarine](https://cordis.europa.eu/project/id/283644) (grant no. 283644);
|
||||
- [EUBrazilOpenBio](https://cordis.europa.eu/project/id/288754) (grant no. 288754).
|
||||
- the H2020 research and innovation programme
|
||||
- [SoBigData](https://cordis.europa.eu/project/id/654024) (grant no. 654024);
|
||||
- [PARTHENOS](https://cordis.europa.eu/project/id/654119) (grant no. 654119);
|
||||
- [EGI-Engage](https://cordis.europa.eu/project/id/654142) (grant no. 654142);
|
||||
- [ENVRI PLUS](https://cordis.europa.eu/project/id/654182) (grant no. 654182);
|
||||
- [BlueBRIDGE](https://cordis.europa.eu/project/id/675680) (grant no. 675680);
|
||||
- [PerformFISH](https://cordis.europa.eu/project/id/727610) (grant no. 727610);
|
||||
- [AGINFRA PLUS](https://cordis.europa.eu/project/id/731001) (grant no. 731001);
|
||||
- [DESIRA](https://cordis.europa.eu/project/id/818194) (grant no. 818194);
|
||||
- [ARIADNEplus](https://cordis.europa.eu/project/id/823914) (grant no. 823914);
|
||||
- [RISIS 2](https://cordis.europa.eu/project/id/824091) (grant no. 824091);
|
||||
- [EOSC-Pillar](https://cordis.europa.eu/project/id/857650) (grant no. 857650);
|
||||
- [Blue Cloud](https://cordis.europa.eu/project/id/862409) (grant no. 862409);
|
||||
- [SoBigData-PlusPlus](https://cordis.europa.eu/project/id/871042) (grant no. 871042);
|
23
README.md
23
README.md
|
@ -45,26 +45,5 @@ open-source software toolkit used for building and operating Hybrid Data
|
|||
Infrastructures enabling the dynamic deployment of Virtual Research Environments
|
||||
by favouring the realisation of reuse oriented policies.
|
||||
|
||||
The projects leading to this software have received funding from a series of European Union programmes including:
|
||||
|
||||
- the Sixth Framework Programme for Research and Technological Development
|
||||
- DILIGENT (grant no. 004260).
|
||||
- the Seventh Framework Programme for research, technological development and demonstration
|
||||
- D4Science (grant no. 212488);
|
||||
- D4Science-II (grant no.239019);
|
||||
- ENVRI (grant no. 283465);
|
||||
- iMarine(grant no. 283644);
|
||||
- EUBrazilOpenBio (grant no. 288754).
|
||||
- the H2020 research and innovation programme
|
||||
- SoBigData (grant no. 654024);
|
||||
- PARTHENOS (grant no. 654119);
|
||||
- EGIEngage (grant no. 654142);
|
||||
- ENVRIplus (grant no. 654182);
|
||||
- BlueBRIDGE (grant no. 675680);
|
||||
- PerformFish (grant no. 727610);
|
||||
- AGINFRAplus (grant no. 731001);
|
||||
- DESIRA (grant no. 818194);
|
||||
- ARIADNEplus (grant no. 823914);
|
||||
- RISIS2 (grant no. 824091);
|
||||
|
||||
The projects leading to this software have received funding from a series of European Union programmes see [FUNDING.md](FUNDING.md)
|
||||
|
||||
|
|
18
pom.xml
18
pom.xml
|
@ -8,7 +8,7 @@
|
|||
</parent>
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>resource-registry-schema-client</artifactId>
|
||||
<version>4.0.0</version>
|
||||
<version>4.3.0-SNAPSHOT</version>
|
||||
<name>Resource Registry Schema Client</name>
|
||||
<description>Contains Non Idempotent API to manage Schemas in Resource Registry</description>
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.4.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -37,14 +37,6 @@
|
|||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources.discovery</groupId>
|
||||
<artifactId>ic-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>resource-registry-api</artifactId>
|
||||
|
@ -78,5 +70,11 @@
|
|||
<artifactId>gcube-model</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-utils</artifactId>
|
||||
<version>[2.2.0, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -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 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.schema.SchemaException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -13,16 +16,35 @@ import org.gcube.informationsystem.types.reference.Type;
|
|||
*/
|
||||
public interface ResourceRegistrySchemaClient {
|
||||
|
||||
public <E extends Element> Type create(Class<E> clz)
|
||||
throws SchemaException, ResourceRegistryException;
|
||||
public ModelKnowledge<Type, TypeInformation> getModelKnowledge();
|
||||
|
||||
public String create(String typeDefinitition)
|
||||
throws SchemaException, ResourceRegistryException;
|
||||
public void renewModelKnowledge();
|
||||
|
||||
public <E extends Element> List<Type> read(Class<E> clz, Boolean polymorphic)
|
||||
public void addHeader(String name, String value);
|
||||
|
||||
public String create(String typeDefinitition) throws SchemaException, ResourceRegistryException;
|
||||
|
||||
public <ME extends ModelElement> Type create(Class<ME> clz) throws SchemaException, ResourceRegistryException;
|
||||
|
||||
public boolean exist(String typeName) throws ResourceRegistryException;
|
||||
|
||||
public <ME extends ModelElement> boolean exist(Class<ME> clz) throws 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 String read(String typeName, 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;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,17 +1,7 @@
|
|||
package org.gcube.informationsystem.resourceregistry.schema;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.resourceregistry.api.Constants;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.resources.discovery.icclient.ICFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.ServiceInstance;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -22,99 +12,25 @@ public class ResourceRegistrySchemaClientFactory {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistrySchemaClientFactory.class);
|
||||
|
||||
protected static List<String> addresses;
|
||||
|
||||
static {
|
||||
addresses = new ArrayList<>();
|
||||
public static String getResourceRegistryURL() {
|
||||
String address = String.format("%s/%s", ServiceInstance.getServiceURL(),Constants.SERVICE_NAME);
|
||||
return address;
|
||||
}
|
||||
|
||||
private static String FORCED_URL = null;
|
||||
|
||||
protected static void forceToURL(String url){
|
||||
FORCED_URL = url;
|
||||
}
|
||||
|
||||
private static String classFormat = "$resource/Profile/ServiceClass/text() eq '%1s'";
|
||||
private static String nameFormat = "$resource/Profile/ServiceName/text() eq '%1s'";
|
||||
private static String statusFormat = "$resource/Profile/DeploymentData/Status/text() eq 'ready'";
|
||||
private static String containsFormat = "$entry/@EntryName eq '%1s'";
|
||||
|
||||
|
||||
private static String serviceEndpointCategoryFormat = "$resource/Profile/Category/text() eq '%1s'";
|
||||
private static String serviceEndpointNameFormat = "$resource/Profile/Name/text() eq '%1s'";
|
||||
private static String serviceEndpointstatusFormat = "$resource/Profile/RunTime/Status/text() eq 'READY'";
|
||||
|
||||
public static String getCurrentContextFullName() {
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
AuthorizationEntry authorizationEntry = null;
|
||||
try {
|
||||
authorizationEntry = org.gcube.common.authorization.client.Constants.authorizationService().get(token);
|
||||
} catch(Exception e) {
|
||||
return ScopeProvider.instance.get();
|
||||
}
|
||||
return authorizationEntry.getContext();
|
||||
}
|
||||
|
||||
private static SimpleQuery queryForService(){
|
||||
return ICFactory.queryFor(GCoreEndpoint.class)
|
||||
.addCondition(String.format(classFormat, Constants.SERVICE_CLASS))
|
||||
.addCondition(String.format(nameFormat, Constants.SERVICE_NAME))
|
||||
.addCondition(String.format(statusFormat))
|
||||
.addVariable("$entry","$resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint")
|
||||
.addCondition(String.format(containsFormat, Constants.SERVICE_ENTRY_NAME))
|
||||
.setResult("$entry/text()");
|
||||
}
|
||||
|
||||
private static SimpleQuery queryForProxy(){
|
||||
return ICFactory.queryFor(ServiceEndpoint.class)
|
||||
.addCondition(String.format(serviceEndpointCategoryFormat, Constants.SERVICE_CLASS))
|
||||
.addCondition(String.format(serviceEndpointNameFormat, Constants.SERVICE_NAME))
|
||||
.addCondition(String.format(serviceEndpointstatusFormat))
|
||||
.addVariable("$entry","$resource/Profile/AccessPoint/Interface/Endpoint")
|
||||
.addCondition(String.format(containsFormat, Constants.SERVICE_ENTRY_NAME))
|
||||
.setResult("$entry/text()");
|
||||
}
|
||||
|
||||
|
||||
protected static List<String> getAddresses(){
|
||||
List<String> addresses = new ArrayList<>();
|
||||
|
||||
try {
|
||||
SimpleQuery proxyQuery = queryForProxy();
|
||||
addresses = ICFactory.client().submit(proxyQuery);
|
||||
if(addresses==null || addresses.isEmpty()){
|
||||
throw new Exception("No ResourceRegistry Proxy Found");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.debug("{}. Looking for RunningInstance.", e.getMessage());
|
||||
SimpleQuery serviceQuery = queryForService();
|
||||
addresses = ICFactory.client().submit(serviceQuery);
|
||||
}
|
||||
|
||||
return addresses;
|
||||
public static String getResourceRegistryURL(String context) {
|
||||
String address = String.format("%s/%s", ServiceInstance.getServiceURL(context),Constants.SERVICE_NAME);
|
||||
return address;
|
||||
}
|
||||
|
||||
public static ResourceRegistrySchemaClient create() {
|
||||
String address = null;
|
||||
|
||||
if(FORCED_URL!=null){
|
||||
address = FORCED_URL;
|
||||
}else {
|
||||
|
||||
if(addresses==null || addresses.isEmpty()) {
|
||||
addresses = getAddresses();
|
||||
}
|
||||
|
||||
if(addresses==null || addresses.isEmpty()){
|
||||
String error = String.format("No %s:%s found in the current context %s", Constants.SERVICE_CLASS, Constants.SERVICE_NAME, getCurrentContextFullName());
|
||||
throw new RuntimeException(error);
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
int index = random.nextInt(addresses.size());
|
||||
address = addresses.get(index);
|
||||
}
|
||||
String address = getResourceRegistryURL();
|
||||
logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address);
|
||||
return new ResourceRegistrySchemaClientImpl(address);
|
||||
}
|
||||
|
||||
public static ResourceRegistrySchemaClient create(String context) {
|
||||
String address = getResourceRegistryURL(context);
|
||||
logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address);
|
||||
return new ResourceRegistrySchemaClientImpl(address);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,34 @@
|
|||
package org.gcube.informationsystem.resourceregistry.schema;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.common.gxhttp.reference.GXConnection;
|
||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.common.http.GXHTTPUtility;
|
||||
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.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.exceptions.contexts.ContextAlreadyPresentException;
|
||||
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.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
|
||||
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.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;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -28,15 +39,95 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistrySchemaClientImpl.class);
|
||||
|
||||
private static final String ACCEPT_HTTP_HEADER_KEY = "Accept";
|
||||
private static final String CONTENT_TYPE_HTTP_HEADER_KEY = "Content-Type";
|
||||
|
||||
protected final String address;
|
||||
|
||||
public ResourceRegistrySchemaClientImpl(String address) {
|
||||
this.address = address;
|
||||
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
|
||||
public <E extends Element> Type create(Class<E> clz)
|
||||
public void addHeader(String name, String value) {
|
||||
headers.put(name, value);
|
||||
}
|
||||
|
||||
protected GXHTTPStringRequest getGXHTTPStringRequest() {
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
||||
gxHTTPStringRequest.from(this.getClass().getSimpleName());
|
||||
for(String name : headers.keySet()) {
|
||||
gxHTTPStringRequest.header(name, headers.get(name));
|
||||
}
|
||||
return gxHTTPStringRequest;
|
||||
}
|
||||
|
||||
public ResourceRegistrySchemaClientImpl(String address) {
|
||||
this(address, true);
|
||||
|
||||
}
|
||||
|
||||
public ResourceRegistrySchemaClientImpl(String address, boolean sharedModelKnowledge) {
|
||||
this.address = address;
|
||||
this.headers = new HashMap<>();
|
||||
this.includeMeta = false;
|
||||
|
||||
if(sharedModelKnowledge) {
|
||||
this.typesKnowledge = TypesKnowledge.getInstance();
|
||||
}else {
|
||||
this.typesKnowledge = new TypesKnowledge();
|
||||
}
|
||||
typesKnowledge.setTypesDiscoverer(new RRCCTypesDiscoverer(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
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 {
|
||||
try {
|
||||
String typeDefinition = TypeMapper.serializeType(clz);
|
||||
|
@ -56,16 +147,20 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
logger.trace("Going to create: {}", typeDefinitition);
|
||||
Type typeDefinitionObj = TypeMapper.deserializeTypeDefinition(typeDefinitition);
|
||||
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
||||
gxHTTPStringRequest.from(ResourceRegistrySchemaClient.class.getSimpleName());
|
||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.header("Content-type", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.header(CONTENT_TYPE_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.path(TypePath.TYPES_PATH_PART);
|
||||
gxHTTPStringRequest.path(typeDefinitionObj.getName());
|
||||
|
||||
includeAdditionalQueryParameters(gxHTTPStringRequest);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(typeDefinitition);
|
||||
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
Type t = TypeMapper.deserializeTypeDefinition(c);
|
||||
typesKnowledge.getModelKnowledge().addType(t);
|
||||
|
||||
logger.trace("{} successfully created", c);
|
||||
return c;
|
||||
|
||||
|
@ -76,14 +171,154 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <ME extends ModelElement> boolean exist(Class<ME> clazz) throws ResourceRegistryException {
|
||||
return exist(TypeUtility.getTypeName(clazz));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <ISM extends Element> List<Type> read(Class<ISM> clz, Boolean polymorphic)
|
||||
public boolean exist(String typeName) throws ResourceRegistryException {
|
||||
try {
|
||||
return typesKnowledge.getModelKnowledge().getTypeByName(typeName) != null;
|
||||
}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) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <ME extends ModelElement> List<Type> read(Class<ME> clazz, Boolean polymorphic)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
String typeName = Utility.getTypeName(clz);
|
||||
String res = read(typeName, polymorphic);
|
||||
return TypeMapper.deserializeTypeDefinitions(res);
|
||||
String typeName = TypeUtility.getTypeName(clazz);
|
||||
return getTypeFromTypesKnowledge(typeName, polymorphic);
|
||||
} catch (Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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 {
|
||||
logger.info("Going to get {} schema", typeName);
|
||||
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.path(TypePath.TYPES_PATH_PART);
|
||||
gxHTTPStringRequest.path(typeName);
|
||||
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
parameters.put(TypePath.POLYMORPHIC_QUERY_PARAMETER, Boolean.FALSE.toString());
|
||||
gxHTTPStringRequest.queryParams(parameters);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.head();
|
||||
HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
return true;
|
||||
} catch (NotFoundException e) {
|
||||
return false;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
|
@ -91,21 +326,32 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String read(String typeName, Boolean polymorphic) throws ContextNotFoundException, ResourceRegistryException {
|
||||
public <ME extends ModelElement> List<Type> getTypeFromServer(Class<ME> clz, Boolean polymorphic)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
String typeName = TypeUtility.getTypeName(clz);
|
||||
String json = getTypeFromServer(typeName, polymorphic);
|
||||
return TypeMapper.deserializeTypeDefinitions(json);
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getTypeFromServer(String typeName, Boolean polymorphic) throws ContextNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
logger.info("Going to get {} schema", typeName);
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
||||
gxHTTPStringRequest.from(ResourceRegistrySchemaClient.class.getSimpleName());
|
||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.path(TypePath.TYPES_PATH_PART);
|
||||
gxHTTPStringRequest.path(typeName);
|
||||
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
if(polymorphic != null) {
|
||||
parameters.put(TypePath.POLYMORPHIC_PARAM, polymorphic.toString());
|
||||
parameters.put(TypePath.POLYMORPHIC_QUERY_PARAMETER, polymorphic.toString());
|
||||
}
|
||||
gxHTTPStringRequest.queryParams(parameters);
|
||||
includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||
String json = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
|
|
@ -7,14 +7,15 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.common.authorization.client.Constants;
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.authorization.library.utils.Caller;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||
import org.gcube.common.authorization.utils.secret.JWTSecret;
|
||||
import org.gcube.common.authorization.utils.secret.Secret;
|
||||
import org.gcube.common.authorization.utils.secret.SecretUtility;
|
||||
import org.gcube.common.keycloak.KeycloakClientFactory;
|
||||
import org.gcube.common.keycloak.KeycloakClientHelper;
|
||||
import org.gcube.common.keycloak.model.TokenResponse;
|
||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -22,91 +23,147 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
public class ContextTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
||||
|
||||
protected static Properties properties;
|
||||
protected static final String PROPERTIES_FILENAME = "token.properties";
|
||||
protected static final String CONFIG_INI_FILENAME = "config.ini";
|
||||
|
||||
public static final String PARENT_DEFAULT_TEST_SCOPE;
|
||||
public static final String DEFAULT_TEST_SCOPE;
|
||||
public static final String ALTERNATIVE_TEST_SCOPE;
|
||||
|
||||
public static final String DEFAULT_TEST_SCOPE_ANOTHER_USER;
|
||||
public static final String GCUBE;
|
||||
public static final String DEVNEXT;
|
||||
public static final String NEXTNEXT;
|
||||
public static final String DEVSEC;
|
||||
public static final String DEVVRE;
|
||||
|
||||
protected static final Properties properties;
|
||||
|
||||
public static final String TYPE_PROPERTY_KEY = "type";
|
||||
public static final String USERNAME_PROPERTY_KEY = "username";
|
||||
public static final String PASSWORD_PROPERTY_KEY = "password";
|
||||
public static final String CLIENT_ID_PROPERTY_KEY = "clientId";
|
||||
|
||||
protected static final String REGISTRY_PROPERTIES_FILENAME = "registry.properties";
|
||||
public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL";
|
||||
public static final String RESOURCE_REGISTRY_URL;
|
||||
|
||||
static {
|
||||
properties = new Properties();
|
||||
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
|
||||
GCUBE = "/gcube";
|
||||
DEVNEXT = GCUBE + "/devNext";
|
||||
NEXTNEXT = DEVNEXT + "/NextNext";
|
||||
DEVSEC = GCUBE + "/devsec";
|
||||
DEVVRE = DEVSEC + "/devVRE";
|
||||
|
||||
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
|
||||
DEFAULT_TEST_SCOPE = DEVNEXT;
|
||||
ALTERNATIVE_TEST_SCOPE = NEXTNEXT;
|
||||
|
||||
properties = new Properties();
|
||||
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(CONFIG_INI_FILENAME);
|
||||
try {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// PARENT_DEFAULT_TEST_SCOPE = "/pred4s"
|
||||
// DEFAULT_TEST_SCOPE_NAME = PARENT_DEFAULT_TEST_SCOPE + "/preprod";
|
||||
// ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE_NAME + "/preVRE";
|
||||
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
|
||||
|
||||
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
|
||||
DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "/devNext";
|
||||
ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE + "/NextNext";
|
||||
|
||||
DEFAULT_TEST_SCOPE_ANOTHER_USER = "lucio.lelii_" + DEFAULT_TEST_SCOPE;
|
||||
|
||||
try {
|
||||
setContextByName(DEFAULT_TEST_SCOPE);
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
Properties registryProperties = new Properties();
|
||||
input = ContextTest.class.getClassLoader().getResourceAsStream(REGISTRY_PROPERTIES_FILENAME);
|
||||
try {
|
||||
// load the properties file
|
||||
registryProperties.load(input);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
RESOURCE_REGISTRY_URL = registryProperties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
}
|
||||
|
||||
private enum Type{
|
||||
USER, CLIENT_ID
|
||||
};
|
||||
|
||||
public static void set(Secret secret) throws Exception {
|
||||
SecretManagerProvider.instance.reset();
|
||||
SecretManager secretManager = new SecretManager();
|
||||
secretManager.addSecret(secret);
|
||||
SecretManagerProvider.instance.set(secretManager);
|
||||
SecretManagerProvider.instance.get().set();
|
||||
}
|
||||
|
||||
public static void setContextByName(String fullContextName) throws Exception {
|
||||
logger.debug("Going to set credentials for context {}", fullContextName);
|
||||
Secret secret = getSecretByContextName(fullContextName);
|
||||
set(secret);
|
||||
}
|
||||
|
||||
|
||||
private static TokenResponse getJWTAccessToken(String context) throws Exception {
|
||||
Type type = Type.valueOf(properties.get(TYPE_PROPERTY_KEY).toString());
|
||||
|
||||
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;
|
||||
|
||||
if(RESOURCE_REGISTRY_URL!=null){
|
||||
ResourceRegistrySchemaClientFactory.forceToURL(RESOURCE_REGISTRY_URL);
|
||||
}
|
||||
|
||||
return tr;
|
||||
|
||||
}
|
||||
|
||||
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
String context = authorizationEntry.getContext();
|
||||
logger.info("Context of token {} is {}", token, context);
|
||||
return context;
|
||||
public static Secret getSecretByContextName(String context) throws Exception {
|
||||
TokenResponse tr = getJWTAccessToken(context);
|
||||
Secret secret = new JWTSecret(tr.getAccessToken());
|
||||
return secret;
|
||||
}
|
||||
|
||||
public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
|
||||
String token = ContextTest.properties.getProperty(fullContextName);
|
||||
setContext(token);
|
||||
public static void setContext(String token) throws Exception {
|
||||
Secret secret = getSecret(token);
|
||||
set(secret);
|
||||
}
|
||||
|
||||
private static void setContext(String token) throws ObjectNotFound, Exception {
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
ClientInfo clientInfo = authorizationEntry.getClientInfo();
|
||||
logger.debug("User : {} - Type : {}", clientInfo.getId(), clientInfo.getType().name());
|
||||
String qualifier = authorizationEntry.getQualifier();
|
||||
Caller caller = new Caller(clientInfo, qualifier);
|
||||
AuthorizationProvider.instance.set(caller);
|
||||
ScopeProvider.instance.set(getCurrentScope(token));
|
||||
private static Secret getSecret(String token) throws Exception {
|
||||
Secret secret = SecretUtility.getSecretByTokenString(token);
|
||||
return secret;
|
||||
}
|
||||
|
||||
public static String getUser() {
|
||||
String user = Metadata.UNKNOWN_USER;
|
||||
try {
|
||||
user = SecretManagerProvider.instance.get().getUser().getUsername();
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to retrieve user. {} will be used", user);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -116,8 +173,7 @@ public class ContextTest {
|
|||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
SecretManagerProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,8 +3,12 @@ package org.gcube.informationsystem.resourceregistry.schema;
|
|||
import java.util.List;
|
||||
|
||||
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.annotations.Abstract;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -15,23 +19,19 @@ public class ResourceRegistrySchemaClientTest extends ContextTest {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(ResourceRegistrySchemaClientTest.class);
|
||||
|
||||
@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";
|
||||
protected ResourceRegistrySchemaClient resourceRegistrySchemaClient;
|
||||
|
||||
public ResourceRegistrySchemaClientTest() {
|
||||
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
|
||||
resourceRegistrySchemaClient = new ResourceRegistrySchemaClientImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
||||
}else {
|
||||
resourceRegistrySchemaClient = ResourceRegistrySchemaClientFactory.create();
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testCreate() throws Exception {
|
||||
ResourceRegistrySchemaClient resourceRegistrySchemaClient = ResourceRegistrySchemaClientFactory.create();
|
||||
Type td = resourceRegistrySchemaClient.create(AuxFacet.class);
|
||||
logger.debug("{}", td);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead() throws Exception {
|
||||
ResourceRegistrySchemaClient resourceRegistrySchemaClient = ResourceRegistrySchemaClientFactory.create();
|
||||
List<Type> types = resourceRegistrySchemaClient.read(Facet.class, true);
|
||||
Assert.assertTrue(types.size()>1);
|
||||
for(Type td : types) {
|
||||
|
@ -45,9 +45,22 @@ public class ResourceRegistrySchemaClientTest extends ContextTest {
|
|||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,3 +6,4 @@
|
|||
/registry.properties.empty
|
||||
/registry.properties.redirect-test
|
||||
/registry.properties.test
|
||||
/config.ini
|
||||
|
|
Loading…
Reference in New Issue