Changed code to allow to pass ResourceRegistry URL for testing purpose
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-client@146758 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
fc020c3f9b
commit
73f7d5bc92
|
@ -1,9 +1,13 @@
|
|||
package org.gcube.informationsystem.resourceregistry.client;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
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;
|
||||
|
@ -13,7 +17,17 @@ import org.gcube.resources.discovery.icclient.ICFactory;
|
|||
*/
|
||||
public class ResourceRegistryClientFactory {
|
||||
|
||||
protected static ResourceRegistryClient singleton;
|
||||
protected static Map<String, ResourceRegistryClient> clients;
|
||||
|
||||
static {
|
||||
clients = new HashMap<>();
|
||||
}
|
||||
|
||||
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'";
|
||||
|
@ -30,9 +44,25 @@ public class ResourceRegistryClientFactory {
|
|||
.setResult("$entry/text()");
|
||||
}
|
||||
|
||||
|
||||
public static ResourceRegistryClient create(){
|
||||
if(singleton==null){
|
||||
if(FORCED_URL!=null){
|
||||
return new ResourceRegistryClientImpl(FORCED_URL);
|
||||
}
|
||||
|
||||
String key = null;
|
||||
if (SecurityTokenProvider.instance.get() == null) {
|
||||
if (ScopeProvider.instance.get() == null) {
|
||||
throw new RuntimeException(
|
||||
"Null Token and Scope. Please set your token first.");
|
||||
}
|
||||
key = ScopeProvider.instance.get();
|
||||
} else {
|
||||
key = SecurityTokenProvider.instance.get();
|
||||
}
|
||||
|
||||
ResourceRegistryClient client = clients.get(key);
|
||||
|
||||
if(client==null){
|
||||
SimpleQuery query = getQuery();
|
||||
List<String> addresses = ICFactory.client().submit(query);
|
||||
|
||||
|
@ -44,10 +74,11 @@ public class ResourceRegistryClientFactory {
|
|||
Random random = new Random();
|
||||
int index = random.nextInt(addresses.size());
|
||||
|
||||
singleton = new ResourceRegistryClientImpl(addresses.get(index));
|
||||
client = new ResourceRegistryClientImpl(addresses.get(index));
|
||||
|
||||
}
|
||||
return singleton;
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -223,7 +223,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
|
|||
Map<String, String> parameters = new HashMap<>();
|
||||
parameters.put(AccessPath.QUERY_PARAM, query);
|
||||
if (limit <= 0) {
|
||||
limit = AccessPath.DEFAULT_LIMIT;
|
||||
limit = AccessPath.UNBOUNDED;
|
||||
}
|
||||
parameters.put(AccessPath.LIMIT_PARAM, Integer.toString(limit));
|
||||
|
||||
|
|
|
@ -39,9 +39,18 @@ public class ScopedTest {
|
|||
public static final String GCUBE_DEVSEC_DEVVRE_VARNAME = "GCUBE_DEVSEC_DEVVRE";
|
||||
public static final String GCUBE_DEVSEC_DEVVRE;
|
||||
|
||||
public static final String GCUBE_VARNAME = "GCUBE";
|
||||
public static final String GCUBE;
|
||||
|
||||
|
||||
public static final String DEFAULT_TEST_SCOPE;
|
||||
public static final String ALTERNATIVE_TEST_SCOPE;
|
||||
|
||||
|
||||
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 properties = new Properties();
|
||||
InputStream input = ScopedTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
|
||||
|
@ -59,8 +68,27 @@ public class ScopedTest {
|
|||
GCUBE_DEVSEC = properties.getProperty(GCUBE_DEVSEC_VARNAME);
|
||||
GCUBE_DEVSEC_DEVVRE = properties.getProperty(GCUBE_DEVSEC_DEVVRE_VARNAME);
|
||||
|
||||
DEFAULT_TEST_SCOPE = GCUBE_DEVNEXT_NEXTNEXT;
|
||||
ALTERNATIVE_TEST_SCOPE = GCUBE_DEVNEXT;
|
||||
GCUBE = properties.getProperty(GCUBE_VARNAME);
|
||||
|
||||
DEFAULT_TEST_SCOPE = GCUBE_DEVSEC;
|
||||
ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC_DEVVRE;
|
||||
|
||||
|
||||
properties = new Properties();
|
||||
input = ScopedTest.class.getClassLoader().getResourceAsStream(REGISTRY_PROPERTIES_FILENAME);
|
||||
try {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
|
||||
if(RESOURCE_REGISTRY_URL!=null){
|
||||
ResourceRegistryClientFactory.forceToURL(RESOURCE_REGISTRY_URL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String getCurrentScope(String token) throws ObjectNotFound, Exception{
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
registry.properties.test
|
|
@ -0,0 +1 @@
|
|||
RESOURCE_REGISTRY_URL=http://pc-frosini.isti.cnr.it:8080/resource-registry
|
Loading…
Reference in New Issue