2017-04-03 18:44:47 +02:00
|
|
|
package org.gcube.informationsystem.resourceregistry.publisher;
|
2016-09-14 14:49:50 +02:00
|
|
|
|
2020-10-29 16:54:32 +01:00
|
|
|
import java.io.UnsupportedEncodingException;
|
2019-01-17 11:18:02 +01:00
|
|
|
import java.net.HttpURLConnection;
|
2020-10-29 16:54:32 +01:00
|
|
|
import java.util.HashMap;
|
2020-11-03 16:32:41 +01:00
|
|
|
import java.util.List;
|
2020-10-29 16:54:32 +01:00
|
|
|
import java.util.Map;
|
2020-11-11 14:18:43 +01:00
|
|
|
import java.util.Set;
|
2016-11-14 12:33:14 +01:00
|
|
|
import java.util.UUID;
|
2016-09-14 18:08:46 +02:00
|
|
|
|
2019-02-06 12:03:35 +01:00
|
|
|
import org.gcube.common.gxhttp.reference.GXConnection;
|
2019-01-17 11:18:02 +01:00
|
|
|
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
2019-10-25 17:44:56 +02:00
|
|
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
2020-01-20 10:32:54 +01:00
|
|
|
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
2021-07-05 17:31:42 +02:00
|
|
|
import org.gcube.informationsystem.model.reference.ERElement;
|
2019-02-06 10:01:35 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
|
|
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
2020-01-20 10:32:54 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.properties.Header;
|
2019-02-06 10:01:35 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
|
|
|
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
2020-11-04 16:23:29 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
|
2020-11-11 14:18:43 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility;
|
2018-06-11 19:47:40 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
2020-10-29 16:54:32 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
2018-06-11 19:47:40 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
2016-11-14 12:33:14 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
2017-02-24 12:46:18 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException;
|
2016-11-29 08:27:30 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
|
2017-02-24 12:46:18 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException;
|
2016-11-29 08:27:30 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
2021-02-16 17:00:46 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
2018-06-12 11:24:05 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
2018-06-11 19:47:40 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
|
2019-01-17 11:18:02 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
|
2020-02-03 10:52:43 +01:00
|
|
|
import org.gcube.informationsystem.utils.ElementMapper;
|
2019-02-06 10:14:05 +01:00
|
|
|
import org.gcube.informationsystem.utils.Utility;
|
2016-09-14 14:49:50 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher {
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherImpl.class);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
protected final String address;
|
2021-02-16 17:00:46 +01:00
|
|
|
|
|
|
|
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest)
|
|
|
|
throws UnsupportedEncodingException {
|
2020-11-09 15:48:06 +01:00
|
|
|
return includeAdditionalQueryParameters(gxHTTPStringRequest, null);
|
2020-10-29 16:54:32 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
|
|
|
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest,
|
|
|
|
Map<String, String> queryParams) throws UnsupportedEncodingException {
|
2020-11-09 15:48:06 +01:00
|
|
|
gxHTTPStringRequest = checkHierarchicalMode(gxHTTPStringRequest, queryParams);
|
|
|
|
return checkIncludeContextsInInstanceHeader(gxHTTPStringRequest, queryParams);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
|
|
|
private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest,
|
|
|
|
Map<String, String> queryParams) throws UnsupportedEncodingException {
|
|
|
|
if (ResourceRegistryPublisherFactory.isHierarchicalMode()) {
|
|
|
|
if (queryParams == null) {
|
2020-10-29 16:54:32 +01:00
|
|
|
queryParams = new HashMap<>();
|
|
|
|
}
|
|
|
|
queryParams.put(AccessPath.HIERARCHICAL_MODE_PARAM, Boolean.toString(true));
|
|
|
|
}
|
2020-11-09 15:48:06 +01:00
|
|
|
return gxHTTPStringRequest.queryParams(queryParams);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
|
|
|
private GXHTTPStringRequest checkIncludeContextsInInstanceHeader(GXHTTPStringRequest gxHTTPStringRequest,
|
|
|
|
Map<String, String> queryParams) throws UnsupportedEncodingException {
|
|
|
|
if (ResourceRegistryPublisherFactory.includeContextsInInstanceHeader()) {
|
|
|
|
if (queryParams == null) {
|
2020-11-09 15:48:06 +01:00
|
|
|
queryParams = new HashMap<>();
|
|
|
|
}
|
|
|
|
queryParams.put(AccessPath.INCLUDE_CONTEXTS_IN_HEADER_PARAM, Boolean.toString(true));
|
|
|
|
}
|
|
|
|
return gxHTTPStringRequest.queryParams(queryParams);
|
2020-10-29 16:54:32 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-04 17:39:26 +01:00
|
|
|
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-04 17:39:26 +01:00
|
|
|
@Override
|
|
|
|
public List<Context> renew() throws ResourceRegistryException {
|
|
|
|
return getAllContextFromServer();
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-04 17:39:26 +01:00
|
|
|
};
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
public ResourceRegistryPublisherImpl(String address) {
|
|
|
|
this.address = address;
|
2020-11-04 17:39:26 +01:00
|
|
|
ContextCache contextCache = ContextCache.getInstance();
|
|
|
|
contextCache.setContextCacheRenewal(contextCacheRenewal);
|
2017-04-03 18:44:47 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-04 16:23:29 +01:00
|
|
|
public List<Context> getAllContextFromServer() throws ResourceRegistryException {
|
2016-11-14 12:33:14 +01:00
|
|
|
try {
|
2020-11-04 16:23:29 +01:00
|
|
|
logger.info("Going to read all {}s", Context.NAME);
|
2021-02-16 17:00:46 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
2020-11-04 16:23:29 +01:00
|
|
|
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
|
|
|
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
|
|
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
|
|
|
|
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-04 16:23:29 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
|
|
|
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-04 16:23:29 +01:00
|
|
|
logger.debug("Got Contexts are {}", ret);
|
|
|
|
return ElementMapper.unmarshalList(Context.class, ret);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
|
|
|
} catch (ResourceRegistryException e) {
|
2020-11-03 16:32:41 +01:00
|
|
|
// logger.trace("Error while getting {} schema for {}", polymorphic ?
|
|
|
|
// AccessPath.POLYMORPHIC_PARAM + " " : "",
|
|
|
|
// type, e);
|
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2020-11-03 16:32:41 +01:00
|
|
|
// logger.trace("Error while getting {}schema for {}", polymorphic ?
|
|
|
|
// AccessPath.POLYMORPHIC_PARAM + " " : "",
|
|
|
|
// type, e);
|
|
|
|
throw new RuntimeException(e);
|
2016-11-14 12:33:14 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-04 16:23:29 +01:00
|
|
|
@Override
|
|
|
|
public List<Context> getAllContext() throws ResourceRegistryException {
|
|
|
|
ContextCache contextCache = ContextCache.getInstance();
|
|
|
|
return contextCache.getContexts();
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-04 16:23:29 +01:00
|
|
|
protected Context getContextFromServer(String id) throws ContextNotFoundException, ResourceRegistryException {
|
2018-06-12 11:24:05 +02:00
|
|
|
try {
|
2020-11-03 16:32:41 +01:00
|
|
|
// TODO use cache
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-12 11:24:05 +02:00
|
|
|
logger.info("Going to get current {} ", Context.NAME);
|
2021-02-16 17:00:46 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
2019-02-06 12:03:35 +01:00
|
|
|
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
|
|
|
|
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
|
2020-11-03 16:32:41 +01:00
|
|
|
gxHTTPStringRequest.path(id);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2019-01-17 11:18:02 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
|
|
|
Context context = HTTPUtility.getResponse(Context.class, httpURLConnection);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-02-03 10:52:43 +01:00
|
|
|
logger.debug("Got Context is {}", ElementMapper.marshal(context));
|
2020-11-03 16:32:41 +01:00
|
|
|
return context;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2018-06-12 11:24:05 +02:00
|
|
|
// logger.trace("Error while getting {} schema for {}", polymorphic ?
|
|
|
|
// AccessPath.POLYMORPHIC_PARAM + " " : "",
|
|
|
|
// type, e);
|
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2018-06-12 11:24:05 +02:00
|
|
|
// logger.trace("Error while getting {}schema for {}", polymorphic ?
|
|
|
|
// AccessPath.POLYMORPHIC_PARAM + " " : "",
|
|
|
|
// type, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-03 16:32:41 +01:00
|
|
|
@Override
|
|
|
|
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException {
|
2020-11-04 17:39:26 +01:00
|
|
|
ContextCache contextCache = ContextCache.getInstance();
|
2021-02-16 17:00:46 +01:00
|
|
|
Context context = ContextCache.getInstance().getContextByUUID(uuid);
|
|
|
|
;
|
|
|
|
if (context == null) {
|
2020-11-04 17:39:26 +01:00
|
|
|
context = getContextFromServer(uuid.toString());
|
|
|
|
contextCache.cleanCache();
|
|
|
|
contextCache.refreshContextsIfNeeded();
|
|
|
|
Context c = contextCache.getContextByUUID(context.getHeader().getUUID());
|
2021-02-16 17:00:46 +01:00
|
|
|
if (c != null) {
|
2020-11-04 17:39:26 +01:00
|
|
|
context = c;
|
2021-02-16 17:00:46 +01:00
|
|
|
} else {
|
|
|
|
logger.error(
|
|
|
|
"Context with UUID {} is {}. It is possibile to get it from the server but not from the cache. This is very strange and should not occur.",
|
|
|
|
uuid, context);
|
2020-11-04 17:39:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return context;
|
2020-11-03 16:32:41 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-03 16:32:41 +01:00
|
|
|
@Override
|
|
|
|
public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException {
|
2020-11-04 16:23:29 +01:00
|
|
|
String contextFullName = ResourceRegistryPublisherFactory.getCurrentContextFullName();
|
|
|
|
ContextCache contextCache = ContextCache.getInstance();
|
|
|
|
UUID uuid = contextCache.getUUIDByFullName(contextFullName);
|
|
|
|
Context context = null;
|
2021-02-16 17:00:46 +01:00
|
|
|
if (uuid == null) {
|
2020-11-04 16:23:29 +01:00
|
|
|
context = getContextFromServer(AccessPath.CURRENT_CONTEXT);
|
|
|
|
contextCache.cleanCache();
|
|
|
|
contextCache.refreshContextsIfNeeded();
|
|
|
|
Context c = contextCache.getContextByUUID(context.getHeader().getUUID());
|
2021-02-16 17:00:46 +01:00
|
|
|
if (c != null) {
|
2020-11-04 16:23:29 +01:00
|
|
|
context = c;
|
2021-02-16 17:00:46 +01:00
|
|
|
} 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);
|
2020-11-04 16:23:29 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
} else {
|
2020-11-04 16:23:29 +01:00
|
|
|
context = contextCache.getContextByUUID(uuid);
|
|
|
|
}
|
|
|
|
return context;
|
2020-11-03 16:32:41 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-03 16:32:41 +01:00
|
|
|
private UUID getCurrentContextUUID() throws ResourceRegistryException {
|
|
|
|
return getCurrentContext().getHeader().getUUID();
|
|
|
|
}
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public <ERElem extends ERElement, R extends Resource> List<R> list(Class<ERElem> clazz, Boolean polymorphic)
|
|
|
|
throws ResourceRegistryException {
|
|
|
|
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz);
|
|
|
|
String ret = list(type, polymorphic);
|
|
|
|
try {
|
|
|
|
return (List<R>) ElementMapper.unmarshalList(Resource.class, ret);
|
|
|
|
} catch(Exception e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String list(String type, Boolean polymorphic) throws ResourceRegistryException {
|
|
|
|
try {
|
|
|
|
logger.info("Going to get all instances of {} ", type);
|
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
|
|
|
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
|
|
|
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
|
|
gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART);
|
|
|
|
gxHTTPStringRequest.path(type);
|
|
|
|
|
|
|
|
Map<String,String> parameters = new HashMap<>();
|
|
|
|
parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString());
|
|
|
|
includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
|
|
|
|
|
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
|
|
|
|
|
|
|
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
|
|
|
|
|
|
|
|
logger.debug("Got instances of {} are {}", type, ret);
|
|
|
|
return ret;
|
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error while getting {} instances", type, e);
|
|
|
|
throw e;
|
|
|
|
} catch(Exception e) {
|
|
|
|
// logger.trace("Error while getting {} instances", type, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-11 14:18:43 +01:00
|
|
|
protected String create(String type, String json, UUID uuid)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
|
2017-10-03 17:44:13 +02:00
|
|
|
try {
|
2020-11-11 14:18:43 +01:00
|
|
|
logger.trace("Going to create {} : {}", type, json);
|
2019-01-17 11:18:02 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
|
|
|
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
2019-02-06 12:03:35 +01:00
|
|
|
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
|
|
gxHTTPStringRequest.header("Content-type", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
2020-11-11 14:18:43 +01:00
|
|
|
gxHTTPStringRequest.path(type);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(uuid.toString());
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-02-03 10:52:43 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json);
|
2019-01-17 11:18:02 +01:00
|
|
|
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
logger.trace("{} successfully created", ret);
|
|
|
|
return ret;
|
2021-02-16 17:00:46 +01:00
|
|
|
|
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 17:44:13 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2017-10-03 17:44:13 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
public <ERElem extends ERElement> String internalCreate(ERElem er)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
|
2016-09-14 18:08:46 +02:00
|
|
|
try {
|
2021-02-16 17:00:46 +01:00
|
|
|
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
|
2021-07-05 17:31:42 +02:00
|
|
|
.getTypeName(er);
|
|
|
|
String json = ElementMapper.marshal(er);
|
|
|
|
Header header = er.getHeader();
|
2021-02-16 17:00:46 +01:00
|
|
|
if (header == null) {
|
2018-06-12 16:06:59 +02:00
|
|
|
header = new HeaderImpl(UUID.randomUUID());
|
2021-07-05 17:31:42 +02:00
|
|
|
er.setHeader(header);
|
2018-06-12 16:06:59 +02:00
|
|
|
}
|
2021-07-05 17:31:42 +02:00
|
|
|
UUID uuid = er.getHeader().getUUID();
|
2020-11-11 14:18:43 +01:00
|
|
|
return create(type, json, uuid);
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-12 16:06:59 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2017-10-03 15:49:47 +02:00
|
|
|
@Override
|
2021-07-05 17:31:42 +02:00
|
|
|
public <ERElem extends ERElement> ERElem create(ERElem er)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
|
2017-10-03 15:49:47 +02:00
|
|
|
try {
|
2021-07-05 17:31:42 +02:00
|
|
|
String ret = internalCreate(er);
|
|
|
|
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-04-05 17:18:53 +02:00
|
|
|
throw new RuntimeException(e);
|
2016-09-14 18:08:46 +02:00
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public String create(String json)
|
|
|
|
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
|
2017-10-02 18:28:47 +02:00
|
|
|
try {
|
2021-07-05 17:31:42 +02:00
|
|
|
ERElement e = ElementMapper.unmarshal(ERElement.class, json);
|
2018-06-12 16:06:59 +02:00
|
|
|
return internalCreate(e);
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-10-29 16:54:32 +01:00
|
|
|
@Override
|
2021-07-05 17:31:42 +02:00
|
|
|
public <ERElem extends ERElement> boolean exists(Class<ERElem> clazz, UUID uuid)
|
2020-10-29 16:54:32 +01:00
|
|
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
|
|
|
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz);
|
|
|
|
return exists(type, uuid);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-10-29 16:54:32 +01:00
|
|
|
@Override
|
2021-07-05 17:31:42 +02:00
|
|
|
public <ERElem extends ERElement> boolean exists(ERElem er)
|
2020-10-29 16:54:32 +01:00
|
|
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
2021-07-05 17:31:42 +02:00
|
|
|
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(er);
|
|
|
|
UUID uuid = er.getHeader().getUUID();
|
2020-10-29 16:54:32 +01:00
|
|
|
return exists(type, uuid);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-10-29 16:54:32 +01:00
|
|
|
@Override
|
|
|
|
public boolean exists(String type, UUID uuid)
|
|
|
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
|
|
|
try {
|
|
|
|
logger.info("Going to check if {} with UUID {} exists", type, uuid);
|
2021-02-16 17:00:46 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
2020-10-29 16:54:32 +01:00
|
|
|
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
|
|
|
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
|
|
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
|
|
|
|
gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART);
|
|
|
|
gxHTTPStringRequest.path(type);
|
|
|
|
gxHTTPStringRequest.path(uuid.toString());
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-09 15:48:06 +01:00
|
|
|
includeAdditionalQueryParameters(gxHTTPStringRequest);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-10-29 16:54:32 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.head();
|
|
|
|
HTTPUtility.getResponse(String.class, httpURLConnection);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-10-29 16:54:32 +01:00
|
|
|
logger.debug("{} with UUID {} exists", type, uuid);
|
|
|
|
return true;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2020-10-29 16:54:32 +01:00
|
|
|
// logger.trace("Error while checking if {} with UUID {} exists.", type, uuid,
|
|
|
|
// e);
|
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2020-10-29 16:54:32 +01:00
|
|
|
// logger.trace("Error while checking if {} with UUID {} exists.", type, uuid,
|
|
|
|
// e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-03 17:44:13 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
2021-07-05 17:31:42 +02:00
|
|
|
public <ERElem extends ERElement> ERElem read(ERElem er)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws NotFoundException, ResourceRegistryException {
|
2016-09-15 17:24:24 +02:00
|
|
|
try {
|
2021-02-16 17:00:46 +01:00
|
|
|
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
|
2021-07-05 17:31:42 +02:00
|
|
|
.getTypeName(er);
|
|
|
|
UUID uuid = er.getHeader().getUUID();
|
2020-11-11 14:18:43 +01:00
|
|
|
String ret = read(type, uuid);
|
2021-07-05 17:31:42 +02:00
|
|
|
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2017-04-05 17:18:53 +02:00
|
|
|
throw new RuntimeException(e);
|
2016-09-15 17:24:24 +02:00
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public <ERElem extends ERElement> ERElem read(Class<ERElem> clazz, UUID uuid)
|
|
|
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
|
|
|
try {
|
|
|
|
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz);
|
|
|
|
String ret = read(type, uuid);
|
|
|
|
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
|
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public String read(String type, UUID uuid) throws NotFoundException, ResourceRegistryException {
|
2017-10-02 18:28:47 +02:00
|
|
|
try {
|
2020-11-11 14:18:43 +01:00
|
|
|
logger.trace("Going to read {} with UUID {}", type, uuid);
|
2019-01-17 11:18:02 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
|
|
|
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
2019-02-06 12:03:35 +01:00
|
|
|
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
2020-11-11 14:18:43 +01:00
|
|
|
gxHTTPStringRequest.path(type);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(uuid.toString());
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-09 15:48:06 +01:00
|
|
|
includeAdditionalQueryParameters(gxHTTPStringRequest);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2019-01-17 11:18:02 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
|
|
|
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-11 14:18:43 +01:00
|
|
|
logger.debug("Got {} with UUID {} is {}", type, uuid, ret);
|
2018-06-11 19:47:40 +02:00
|
|
|
return ret;
|
2021-02-16 17:00:46 +01:00
|
|
|
|
|
|
|
} catch (ResourceRegistryException e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 15:49:47 +02:00
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2021-07-05 17:31:42 +02:00
|
|
|
@Override
|
|
|
|
public String update(String type, String json, UUID uuid)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
|
2016-09-15 14:57:14 +02:00
|
|
|
try {
|
2020-11-11 14:18:43 +01:00
|
|
|
logger.trace("Going to create {} : {}", type, json);
|
2019-01-17 11:18:02 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
|
|
|
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
2019-02-06 12:03:35 +01:00
|
|
|
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
|
|
gxHTTPStringRequest.header("Content-type", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
2020-11-11 14:18:43 +01:00
|
|
|
gxHTTPStringRequest.path(type);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(uuid.toString());
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-02-03 10:52:43 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json);
|
2019-01-17 11:18:02 +01:00
|
|
|
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-11 14:18:43 +01:00
|
|
|
logger.trace("{} with UUID {} successfully created : {}", type, uuid, ret);
|
2018-06-11 19:47:40 +02:00
|
|
|
return ret;
|
2021-02-16 17:00:46 +01:00
|
|
|
|
|
|
|
} catch (ResourceRegistryException e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-04-05 17:18:53 +02:00
|
|
|
throw new RuntimeException(e);
|
2016-09-15 14:57:14 +02:00
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2021-07-05 17:31:42 +02:00
|
|
|
public <ERElem extends ERElement> ERElem update(ERElem er)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2017-10-03 17:44:13 +02:00
|
|
|
try {
|
2021-02-16 17:00:46 +01:00
|
|
|
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
|
2021-07-05 17:31:42 +02:00
|
|
|
.getTypeName(er);
|
|
|
|
String json = ElementMapper.marshal(er);
|
|
|
|
UUID uuid = er.getHeader().getUUID();
|
2020-11-11 14:18:43 +01:00
|
|
|
String ret = update(type, json, uuid);
|
2021-07-05 17:31:42 +02:00
|
|
|
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 17:44:13 +02:00
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 17:44:13 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-03 17:44:13 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public String update(String type, String json)
|
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
UUID uuid = Utility.getUUIDFromJSONString(json);
|
2020-11-11 14:18:43 +01:00
|
|
|
return update(type, json, uuid);
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public String update(String json) throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2016-09-15 13:46:48 +02:00
|
|
|
try {
|
2020-11-11 14:18:43 +01:00
|
|
|
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(json);
|
|
|
|
return update(type, json);
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 15:49:47 +02:00
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 15:49:47 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
@Override
|
2021-07-05 17:31:42 +02:00
|
|
|
public <ERElem extends ERElement> boolean delete(ERElem er)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2017-10-03 15:49:47 +02:00
|
|
|
try {
|
2021-02-16 17:00:46 +01:00
|
|
|
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
|
2021-07-05 17:31:42 +02:00
|
|
|
.getTypeName(er);
|
|
|
|
UUID uuid = er.getHeader().getUUID();
|
2020-11-11 14:18:43 +01:00
|
|
|
return delete(type, uuid);
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-04-05 17:18:53 +02:00
|
|
|
throw new RuntimeException(e);
|
2016-09-15 13:46:48 +02:00
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public boolean delete(String type, UUID uuid)
|
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2017-10-02 18:28:47 +02:00
|
|
|
try {
|
2020-11-11 14:18:43 +01:00
|
|
|
logger.trace("Going to delete {} with UUID {}", type, uuid);
|
2019-01-17 11:18:02 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
|
|
|
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
2019-02-06 12:03:35 +01:00
|
|
|
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
2020-11-11 14:18:43 +01:00
|
|
|
gxHTTPStringRequest.path(type);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(uuid.toString());
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2019-01-17 11:18:02 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.delete();
|
2019-02-12 18:05:48 +01:00
|
|
|
HTTPUtility.getResponse(String.class, httpURLConnection);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2019-02-12 18:05:48 +01:00
|
|
|
boolean deleted = true;
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-11 14:18:43 +01:00
|
|
|
logger.info("{} with UUID {} {}", type, uuid, deleted ? " successfully deleted" : "was NOT deleted");
|
2018-06-11 19:47:40 +02:00
|
|
|
return deleted;
|
2021-02-16 17:00:46 +01:00
|
|
|
|
|
|
|
} catch (ResourceRegistryException e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-11-28 12:49:27 +01:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <F extends Facet> F createFacet(F facet)
|
|
|
|
throws SchemaViolationException, FacetAlreadyPresentException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return create(facet);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public String createFacet(String facet)
|
|
|
|
throws SchemaViolationException, FacetAlreadyPresentException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return create(facet);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
|
|
|
public <F extends Facet> F readFacet(F facet) throws FacetNotFoundException, ResourceRegistryException {
|
|
|
|
return read(facet);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public String readFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException {
|
|
|
|
return read(facetType, uuid);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-07-05 17:31:42 +02:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <F extends Facet> F updateFacet(F facet)
|
|
|
|
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return update(facet);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public String updateFacet(String facet)
|
|
|
|
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return update(facet);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <F extends Facet> boolean deleteFacet(F facet)
|
|
|
|
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return delete(facet);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public boolean deleteFacet(String facetType, UUID uuid)
|
|
|
|
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return delete(facetType, uuid);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
|
|
|
public <R extends Resource> R createResource(R resource)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, ResourceAlreadyPresentException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return create(resource);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public String createResource(String resource)
|
|
|
|
throws SchemaViolationException, ResourceAlreadyPresentException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return create(resource);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
|
|
|
public <R extends Resource> R readResource(R resource) throws ResourceNotFoundException, ResourceRegistryException {
|
|
|
|
return read(resource);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public String readResource(String resourceType, UUID uuid)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws ResourceNotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return read(resourceType, uuid);
|
2017-10-03 17:44:13 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-03 17:44:13 +02:00
|
|
|
@Override
|
|
|
|
public <R extends Resource> R updateResource(R resource)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return update(resource);
|
2017-10-03 15:49:47 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-03 17:44:13 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public String updateResource(String resource)
|
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return update(resource);
|
2016-11-28 12:49:27 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
@Override
|
2018-06-11 19:47:40 +02:00
|
|
|
public <R extends Resource> boolean deleteResource(R resource)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return delete(resource);
|
2017-10-02 18:28:47 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public boolean deleteResource(String resourceType, UUID uuid)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return delete(resourceType, uuid);
|
2017-04-18 11:49:34 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-04-18 11:49:34 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(C consistsOf)
|
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return create(consistsOf);
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-03 17:44:13 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public String createConsistsOf(String consistsOf)
|
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return create(consistsOf);
|
2017-10-03 15:49:47 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C readConsistsOf(C consistsOf)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws NotFoundException, ResourceRegistryException {
|
|
|
|
return read(consistsOf);
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-03 17:44:13 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public String readConsistsOf(String consistsOfType, UUID uuid) throws NotFoundException, ResourceRegistryException {
|
|
|
|
return read(consistsOfType, uuid);
|
2017-10-02 18:28:47 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C updateConsistsOf(C consistsOf)
|
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return update(consistsOf);
|
2017-02-24 12:46:18 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-02-24 12:46:18 +01:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public String updateConsistsOf(String consistsOf)
|
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return update(consistsOf);
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(C consistsOf)
|
|
|
|
throws SchemaViolationException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return delete(consistsOf);
|
2017-10-03 17:44:13 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-03 17:44:13 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public boolean deleteConsistsOf(String consistsOfType, UUID uuid)
|
|
|
|
throws SchemaViolationException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return delete(consistsOfType, uuid);
|
2017-10-03 15:49:47 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo(I isRelatedTo)
|
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return create(isRelatedTo);
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public String createIsRelatedTo(String isRelatedTo)
|
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return create(isRelatedTo);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I readIsRelatedTo(I isRelatedTo)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws NotFoundException, ResourceRegistryException {
|
|
|
|
return read(isRelatedTo);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public String readIsRelatedTo(String isRelatedToType, UUID uuid)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws NotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return read(isRelatedToType, uuid);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I updateIsRelatedTo(I isRelatedTo)
|
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return update(isRelatedTo);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public String updateIsRelatedTo(String isRelatedTo)
|
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return update(isRelatedTo);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(I isRelatedTo)
|
|
|
|
throws SchemaViolationException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return delete(isRelatedTo);
|
2017-02-24 12:46:18 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid)
|
|
|
|
throws SchemaViolationException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return delete(isRelatedToType, uuid);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-02-24 12:46:18 +01:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public boolean addToContext(String type, UUID instanceUUID, UUID contextUUID)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2016-09-15 14:57:14 +02:00
|
|
|
try {
|
2020-11-11 14:18:43 +01:00
|
|
|
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME,
|
2018-06-11 19:47:40 +02:00
|
|
|
contextUUID);
|
2019-01-17 11:18:02 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
|
|
|
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
|
|
|
gxHTTPStringRequest.path(SharingPath.SHARING_PATH_PART);
|
2020-10-30 21:05:56 +01:00
|
|
|
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
|
|
|
|
gxHTTPStringRequest.path(contextUUID.toString());
|
2021-01-24 23:33:34 +01:00
|
|
|
gxHTTPStringRequest.path(type);
|
|
|
|
gxHTTPStringRequest.path(instanceUUID.toString());
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2019-01-17 11:18:02 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put();
|
|
|
|
boolean added = HTTPUtility.getResponse(Boolean.class, httpURLConnection);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-11 14:18:43 +01:00
|
|
|
logger.info("{} with UUID {} {} to {} with UUID {}", type, instanceUUID,
|
2018-06-11 19:47:40 +02:00
|
|
|
added ? " successfully added" : "was NOT added", Context.NAME, contextUUID);
|
|
|
|
return added;
|
2021-02-16 17:00:46 +01:00
|
|
|
|
|
|
|
} catch (ResourceRegistryException e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-04-05 17:18:53 +02:00
|
|
|
throw new RuntimeException(e);
|
2016-09-15 14:57:14 +02:00
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
@Override
|
2021-07-05 17:31:42 +02:00
|
|
|
public <ERElem extends ERElement> boolean addToContext(ERElem er, UUID contextUUID)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2016-11-14 12:33:14 +01:00
|
|
|
try {
|
2021-02-16 17:00:46 +01:00
|
|
|
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
|
2021-07-05 17:31:42 +02:00
|
|
|
.getTypeName(er);
|
|
|
|
UUID instanceUUID = er.getHeader().getUUID();
|
2020-11-11 14:18:43 +01:00
|
|
|
return addToContext(type, instanceUUID, contextUUID);
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 15:49:47 +02:00
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-04-05 17:18:53 +02:00
|
|
|
throw new RuntimeException(e);
|
2016-11-14 12:33:14 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public boolean addToCurrentContext(String type, UUID instanceUUID)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
UUID contextUUID = getCurrentContextUUID();
|
2020-11-11 14:18:43 +01:00
|
|
|
return addToContext(type, instanceUUID, contextUUID);
|
2016-11-14 12:33:14 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
@Override
|
2021-07-05 17:31:42 +02:00
|
|
|
public <ERElem extends ERElement> boolean addToCurrentContext(ERElem er)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
UUID contextUUID = getCurrentContextUUID();
|
2021-07-05 17:31:42 +02:00
|
|
|
return addToContext(er, contextUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public boolean removeFromContext(String type, UUID instanceUUID, UUID contextUUID)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2016-11-14 12:33:14 +01:00
|
|
|
try {
|
2020-11-11 14:18:43 +01:00
|
|
|
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME,
|
2018-06-11 19:47:40 +02:00
|
|
|
contextUUID);
|
2019-01-17 11:18:02 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
|
|
|
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
|
|
|
gxHTTPStringRequest.path(SharingPath.SHARING_PATH_PART);
|
2020-10-30 21:05:56 +01:00
|
|
|
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
|
|
|
|
gxHTTPStringRequest.path(contextUUID.toString());
|
2021-01-24 23:33:34 +01:00
|
|
|
gxHTTPStringRequest.path(type);
|
|
|
|
gxHTTPStringRequest.path(instanceUUID.toString());
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2019-01-17 11:18:02 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.delete();
|
|
|
|
boolean removed = HTTPUtility.getResponse(Boolean.class, httpURLConnection);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-11 14:18:43 +01:00
|
|
|
logger.info("{} with UUID {} {} to {} with UUID {}", type, instanceUUID,
|
2018-06-11 19:47:40 +02:00
|
|
|
removed ? " successfully removed" : "was NOT removed", Context.NAME, contextUUID);
|
|
|
|
return removed;
|
2021-02-16 17:00:46 +01:00
|
|
|
|
|
|
|
} catch (ResourceRegistryException e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-04-05 17:18:53 +02:00
|
|
|
throw new RuntimeException(e);
|
2016-11-14 12:33:14 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-12-21 16:29:37 +01:00
|
|
|
@Override
|
2021-07-05 17:31:42 +02:00
|
|
|
public <ERElem extends ERElement> boolean removeFromContext(ERElem er, UUID contextUUID)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
2016-12-21 16:29:37 +01:00
|
|
|
try {
|
2021-02-16 17:00:46 +01:00
|
|
|
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
|
2021-07-05 17:31:42 +02:00
|
|
|
.getTypeName(er);
|
|
|
|
UUID instanceUUID = er.getHeader().getUUID();
|
2020-11-11 14:18:43 +01:00
|
|
|
return removeFromContext(type, instanceUUID, contextUUID);
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 15:49:47 +02:00
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2018-06-11 19:47:40 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-04-05 17:18:53 +02:00
|
|
|
throw new RuntimeException(e);
|
2016-12-21 16:29:37 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-12-21 16:29:37 +01:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public boolean removeFromCurrentContext(String type, UUID instanceUUID) throws SchemaViolationException,
|
|
|
|
ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
UUID contextUUID = getCurrentContextUUID();
|
2020-11-11 14:18:43 +01:00
|
|
|
return removeFromContext(type, instanceUUID, contextUUID);
|
2016-12-21 16:29:37 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-07-05 17:31:42 +02:00
|
|
|
public <ERElem extends ERElement> boolean removeFromCurrentContext(ERElem er)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
UUID contextUUID = getCurrentContextUUID();
|
2021-07-05 17:31:42 +02:00
|
|
|
return removeFromContext(er, contextUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public Set<UUID> getElementContexts(String type, UUID instanceUUID)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
try {
|
|
|
|
logger.trace("Going to get contexts of {} with UUID {}", type, instanceUUID);
|
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
|
|
|
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
2021-01-24 23:33:34 +01:00
|
|
|
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
2020-11-11 14:18:43 +01:00
|
|
|
gxHTTPStringRequest.path(type);
|
|
|
|
gxHTTPStringRequest.path(instanceUUID.toString());
|
|
|
|
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-11 14:18:43 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
|
|
|
String jsonArray = HTTPUtility.getResponse(String.class, httpURLConnection);
|
|
|
|
Set<UUID> contexts = ContextUtility.getContextUUIDSet(jsonArray);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-11 14:18:43 +01:00
|
|
|
logger.info("Contexts of {} with UUID {} are {}", type, instanceUUID, contexts);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-11 14:18:43 +01:00
|
|
|
return contexts;
|
2021-02-16 17:00:46 +01:00
|
|
|
|
|
|
|
} catch (ResourceRegistryException e) {
|
2020-11-11 14:18:43 +01:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw e;
|
2021-02-16 17:00:46 +01:00
|
|
|
} catch (Exception e) {
|
2020-11-11 14:18:43 +01:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-07-05 17:31:42 +02:00
|
|
|
public <ERElem extends ERElement> Set<UUID> getElementContexts(ERElem er)
|
2020-11-11 14:18:43 +01:00
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-07-05 17:31:42 +02:00
|
|
|
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(er);
|
|
|
|
UUID instanceUUID = er.getHeader().getUUID();
|
2020-11-11 14:18:43 +01:00
|
|
|
return getElementContexts(type, instanceUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public boolean addResourceToContext(String resourceType, UUID resourceUUID, UUID contextUUID)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return addToContext(resourceType, resourceUUID, contextUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-12-21 16:29:37 +01:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public <R extends Resource> boolean addResourceToContext(R resource, UUID contextUUID)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return addToContext(resource, contextUUID);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-11 14:18:43 +01:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID) throws SchemaViolationException,
|
|
|
|
ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return addToCurrentContext(resourceType, resourceUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <R extends Resource> boolean addResourceToCurrentContext(R resource) throws SchemaViolationException,
|
|
|
|
ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return addToCurrentContext(resource);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public boolean removeResourceFromContext(String resourceType, UUID resourceUUID, UUID contextUUID)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return removeFromContext(resourceType, resourceUUID, contextUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public <R extends Resource> boolean removeResourceFromContext(R resource, UUID contextUUID)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return removeFromContext(resource, contextUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public boolean removeResourceFromCurrentContext(String resourceType, UUID resourceUUID)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return removeFromCurrentContext(resourceType, resourceUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <R extends Resource> boolean removeResourceFromCurrentContext(R resource) throws SchemaViolationException,
|
|
|
|
ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return removeFromCurrentContext(resource);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public boolean addFacetToContext(String facetType, UUID facetUUID, UUID contextUUID)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return addToContext(facetType, facetUUID, contextUUID);
|
2016-12-21 16:29:37 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-12-21 16:29:37 +01:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public <F extends Facet> boolean addFacetToContext(F facet, UUID contextUUID)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return addToContext(facet, contextUUID);
|
2016-12-21 16:29:37 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public boolean addFacetToCurrentContext(String facetType, UUID facetUUID)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return addToCurrentContext(facetType, facetUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
|
|
|
public <F extends Facet> boolean addFacetToCurrentContext(F facet)
|
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
|
|
return addToCurrentContext(facet);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2020-11-11 14:18:43 +01:00
|
|
|
public boolean removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return removeFromContext(facetType, facetUUID, contextUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <F extends Facet> boolean removeFacetFromContext(F facet, UUID contextUUID) throws SchemaViolationException,
|
|
|
|
FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return removeFromContext(facet, contextUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID) throws SchemaViolationException,
|
|
|
|
FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return removeFromCurrentContext(facetType, facetUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-02-16 17:00:46 +01:00
|
|
|
public <F extends Facet> boolean removeFacetFromCurrentContext(F facet) throws SchemaViolationException,
|
|
|
|
FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return removeFromCurrentContext(facet);
|
|
|
|
}
|
2020-11-11 14:18:43 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Set<UUID> getResourceContexts(String resourceType, UUID resourceUUID)
|
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
|
|
return getElementContexts(resourceType, resourceUUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <R extends Resource> Set<UUID> getResourceContexts(R resource)
|
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
|
|
return getElementContexts(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Set<UUID> getFacetContexts(String facetType, UUID facetUUID)
|
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
|
|
return getElementContexts(facetType, facetUUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <F extends Facet> Set<UUID> getFacetContexts(F facet)
|
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
|
|
return getElementContexts(facet);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|