2017-04-03 18:44:47 +02:00
|
|
|
package org.gcube.informationsystem.resourceregistry.publisher;
|
2016-09-14 14:49:50 +02:00
|
|
|
|
2016-09-14 18:08:46 +02:00
|
|
|
import java.io.StringWriter;
|
2017-04-03 18:44:47 +02:00
|
|
|
import java.net.MalformedURLException;
|
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;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
2017-01-30 11:43:18 +01:00
|
|
|
import org.gcube.informationsystem.impl.utils.ISMapper;
|
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;
|
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;
|
2016-12-30 17:31:44 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.ERPath;
|
2017-02-24 11:25:41 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall.HTTPMETHOD;
|
2017-10-03 15:49:47 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
|
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 {
|
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherImpl.class);
|
2016-09-15 13:46:48 +02:00
|
|
|
|
|
|
|
public static final String PATH_SEPARATOR = "/";
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
protected final String address;
|
2017-10-03 15:49:47 +02:00
|
|
|
protected HTTPCall httpCall;
|
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
public ResourceRegistryPublisherImpl(String address) {
|
|
|
|
this.address = address;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected HTTPCall getHTTPCall() throws MalformedURLException {
|
2017-10-03 15:49:47 +02:00
|
|
|
if (httpCall == null) {
|
2017-04-03 18:44:47 +02:00
|
|
|
httpCall = new HTTPCall(address, ResourceRegistryPublisher.class.getSimpleName());
|
|
|
|
}
|
|
|
|
return httpCall;
|
2016-09-14 14:49:50 +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);
|
|
|
|
} catch (Exception e) {
|
|
|
|
return ScopeProvider.instance.get();
|
|
|
|
}
|
|
|
|
return authorizationEntry.getContext();
|
|
|
|
}
|
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2017-10-03 15:49:47 +02:00
|
|
|
public <F extends Facet> F createFacet(Class<F> facetClass, F facet)
|
|
|
|
throws FacetAlreadyPresentException, ResourceRegistryException {
|
2016-09-14 18:08:46 +02:00
|
|
|
try {
|
2017-10-03 15:49:47 +02:00
|
|
|
String facetString = ISMapper.marshal(facet);
|
|
|
|
String facetType = facetClass.getSimpleName();
|
|
|
|
String res = createFacet(facetType, facetString);
|
|
|
|
return ISMapper.unmarshal(facetClass, res);
|
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw e;
|
|
|
|
} catch (Exception e) {
|
|
|
|
// logger.trace("Error Creating {}", facet, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2016-09-15 13:46:48 +02:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
@Override
|
|
|
|
public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException {
|
|
|
|
try {
|
2017-10-03 15:56:42 +02:00
|
|
|
String facetType = Utility.getClassFromJsonString(facet);
|
2017-10-03 15:49:47 +02:00
|
|
|
return createFacet(facetType, facet);
|
2017-02-24 11:51:22 +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;
|
2016-09-14 18:08:46 +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
|
|
|
}
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
@Override
|
2017-10-03 15:49:47 +02:00
|
|
|
public String createFacet(String facetType, String facet)
|
|
|
|
throws FacetAlreadyPresentException, ResourceRegistryException {
|
2017-10-02 18:28:47 +02:00
|
|
|
try {
|
|
|
|
logger.info("Going to create: {}", facet);
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(ERPath.FACET_PATH_PART);
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(facetType);
|
2016-09-14 14:49:50 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
String f = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, facet);
|
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
logger.info("{} successfully created", f);
|
|
|
|
return f;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-10-02 18:28:47 +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;
|
|
|
|
} 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 15:49:47 +02:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2017-10-03 15:49:47 +02:00
|
|
|
public <F extends Facet> F updateFacet(Class<F> facetClass, F facet)
|
|
|
|
throws FacetNotFoundException, ResourceRegistryException {
|
2016-09-15 17:24:24 +02:00
|
|
|
try {
|
2017-10-03 15:49:47 +02:00
|
|
|
String facetString = ISMapper.marshal(facet);
|
|
|
|
UUID uuid = facet.getHeader().getUUID();
|
|
|
|
String res = updateFacet(uuid, facetString);
|
|
|
|
return ISMapper.unmarshal(facetClass, res);
|
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Updating {}", facet, e);
|
|
|
|
throw e;
|
|
|
|
} catch (Exception e) {
|
|
|
|
// logger.trace("Error Updating {}", facet, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
@Override
|
|
|
|
public String updateFacet(String facet) throws FacetNotFoundException, ResourceRegistryException {
|
|
|
|
try {
|
|
|
|
UUID uuid = Utility.getUUIDFromJsonString(facet);
|
|
|
|
return updateFacet(uuid, facet);
|
2017-02-24 11:51:22 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Updating {}", facet, e);
|
|
|
|
throw e;
|
2016-09-15 17:24:24 +02:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Updating {}", 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
|
|
|
}
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
@Override
|
|
|
|
public String updateFacet(UUID uuid, String facet) throws FacetNotFoundException, ResourceRegistryException {
|
|
|
|
try {
|
|
|
|
logger.info("Going to update: {}", facet);
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(ERPath.FACET_PATH_PART);
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(uuid.toString());
|
2016-09-14 14:49:50 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
String f = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.POST, facet);
|
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
logger.info("{} successfully updated", f);
|
|
|
|
return f;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Updating {}", facet, e);
|
|
|
|
throw e;
|
2017-10-02 18:28:47 +02:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Updating {}", facet, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2017-02-24 12:46:18 +01:00
|
|
|
public <F extends Facet> boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException {
|
2017-04-18 11:49:34 +02:00
|
|
|
logger.info("Going to delete : {}", facet);
|
|
|
|
return deleteFacet(facet.getHeader().getUUID());
|
|
|
|
}
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-04-18 11:49:34 +02:00
|
|
|
@Override
|
|
|
|
public boolean deleteFacet(UUID uuid) throws FacetNotFoundException, ResourceRegistryException {
|
2016-09-15 14:57:14 +02:00
|
|
|
try {
|
2017-04-18 11:49:34 +02:00
|
|
|
logger.info("Going to delete {} with UUID {}", Facet.NAME, uuid.toString());
|
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);
|
2017-04-18 11:49:34 +02:00
|
|
|
stringWriter.append(uuid.toString());
|
2016-09-15 14:57:14 +02:00
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
boolean deleted = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.DELETE);
|
|
|
|
|
|
|
|
logger.info("{} with UUID {} {}", Facet.NAME, uuid.toString(),
|
|
|
|
deleted ? " successfully deleted" : "was NOT deleted");
|
2016-10-28 12:06:54 +02:00
|
|
|
return deleted;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-02-24 11:51:22 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Removing {}", facet, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2016-09-15 14:57:14 +02:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Removing {}", 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
|
|
|
}
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2017-10-03 15:49:47 +02:00
|
|
|
public <R extends Resource> R createResource(Class<R> resourceClass, R resource)
|
|
|
|
throws ResourceAlreadyPresentException, ResourceRegistryException {
|
2016-09-15 13:46:48 +02:00
|
|
|
try {
|
2017-10-03 15:49:47 +02:00
|
|
|
String resourceString = ISMapper.marshal(resource);
|
|
|
|
String resourceType = resourceClass.getSimpleName();
|
|
|
|
String res = createResource(resourceType, resourceString);
|
|
|
|
return ISMapper.unmarshal(resourceClass, res);
|
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", resource, e);
|
|
|
|
throw e;
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
// logger.trace("Error Creating {}", resource, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
@Override
|
|
|
|
public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException {
|
|
|
|
try {
|
2017-10-03 15:56:42 +02:00
|
|
|
String resourceType = Utility.getClassFromJsonString(resource);
|
2017-10-03 15:49:47 +02:00
|
|
|
return createResource(resourceType, resource);
|
2017-02-24 11:51:22 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", resource, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2016-09-15 13:46:48 +02:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", resource, 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
|
|
|
}
|
2016-12-21 16:29:37 +01:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
@Override
|
2017-10-03 15:49:47 +02:00
|
|
|
public String createResource(String resourceType, String resource)
|
|
|
|
throws ResourceAlreadyPresentException, ResourceRegistryException {
|
2017-10-02 18:28:47 +02:00
|
|
|
try {
|
|
|
|
logger.info("Going to create: {}", resource);
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(ERPath.RESOURCE_PATH_PART);
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(resourceType);
|
|
|
|
|
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
String r = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, resource);
|
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
logger.info("{} successfully created", r);
|
|
|
|
return r;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", resource, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw e;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", resource, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2016-11-28 12:49:27 +01:00
|
|
|
@Override
|
2017-10-03 15:49:47 +02:00
|
|
|
public <R extends Resource> R updateResource(Class<R> resourceClass, R resource)
|
|
|
|
throws ResourceNotFoundException, ResourceRegistryException {
|
2016-11-28 12:49:27 +01:00
|
|
|
try {
|
2017-10-03 15:49:47 +02:00
|
|
|
String resourceString = ISMapper.marshal(resource);
|
|
|
|
UUID uuid = resource.getHeader().getUUID();
|
|
|
|
String res = updateResource(uuid, resourceString);
|
|
|
|
return ISMapper.unmarshal(resourceClass, res);
|
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", resource, e);
|
|
|
|
throw e;
|
|
|
|
} catch (Exception e) {
|
|
|
|
// logger.trace("Error Creating {}", resource, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 12:49:27 +01:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
public String updateResource(String resource) throws ResourceNotFoundException, ResourceRegistryException {
|
|
|
|
try {
|
|
|
|
UUID uuid = Utility.getUUIDFromJsonString(resource);
|
|
|
|
return updateResource(uuid, resource);
|
2017-02-24 11:51:22 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", resource, e);
|
|
|
|
throw e;
|
2016-11-28 12:49:27 +01:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", resource, e);
|
2017-04-05 17:18:53 +02:00
|
|
|
throw new RuntimeException(e);
|
2016-11-28 12:49:27 +01:00
|
|
|
}
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
@Override
|
2017-10-03 15:49:47 +02:00
|
|
|
public String updateResource(UUID uuid, String resource)
|
|
|
|
throws ResourceNotFoundException, ResourceRegistryException {
|
2017-10-02 18:28:47 +02:00
|
|
|
try {
|
|
|
|
logger.info("Going to update: {}", resource);
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(ERPath.RESOURCE_PATH_PART);
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(uuid.toString());
|
|
|
|
|
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
String r = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.POST, resource);
|
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
logger.info("{} successfully updated", r);
|
|
|
|
return r;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", resource, e);
|
|
|
|
throw e;
|
2017-10-02 18:28:47 +02:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", resource, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2017-10-03 15:49:47 +02:00
|
|
|
public <R extends Resource> boolean deleteResource(R resource)
|
|
|
|
throws ResourceNotFoundException, ResourceRegistryException {
|
2017-04-18 11:49:34 +02:00
|
|
|
logger.info("Going to delete {}", resource);
|
|
|
|
return deleteResource(resource.getHeader().getUUID());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean deleteResource(UUID uuid) throws ResourceNotFoundException, ResourceRegistryException {
|
2016-09-15 14:57:14 +02:00
|
|
|
try {
|
2017-04-18 11:49:34 +02:00
|
|
|
logger.info("Going to delete {} with UUID {}", Resource.NAME, uuid.toString());
|
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);
|
2017-04-18 11:49:34 +02:00
|
|
|
stringWriter.append(uuid.toString());
|
2016-09-15 14:57:14 +02:00
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
boolean deleted = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.DELETE);
|
|
|
|
|
|
|
|
logger.info("{} with UUID {} {}", Resource.NAME, uuid.toString(),
|
|
|
|
deleted ? " successfully deleted" : "was NOT deleted");
|
2016-10-28 12:06:54 +02:00
|
|
|
return deleted;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-02-24 11:51:22 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Removing {}", resource, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2016-09-15 14:57:14 +02:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Removing {}", resource, 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
|
|
|
}
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
@Override
|
2017-10-03 15:49:47 +02:00
|
|
|
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(Class<C> consistsOfClass,
|
|
|
|
C consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException {
|
2016-09-15 14:57:14 +02:00
|
|
|
try {
|
2017-10-03 15:49:47 +02:00
|
|
|
String consistsOfString = ISMapper.marshal(consistsOf);
|
|
|
|
String consistsOfType = consistsOfClass.getSimpleName();
|
|
|
|
String res = createConsistsOf(consistsOfType, consistsOfString);
|
|
|
|
return ISMapper.unmarshal(consistsOfClass, res);
|
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", consistsOf, e);
|
|
|
|
throw e;
|
|
|
|
} catch (Exception e) {
|
|
|
|
// logger.trace("Error Creating {}", consistsOf, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2016-11-14 12:33:14 +01:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
@Override
|
|
|
|
public String createConsistsOf(String consistsOf)
|
|
|
|
throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException {
|
|
|
|
try {
|
2017-10-03 15:56:42 +02:00
|
|
|
String consistsOfType = Utility.getClassFromJsonString(consistsOf);
|
2017-10-03 15:49:47 +02:00
|
|
|
return createConsistsOf(consistsOfType, consistsOf);
|
2017-02-24 11:51:22 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", consistsOf, e);
|
|
|
|
throw e;
|
2016-09-15 14:57:14 +02:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", consistsOf, 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
|
|
|
}
|
2017-10-03 15:49:47 +02:00
|
|
|
|
|
|
|
public String createConsistsOf(String consistsOfType, String consistsOf)
|
|
|
|
throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException {
|
2017-10-02 18:28:47 +02:00
|
|
|
try {
|
|
|
|
logger.info("Going to create: {}", consistsOf);
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(ERPath.CONSISTS_OF_PATH_PART);
|
|
|
|
/*
|
2017-10-03 15:49:47 +02:00
|
|
|
* stringWriter.append(PATH_SEPARATOR);
|
|
|
|
* stringWriter.append(ERPath.SOURCE_PATH_PART);
|
|
|
|
* stringWriter.append(PATH_SEPARATOR);
|
|
|
|
* stringWriter.append(consistsOf.getSource().getHeader().getUUID()
|
|
|
|
* .toString()); stringWriter.append(PATH_SEPARATOR);
|
|
|
|
* stringWriter.append(ERPath.TARGET_PATH_PART);
|
|
|
|
* stringWriter.append(PATH_SEPARATOR);
|
|
|
|
* stringWriter.append(consistsOf.getTarget().getHeader().getUUID()
|
|
|
|
* .toString());
|
|
|
|
*/
|
2017-10-02 18:28:47 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(consistsOfType);
|
|
|
|
|
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
String c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, consistsOf);
|
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
logger.info("{} successfully created", c);
|
|
|
|
return c;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", consistsOf, e);
|
|
|
|
throw e;
|
2017-10-02 18:28:47 +02:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", consistsOf, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
|
|
|
|
@Override
|
2017-10-03 15:49:47 +02:00
|
|
|
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(C consistsOf)
|
|
|
|
throws ResourceRegistryException {
|
2017-02-24 12:46:18 +01:00
|
|
|
return deleteConsistsOf(consistsOf.getHeader().getUUID());
|
|
|
|
}
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-02-24 12:46:18 +01:00
|
|
|
@Override
|
|
|
|
public boolean deleteConsistsOf(UUID uuid) throws ResourceRegistryException {
|
2017-10-03 15:49:47 +02:00
|
|
|
try {
|
|
|
|
|
2017-02-24 12:46:18 +01:00
|
|
|
logger.info("Going to delete {} with UUID {}", ConsistsOf.NAME, uuid);
|
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);
|
2017-02-24 12:46:18 +01:00
|
|
|
stringWriter.append(uuid.toString());
|
2016-09-15 14:57:14 +02:00
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
boolean deleted = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.DELETE);
|
|
|
|
|
|
|
|
logger.info("{} with UUID {} {}", ConsistsOf.NAME, uuid,
|
|
|
|
deleted ? " successfully deleted" : "was NOT deleted");
|
2016-10-28 12:06:54 +02:00
|
|
|
return deleted;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-02-24 11:51:22 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Removing {} with UUID {}", ConsistsOf.NAME,
|
|
|
|
// uuid, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2016-09-15 14:57:14 +02:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Removing {} with UUID {}", ConsistsOf.NAME,
|
|
|
|
// uuid, 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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-09-16 18:38:12 +02:00
|
|
|
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo(
|
2017-02-24 12:46:18 +01:00
|
|
|
Class<I> isRelatedToClass, I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException {
|
2016-09-15 14:57:14 +02:00
|
|
|
|
|
|
|
try {
|
2017-10-03 15:49:47 +02:00
|
|
|
String isRelatedToString = ISMapper.marshal(isRelatedTo);
|
|
|
|
String isRelatedToType = isRelatedToClass.getSimpleName();
|
|
|
|
String res = createConsistsOf(isRelatedToType, isRelatedToString);
|
|
|
|
return ISMapper.unmarshal(isRelatedToClass, res);
|
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
// logger.trace("Error Creating {}", isRelatedTo, e);
|
|
|
|
throw e;
|
|
|
|
} catch (Exception e) {
|
|
|
|
// logger.trace("Error Creating {}", isRelatedTo, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String createIsRelatedTo(String isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException {
|
|
|
|
try {
|
2017-10-03 15:56:42 +02:00
|
|
|
String isRelatedToType = Utility.getClassFromJsonString(isRelatedTo);
|
2017-10-03 15:49:47 +02:00
|
|
|
return createConsistsOf(isRelatedToType, isRelatedTo);
|
2017-02-24 11:51:22 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", isRelatedTo, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2016-09-15 14:57:14 +02:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", isRelatedTo, 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
|
|
|
}
|
2017-10-02 18:28:47 +02:00
|
|
|
|
2017-10-03 15:49:47 +02:00
|
|
|
public String createIsRelatedTo(String isRelatedToType, String isRelatedTo)
|
|
|
|
throws ResourceNotFoundException, ResourceRegistryException {
|
2017-10-02 18:28:47 +02:00
|
|
|
try {
|
|
|
|
logger.info("Going to create: {}", isRelatedTo);
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(ERPath.ER_PATH_PART);
|
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(ERPath.IS_RELATED_TO_PATH_PART);
|
|
|
|
/*
|
2017-10-03 15:49:47 +02:00
|
|
|
* stringWriter.append(PATH_SEPARATOR);
|
|
|
|
* stringWriter.append(ERPath.SOURCE_PATH_PART);
|
|
|
|
* stringWriter.append(PATH_SEPARATOR);
|
|
|
|
* stringWriter.append(isRelatedTo.getSource().getHeader().getUUID()
|
|
|
|
* .toString()); stringWriter.append(PATH_SEPARATOR);
|
|
|
|
* stringWriter.append(ERPath.TARGET_PATH_PART);
|
|
|
|
* stringWriter.append(PATH_SEPARATOR);
|
|
|
|
* stringWriter.append(isRelatedTo.getTarget().getHeader().getUUID()
|
|
|
|
* .toString());
|
|
|
|
*/
|
2017-10-02 18:28:47 +02:00
|
|
|
stringWriter.append(PATH_SEPARATOR);
|
|
|
|
stringWriter.append(isRelatedToType);
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
String i = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, isRelatedTo);
|
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
logger.info("{} successfully created", i);
|
|
|
|
return i;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-10-02 18:28:47 +02:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", isRelatedTo, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw e;
|
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Creating {}", isRelatedTo, e);
|
2017-10-02 18:28:47 +02:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2016-09-14 14:49:50 +02:00
|
|
|
|
|
|
|
@Override
|
2017-10-03 15:49:47 +02:00
|
|
|
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(I isRelatedTo)
|
|
|
|
throws ResourceRegistryException {
|
2017-02-24 12:46:18 +01:00
|
|
|
return deleteIsRelatedTo(isRelatedTo.getHeader().getUUID());
|
|
|
|
}
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-02-24 12:46:18 +01:00
|
|
|
@Override
|
|
|
|
public boolean deleteIsRelatedTo(UUID uuid) throws ResourceRegistryException {
|
2016-09-15 14:57:14 +02:00
|
|
|
try {
|
2017-02-24 12:46:18 +01:00
|
|
|
logger.info("Going to delete {} with UUID {}", IsRelatedTo.NAME, uuid);
|
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);
|
2017-02-24 12:46:18 +01:00
|
|
|
stringWriter.append(uuid.toString());
|
2016-09-15 14:57:14 +02:00
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
boolean deleted = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.DELETE);
|
|
|
|
|
|
|
|
logger.info("{} with UUID {} {}", IsRelatedTo.NAME, uuid,
|
|
|
|
deleted ? " successfully deleted" : "was NOT deleted");
|
2016-10-28 12:06:54 +02:00
|
|
|
return deleted;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-02-24 11:51:22 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Removing {} with UUID {}", IsRelatedTo.NAME,
|
|
|
|
// uuid, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2016-09-15 14:57:14 +02:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Removing {} with UUID {}", IsRelatedTo.NAME,
|
|
|
|
// uuid, 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
|
|
|
}
|
|
|
|
|
2016-11-14 12:33:14 +01:00
|
|
|
@Override
|
|
|
|
public boolean addResourceToContext(UUID uuid)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2016-11-14 12:33:14 +01:00
|
|
|
String context = getCurrentContext();
|
|
|
|
try {
|
2017-10-03 15:49:47 +02:00
|
|
|
logger.info("Going to add {} with UUID {} to current {} : {}", 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());
|
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
boolean added = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.POST);
|
|
|
|
|
|
|
|
logger.info("{} with UUID {} was {} added to current {} : {}", Resource.NAME, uuid,
|
|
|
|
added ? "successfully" : "NOT", Context.NAME, context);
|
2016-11-14 12:33:14 +01:00
|
|
|
return added;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-02-24 11:51:22 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Adding {} with UUID {} to current {} : {}",
|
|
|
|
// Resource.NAME, uuid, Context.NAME, context, e);
|
|
|
|
throw e;
|
2016-11-14 12:33:14 +01:00
|
|
|
} catch (Exception e) {
|
2017-10-03 15:49:47 +02:00
|
|
|
// logger.trace("Error Adding {} with UUID {} to current {} : {}",
|
|
|
|
// Resource.NAME, uuid, Context.NAME, context, e);
|
2017-04-05 17:18:53 +02:00
|
|
|
throw new RuntimeException(e);
|
2016-11-14 12:33:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <R extends Resource> boolean addResourceToContext(R resource)
|
2017-10-03 15:49:47 +02:00
|
|
|
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
|
2017-10-03 15:49:47 +02:00
|
|
|
public boolean addFacetToContext(UUID uuid)
|
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2016-11-14 12:33:14 +01:00
|
|
|
String context = getCurrentContext();
|
|
|
|
try {
|
2017-10-03 15:49:47 +02:00
|
|
|
logger.info("Going to add {} with UUID {} to current {} : {}", 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());
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
boolean added = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.POST);
|
|
|
|
|
|
|
|
logger.info("{} with UUID {} was {} added to current {} : {}", Facet.NAME, uuid,
|
|
|
|
added ? "successfully" : "NOT", Context.NAME, context);
|
2016-11-14 12:33:14 +01:00
|
|
|
return added;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-02-24 11:51:22 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-04-18 10:54:18 +02:00
|
|
|
// logger.trace("Error Adding {} with UUID {} to current {} : {}",
|
2017-10-03 15:49:47 +02:00
|
|
|
// Facet.NAME, uuid, Context.NAME, context, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2016-11-14 12:33:14 +01:00
|
|
|
} catch (Exception e) {
|
2017-04-18 10:54:18 +02:00
|
|
|
// logger.trace("Error Adding {} with UUID {} to current {} : {}",
|
2017-10-03 15:49:47 +02:00
|
|
|
// Facet.NAME, uuid, Context.NAME, context, e);
|
2017-04-05 17:18:53 +02:00
|
|
|
throw new RuntimeException(e);
|
2016-11-14 12:33:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <F extends Facet> boolean addFacetToContext(F facet)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2016-11-14 12:33:14 +01:00
|
|
|
return addFacetToContext(facet.getHeader().getUUID());
|
|
|
|
}
|
|
|
|
|
2016-12-21 16:29:37 +01:00
|
|
|
@Override
|
|
|
|
public boolean removeResourceFromContext(UUID uuid)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2016-12-21 16:29:37 +01:00
|
|
|
String context = getCurrentContext();
|
|
|
|
try {
|
2017-10-03 15:49:47 +02:00
|
|
|
logger.info("Going to add {} with UUID {} to current {} : {}", Resource.NAME, uuid, Context.NAME, context);
|
2016-12-21 16:29:37 +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-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());
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
boolean removed = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.POST);
|
|
|
|
|
|
|
|
logger.info("{} with UUID {} was {} removed from current {} : {}", Resource.NAME, uuid,
|
|
|
|
removed ? "successfully" : "NOT", Context.NAME, context);
|
2016-12-21 16:29:37 +01:00
|
|
|
return removed;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-02-24 11:51:22 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-04-18 10:54:18 +02:00
|
|
|
// logger.trace("Error Adding {} with UUID {} to current {} : {}",
|
2017-10-03 15:49:47 +02:00
|
|
|
// Resource.NAME, uuid, Context.NAME, context, e);
|
|
|
|
throw e;
|
|
|
|
|
2016-12-21 16:29:37 +01:00
|
|
|
} catch (Exception e) {
|
2017-04-18 10:54:18 +02:00
|
|
|
// logger.trace("Error Adding {} with UUID {} to current {} : {}",
|
2017-10-03 15:49:47 +02:00
|
|
|
// Resource.NAME, uuid, Context.NAME, context, e);
|
2017-04-05 17:18:53 +02:00
|
|
|
throw new RuntimeException(e);
|
2016-12-21 16:29:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <R extends Resource> boolean removeResourceFromContext(R resource)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2016-12-21 16:29:37 +01:00
|
|
|
return removeResourceFromContext(resource.getHeader().getUUID());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean removeFacetFromContext(UUID uuid)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2016-12-21 16:29:37 +01:00
|
|
|
String context = getCurrentContext();
|
|
|
|
try {
|
2017-10-03 15:49:47 +02:00
|
|
|
logger.info("Going to add {} with UUID {} to current {} : {}", Facet.NAME, uuid, Context.NAME, context);
|
2016-12-21 16:29:37 +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-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());
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-04-03 18:44:47 +02:00
|
|
|
HTTPCall httpCall = getHTTPCall();
|
2017-10-03 15:49:47 +02:00
|
|
|
boolean removed = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.POST);
|
|
|
|
|
|
|
|
logger.info("{} with UUID {} was {} removed from current {} : {}", Facet.NAME, uuid,
|
|
|
|
removed ? "successfully" : "NOT", Context.NAME, context);
|
2016-12-21 16:29:37 +01:00
|
|
|
return removed;
|
2017-10-03 15:49:47 +02:00
|
|
|
|
2017-02-24 11:51:22 +01:00
|
|
|
} catch (ResourceRegistryException e) {
|
2017-04-18 10:54:18 +02:00
|
|
|
// logger.trace("Error Adding {} with UUID {} to current {} : {}",
|
2017-10-03 15:49:47 +02:00
|
|
|
// Facet.NAME, uuid, Context.NAME, context, e);
|
2017-02-24 11:51:22 +01:00
|
|
|
throw e;
|
2016-12-21 16:29:37 +01:00
|
|
|
} catch (Exception e) {
|
2017-04-18 10:54:18 +02:00
|
|
|
// logger.trace("Error Adding {} with UUID {} to current {} : {}",
|
2017-10-03 15:49:47 +02:00
|
|
|
// Facet.NAME, uuid, Context.NAME, context, e);
|
2017-04-05 17:18:53 +02:00
|
|
|
throw new RuntimeException(e);
|
2016-12-21 16:29:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <F extends Facet> boolean removeFacetFromContext(F facet)
|
2017-10-03 15:49:47 +02:00
|
|
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
2016-12-21 16:29:37 +01:00
|
|
|
return removeFacetFromContext(facet.getHeader().getUUID());
|
|
|
|
}
|
|
|
|
|
2016-09-14 14:49:50 +02:00
|
|
|
}
|