36 lines
1.3 KiB
Java
36 lines
1.3 KiB
Java
package org.gcube.informationsystem.resourceregistry.schema;
|
|
|
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
import org.gcube.informationsystem.resourceregistry.api.Constants;
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.ServiceInstance;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
*/
|
|
public class ResourceRegistrySchemaClientFactory {
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistrySchemaClientFactory.class);
|
|
|
|
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();
|
|
}
|
|
|
|
public static ResourceRegistrySchemaClient create() {
|
|
String address = String.format("%s/%s", ServiceInstance.getServiceURL(),Constants.SERVICE_NAME);
|
|
logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address);
|
|
return new ResourceRegistrySchemaClientImpl(address);
|
|
}
|
|
|
|
}
|