Added facilities to use the client outside of container
This commit is contained in:
parent
40df50ed76
commit
981fe278c6
|
@ -12,14 +12,24 @@ public class ResourceRegistryPublisherFactory {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherFactory.class);
|
||||
|
||||
public static ResourceRegistryPublisher create() {
|
||||
public static String getResourceRegistryURL() {
|
||||
String address = String.format("%s/%s", ServiceInstance.getServiceURL(),Constants.SERVICE_NAME);
|
||||
return address;
|
||||
}
|
||||
|
||||
public static String getResourceRegistryURL(String context) {
|
||||
String address = String.format("%s/%s", ServiceInstance.getServiceURL(context),Constants.SERVICE_NAME);
|
||||
return address;
|
||||
}
|
||||
|
||||
public static ResourceRegistryPublisher create() {
|
||||
String address = getResourceRegistryURL();
|
||||
logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address);
|
||||
return new ResourceRegistryPublisherImpl(address);
|
||||
}
|
||||
|
||||
public static ResourceRegistryPublisher create(String context) {
|
||||
String address = String.format("%s/%s", ServiceInstance.getServiceURL(context),Constants.SERVICE_NAME);
|
||||
String address = getResourceRegistryURL(context);
|
||||
logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address);
|
||||
return new ResourceRegistryPublisherImpl(address);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isr
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
|
||||
|
@ -65,6 +64,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
protected boolean hierarchicalMode;
|
||||
protected boolean includeContextsInHeader;
|
||||
|
||||
protected ContextCache contextCache;
|
||||
|
||||
@Override
|
||||
public boolean isHierarchicalMode() {
|
||||
return hierarchicalMode;
|
||||
|
@ -142,9 +143,17 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
}
|
||||
|
||||
public ResourceRegistryPublisherImpl(String address) {
|
||||
this(address, true);
|
||||
}
|
||||
|
||||
public ResourceRegistryPublisherImpl(String address, boolean sharedContextCache) {
|
||||
this.address = address;
|
||||
this.headers = new HashMap<>();
|
||||
ContextCache contextCache = ContextCache.getInstance();
|
||||
if(sharedContextCache) {
|
||||
contextCache = ContextCache.getInstance();
|
||||
}else {
|
||||
contextCache = new ContextCache();
|
||||
}
|
||||
contextCache.setContextCacheRenewal(contextCacheRenewal);
|
||||
}
|
||||
|
||||
|
@ -177,7 +186,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
|
||||
@Override
|
||||
public List<Context> getAllContext() throws ResourceRegistryException {
|
||||
ContextCache contextCache = ContextCache.getInstance();
|
||||
return contextCache.getContexts();
|
||||
}
|
||||
|
||||
|
@ -210,8 +218,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
|
||||
@Override
|
||||
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException {
|
||||
ContextCache contextCache = ContextCache.getInstance();
|
||||
Context context = ContextCache.getInstance().getContextByUUID(uuid);
|
||||
Context context = contextCache.getContextByUUID(uuid);
|
||||
if (context == null) {
|
||||
context = getContextFromServer(uuid.toString());
|
||||
contextCache.cleanCache();
|
||||
|
@ -231,25 +238,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
@Override
|
||||
public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException {
|
||||
String contextFullName = org.gcube.common.context.ContextUtility.getCurrentContextFullName();
|
||||
ContextCache contextCache = ContextCache.getInstance();
|
||||
UUID uuid = contextCache.getUUIDByFullName(contextFullName);
|
||||
Context context = null;
|
||||
if (uuid == null) {
|
||||
context = getContextFromServer(ContextPath.CURRENT_CONTEXT_PATH_PART);
|
||||
contextCache.cleanCache();
|
||||
contextCache.refreshContextsIfNeeded();
|
||||
Context c = contextCache.getContextByUUID(context.getHeader().getUUID());
|
||||
if (c != null) {
|
||||
context = c;
|
||||
} else {
|
||||
logger.error(
|
||||
"Current Context is {}. It is possibile to get it from the server but not from the cache. This is very strange and should not occur.",
|
||||
contextFullName);
|
||||
}
|
||||
} else {
|
||||
context = contextCache.getContextByUUID(uuid);
|
||||
}
|
||||
return context;
|
||||
return getContext(uuid);
|
||||
}
|
||||
|
||||
private UUID getCurrentContextUUID() throws ResourceRegistryException {
|
||||
|
|
Loading…
Reference in New Issue