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;
|
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;
|
2023-02-22 15:15:11 +01:00
|
|
|
import org.gcube.common.http.GXHTTPUtility;
|
2021-10-25 11:40:21 +02:00
|
|
|
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
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;
|
|
|
|
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;
|
2022-02-01 16:47:27 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException;
|
2021-10-25 10:59:52 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.facet.FacetAlreadyPresentException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.facet.FacetAvailableInAnotherContextException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.facet.FacetNotFoundException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceAlreadyPresentException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceAvailableInAnotherContextException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceNotFoundException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.consistsof.ConsistsOfAlreadyPresentException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.consistsof.ConsistsOfAvailableInAnotherContextException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.consistsof.ConsistsOfNotFoundException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToAlreadyPresentException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToAvailableInAnotherContextException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToNotFoundException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.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;
|
2021-08-25 09:28:03 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
|
2019-01-17 11:18:02 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
|
2023-02-10 14:32:45 +01:00
|
|
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
2023-04-21 15:57:26 +02:00
|
|
|
import org.gcube.informationsystem.utils.TypeUtility;
|
2021-10-21 16:33:26 +02:00
|
|
|
import org.gcube.informationsystem.utils.UUIDManager;
|
2023-04-21 15:57:26 +02:00
|
|
|
import org.gcube.informationsystem.utils.UUIDUtility;
|
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
|
|
|
|
2023-02-27 18:24:59 +01:00
|
|
|
private static final String ACCEPT_HTTP_HEADER_KEY = "Accept";
|
|
|
|
private static final String CONTENT_TYPE_HTTP_HEADER_KEY = "Content-Type";
|
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
protected final String address;
|
2023-02-27 18:24:59 +01:00
|
|
|
|
|
|
|
protected Map<String, String> headers;
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2022-07-21 17:08:24 +02:00
|
|
|
protected boolean hierarchicalMode;
|
2023-04-19 11:38:22 +02:00
|
|
|
protected boolean includeContexts;
|
2022-07-21 17:08:24 +02:00
|
|
|
|
2023-03-02 14:52:30 +01:00
|
|
|
protected ContextCache contextCache;
|
|
|
|
|
2022-07-21 17:08:24 +02:00
|
|
|
@Override
|
|
|
|
public boolean isHierarchicalMode() {
|
|
|
|
return hierarchicalMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setHierarchicalMode(boolean hierarchicalMode) {
|
|
|
|
this.hierarchicalMode = hierarchicalMode;
|
|
|
|
}
|
|
|
|
|
2023-04-26 10:46:08 +02:00
|
|
|
@Deprecated
|
2022-07-21 17:08:24 +02:00
|
|
|
@Override
|
2023-04-26 10:46:08 +02:00
|
|
|
public boolean isIncludeContextsInHeader() {
|
|
|
|
return includeContexts();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
@Override
|
|
|
|
public void setIncludeContextsInHeader(boolean includeContexts) {
|
|
|
|
includeContexts(includeContexts);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean includeContexts() {
|
2023-04-19 11:38:22 +02:00
|
|
|
return includeContexts;
|
2022-07-21 17:08:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-04-26 10:46:08 +02:00
|
|
|
public void includeContexts(boolean includeContexts) {
|
2023-04-19 11:38:22 +02:00
|
|
|
this.includeContexts = includeContexts;
|
2022-07-21 17:08:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2023-04-19 11:38:22 +02:00
|
|
|
return checkIncludeContextsInInstance(gxHTTPStringRequest, queryParams);
|
2020-11-09 15:48:06 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
|
|
|
private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest,
|
|
|
|
Map<String, String> queryParams) throws UnsupportedEncodingException {
|
2022-07-21 17:08:24 +02:00
|
|
|
if(hierarchicalMode) {
|
|
|
|
if(queryParams==null) {
|
2020-10-29 16:54:32 +01:00
|
|
|
queryParams = new HashMap<>();
|
|
|
|
}
|
2022-07-21 17:08:24 +02:00
|
|
|
queryParams.put(AccessPath.HIERARCHICAL_MODE_QUERY_PARAMETER, Boolean.toString(hierarchicalMode));
|
2020-10-29 16:54:32 +01:00
|
|
|
}
|
2020-11-09 15:48:06 +01:00
|
|
|
return gxHTTPStringRequest.queryParams(queryParams);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2023-04-19 11:38:22 +02:00
|
|
|
private GXHTTPStringRequest checkIncludeContextsInInstance(GXHTTPStringRequest gxHTTPStringRequest,
|
2021-02-16 17:00:46 +01:00
|
|
|
Map<String, String> queryParams) throws UnsupportedEncodingException {
|
2023-04-19 11:38:22 +02:00
|
|
|
if(includeContexts) {
|
2022-07-21 17:08:24 +02:00
|
|
|
if(queryParams==null) {
|
2020-11-09 15:48:06 +01:00
|
|
|
queryParams = new HashMap<>();
|
|
|
|
}
|
2023-04-19 11:38:22 +02:00
|
|
|
queryParams.put(AccessPath.INCLUDE_CONTEXTS_QUERY_PARAMETER, Boolean.toString(includeContexts));
|
2020-11-09 15:48:06 +01:00
|
|
|
}
|
|
|
|
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
|
|
|
};
|
2023-02-27 18:24:59 +01:00
|
|
|
|
2023-03-01 14:24:47 +01:00
|
|
|
@Override
|
2023-02-27 18:24:59 +01:00
|
|
|
public void addHeader(String name, String value) {
|
|
|
|
headers.put(name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected GXHTTPStringRequest getGXHTTPStringRequest() {
|
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
|
|
|
gxHTTPStringRequest.from(this.getClass().getSimpleName());
|
|
|
|
for(String name : headers.keySet()) {
|
|
|
|
gxHTTPStringRequest.header(name, headers.get(name));
|
|
|
|
}
|
|
|
|
return gxHTTPStringRequest;
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
public ResourceRegistryPublisherImpl(String address) {
|
2023-03-02 14:52:30 +01:00
|
|
|
this(address, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ResourceRegistryPublisherImpl(String address, boolean sharedContextCache) {
|
2017-04-03 18:44:47 +02:00
|
|
|
this.address = address;
|
2023-02-27 18:24:59 +01:00
|
|
|
this.headers = new HashMap<>();
|
2023-03-02 14:52:30 +01:00
|
|
|
if(sharedContextCache) {
|
|
|
|
contextCache = ContextCache.getInstance();
|
|
|
|
}else {
|
|
|
|
contextCache = new ContextCache();
|
|
|
|
}
|
2020-11-04 17:39:26 +01:00
|
|
|
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);
|
2023-02-27 18:24:59 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
|
|
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
2020-11-04 16:23:29 +01:00
|
|
|
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 {
|
|
|
|
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 {
|
|
|
|
logger.info("Going to get current {} ", Context.NAME);
|
2023-02-27 18:24:59 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
|
|
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, 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 {
|
2023-03-02 14:52:30 +01:00
|
|
|
Context context = contextCache.getContextByUUID(uuid);
|
2021-02-16 17:00:46 +01:00
|
|
|
if (context == null) {
|
2020-11-04 17:39:26 +01:00
|
|
|
context = getContextFromServer(uuid.toString());
|
|
|
|
contextCache.cleanCache();
|
|
|
|
contextCache.refreshContextsIfNeeded();
|
2023-04-28 11:47:50 +02:00
|
|
|
Context c = contextCache.getContextByUUID(context.getID());
|
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 {
|
2023-02-22 15:15:11 +01:00
|
|
|
String contextFullName = org.gcube.common.context.ContextUtility.getCurrentContextFullName();
|
2020-11-04 16:23:29 +01:00
|
|
|
UUID uuid = contextCache.getUUIDByFullName(contextFullName);
|
2023-03-02 14:52:30 +01:00
|
|
|
return getContext(uuid);
|
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 {
|
2023-04-28 11:47:50 +02:00
|
|
|
return getCurrentContext().getID();
|
2020-11-03 16:32:41 +01:00
|
|
|
}
|
2021-07-05 17:31:42 +02:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
2021-09-08 19:53:36 +02:00
|
|
|
public <ERElem extends ERElement> List<ERElem> list(Class<ERElem> clazz, Boolean polymorphic)
|
2021-07-05 17:31:42 +02:00
|
|
|
throws ResourceRegistryException {
|
2023-04-21 15:57:26 +02:00
|
|
|
String type = TypeUtility.getTypeName(clazz);
|
2021-07-05 17:31:42 +02:00
|
|
|
String ret = list(type, polymorphic);
|
|
|
|
try {
|
2021-09-08 19:53:36 +02:00
|
|
|
return (List<ERElem>) ElementMapper.unmarshalList(ERElement.class, ret);
|
2021-07-05 17:31:42 +02:00
|
|
|
} 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);
|
2023-02-27 18:24:59 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
|
|
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
2021-07-05 17:31:42 +02:00
|
|
|
gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART);
|
|
|
|
gxHTTPStringRequest.path(type);
|
|
|
|
|
|
|
|
Map<String,String> parameters = new HashMap<>();
|
2022-07-20 12:09:39 +02:00
|
|
|
parameters.put(InstancePath.POLYMORPHIC_QUERY_PARAMETER, polymorphic.toString());
|
2021-07-05 17:31:42 +02:00
|
|
|
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);
|
2023-02-27 18:24:59 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
|
|
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
|
|
gxHTTPStringRequest.header(CONTENT_TYPE_HTTP_HEADER_KEY, 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-09-08 19:53:36 +02:00
|
|
|
protected <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 {
|
2023-04-27 11:13:35 +02:00
|
|
|
String type = er.getTypeName();
|
2021-07-05 17:31:42 +02:00
|
|
|
String json = ElementMapper.marshal(er);
|
2023-04-28 11:47:50 +02:00
|
|
|
UUID uuid = er.getID();
|
2023-04-19 11:38:22 +02:00
|
|
|
if (uuid == null) {
|
2023-04-21 15:57:26 +02:00
|
|
|
uuid = UUIDManager.getInstance().generateValidUUID();
|
2023-04-28 11:47:50 +02:00
|
|
|
er.setID(uuid);
|
2018-06-12 16:06:59 +02:00
|
|
|
}
|
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
|
2022-02-09 12:16:01 +01:00
|
|
|
public <ERElem extends ERElement> boolean exist(ERElem er)
|
2022-02-09 12:10:08 +01:00
|
|
|
throws AvailableInAnotherContextException, ResourceRegistryException {
|
2023-04-27 11:13:35 +02:00
|
|
|
String type = er.getTypeName();
|
2023-04-28 11:47:50 +02:00
|
|
|
UUID uuid = er.getID();
|
2022-02-09 12:16:01 +01:00
|
|
|
return exist(type, uuid);
|
2020-10-29 16:54:32 +01:00
|
|
|
}
|
2021-09-08 19:53:36 +02:00
|
|
|
|
2020-10-29 16:54:32 +01:00
|
|
|
@Override
|
2022-02-09 12:16:01 +01:00
|
|
|
public <ERElem extends ERElement> boolean exist(Class<ERElem> clazz, UUID uuid)
|
2022-02-09 12:10:08 +01:00
|
|
|
throws AvailableInAnotherContextException, ResourceRegistryException {
|
2023-04-21 15:57:26 +02:00
|
|
|
String type = TypeUtility.getTypeName(clazz);
|
2022-02-09 12:16:01 +01:00
|
|
|
return exist(type, uuid);
|
2020-10-29 16:54:32 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-10-29 16:54:32 +01:00
|
|
|
@Override
|
2022-02-09 12:16:01 +01:00
|
|
|
public boolean exist(String type, UUID uuid)
|
2022-02-09 12:10:08 +01:00
|
|
|
throws AvailableInAnotherContextException, ResourceRegistryException {
|
2020-10-29 16:54:32 +01:00
|
|
|
try {
|
|
|
|
logger.info("Going to check if {} with UUID {} exists", type, uuid);
|
2023-02-27 18:24:59 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
|
|
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
2020-10-29 16:54:32 +01:00
|
|
|
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;
|
2022-02-09 12:10:08 +01:00
|
|
|
} catch (NotFoundException e) {
|
|
|
|
return false;
|
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-09-08 19:53:36 +02:00
|
|
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
2016-09-15 17:24:24 +02:00
|
|
|
try {
|
2023-04-27 11:13:35 +02:00
|
|
|
String type = er.getTypeName();
|
2023-04-28 11:47:50 +02:00
|
|
|
UUID uuid = er.getID();
|
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 {
|
2023-04-21 15:57:26 +02:00
|
|
|
String type = TypeUtility.getTypeName(clazz);
|
2021-07-05 17:31:42 +02:00
|
|
|
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
|
2021-09-08 19:53:36 +02:00
|
|
|
public String read(String type, UUID uuid)
|
|
|
|
throws NotFoundException, AvailableInAnotherContextException, 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);
|
2023-02-27 18:24:59 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
|
|
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, 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-09-08 19:53:36 +02:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2021-07-05 17:31:42 +02:00
|
|
|
@Override
|
2021-09-08 19:53:36 +02:00
|
|
|
public <ERElem extends ERElement> ERElem update(ERElem er)
|
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2016-09-15 14:57:14 +02:00
|
|
|
try {
|
2023-04-27 11:13:35 +02:00
|
|
|
String type = er.getTypeName();
|
2021-09-08 19:53:36 +02:00
|
|
|
String json = ElementMapper.marshal(er);
|
2023-04-28 11:47:50 +02:00
|
|
|
UUID uuid = er.getID();
|
2021-09-08 19:53:36 +02:00
|
|
|
String ret = update(type, json, uuid);
|
|
|
|
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-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-09-08 19:53:36 +02:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2021-09-08 19:53:36 +02:00
|
|
|
public String update(String json)
|
2021-02-16 17:00:46 +01:00
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2017-10-03 17:44:13 +02:00
|
|
|
try {
|
2023-04-21 15:57:26 +02:00
|
|
|
String type = TypeUtility.getTypeName(json);
|
2021-09-08 19:53:36 +02:00
|
|
|
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 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-09-08 19:53:36 +02: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 {
|
2023-04-21 15:57:26 +02:00
|
|
|
UUID uuid = UUIDUtility.getUUID(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-09-08 19:53:36 +02:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-09-08 19:53:36 +02:00
|
|
|
public String update(String type, String json, UUID uuid)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
2016-09-15 13:46:48 +02:00
|
|
|
try {
|
2021-09-08 19:53:36 +02:00
|
|
|
logger.trace("Going to create {} : {}", type, json);
|
2023-02-27 18:24:59 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
|
|
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
|
|
gxHTTPStringRequest.header(CONTENT_TYPE_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
2021-09-08 19:53:36 +02:00
|
|
|
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
|
|
|
gxHTTPStringRequest.path(type);
|
|
|
|
gxHTTPStringRequest.path(uuid.toString());
|
|
|
|
|
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json);
|
|
|
|
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
|
|
|
|
|
|
|
|
logger.trace("{} with UUID {} successfully created : {}", type, uuid, ret);
|
|
|
|
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-03 15:49:47 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2021-09-08 19:53:36 +02: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 {
|
2023-04-27 11:13:35 +02:00
|
|
|
String type = er.getTypeName();
|
2023-04-28 11:47:50 +02:00
|
|
|
UUID uuid = er.getID();
|
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);
|
2023-02-27 18:24:59 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
|
|
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, 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
|
|
|
|
2021-09-08 19:53:36 +02: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
|
2021-09-08 19:53:36 +02:00
|
|
|
public <F extends Facet> F readFacet(F facet)
|
|
|
|
throws FacetNotFoundException, FacetAvailableInAnotherContextException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return read(facet);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-09-08 19:53:36 +02:00
|
|
|
public String readFacet(String facetType, UUID uuid)
|
|
|
|
throws FacetNotFoundException, FacetAvailableInAnotherContextException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
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
|
2021-09-09 10:19:00 +02:00
|
|
|
public <R extends Resource> R readResource(R resource)
|
|
|
|
throws ResourceNotFoundException, ResourceAvailableInAnotherContextException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws ResourceNotFoundException, ResourceAvailableInAnotherContextException, 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-09-09 10:19:00 +02:00
|
|
|
throws 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-09-09 10:19:00 +02:00
|
|
|
throws 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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, ConsistsOfAlreadyPresentException, ResourceNotFoundException, 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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, ConsistsOfAlreadyPresentException, ResourceNotFoundException, 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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws ConsistsOfNotFoundException, ConsistsOfAvailableInAnotherContextException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
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
|
2021-09-09 10:19:00 +02:00
|
|
|
public String readConsistsOf(String consistsOfType, UUID uuid)
|
|
|
|
throws ConsistsOfNotFoundException, ConsistsOfAvailableInAnotherContextException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, ConsistsOfNotFoundException, 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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, ConsistsOfNotFoundException, 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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, ConsistsOfNotFoundException, 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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, ConsistsOfNotFoundException, 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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, IsRelatedToAlreadyPresentException, 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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, IsRelatedToAlreadyPresentException, 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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws IsRelatedToNotFoundException, IsRelatedToAvailableInAnotherContextException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws IsRelatedToNotFoundException, IsRelatedToAvailableInAnotherContextException, 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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, IsRelatedToNotFoundException, 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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, IsRelatedToNotFoundException, 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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws IsRelatedToNotFoundException, 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)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws IsRelatedToNotFoundException, 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
|
2021-08-25 09:28:03 +02:00
|
|
|
public List<ERElement> addToContext(String type, UUID instanceUUID, UUID contextUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, NotFoundException, ContextNotFoundException, 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);
|
2023-02-27 18:24:59 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
2019-01-17 11:18:02 +01:00
|
|
|
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
|
|
|
|
2021-08-25 09:28:03 +02:00
|
|
|
|
|
|
|
Map<String, String> queryParams = new HashMap<>();
|
|
|
|
queryParams.put(SharingPath.OPERATION_QUERY_PARAMETER, SharingOperation.ADD.name());
|
2022-07-20 12:09:39 +02:00
|
|
|
queryParams.put(SharingPath.DRY_RUN_QUERY_QUERY_PARAMETER, dryRun.toString());
|
2022-06-08 17:43:43 +02:00
|
|
|
Boolean forceAddToContext = getCurrentContextUUID().compareTo(contextUUID)==0;
|
|
|
|
queryParams.put(SharingPath.FORCE_ADD_TO_CONTEXT_QUERY_PARAMETER, forceAddToContext.toString());
|
2021-08-25 09:28:03 +02:00
|
|
|
|
|
|
|
includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams);
|
|
|
|
|
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post();
|
2021-07-07 10:18:57 +02:00
|
|
|
String jsonArray = HTTPUtility.getResponse(String.class, httpURLConnection);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2021-07-07 10:18:57 +02:00
|
|
|
logger.info("{} with UUID {} successfully added to {} with UUID {}", type, instanceUUID, Context.NAME, contextUUID);
|
|
|
|
List<ERElement> affectedInstaces = ElementMapper.unmarshalList(jsonArray);
|
|
|
|
|
|
|
|
return affectedInstaces;
|
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-08-25 09:28:03 +02:00
|
|
|
public List<ERElement> addToContext(ERElement er, UUID contextUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2016-11-14 12:33:14 +01:00
|
|
|
try {
|
2023-04-27 11:13:35 +02:00
|
|
|
String type = er.getTypeName();
|
2023-04-28 11:47:50 +02:00
|
|
|
UUID instanceUUID = er.getID();
|
2021-08-25 09:28:03 +02:00
|
|
|
return addToContext(type, instanceUUID, contextUUID, dryRun);
|
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
|
2021-08-25 09:28:03 +02:00
|
|
|
public List<ERElement> addToCurrentContext(String type, UUID instanceUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
UUID contextUUID = getCurrentContextUUID();
|
2021-08-25 09:28:03 +02:00
|
|
|
return addToContext(type, instanceUUID, contextUUID, dryRun);
|
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-08-25 09:28:03 +02:00
|
|
|
public List<ERElement> addToCurrentContext(ERElement er, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
UUID contextUUID = getCurrentContextUUID();
|
2021-08-25 09:28:03 +02:00
|
|
|
return addToContext(er, contextUUID, dryRun);
|
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-08-25 09:28:03 +02:00
|
|
|
public List<ERElement> removeFromContext(String type, UUID instanceUUID, UUID contextUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, NotFoundException, ContextNotFoundException, 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);
|
2023-02-27 18:24:59 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
2019-01-17 11:18:02 +01:00
|
|
|
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-08-25 09:28:03 +02:00
|
|
|
|
|
|
|
Map<String, String> queryParams = new HashMap<>();
|
|
|
|
queryParams.put(SharingPath.OPERATION_QUERY_PARAMETER, SharingOperation.REMOVE.name());
|
2022-07-20 12:09:39 +02:00
|
|
|
queryParams.put(SharingPath.DRY_RUN_QUERY_QUERY_PARAMETER, dryRun.toString());
|
2021-08-25 09:28:03 +02:00
|
|
|
|
|
|
|
includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams);
|
|
|
|
|
|
|
|
|
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post();
|
2021-07-07 10:18:57 +02:00
|
|
|
String jsonArray = HTTPUtility.getResponse(String.class, httpURLConnection);
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2021-07-07 10:18:57 +02:00
|
|
|
logger.info("{} with UUID {} successfully removed from {} with UUID {}", type, instanceUUID, Context.NAME, contextUUID);
|
|
|
|
List<ERElement> affectedInstaces = ElementMapper.unmarshalList(jsonArray);
|
|
|
|
|
|
|
|
return affectedInstaces;
|
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-08-25 09:28:03 +02:00
|
|
|
public List<ERElement> removeFromContext(ERElement er, UUID contextUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2016-12-21 16:29:37 +01:00
|
|
|
try {
|
2023-04-27 11:13:35 +02:00
|
|
|
String type = er.getTypeName();
|
2023-04-28 11:47:50 +02:00
|
|
|
UUID instanceUUID = er.getID();
|
2021-08-25 09:28:03 +02:00
|
|
|
return removeFromContext(type, instanceUUID, contextUUID, dryRun);
|
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-09-09 10:19:00 +02:00
|
|
|
public List<ERElement> removeFromCurrentContext(String type, UUID instanceUUID, Boolean dryRun)
|
|
|
|
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
UUID contextUUID = getCurrentContextUUID();
|
2021-08-25 09:28:03 +02:00
|
|
|
return removeFromContext(type, instanceUUID, contextUUID, dryRun);
|
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-08-25 09:28:03 +02:00
|
|
|
public List<ERElement> removeFromCurrentContext(ERElement er, Boolean dryRun)
|
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-08-25 09:28:03 +02:00
|
|
|
return removeFromContext(er, contextUUID, dryRun);
|
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-10-28 13:26:14 +02:00
|
|
|
public Map<UUID, String> getElementContexts(String type, UUID instanceUUID)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws NotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
try {
|
|
|
|
logger.trace("Going to get contexts of {} with UUID {}", type, instanceUUID);
|
2023-02-27 18:24:59 +01:00
|
|
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
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();
|
2021-10-28 13:26:14 +02:00
|
|
|
String objectNode = HTTPUtility.getResponse(String.class, httpURLConnection);
|
|
|
|
|
|
|
|
logger.info("Contexts of {} with UUID {} are {}", type, instanceUUID, objectNode);
|
|
|
|
|
|
|
|
Map<UUID, String> contexts = ContextUtility.getContextMap(objectNode);
|
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-10-28 13:26:14 +02:00
|
|
|
public <ERElem extends ERElement> Map<UUID, String> getElementContexts(ERElem er)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws NotFoundException, ResourceRegistryException {
|
2023-04-27 11:13:35 +02:00
|
|
|
String type = er.getTypeName();
|
2023-04-28 11:47:50 +02:00
|
|
|
UUID instanceUUID = er.getID();
|
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
|
2021-08-25 09:28:03 +02:00
|
|
|
public List<ERElement> addResourceToContext(String resourceType, UUID resourceUUID, UUID contextUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return addToContext(resourceType, resourceUUID, contextUUID, dryRun);
|
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
|
2021-08-25 09:28:03 +02:00
|
|
|
public <R extends Resource> List<ERElement> addResourceToContext(R resource, UUID contextUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return addToContext(resource, contextUUID, dryRun);
|
2020-11-11 14:18:43 +01:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2020-11-11 14:18:43 +01:00
|
|
|
@Override
|
2021-09-09 10:19:00 +02:00
|
|
|
public List<ERElement> addResourceToCurrentContext(String resourceType, UUID resourceUUID, Boolean dryRun)
|
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return addToCurrentContext(resourceType, resourceUUID, dryRun);
|
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-09-09 10:19:00 +02:00
|
|
|
public <R extends Resource> List<ERElement> addResourceToCurrentContext(R resource, Boolean dryRun)
|
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return addToCurrentContext(resource, dryRun);
|
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-08-25 09:28:03 +02:00
|
|
|
public List<ERElement> removeResourceFromContext(String resourceType, UUID resourceUUID, UUID contextUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return removeFromContext(resourceType, resourceUUID, contextUUID, dryRun);
|
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-08-25 09:28:03 +02:00
|
|
|
public <R extends Resource> List<ERElement> removeResourceFromContext(R resource, UUID contextUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return removeFromContext(resource, contextUUID, dryRun);
|
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-08-25 09:28:03 +02:00
|
|
|
public List<ERElement> removeResourceFromCurrentContext(String resourceType, UUID resourceUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return removeFromCurrentContext(resourceType, resourceUUID, dryRun);
|
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-08-25 09:28:03 +02:00
|
|
|
public <R extends Resource> List<ERElement> removeResourceFromCurrentContext(R resource, Boolean dryRun) throws SchemaViolationException,
|
2021-02-16 17:00:46 +01:00
|
|
|
ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return removeFromCurrentContext(resource, dryRun);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2021-09-09 10:19:00 +02:00
|
|
|
@Override
|
2021-10-28 13:26:14 +02:00
|
|
|
public Map<UUID, String> getResourceContexts(String resourceType, UUID resourceUUID)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws ResourceNotFoundException, ResourceRegistryException {
|
|
|
|
return getElementContexts(resourceType, resourceUUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-10-28 13:26:14 +02:00
|
|
|
public <R extends Resource> Map<UUID, String> getResourceContexts(R resource)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws ResourceNotFoundException, ResourceRegistryException {
|
|
|
|
return getElementContexts(resource);
|
|
|
|
}
|
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
2021-08-25 09:28:03 +02:00
|
|
|
public List<ERElement> addFacetToContext(String facetType, UUID facetUUID, UUID contextUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return addToContext(facetType, facetUUID, contextUUID, dryRun);
|
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-08-25 09:28:03 +02:00
|
|
|
public <F extends Facet> List<ERElement> addFacetToContext(F facet, UUID contextUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return addToContext(facet, contextUUID, dryRun);
|
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-08-25 09:28:03 +02:00
|
|
|
public List<ERElement> addFacetToCurrentContext(String facetType, UUID facetUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return addToCurrentContext(facetType, facetUUID, dryRun);
|
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-08-25 09:28:03 +02:00
|
|
|
public <F extends Facet> List<ERElement> addFacetToCurrentContext(F facet, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return addToCurrentContext(facet, dryRun);
|
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-08-25 09:28:03 +02:00
|
|
|
public List<ERElement> removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID, Boolean dryRun)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return removeFromContext(facetType, facetUUID, contextUUID, dryRun);
|
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-09-09 10:19:00 +02:00
|
|
|
public <F extends Facet> List<ERElement> removeFacetFromContext(F facet, UUID contextUUID, Boolean dryRun)
|
|
|
|
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return removeFromContext(facet, contextUUID, dryRun);
|
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-09-09 10:19:00 +02:00
|
|
|
public List<ERElement> removeFacetFromCurrentContext(String facetType, UUID facetUUID, Boolean dryRun)
|
|
|
|
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return removeFromCurrentContext(facetType, facetUUID, dryRun);
|
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-09-09 10:19:00 +02:00
|
|
|
public <F extends Facet> List<ERElement> removeFacetFromCurrentContext(F facet, Boolean dryRun)
|
|
|
|
throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2021-08-25 09:28:03 +02:00
|
|
|
return removeFromCurrentContext(facet, dryRun);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
2020-11-11 14:18:43 +01:00
|
|
|
|
|
|
|
@Override
|
2021-10-28 13:26:14 +02:00
|
|
|
public Map<UUID, String> getFacetContexts(String facetType, UUID facetUUID)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws FacetNotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return getElementContexts(facetType, facetUUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-10-28 13:26:14 +02:00
|
|
|
public <F extends Facet> Map<UUID, String> getFacetContexts(F facet)
|
2021-09-09 10:19:00 +02:00
|
|
|
throws FacetNotFoundException, ResourceRegistryException {
|
2020-11-11 14:18:43 +01:00
|
|
|
return getElementContexts(facet);
|
|
|
|
}
|
2021-02-16 17:00:46 +01:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|