2016-09-14 14:49:50 +02:00
|
|
|
package org.gcube.informationsystem.resourceregistry.publisher.proxy;
|
|
|
|
|
2016-09-14 18:08:46 +02:00
|
|
|
import java.io.BufferedReader;
|
2016-11-21 10:03:45 +01:00
|
|
|
import java.io.DataOutputStream;
|
2016-09-14 18:08:46 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.StringWriter;
|
2016-09-15 17:24:24 +02:00
|
|
|
import java.io.UnsupportedEncodingException;
|
2016-09-14 14:49:50 +02:00
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.URL;
|
2016-09-15 17:24:24 +02:00
|
|
|
import java.net.URLEncoder;
|
2016-09-16 12:36:06 +02:00
|
|
|
import java.util.List;
|
2016-09-15 17:24:24 +02:00
|
|
|
import java.util.Map;
|
2017-01-12 16:37:46 +01:00
|
|
|
import java.util.Map.Entry;
|
2016-11-14 12:33:14 +01:00
|
|
|
import java.util.UUID;
|
2016-09-14 18:08:46 +02:00
|
|
|
|
|
|
|
import javax.xml.ws.EndpointReference;
|
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;
|
2016-09-14 18:08:46 +02:00
|
|
|
import org.gcube.common.clients.Call;
|
|
|
|
import org.gcube.common.clients.delegates.AsyncProxyDelegate;
|
|
|
|
import org.gcube.common.clients.delegates.ProxyDelegate;
|
|
|
|
import org.gcube.common.clients.exceptions.ServiceException;
|
2016-09-14 14:49:50 +02:00
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.informationsystem.impl.utils.Entities;
|
2017-01-25 15:34:59 +01:00
|
|
|
import org.gcube.informationsystem.model.ISManageable;
|
2016-11-14 12:33:14 +01:00
|
|
|
import org.gcube.informationsystem.model.entity.Context;
|
2016-09-14 14:49:50 +02:00
|
|
|
import org.gcube.informationsystem.model.entity.Facet;
|
|
|
|
import org.gcube.informationsystem.model.entity.Resource;
|
|
|
|
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
|
|
|
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
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;
|
2016-11-29 08:27:30 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
2016-12-30 17:31:44 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.ERPath;
|
2016-09-14 14:49:50 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2016-10-12 14:36:27 +02:00
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
2016-09-14 14:49:50 +02:00
|
|
|
public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher {
|
|
|
|
|
2016-09-15 13:46:48 +02:00
|
|
|
private static final Logger logger = LoggerFactory
|
2016-09-16 12:36:06 +02:00
|
|
|
.getLogger(ResourceRegistryPublisherImpl.class);
|
2016-09-15 13:46:48 +02:00
|
|
|
|
2016-09-14 18:08:46 +02:00
|
|
|
private final AsyncProxyDelegate<EndpointReference> delegate;
|
|
|
|
|
2016-09-15 13:46:48 +02:00
|
|
|
public static final String PATH_SEPARATOR = "/";
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-09-16 12:36:06 +02:00
|
|
|
public final class RREntry<K, V> implements Map.Entry<K, V> {
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-09-16 12:36:06 +02:00
|
|
|
private final K key;
|
2016-11-14 12:33:14 +01:00
|
|
|
private V value;
|
|
|
|
|
|
|
|
public RREntry(K key, V value) {
|
|
|
|
this.key = key;
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public K getKey() {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public V getValue() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public V setValue(V value) {
|
|
|
|
V old = this.value;
|
|
|
|
this.value = value;
|
|
|
|
return old;
|
|
|
|
}
|
2016-09-16 12:36:06 +02:00
|
|
|
}
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-09-14 18:08:46 +02:00
|
|
|
public ResourceRegistryPublisherImpl(ProxyDelegate<EndpointReference> config) {
|
|
|
|
this.delegate = new AsyncProxyDelegate<EndpointReference>(config);
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
protected enum HTTPMETHOD {
|
|
|
|
GET, POST, PUT, DELETE;
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
@Override
|
2016-11-14 12:33:14 +01:00
|
|
|
public String toString() {
|
2016-09-15 17:24:24 +02:00
|
|
|
return this.name();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
} catch (Exception e) {
|
|
|
|
return ScopeProvider.instance.get();
|
|
|
|
}
|
|
|
|
return authorizationEntry.getContext();
|
|
|
|
}
|
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
class HTTPInputs {
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
public static final String PARAM_STARTER = "?";
|
|
|
|
public static final String PARAM_EQUALS = "=";
|
|
|
|
public static final String PARAM_SEPARATOR = "&";
|
|
|
|
public static final String UTF8 = "UTF-8";
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
protected final String path;
|
|
|
|
protected final HTTPMETHOD method;
|
|
|
|
protected final String urlParameters;
|
2016-11-21 10:03:45 +01:00
|
|
|
protected final String body;
|
2016-11-14 12:33:14 +01:00
|
|
|
|
|
|
|
protected String getParametersDataString(
|
2017-01-12 16:37:46 +01:00
|
|
|
List<Entry<String, String>> parameters)
|
2016-11-14 12:33:14 +01:00
|
|
|
throws UnsupportedEncodingException {
|
|
|
|
if (parameters == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
StringBuilder result = new StringBuilder();
|
2016-11-14 12:33:14 +01:00
|
|
|
boolean first = true;
|
2017-01-12 16:37:46 +01:00
|
|
|
for (Entry<String, String> entry : parameters) {
|
2016-11-14 12:33:14 +01:00
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
result.append(PARAM_SEPARATOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
result.append(URLEncoder.encode(entry.getKey(), UTF8));
|
|
|
|
result.append(PARAM_EQUALS);
|
|
|
|
result.append(URLEncoder.encode(entry.getValue(), UTF8));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result.toString();
|
|
|
|
}
|
2016-12-21 16:29:37 +01:00
|
|
|
|
2016-11-21 10:03:45 +01:00
|
|
|
public HTTPInputs(String path, HTTPMETHOD method,
|
|
|
|
List<Map.Entry<String, String>> parameters)
|
|
|
|
throws UnsupportedEncodingException {
|
|
|
|
this(path, method, parameters, null);
|
|
|
|
}
|
2016-12-21 16:29:37 +01:00
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
/**
|
|
|
|
* @param path
|
|
|
|
* @param method
|
|
|
|
* @param requestProperties
|
2016-11-14 12:33:14 +01:00
|
|
|
* @throws UnsupportedEncodingException
|
2016-09-15 17:24:24 +02:00
|
|
|
*/
|
|
|
|
public HTTPInputs(String path, HTTPMETHOD method,
|
2016-11-21 10:03:45 +01:00
|
|
|
List<Map.Entry<String, String>> parameters, String body)
|
2016-11-14 12:33:14 +01:00
|
|
|
throws UnsupportedEncodingException {
|
2016-09-15 17:24:24 +02:00
|
|
|
super();
|
|
|
|
this.path = path;
|
|
|
|
this.method = method;
|
|
|
|
this.urlParameters = getParametersDataString(parameters);
|
2016-11-21 10:03:45 +01:00
|
|
|
this.body = body;
|
2016-09-15 17:24:24 +02:00
|
|
|
}
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
/**
|
|
|
|
* @return the path
|
|
|
|
*/
|
|
|
|
public String getPath() {
|
2016-11-21 10:03:45 +01:00
|
|
|
return this.path;
|
2016-09-15 17:24:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the method
|
|
|
|
*/
|
|
|
|
public HTTPMETHOD getMethod() {
|
2016-11-21 10:03:45 +01:00
|
|
|
return this.method;
|
2016-09-15 17:24:24 +02:00
|
|
|
}
|
2016-09-15 13:46:48 +02:00
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
/**
|
|
|
|
* @return the urlParameters
|
|
|
|
*/
|
|
|
|
public String getUrlParameters() {
|
2016-11-21 10:03:45 +01:00
|
|
|
return this.urlParameters;
|
|
|
|
}
|
2016-12-21 16:29:37 +01:00
|
|
|
|
|
|
|
public String getBody() {
|
2016-11-21 10:03:45 +01:00
|
|
|
return this.body;
|
2016-09-15 17:24:24 +02:00
|
|
|
}
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
}
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-09-14 18:08:46 +02:00
|
|
|
class ResourceRegistryCall<C> implements Call<EndpointReference, C> {
|
|
|
|
|
|
|
|
protected final Class<C> clazz;
|
2016-09-15 17:24:24 +02:00
|
|
|
protected final HTTPInputs httpInputs;
|
2016-09-15 13:46:48 +02:00
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
public ResourceRegistryCall(Class<C> clazz, HTTPInputs httpInputs) {
|
2016-09-14 18:08:46 +02:00
|
|
|
this.clazz = clazz;
|
2016-09-15 17:24:24 +02:00
|
|
|
this.httpInputs = httpInputs;
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2016-09-15 13:46:48 +02:00
|
|
|
|
|
|
|
protected String getURLStringFromEndpointReference(
|
|
|
|
EndpointReference endpoint) throws IOException {
|
|
|
|
JaxRSEndpointReference jaxRSEndpointReference = new JaxRSEndpointReference(
|
|
|
|
endpoint);
|
2016-09-14 18:08:46 +02:00
|
|
|
return jaxRSEndpointReference.toString();
|
|
|
|
}
|
2016-09-15 13:46:48 +02:00
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
protected HttpURLConnection getConnection(URL url, HTTPMETHOD method)
|
2016-09-15 13:46:48 +02:00
|
|
|
throws Exception {
|
2016-12-21 16:29:37 +01:00
|
|
|
|
|
|
|
if (httpInputs.getUrlParameters() != null) {
|
2016-11-14 16:33:35 +01:00
|
|
|
url = new URL(url + "?" + httpInputs.getUrlParameters());
|
|
|
|
}
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-09-15 13:46:48 +02:00
|
|
|
HttpURLConnection connection = (HttpURLConnection) url
|
|
|
|
.openConnection();
|
|
|
|
if (SecurityTokenProvider.instance.get() == null) {
|
|
|
|
if (ScopeProvider.instance.get() == null) {
|
|
|
|
throw new RuntimeException(
|
|
|
|
"Null Token and Scope. Please set your token first.");
|
2016-09-14 18:08:46 +02:00
|
|
|
}
|
2016-09-15 13:46:48 +02:00
|
|
|
connection.setRequestProperty("gcube-scope",
|
|
|
|
ScopeProvider.instance.get());
|
|
|
|
} else {
|
|
|
|
connection.setRequestProperty(Constants.TOKEN_HEADER_ENTRY,
|
|
|
|
SecurityTokenProvider.instance.get());
|
2016-09-14 18:08:46 +02:00
|
|
|
}
|
|
|
|
connection.setDoOutput(true);
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-11-04 16:51:33 +01:00
|
|
|
connection.setRequestProperty("Content-type", "application/json");
|
2016-11-14 12:33:14 +01:00
|
|
|
connection.setRequestProperty("User-Agent",
|
|
|
|
ResourceRegistryPublisher.class.getSimpleName());
|
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
connection.setRequestMethod(method.toString());
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-11-21 10:03:45 +01:00
|
|
|
String body = httpInputs.getBody();
|
2016-12-21 16:29:37 +01:00
|
|
|
if (body != null
|
|
|
|
&& (method == HTTPMETHOD.POST || method == HTTPMETHOD.PUT)) {
|
|
|
|
DataOutputStream wr = new DataOutputStream(
|
|
|
|
connection.getOutputStream());
|
2016-11-21 10:03:45 +01:00
|
|
|
wr.writeBytes(body);
|
|
|
|
wr.flush();
|
|
|
|
wr.close();
|
|
|
|
}
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-09-14 18:08:46 +02:00
|
|
|
return connection;
|
|
|
|
}
|
2016-09-15 13:46:48 +02:00
|
|
|
|
2017-01-25 15:34:59 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2016-09-14 18:08:46 +02:00
|
|
|
@Override
|
|
|
|
public C call(EndpointReference endpoint) throws Exception {
|
|
|
|
String urlFromEndpointReference = getURLStringFromEndpointReference(endpoint);
|
|
|
|
StringBuilder callUrl = new StringBuilder(urlFromEndpointReference);
|
2016-09-15 17:24:24 +02:00
|
|
|
callUrl.append(httpInputs.getPath());
|
2016-09-15 13:46:48 +02:00
|
|
|
|
2016-09-14 18:08:46 +02:00
|
|
|
URL url = new URL(callUrl.toString());
|
2016-09-15 17:24:24 +02:00
|
|
|
HttpURLConnection connection = getConnection(url, httpInputs.method);
|
2016-11-14 12:33:14 +01:00
|
|
|
|
|
|
|
logger.debug("Response code for {} is {} : {}",
|
|
|
|
connection.getURL(), connection.getResponseCode(),
|
2016-09-14 18:08:46 +02:00
|
|
|
connection.getResponseMessage());
|
|
|
|
|
2016-09-15 17:24:24 +02:00
|
|
|
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
2016-09-15 13:46:48 +02:00
|
|
|
throw new Exception(
|
|
|
|
"Error Contacting Resource Registry Service");
|
2016-09-14 18:08:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
StringBuilder result = new StringBuilder();
|
|
|
|
try (BufferedReader reader = new BufferedReader(
|
2016-09-15 13:46:48 +02:00
|
|
|
new InputStreamReader((InputStream) connection.getContent()))) {
|
2016-09-14 18:08:46 +02:00
|
|
|
String line;
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
|
result.append(line);
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2016-09-15 13:46:48 +02:00
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
String res = result.toString();
|
2016-09-16 12:36:06 +02:00
|
|
|
logger.trace("Server returned content : {}", res);
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2017-01-25 15:34:59 +01:00
|
|
|
return (C) Entities.unmarshal((Class<ISManageable>) clazz, res);
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-09-14 18:08:46 +02:00
|
|
|
public <F extends Facet> F createFacet(Class<F> facetClass, F facet) {
|
2016-09-15 13:46:48 +02:00
|
|
|
|
2016-09-14 18:08:46 +02:00
|
|
|
try {
|
2016-10-28 12:06:54 +02:00
|
|
|
logger.info("Going to create: {}", facet);
|
2016-09-14 18:08:46 +02:00
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-09-14 18:08:46 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.FACET_PATH_PART);
|
2016-09-14 18:08:46 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(facetClass.getSimpleName());
|
2016-09-15 13:46:48 +02:00
|
|
|
|
2016-11-21 10:03:45 +01:00
|
|
|
String body = Entities.marshal(facet);
|
2016-11-14 12:33:14 +01:00
|
|
|
|
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
2016-11-21 10:03:45 +01:00
|
|
|
HTTPMETHOD.PUT, null, body);
|
2016-11-14 12:33:14 +01:00
|
|
|
|
|
|
|
ResourceRegistryCall<F> call = new ResourceRegistryCall<>(
|
|
|
|
facetClass, httpInputs);
|
|
|
|
|
2016-10-28 12:06:54 +02:00
|
|
|
F f = delegate.make(call);
|
2016-11-14 12:33:14 +01:00
|
|
|
logger.info("{} successfully created", f);
|
2016-10-28 12:06:54 +02:00
|
|
|
return f;
|
2016-09-14 18:08:46 +02:00
|
|
|
} catch (Exception e) {
|
2016-09-15 17:24:24 +02:00
|
|
|
logger.error("Error Creating {}", facet, e);
|
2016-09-14 18:08:46 +02:00
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-09-15 17:24:24 +02:00
|
|
|
public <F extends Facet> F updateFacet(Class<F> facetClass, F facet) {
|
|
|
|
try {
|
2016-10-28 12:06:54 +02:00
|
|
|
logger.info("Going to update: {}", facet);
|
2016-09-15 17:24:24 +02:00
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-09-15 17:24:24 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.FACET_PATH_PART);
|
2016-09-15 17:24:24 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(facet.getHeader().getUUID().toString());
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-11-21 10:03:45 +01:00
|
|
|
String body = Entities.marshal(facet);
|
2016-11-14 12:33:14 +01:00
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
2016-11-21 10:03:45 +01:00
|
|
|
HTTPMETHOD.POST, null, body);
|
2016-11-14 12:33:14 +01:00
|
|
|
|
|
|
|
ResourceRegistryCall<F> call = new ResourceRegistryCall<>(
|
|
|
|
facetClass, httpInputs);
|
2016-09-15 17:24:24 +02:00
|
|
|
|
2016-10-28 12:06:54 +02:00
|
|
|
F f = delegate.make(call);
|
2016-11-14 12:33:14 +01:00
|
|
|
logger.info("{} successfully updated", f);
|
2016-10-28 12:06:54 +02:00
|
|
|
return f;
|
2016-09-15 17:24:24 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error Updating {}", facet, e);
|
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-09-15 14:57:14 +02:00
|
|
|
public <F extends Facet> boolean deleteFacet(F facet) {
|
|
|
|
try {
|
2016-10-28 12:06:54 +02:00
|
|
|
logger.info("Going to delete: {}", facet);
|
2016-09-15 14:57:14 +02:00
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.FACET_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(facet.getHeader().getUUID().toString());
|
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
|
|
|
HTTPMETHOD.DELETE, null);
|
|
|
|
|
|
|
|
ResourceRegistryCall<Boolean> call = new ResourceRegistryCall<>(
|
|
|
|
Boolean.class, httpInputs);
|
|
|
|
|
2016-10-28 12:06:54 +02:00
|
|
|
boolean deleted = delegate.make(call);
|
2016-11-14 12:33:14 +01:00
|
|
|
logger.info("{} {}", facet, deleted ? " successfully deleted"
|
|
|
|
: "was NOT deleted");
|
2016-10-28 12:06:54 +02:00
|
|
|
return deleted;
|
2016-09-15 14:57:14 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error Removing {}", facet, e);
|
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-09-15 13:46:48 +02:00
|
|
|
public <R extends Resource> R createResource(Class<R> resourceClass,
|
|
|
|
R resource) {
|
|
|
|
try {
|
2016-10-28 12:06:54 +02:00
|
|
|
logger.info("Going to create: {}", resource);
|
2016-09-15 13:46:48 +02:00
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-09-15 13:46:48 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.RESOURCE_PATH_PART);
|
2016-09-15 13:46:48 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(resourceClass.getSimpleName());
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-11-21 10:03:45 +01:00
|
|
|
String body = Entities.marshal(resource);
|
2016-11-14 12:33:14 +01:00
|
|
|
|
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
2016-11-21 10:03:45 +01:00
|
|
|
HTTPMETHOD.PUT, null, body);
|
2016-11-14 12:33:14 +01:00
|
|
|
|
|
|
|
ResourceRegistryCall<R> call = new ResourceRegistryCall<>(
|
|
|
|
resourceClass, httpInputs);
|
2016-09-15 13:46:48 +02:00
|
|
|
|
2016-10-28 12:06:54 +02:00
|
|
|
R r = delegate.make(call);
|
2016-11-14 12:33:14 +01:00
|
|
|
logger.info("{} successfully created", r);
|
2016-10-28 12:06:54 +02:00
|
|
|
return r;
|
2016-09-15 13:46:48 +02:00
|
|
|
} catch (Exception e) {
|
2016-11-18 18:32:05 +01:00
|
|
|
logger.error("Error Creating {}", resource, e);
|
2016-09-15 13:46:48 +02:00
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
2016-12-21 16:29:37 +01:00
|
|
|
|
2016-11-28 12:49:27 +01:00
|
|
|
@Override
|
2016-12-21 16:29:37 +01:00
|
|
|
public <R extends Resource> R updateResource(Class<R> resourceClass,
|
|
|
|
R resource) {
|
2016-11-28 12:49:27 +01:00
|
|
|
try {
|
|
|
|
logger.info("Going to update: {}", resource);
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-11-28 12:49:27 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.RESOURCE_PATH_PART);
|
2016-11-28 12:49:27 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(resource.getHeader().getUUID().toString());
|
|
|
|
|
|
|
|
String body = Entities.marshal(resource);
|
|
|
|
|
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
|
|
|
HTTPMETHOD.POST, null, body);
|
|
|
|
|
|
|
|
ResourceRegistryCall<R> call = new ResourceRegistryCall<>(
|
|
|
|
resourceClass, httpInputs);
|
|
|
|
|
|
|
|
R r = delegate.make(call);
|
|
|
|
logger.info("{} update created", r);
|
|
|
|
return r;
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error Creating {}", resource, e);
|
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
|
|
|
|
@Override
|
2016-09-15 14:57:14 +02:00
|
|
|
public <R extends Resource> boolean deleteResource(R resource) {
|
|
|
|
try {
|
2016-10-28 12:06:54 +02:00
|
|
|
logger.info("Going to delete: {}", resource);
|
2016-09-15 14:57:14 +02:00
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.RESOURCE_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(resource.getHeader().getUUID().toString());
|
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
|
|
|
HTTPMETHOD.DELETE, null);
|
|
|
|
|
|
|
|
ResourceRegistryCall<Boolean> call = new ResourceRegistryCall<>(
|
|
|
|
Boolean.class, httpInputs);
|
|
|
|
|
2016-10-28 12:06:54 +02:00
|
|
|
boolean deleted = delegate.make(call);
|
2016-11-14 12:33:14 +01:00
|
|
|
logger.info("{} {}", resource, deleted ? " successfully deleted"
|
|
|
|
: "was NOT deleted");
|
2016-10-28 12:06:54 +02:00
|
|
|
return deleted;
|
2016-09-15 14:57:14 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error Removing {}", resource, e);
|
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-09-16 18:38:12 +02:00
|
|
|
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(
|
2016-09-15 13:46:48 +02:00
|
|
|
Class<C> consistsOfClass, C consistsOf) {
|
2016-09-15 14:57:14 +02:00
|
|
|
try {
|
2016-10-28 12:06:54 +02:00
|
|
|
logger.info("Going to create: {}", consistsOf);
|
2016-09-15 14:57:14 +02:00
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.CONSISTS_OF_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.SOURCE_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-11-14 12:33:14 +01:00
|
|
|
stringWriter.append(consistsOf.getSource().getHeader().getUUID()
|
|
|
|
.toString());
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.TARGET_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-11-14 12:33:14 +01:00
|
|
|
stringWriter.append(consistsOf.getTarget().getHeader().getUUID()
|
|
|
|
.toString());
|
2016-11-21 10:03:45 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(consistsOfClass.getSimpleName());
|
2016-12-21 16:29:37 +01:00
|
|
|
|
2016-11-21 10:03:45 +01:00
|
|
|
String body = Entities.marshal(consistsOf);
|
2016-11-14 12:33:14 +01:00
|
|
|
|
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
2016-11-21 10:03:45 +01:00
|
|
|
HTTPMETHOD.PUT, null, body);
|
2016-11-14 12:33:14 +01:00
|
|
|
|
|
|
|
ResourceRegistryCall<C> call = new ResourceRegistryCall<>(
|
|
|
|
consistsOfClass, httpInputs);
|
2016-09-15 17:24:24 +02:00
|
|
|
|
2016-10-28 12:06:54 +02:00
|
|
|
C c = delegate.make(call);
|
2016-11-14 12:33:14 +01:00
|
|
|
logger.info("{} successfully created", c);
|
2016-10-28 12:06:54 +02:00
|
|
|
return c;
|
2016-09-15 14:57:14 +02:00
|
|
|
} catch (Exception e) {
|
2016-11-18 18:32:05 +01:00
|
|
|
logger.error("Error Creating {}", consistsOf, e);
|
2016-09-15 14:57:14 +02:00
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-09-16 18:38:12 +02:00
|
|
|
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(
|
2016-09-14 14:49:50 +02:00
|
|
|
C consistsOf) {
|
2016-09-15 14:57:14 +02:00
|
|
|
try {
|
2016-10-28 12:06:54 +02:00
|
|
|
logger.info("Going to delete: {}", consistsOf);
|
2016-09-15 14:57:14 +02:00
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.CONSISTS_OF_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(consistsOf.getHeader().getUUID().toString());
|
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
|
|
|
HTTPMETHOD.DELETE, null);
|
|
|
|
|
|
|
|
ResourceRegistryCall<Boolean> call = new ResourceRegistryCall<>(
|
|
|
|
Boolean.class, httpInputs);
|
|
|
|
|
2016-10-28 12:06:54 +02:00
|
|
|
boolean deleted = delegate.make(call);
|
2016-11-14 12:33:14 +01:00
|
|
|
logger.info("{} {}", consistsOf, deleted ? " successfully deleted"
|
|
|
|
: "was NOT deleted");
|
2016-10-28 12:06:54 +02:00
|
|
|
return deleted;
|
2016-09-15 14:57:14 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error Removing {}", consistsOf, e);
|
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-09-16 18:38:12 +02:00
|
|
|
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo(
|
2016-09-15 13:46:48 +02:00
|
|
|
Class<I> isRelatedToClass, I isRelatedTo) {
|
2016-09-15 14:57:14 +02:00
|
|
|
|
|
|
|
try {
|
2016-10-28 12:06:54 +02:00
|
|
|
logger.info("Going to create: {}", isRelatedTo);
|
2016-09-15 14:57:14 +02:00
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.IS_RELATED_TO_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.SOURCE_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-11-14 12:33:14 +01:00
|
|
|
stringWriter.append(isRelatedTo.getSource().getHeader().getUUID()
|
|
|
|
.toString());
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.TARGET_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-11-14 12:33:14 +01:00
|
|
|
stringWriter.append(isRelatedTo.getTarget().getHeader().getUUID()
|
|
|
|
.toString());
|
2016-11-21 10:03:45 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(isRelatedToClass.getSimpleName());
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-11-21 10:03:45 +01:00
|
|
|
String body = Entities.marshal(isRelatedTo);
|
2016-11-14 12:33:14 +01:00
|
|
|
|
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
2016-11-21 10:03:45 +01:00
|
|
|
HTTPMETHOD.PUT, null, body);
|
2016-09-15 14:57:14 +02:00
|
|
|
|
|
|
|
ResourceRegistryCall<I> call = new ResourceRegistryCall<>(
|
2016-09-15 17:24:24 +02:00
|
|
|
isRelatedToClass, httpInputs);
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2016-10-28 12:06:54 +02:00
|
|
|
I i = delegate.make(call);
|
2016-11-14 12:33:14 +01:00
|
|
|
logger.info("{} successfully created", i);
|
2016-10-28 12:06:54 +02:00
|
|
|
return i;
|
2016-09-15 14:57:14 +02:00
|
|
|
} catch (Exception e) {
|
2016-11-18 18:32:05 +01:00
|
|
|
logger.error("Error Creating {}", isRelatedTo, e);
|
2016-09-15 14:57:14 +02:00
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-11-14 12:33:14 +01:00
|
|
|
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(
|
|
|
|
I isRelatedTo) {
|
2016-09-15 14:57:14 +02:00
|
|
|
try {
|
2016-10-28 12:06:54 +02:00
|
|
|
logger.info("Going to delete: {}", isRelatedTo);
|
2016-09-15 14:57:14 +02:00
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.IS_RELATED_TO_PATH_PART);
|
2016-09-15 14:57:14 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(isRelatedTo.getHeader().getUUID().toString());
|
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
|
|
|
HTTPMETHOD.DELETE, null);
|
|
|
|
|
|
|
|
ResourceRegistryCall<Boolean> call = new ResourceRegistryCall<>(
|
|
|
|
Boolean.class, httpInputs);
|
|
|
|
|
2016-10-28 12:06:54 +02:00
|
|
|
boolean deleted = delegate.make(call);
|
2016-11-14 12:33:14 +01:00
|
|
|
logger.info("{} {}", isRelatedTo, deleted ? " successfully deleted"
|
|
|
|
: "was NOT deleted");
|
2016-10-28 12:06:54 +02:00
|
|
|
return deleted;
|
2016-09-15 14:57:14 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error Removing {}", isRelatedTo, e);
|
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
@Override
|
|
|
|
public boolean addResourceToContext(UUID uuid)
|
|
|
|
throws ResourceNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
|
|
|
String context = getCurrentContext();
|
|
|
|
try {
|
2016-12-21 16:29:37 +01:00
|
|
|
logger.info("Going to add {} with UUID {} to current {} : {}",
|
2016-11-14 12:33:14 +01:00
|
|
|
Resource.NAME, uuid, Context.NAME, context);
|
2016-12-21 16:29:37 +01:00
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-11-14 16:33:35 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ADD_PATH_PART);
|
2016-11-14 12:33:14 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.RESOURCE_PATH_PART);
|
2016-11-14 12:33:14 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(uuid.toString());
|
|
|
|
|
2016-12-21 16:29:37 +01:00
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
|
|
|
HTTPMETHOD.POST, null);
|
|
|
|
|
|
|
|
ResourceRegistryCall<Boolean> call = new ResourceRegistryCall<>(
|
|
|
|
Boolean.class, httpInputs);
|
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
boolean added = delegate.make(call);
|
|
|
|
logger.info("{} with UUID {} was {} added to current {} : {}",
|
2016-12-21 16:29:37 +01:00
|
|
|
Resource.NAME, uuid, added ? "successfully" : "NOT",
|
|
|
|
Context.NAME, context);
|
2016-11-14 12:33:14 +01:00
|
|
|
return added;
|
|
|
|
} catch (Exception e) {
|
2016-12-21 16:29:37 +01:00
|
|
|
logger.error("Error Adding {} with UUID {} to current {} : {}",
|
2016-11-14 12:33:14 +01:00
|
|
|
Resource.NAME, uuid, Context.NAME, context, e);
|
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <R extends Resource> boolean addResourceToContext(R resource)
|
|
|
|
throws ResourceNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
2016-12-21 16:29:37 +01:00
|
|
|
return addResourceToContext(resource.getHeader().getUUID());
|
2016-11-14 12:33:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean addFacetToContext(UUID uuid) throws FacetNotFoundException,
|
|
|
|
ContextNotFoundException, ResourceRegistryException {
|
|
|
|
String context = getCurrentContext();
|
|
|
|
try {
|
2016-12-21 16:29:37 +01:00
|
|
|
logger.info("Going to add {} with UUID {} to current {} : {}",
|
2016-11-14 12:33:14 +01:00
|
|
|
Facet.NAME, uuid, Context.NAME, context);
|
2016-12-21 16:29:37 +01:00
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-11-14 16:33:35 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ADD_PATH_PART);
|
2016-11-14 12:33:14 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.FACET_PATH_PART);
|
2016-11-14 12:33:14 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(uuid.toString());
|
|
|
|
|
2016-12-21 16:29:37 +01:00
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
|
|
|
HTTPMETHOD.POST, null);
|
|
|
|
|
|
|
|
ResourceRegistryCall<Boolean> call = new ResourceRegistryCall<>(
|
|
|
|
Boolean.class, httpInputs);
|
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
boolean added = delegate.make(call);
|
|
|
|
logger.info("{} with UUID {} was {} added to current {} : {}",
|
2016-12-21 16:29:37 +01:00
|
|
|
Facet.NAME, uuid, added ? "successfully" : "NOT",
|
|
|
|
Context.NAME, context);
|
2016-11-14 12:33:14 +01:00
|
|
|
return added;
|
|
|
|
} catch (Exception e) {
|
2016-12-21 16:29:37 +01:00
|
|
|
logger.error("Error Adding {} with UUID {} to current {} : {}",
|
2016-11-14 12:33:14 +01:00
|
|
|
Facet.NAME, uuid, Context.NAME, context, e);
|
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <F extends Facet> boolean addFacetToContext(F facet)
|
|
|
|
throws FacetNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
|
|
|
return addFacetToContext(facet.getHeader().getUUID());
|
|
|
|
}
|
|
|
|
|
2016-12-21 16:29:37 +01:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
@Override
|
|
|
|
public boolean removeResourceFromContext(UUID uuid)
|
|
|
|
throws ResourceNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
|
|
|
String context = getCurrentContext();
|
|
|
|
try {
|
|
|
|
logger.info("Going to add {} with UUID {} to current {} : {}",
|
|
|
|
Resource.NAME, uuid, Context.NAME, context);
|
|
|
|
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-12-21 16:29:37 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.REMOVE_PATH_PART);
|
2016-12-21 16:29:37 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.RESOURCE_PATH_PART);
|
2016-12-21 16:29:37 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(uuid.toString());
|
|
|
|
|
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
|
|
|
HTTPMETHOD.POST, null);
|
|
|
|
|
|
|
|
ResourceRegistryCall<Boolean> call = new ResourceRegistryCall<>(
|
|
|
|
Boolean.class, httpInputs);
|
|
|
|
|
|
|
|
boolean removed = delegate.make(call);
|
|
|
|
logger.info("{} with UUID {} was {} removed from current {} : {}",
|
|
|
|
Resource.NAME, uuid, removed ? "successfully" : "NOT",
|
|
|
|
Context.NAME, context);
|
|
|
|
return removed;
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error Adding {} with UUID {} to current {} : {}",
|
|
|
|
Resource.NAME, uuid, Context.NAME, context, e);
|
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <R extends Resource> boolean removeResourceFromContext(R resource)
|
|
|
|
throws ResourceNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
|
|
|
return removeResourceFromContext(resource.getHeader().getUUID());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean removeFacetFromContext(UUID uuid)
|
|
|
|
throws FacetNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
|
|
|
String context = getCurrentContext();
|
|
|
|
try {
|
|
|
|
logger.info("Going to add {} with UUID {} to current {} : {}",
|
|
|
|
Facet.NAME, uuid, Context.NAME, context);
|
|
|
|
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
2016-12-21 16:29:37 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.REMOVE_PATH_PART);
|
2016-12-21 16:29:37 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
2016-12-30 17:31:44 +01:00
|
|
|
stringWriter.append(ERPath.FACET_PATH_PART);
|
2016-12-21 16:29:37 +01:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(uuid.toString());
|
|
|
|
|
|
|
|
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
|
|
|
HTTPMETHOD.POST, null);
|
|
|
|
|
|
|
|
ResourceRegistryCall<Boolean> call = new ResourceRegistryCall<>(
|
|
|
|
Boolean.class, httpInputs);
|
|
|
|
|
|
|
|
boolean removed = delegate.make(call);
|
|
|
|
logger.info("{} with UUID {} was {} removed from current {} : {}",
|
|
|
|
Facet.NAME, uuid, removed ? "successfully" : "NOT",
|
|
|
|
Context.NAME, context);
|
|
|
|
return removed;
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error Adding {} with UUID {} to current {} : {}",
|
|
|
|
Facet.NAME, uuid, Context.NAME, context, e);
|
|
|
|
throw new ServiceException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <F extends Facet> boolean removeFacetFromContext(F facet)
|
|
|
|
throws FacetNotFoundException, ContextNotFoundException,
|
|
|
|
ResourceRegistryException {
|
|
|
|
return removeFacetFromContext(facet.getHeader().getUUID());
|
|
|
|
}
|
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|