2017-04-03 18:44:47 +02:00
|
|
|
package org.gcube.informationsystem.resourceregistry.publisher;
|
2016-09-14 14:49:50 +02:00
|
|
|
|
2019-01-17 11:18:02 +01:00
|
|
|
import java.net.HttpURLConnection;
|
2016-11-14 12:33:14 +01:00
|
|
|
import java.util.UUID;
|
2016-09-14 18:08:46 +02:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
import org.gcube.common.authorization.client.Constants;
|
2016-11-14 12:33:14 +01:00
|
|
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
2016-09-14 14:49:50 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
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;
|
2016-09-14 14:49:50 +02:00
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
2020-02-03 10:52:43 +01:00
|
|
|
import org.gcube.informationsystem.base.reference.Element;
|
|
|
|
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
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;
|
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;
|
2018-06-11 19:47:40 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
|
|
|
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;
|
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 {
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherImpl.class);
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
protected final String address;
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
public ResourceRegistryPublisherImpl(String address) {
|
|
|
|
this.address = address;
|
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
private static String getCurrentContext() {
|
|
|
|
String token = SecurityTokenProvider.instance.get();
|
|
|
|
AuthorizationEntry authorizationEntry = null;
|
|
|
|
try {
|
|
|
|
authorizationEntry = Constants.authorizationService().get(token);
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
2016-11-14 12:33:14 +01:00
|
|
|
return ScopeProvider.instance.get();
|
|
|
|
}
|
|
|
|
return authorizationEntry.getContext();
|
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2018-06-12 11:24:05 +02:00
|
|
|
private UUID getCurrentContextUUID() throws ResourceRegistryException {
|
|
|
|
logger.debug("Going to read current {} ({}) definition", Context.NAME, getCurrentContext());
|
|
|
|
try {
|
|
|
|
logger.info("Going to get current {} ", Context.NAME);
|
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(AccessPath.ACCESS_PATH_PART);
|
|
|
|
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
|
|
|
|
gxHTTPStringRequest.path(AccessPath.CURRENT_CONTEXT);
|
2018-06-12 11:24:05 +02:00
|
|
|
|
2019-01-17 11:18:02 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
|
|
|
Context context = HTTPUtility.getResponse(Context.class, httpURLConnection);
|
2018-06-12 11:24:05 +02:00
|
|
|
|
2020-02-03 10:52:43 +01:00
|
|
|
logger.debug("Got Context is {}", ElementMapper.marshal(context));
|
2018-06-12 11:24:05 +02:00
|
|
|
return context.getHeader().getUUID();
|
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error while getting {} schema for {}", polymorphic ?
|
|
|
|
// AccessPath.POLYMORPHIC_PARAM + " " : "",
|
|
|
|
// type, e);
|
|
|
|
throw e;
|
|
|
|
} catch(Exception e) {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2020-02-03 10:52:43 +01:00
|
|
|
protected String create(String identifiableElementTypeName, String json, UUID uuid)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws AlreadyPresentException, ResourceRegistryException {
|
2017-10-03 17:44:13 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
logger.trace("Going to create {} : {}", identifiableElementTypeName, 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-02-03 10:52:43 +01:00
|
|
|
gxHTTPStringRequest.path(identifiableElementTypeName);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(uuid.toString());
|
2018-06-11 19:47:40 +02: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);
|
2018-06-11 19:47:40 +02:00
|
|
|
|
|
|
|
logger.trace("{} successfully created", ret);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
} catch(ResourceRegistryException e) {
|
2017-10-03 17:44:13 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw e;
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
2017-10-03 17:44:13 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-03 10:52:43 +01:00
|
|
|
public <IE extends IdentifiableElement> String internalCreate(IE identifiableElement) throws AlreadyPresentException, ResourceRegistryException {
|
2016-09-14 18:08:46 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
|
|
|
|
String json = ElementMapper.marshal(identifiableElement);
|
|
|
|
Header header = identifiableElement.getHeader();
|
2018-06-12 16:06:59 +02:00
|
|
|
if(header==null) {
|
|
|
|
header = new HeaderImpl(UUID.randomUUID());
|
2020-02-03 10:52:43 +01:00
|
|
|
identifiableElement.setHeader(header);
|
2018-06-12 16:06:59 +02:00
|
|
|
}
|
2020-02-03 10:52:43 +01:00
|
|
|
UUID uuid = identifiableElement.getHeader().getUUID();
|
|
|
|
return create(identifiableElementTypeName, json, uuid);
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw e;
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2018-06-12 16:06:59 +02:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2017-10-03 15:49:47 +02:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public <IE extends IdentifiableElement> IE create(IE identifiableElement) throws AlreadyPresentException, ResourceRegistryException {
|
2017-10-03 15:49:47 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
String ret = internalCreate(identifiableElement);
|
|
|
|
return (IE) ElementMapper.unmarshal(IdentifiableElement.class, ret);
|
2018-06-11 19:47:40 +02: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;
|
2018-06-11 19:47:40 +02: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
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public String create(String identifiableElement) throws AlreadyPresentException, ResourceRegistryException {
|
2017-10-02 18:28:47 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
IdentifiableElement e = ElementMapper.unmarshal(IdentifiableElement.class, identifiableElement);
|
2018-06-12 16:06:59 +02:00
|
|
|
return internalCreate(e);
|
2018-06-11 19:47:40 +02: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;
|
2018-06-11 19:47:40 +02: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);
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 17:44:13 +02:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public <IE extends IdentifiableElement> IE read(IE identifiableElement) throws NotFoundException, ResourceRegistryException {
|
2016-09-15 17:24:24 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
|
|
|
|
UUID uuid = identifiableElement.getHeader().getUUID();
|
|
|
|
String ret = read(identifiableElementTypeName, uuid);
|
|
|
|
return (IE) ElementMapper.unmarshal(IdentifiableElement.class, ret);
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 15:49:47 +02:00
|
|
|
throw e;
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, 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
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public String read(String identifiableElementTypeName, UUID uuid) throws NotFoundException, ResourceRegistryException {
|
2017-10-02 18:28:47 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
logger.trace("Going to read {} with UUID {}", identifiableElementTypeName, 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-02-03 10:52:43 +01:00
|
|
|
gxHTTPStringRequest.path(identifiableElementTypeName);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(uuid.toString());
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2019-01-17 11:18:02 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
|
|
|
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2020-02-03 10:52:43 +01:00
|
|
|
logger.debug("Got {} with UUID {} is {}", identifiableElementTypeName, uuid, ret);
|
2018-06-11 19:47:40 +02:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 15:49:47 +02:00
|
|
|
throw e;
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2020-02-03 10:52:43 +01:00
|
|
|
protected String update(String identifiableElementTypeName, String json, UUID uuid)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws AlreadyPresentException, ResourceRegistryException {
|
2016-09-15 14:57:14 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
logger.trace("Going to create {} : {}", identifiableElementTypeName, 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-02-03 10:52:43 +01:00
|
|
|
gxHTTPStringRequest.path(identifiableElementTypeName);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(uuid.toString());
|
2018-06-11 19:47:40 +02: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);
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2020-02-03 10:52:43 +01:00
|
|
|
logger.trace("{} with UUID {} successfully created : {}", identifiableElementTypeName, uuid, ret);
|
2018-06-11 19:47:40 +02:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
// 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
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public <IE extends IdentifiableElement> IE update(IE identifiableElement) throws NotFoundException, ResourceRegistryException {
|
2017-10-03 17:44:13 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
|
|
|
|
String json = ElementMapper.marshal(identifiableElement);
|
|
|
|
UUID uuid = identifiableElement.getHeader().getUUID();
|
|
|
|
String ret = update(identifiableElementTypeName, json, uuid);
|
|
|
|
return (IE) ElementMapper.unmarshal(Element.class, ret);
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 17:44:13 +02:00
|
|
|
throw e;
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 17:44:13 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2017-10-03 17:44:13 +02:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public String update(String identifiableElementTypeName, String json) throws NotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
UUID uuid = Utility.getUUIDFromJSONString(json);
|
|
|
|
return update(identifiableElementTypeName, json, uuid);
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw e;
|
|
|
|
} catch(Exception e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public String update(String json) throws NotFoundException, ResourceRegistryException {
|
2016-09-15 13:46:48 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(json);
|
|
|
|
return update(identifiableElementTypeName, json);
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 15:49:47 +02:00
|
|
|
throw e;
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 15:49:47 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 17:44:13 +02:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public <IE extends IdentifiableElement> boolean delete(IE identifiableElement) throws NotFoundException, ResourceRegistryException {
|
2017-10-03 15:49:47 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
|
|
|
|
UUID uuid = identifiableElement.getHeader().getUUID();
|
|
|
|
return delete(identifiableElementTypeName, uuid);
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
// 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
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean delete(String identifiableElementTypeName, UUID uuid) throws NotFoundException, ResourceRegistryException {
|
2017-10-02 18:28:47 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
logger.trace("Going to delete {} with UUID {}", identifiableElementTypeName, 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-02-03 10:52:43 +01:00
|
|
|
gxHTTPStringRequest.path(identifiableElementTypeName);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(uuid.toString());
|
2018-06-11 19:47:40 +02: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);
|
|
|
|
|
|
|
|
boolean deleted = true;
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2020-02-03 10:52:43 +01:00
|
|
|
logger.info("{} with UUID {} {}", identifiableElementTypeName, uuid, deleted ? " successfully deleted" : "was NOT deleted");
|
2018-06-11 19:47:40 +02:00
|
|
|
return deleted;
|
|
|
|
|
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw e;
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2016-11-28 12:49:27 +01:00
|
|
|
@Override
|
2018-06-11 19:47:40 +02:00
|
|
|
public <F extends Facet> F createFacet(F facet) throws FacetAlreadyPresentException, ResourceRegistryException {
|
|
|
|
return create(facet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException {
|
|
|
|
return create(facet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <F extends Facet> F readFacet(F facet) throws FacetNotFoundException, ResourceRegistryException {
|
|
|
|
return read(facet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public String readFacet(String facetTypeName, UUID uuid) throws FacetNotFoundException, ResourceRegistryException {
|
|
|
|
return read(facetTypeName, uuid);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <F extends Facet> F updateFacet(F facet) throws FacetNotFoundException, ResourceRegistryException {
|
|
|
|
return update(facet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String updateFacet(String facet) throws FacetNotFoundException, ResourceRegistryException {
|
|
|
|
return update(facet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <F extends Facet> boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException {
|
|
|
|
return delete(facet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean deleteFacet(String facetTypeName, UUID uuid) throws FacetNotFoundException, ResourceRegistryException {
|
|
|
|
return delete(facetTypeName, uuid);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <R extends Resource> R createResource(R resource)
|
|
|
|
throws ResourceAlreadyPresentException, ResourceRegistryException {
|
|
|
|
return create(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException {
|
|
|
|
return create(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <R extends Resource> R readResource(R resource) throws ResourceNotFoundException, ResourceRegistryException {
|
|
|
|
return read(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public String readResource(String resourceTypeName, UUID uuid)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws ResourceNotFoundException, ResourceRegistryException {
|
2020-02-03 10:52:43 +01:00
|
|
|
return read(resourceTypeName, uuid);
|
2017-10-03 17:44:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <R extends Resource> R updateResource(R resource)
|
|
|
|
throws ResourceNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return update(resource);
|
2017-10-03 15:49:47 +02:00
|
|
|
}
|
2017-10-03 17:44:13 +02:00
|
|
|
|
|
|
|
@Override
|
2017-10-03 15:49:47 +02:00
|
|
|
public String updateResource(String resource) throws ResourceNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return update(resource);
|
2016-11-28 12:49:27 +01:00
|
|
|
}
|
2018-06-11 19:47:40 +02: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)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws ResourceNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return delete(resource);
|
2017-10-02 18:28:47 +02:00
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean deleteResource(String resourceTypeName, UUID uuid)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws ResourceNotFoundException, ResourceRegistryException {
|
2020-02-03 10:52:43 +01:00
|
|
|
return delete(resourceTypeName, uuid);
|
2017-04-18 11:49:34 +02:00
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2017-04-18 11:49:34 +02:00
|
|
|
@Override
|
2018-06-11 19:47:40 +02:00
|
|
|
public <C extends ConsistsOf<? extends Resource,? extends Facet>> C createConsistsOf(C consistsOf)
|
|
|
|
throws NotFoundException, ResourceRegistryException {
|
|
|
|
return create(consistsOf);
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2017-10-03 17:44:13 +02:00
|
|
|
@Override
|
2018-06-11 19:47:40 +02:00
|
|
|
public String createConsistsOf(String consistsOf) throws NotFoundException, ResourceRegistryException {
|
|
|
|
return create(consistsOf);
|
2017-10-03 15:49:47 +02:00
|
|
|
}
|
2017-10-03 17:44:13 +02:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
@Override
|
2018-06-11 19:47:40 +02:00
|
|
|
public <C extends ConsistsOf<? extends Resource,? extends Facet>> C readConsistsOf(C consistsOf)
|
|
|
|
throws NotFoundException, ResourceRegistryException {
|
|
|
|
return read(consistsOf);
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2017-10-03 17:44:13 +02:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public String readConsistsOf(String consistsOfTypeName, UUID uuid) throws NotFoundException, ResourceRegistryException {
|
|
|
|
return read(consistsOfTypeName, uuid);
|
2017-10-02 18:28:47 +02:00
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2018-06-11 19:47:40 +02:00
|
|
|
public <C extends ConsistsOf<? extends Resource,? extends Facet>> C updateConsistsOf(C consistsOf)
|
|
|
|
throws NotFoundException, ResourceRegistryException {
|
|
|
|
return update(consistsOf);
|
2017-02-24 12:46:18 +01:00
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2017-02-24 12:46:18 +01:00
|
|
|
@Override
|
2018-06-11 19:47:40 +02:00
|
|
|
public String updateConsistsOf(String consistsOf) throws NotFoundException, ResourceRegistryException {
|
|
|
|
return update(consistsOf);
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2018-06-11 19:47:40 +02:00
|
|
|
public <C extends ConsistsOf<? extends Resource,? extends Facet>> boolean deleteConsistsOf(C consistsOf)
|
|
|
|
throws ResourceRegistryException {
|
|
|
|
return delete(consistsOf);
|
2017-10-03 17:44:13 +02:00
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2017-10-03 17:44:13 +02:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean deleteConsistsOf(String consistsOfTypeName, UUID uuid) throws ResourceRegistryException {
|
|
|
|
return delete(consistsOfTypeName, uuid);
|
2017-10-03 15:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-06-11 19:47:40 +02:00
|
|
|
public <I extends IsRelatedTo<? extends Resource,? extends Resource>> I createIsRelatedTo(I isRelatedTo)
|
|
|
|
throws ResourceNotFoundException, ResourceRegistryException {
|
|
|
|
return create(isRelatedTo);
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2017-10-02 18:28:47 +02:00
|
|
|
|
2018-06-11 19:47:40 +02:00
|
|
|
@Override
|
|
|
|
public String createIsRelatedTo(String isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException {
|
|
|
|
return create(isRelatedTo);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <I extends IsRelatedTo<? extends Resource,? extends Resource>> I readIsRelatedTo(I isRelatedTo)
|
|
|
|
throws NotFoundException, ResourceRegistryException {
|
|
|
|
return read(isRelatedTo);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public String readIsRelatedTo(String isRelatedToTypeName, UUID uuid)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws NotFoundException, ResourceRegistryException {
|
2020-02-03 10:52:43 +01:00
|
|
|
return read(isRelatedToTypeName, uuid);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <I extends IsRelatedTo<? extends Resource,? extends Resource>> I updateIsRelatedTo(I isRelatedTo)
|
|
|
|
throws NotFoundException, ResourceRegistryException {
|
|
|
|
return update(isRelatedTo);
|
|
|
|
}
|
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2018-06-11 19:47:40 +02:00
|
|
|
public String updateIsRelatedTo(String isRelatedTo) throws NotFoundException, ResourceRegistryException {
|
|
|
|
return update(isRelatedTo);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <I extends IsRelatedTo<? extends Resource,? extends Resource>> boolean deleteIsRelatedTo(I isRelatedTo)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return delete(isRelatedTo);
|
2017-02-24 12:46:18 +01:00
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean deleteIsRelatedTo(String isRelatedToTypeName, UUID uuid) throws ResourceRegistryException {
|
|
|
|
return delete(isRelatedToTypeName, uuid);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
|
|
|
|
2017-02-24 12:46:18 +01:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean addToContext(UUID contextUUID, String identifiableElementTypeName, UUID instanceUUID)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws NotFoundException, ResourceRegistryException {
|
2016-09-15 14:57:14 +02:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", identifiableElementTypeName, 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);
|
|
|
|
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
|
|
|
|
gxHTTPStringRequest.path(contextUUID.toString());
|
2020-02-03 10:52:43 +01:00
|
|
|
gxHTTPStringRequest.path(identifiableElementTypeName);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(instanceUUID.toString());
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2019-01-17 11:18:02 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put();
|
|
|
|
boolean added = HTTPUtility.getResponse(Boolean.class, httpURLConnection);
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2020-02-03 10:52:43 +01:00
|
|
|
logger.info("{} with UUID {} {} to {} with UUID {}", identifiableElementTypeName, instanceUUID,
|
2018-06-11 19:47:40 +02:00
|
|
|
added ? " successfully added" : "was NOT added", Context.NAME, contextUUID);
|
|
|
|
return added;
|
|
|
|
|
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
// 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
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public <IE extends IdentifiableElement> boolean addToContext(UUID contextUUID, IE identifiableElement)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws NotFoundException, ResourceRegistryException {
|
2016-11-14 12:33:14 +01:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
|
|
|
|
UUID instanceUUID = identifiableElement.getHeader().getUUID();
|
|
|
|
return addToContext(contextUUID, identifiableElementTypeName, instanceUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 15:49:47 +02:00
|
|
|
throw e;
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean addToCurrentContext(String identifiableElementTypeName, UUID instanceUUID)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws NotFoundException, ResourceRegistryException {
|
|
|
|
UUID contextUUID = getCurrentContextUUID();
|
2020-02-03 10:52:43 +01:00
|
|
|
return addToContext(contextUUID, identifiableElementTypeName, instanceUUID);
|
2016-11-14 12:33:14 +01:00
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public <IE extends IdentifiableElement> boolean addToCurrentContext(IE identifiableElement) throws NotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
UUID contextUUID = getCurrentContextUUID();
|
2020-02-03 10:52:43 +01:00
|
|
|
return addToContext(contextUUID, identifiableElement);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean removeFromContext(UUID contextUUID, String identifiableElementTypeName, UUID instanceUUID)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws NotFoundException, ResourceRegistryException {
|
2016-11-14 12:33:14 +01:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", identifiableElementTypeName, 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);
|
|
|
|
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
|
|
|
|
gxHTTPStringRequest.path(contextUUID.toString());
|
2020-02-03 10:52:43 +01:00
|
|
|
gxHTTPStringRequest.path(identifiableElementTypeName);
|
2019-01-17 11:18:02 +01:00
|
|
|
gxHTTPStringRequest.path(instanceUUID.toString());
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2019-01-17 11:18:02 +01:00
|
|
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.delete();
|
|
|
|
boolean removed = HTTPUtility.getResponse(Boolean.class, httpURLConnection);
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2020-02-03 10:52:43 +01:00
|
|
|
logger.info("{} with UUID {} {} to {} with UUID {}", identifiableElementTypeName, instanceUUID,
|
2018-06-11 19:47:40 +02:00
|
|
|
removed ? " successfully removed" : "was NOT removed", Context.NAME, contextUUID);
|
|
|
|
return removed;
|
|
|
|
|
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2016-12-21 16:29:37 +01:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public <IE extends IdentifiableElement> boolean removeFromContext(UUID contextUUID, IE identifiableElement)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2016-12-21 16:29:37 +01:00
|
|
|
try {
|
2020-02-03 10:52:43 +01:00
|
|
|
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
|
|
|
|
UUID instanceUUID = identifiableElement.getHeader().getUUID();
|
|
|
|
return removeFromContext(contextUUID, identifiableElementTypeName, instanceUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
2017-10-03 15:49:47 +02:00
|
|
|
throw e;
|
2018-06-11 19:47:40 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2016-12-21 16:29:37 +01:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean removeFromCurrentContext(String identifiableElementTypeName, UUID instanceUUID)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
UUID contextUUID = getCurrentContextUUID();
|
2020-02-03 10:52:43 +01:00
|
|
|
return removeFromContext(contextUUID, identifiableElementTypeName, instanceUUID);
|
2016-12-21 16:29:37 +01:00
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public <IE extends IdentifiableElement> boolean removeFromCurrentContext(IE identifiableElement)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
|
|
UUID contextUUID = getCurrentContextUUID();
|
2020-02-03 10:52:43 +01:00
|
|
|
return removeFromContext(contextUUID, identifiableElement);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean addResourceToContext(UUID contextUUID, String resourceTypeName, UUID resourceUUID)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-02-03 10:52:43 +01:00
|
|
|
return addToContext(contextUUID, resourceTypeName, resourceUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <R extends Resource> boolean addResourceToContext(UUID contextUUID, R resource)
|
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
|
|
return addToContext(contextUUID, resource);
|
|
|
|
}
|
|
|
|
|
2016-12-21 16:29:37 +01:00
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean addResourceToCurrentContext(String resourceTypeName, UUID resourceUUID)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-02-03 10:52:43 +01:00
|
|
|
return addToCurrentContext(resourceTypeName, resourceUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <R extends Resource> boolean addResourceToCurrentContext(R resource)
|
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
|
|
return addToCurrentContext(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean removeResourceFromContext(UUID contextUUID, String resourceTypeName, UUID resourceUUID)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-02-03 10:52:43 +01:00
|
|
|
return removeFromContext(contextUUID, resourceTypeName, resourceUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <R extends Resource> boolean removeResourceFromContext(UUID contextUUID, R resource)
|
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
|
|
return removeFromContext(contextUUID, resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean removeResourceFromCurrentContext(String resourceTypeName, UUID resourceUUID)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-02-03 10:52:43 +01:00
|
|
|
return removeFromCurrentContext(resourceTypeName, resourceUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <R extends Resource> boolean removeResourceFromCurrentContext(R resource)
|
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
|
|
return removeFromCurrentContext(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean addFacetToContext(UUID contextUUID, String facetTypeName, UUID facetUUID)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-02-03 10:52:43 +01:00
|
|
|
return addToContext(contextUUID, facetTypeName, facetUUID);
|
2016-12-21 16:29:37 +01:00
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
2016-12-21 16:29:37 +01:00
|
|
|
@Override
|
2018-06-11 19:47:40 +02:00
|
|
|
public <F extends Facet> boolean addFacetToContext(UUID contextUUID, F facet)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2018-06-11 19:47:40 +02:00
|
|
|
return addToContext(contextUUID, facet);
|
2016-12-21 16:29:37 +01:00
|
|
|
}
|
2018-06-11 19:47:40 +02:00
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean addFacetToCurrentContext(String facetTypeName, UUID facetUUID)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-02-03 10:52:43 +01:00
|
|
|
return addToCurrentContext(facetTypeName, facetUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <F extends Facet> boolean addFacetToCurrentContext(F facet)
|
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
|
|
return addToCurrentContext(facet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean removeFacetFromContext(UUID contextUUID, String facetTypeName, UUID facetUUID)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-02-03 10:52:43 +01:00
|
|
|
return removeFromContext(contextUUID, facetTypeName, facetUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <F extends Facet> boolean removeFacetFromContext(UUID contextUUID, F facet)
|
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
|
|
return removeFromContext(contextUUID, facet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-02-03 10:52:43 +01:00
|
|
|
public boolean removeFacetFromCurrentContext(String facetTypeName, UUID facetUUID)
|
2018-06-11 19:47:40 +02:00
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2020-02-03 10:52:43 +01:00
|
|
|
return removeFromCurrentContext(facetTypeName, facetUUID);
|
2018-06-11 19:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <F extends Facet> boolean removeFacetFromCurrentContext(F facet)
|
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
|
|
|
return removeFromCurrentContext(facet);
|
|
|
|
}
|
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|