Fixed interface
This commit is contained in:
parent
c1128dd10b
commit
3a7649a73c
|
@ -2,9 +2,8 @@ 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.ERElement;
|
||||
import org.gcube.informationsystem.model.reference.ModelElement;
|
||||
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.SchemaNotFoundException;
|
||||
|
@ -25,27 +24,27 @@ public interface ResourceRegistrySchemaClient {
|
|||
|
||||
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 <ERElem extends ERElement> boolean exist(Class<ERElem> 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 <ERElem extends ERElement> List<Type> read(Class<ERElem> clazz, Boolean polymorphic)
|
||||
public <ME extends ModelElement> List<Type> read(Class<ME> clz, Boolean polymorphic)
|
||||
throws SchemaNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String read(String typeName, int level)
|
||||
throws SchemaNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <ERElem extends ERElement> List<Type> read(Class<ERElem> clazz, int level)
|
||||
public <ME extends ModelElement> List<Type> read(Class<ME> clz, int level)
|
||||
throws SchemaNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <ERElem extends ERElement> Node<Type> getTypeTreeNode(String typeName)
|
||||
public Node<Type> getTypeTreeNode(String typeName)
|
||||
throws SchemaNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <ERElem extends ERElement> Node<Type> getTypeTreeNode(Class<ERElem> clazz)
|
||||
public <ME extends ModelElement> Node<Type> getTypeTreeNode(Class<ME> clz)
|
||||
throws SchemaNotFoundException, ResourceRegistryException;
|
||||
|
||||
}
|
||||
|
|
|
@ -11,9 +11,8 @@ import java.util.Set;
|
|||
import org.gcube.common.gxhttp.reference.GXConnection;
|
||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||
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.ERElement;
|
||||
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;
|
||||
|
@ -128,7 +127,7 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
}
|
||||
|
||||
@Override
|
||||
public <E extends Element> Type create(Class<E> clz)
|
||||
public <ME extends ModelElement> Type create(Class<ME> clz)
|
||||
throws SchemaException, ResourceRegistryException {
|
||||
try {
|
||||
String typeDefinition = TypeMapper.serializeType(clz);
|
||||
|
@ -173,7 +172,7 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
}
|
||||
|
||||
@Override
|
||||
public <ERElem extends ERElement> boolean exist(Class<ERElem> clazz) throws ResourceRegistryException {
|
||||
public <ME extends ModelElement> boolean exist(Class<ME> clazz) throws ResourceRegistryException {
|
||||
return exist(TypeUtility.getTypeName(clazz));
|
||||
}
|
||||
|
||||
|
@ -186,13 +185,13 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
}
|
||||
}
|
||||
|
||||
public <ERElem extends ERElement> List<Type> getTypeFromTypesKnowledge(String typeName, Boolean polymorphic)
|
||||
public List<Type> getTypeFromTypesKnowledge(String typeName, Boolean polymorphic)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
return getTypeFromTypesKnowledge(typeName, polymorphic, -1);
|
||||
}
|
||||
|
||||
|
||||
public <ERElem extends ERElement> List<Type> getTypeFromTypesKnowledge(String typeName, int level)
|
||||
public List<Type> getTypeFromTypesKnowledge(String typeName, int level)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
return getTypeFromTypesKnowledge(typeName, true, level);
|
||||
}
|
||||
|
@ -213,7 +212,7 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
return types;
|
||||
}
|
||||
|
||||
public <ERElem extends ERElement> List<Type> getTypeFromTypesKnowledge(String typeName, Boolean polymorphic, int level)
|
||||
public List<Type> getTypeFromTypesKnowledge(String typeName, Boolean polymorphic, int level)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
|
||||
Node<Type> node = getTypeTreeNode(typeName);
|
||||
|
@ -241,7 +240,7 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
}
|
||||
|
||||
@Override
|
||||
public <ERElem extends ERElement> List<Type> read(Class<ERElem> clazz, Boolean polymorphic)
|
||||
public <ME extends ModelElement> List<Type> read(Class<ME> clazz, Boolean polymorphic)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
String typeName = TypeUtility.getTypeName(clazz);
|
||||
|
@ -264,7 +263,7 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
}
|
||||
|
||||
@Override
|
||||
public <ERElem extends ERElement> List<Type> read(Class<ERElem> clazz, int level)
|
||||
public <ME extends ModelElement> List<Type> read(Class<ME> clazz, int level)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
String typeName = TypeUtility.getTypeName(clazz);
|
||||
|
@ -292,7 +291,7 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
}
|
||||
|
||||
@Override
|
||||
public <ERElem extends ERElement> Node<Type> getTypeTreeNode(Class<ERElem> clazz)
|
||||
public <ME extends ModelElement> Node<Type> getTypeTreeNode(Class<ME> clazz)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
String typeName = TypeUtility.getTypeName(clazz);
|
||||
|
@ -327,7 +326,7 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
|||
}
|
||||
}
|
||||
|
||||
public <ERElem extends ERElement> List<Type> getTypeFromServer(Class<ERElem> clz, Boolean polymorphic)
|
||||
public <ME extends ModelElement> List<Type> getTypeFromServer(Class<ME> clz, Boolean polymorphic)
|
||||
throws SchemaNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
String typeName = TypeUtility.getTypeName(clz);
|
||||
|
|
|
@ -13,8 +13,8 @@ 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.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -24,7 +24,6 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ContextTest {
|
||||
|
||||
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 DEVSEC;
|
||||
public static final String DEVVRE;
|
||||
|
||||
|
||||
protected static final Properties properties;
|
||||
|
||||
protected static final String CLIENT_ID_PROPERTY_KEY = "client_id";
|
||||
protected static final String CLIENT_SECRET_PROPERTY_KEY = "client_secret";
|
||||
|
||||
protected static final String clientID;
|
||||
protected static final String clientSecret;
|
||||
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";
|
||||
|
||||
public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL";
|
||||
public static final String RESOURCE_REGISTRY_URL;
|
||||
|
@ -69,9 +67,6 @@ public class ContextTest {
|
|||
// load the properties file
|
||||
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);
|
||||
|
||||
} catch (IOException e) {
|
||||
|
@ -80,6 +75,10 @@ public class ContextTest {
|
|||
|
||||
}
|
||||
|
||||
private enum Type{
|
||||
USER, CLIENT_ID
|
||||
};
|
||||
|
||||
public static void set(Secret secret) throws Exception {
|
||||
SecretManagerProvider.instance.reset();
|
||||
SecretManager secretManager = new SecretManager();
|
||||
|
@ -89,15 +88,56 @@ public class ContextTest {
|
|||
}
|
||||
|
||||
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 {
|
||||
ScopeProvider.instance.set(context);
|
||||
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, context, null);
|
||||
return tr;
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
return tr;
|
||||
|
||||
}
|
||||
|
||||
public static Secret getSecretByContextName(String context) throws Exception {
|
||||
|
|
|
@ -3,6 +3,11 @@ 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.reference.Type;
|
||||
import org.junit.Assert;
|
||||
|
@ -41,6 +46,21 @@ public class ResourceRegistrySchemaClientTest extends ContextTest {
|
|||
|
||||
Assert.assertTrue(gotFacetDefinition.getName().compareTo(facetDefinition.getName())==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