refs #5753: Expose Remove From Context API
https://support.d4science.org/issues/5753 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@141324 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
2bab42cc87
commit
5699ce9dab
|
@ -56,4 +56,19 @@ public interface ResourceRegistryPublisher {
|
|||
throws FacetNotFoundException, ContextNotFoundException,
|
||||
ResourceRegistryException;
|
||||
|
||||
|
||||
public boolean removeResourceFromContext(UUID uuid)
|
||||
throws ResourceNotFoundException, ContextNotFoundException,
|
||||
ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> boolean removeResourceFromContext(R resource)
|
||||
throws ResourceNotFoundException, ContextNotFoundException,
|
||||
ResourceRegistryException;
|
||||
|
||||
public boolean removeFacetFromContext(UUID uuid) throws FacetNotFoundException,
|
||||
ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <F extends Facet> boolean removeFacetFromContext(F facet)
|
||||
throws FacetNotFoundException, ContextNotFoundException,
|
||||
ResourceRegistryException;
|
||||
}
|
||||
|
|
|
@ -139,7 +139,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
public HTTPInputs(String path, HTTPMETHOD method,
|
||||
List<Map.Entry<String, String>> parameters)
|
||||
throws UnsupportedEncodingException {
|
||||
|
@ -183,7 +182,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
return this.urlParameters;
|
||||
}
|
||||
|
||||
public String getBody(){
|
||||
public String getBody() {
|
||||
return this.body;
|
||||
}
|
||||
|
||||
|
@ -209,7 +208,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
protected HttpURLConnection getConnection(URL url, HTTPMETHOD method)
|
||||
throws Exception {
|
||||
|
||||
if(httpInputs.getUrlParameters()!=null){
|
||||
if (httpInputs.getUrlParameters() != null) {
|
||||
url = new URL(url + "?" + httpInputs.getUrlParameters());
|
||||
}
|
||||
|
||||
|
@ -235,8 +234,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
connection.setRequestMethod(method.toString());
|
||||
|
||||
String body = httpInputs.getBody();
|
||||
if (body!=null && (method == HTTPMETHOD.POST || method == HTTPMETHOD.PUT)) {
|
||||
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
|
||||
if (body != null
|
||||
&& (method == HTTPMETHOD.POST || method == HTTPMETHOD.PUT)) {
|
||||
DataOutputStream wr = new DataOutputStream(
|
||||
connection.getOutputStream());
|
||||
wr.writeBytes(body);
|
||||
wr.flush();
|
||||
wr.close();
|
||||
|
@ -322,7 +323,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(facet.getHeader().getUUID().toString());
|
||||
|
||||
|
||||
String body = Entities.marshal(facet);
|
||||
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
||||
HTTPMETHOD.POST, null, body);
|
||||
|
@ -398,7 +398,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
}
|
||||
|
||||
@Override
|
||||
public <R extends Resource> R updateResource(Class<R> resourceClass, R resource) {
|
||||
public <R extends Resource> R updateResource(Class<R> resourceClass,
|
||||
R resource) {
|
||||
try {
|
||||
logger.info("Going to update: {}", resource);
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
|
@ -612,14 +613,16 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(uuid.toString());
|
||||
|
||||
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(), HTTPMETHOD.POST, null);
|
||||
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
||||
HTTPMETHOD.POST, null);
|
||||
|
||||
ResourceRegistryCall<Boolean> call = new ResourceRegistryCall<>(Boolean.class, httpInputs);
|
||||
ResourceRegistryCall<Boolean> call = new ResourceRegistryCall<>(
|
||||
Boolean.class, httpInputs);
|
||||
|
||||
boolean added = delegate.make(call);
|
||||
logger.info("{} with UUID {} was {} added to current {} : {}",
|
||||
Resource.NAME, uuid, added ? "successfully": "NOT",
|
||||
Context.NAME, context);
|
||||
Resource.NAME, uuid, added ? "successfully" : "NOT",
|
||||
Context.NAME, context);
|
||||
return added;
|
||||
} catch (Exception e) {
|
||||
logger.error("Error Adding {} with UUID {} to current {} : {}",
|
||||
|
@ -632,7 +635,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
public <R extends Resource> boolean addResourceToContext(R resource)
|
||||
throws ResourceNotFoundException, ContextNotFoundException,
|
||||
ResourceRegistryException {
|
||||
return addFacetToContext(resource.getHeader().getUUID());
|
||||
return addResourceToContext(resource.getHeader().getUUID());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -653,14 +656,16 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(uuid.toString());
|
||||
|
||||
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(), HTTPMETHOD.POST, null);
|
||||
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
||||
HTTPMETHOD.POST, null);
|
||||
|
||||
ResourceRegistryCall<Boolean> call = new ResourceRegistryCall<>(Boolean.class, httpInputs);
|
||||
ResourceRegistryCall<Boolean> call = new ResourceRegistryCall<>(
|
||||
Boolean.class, httpInputs);
|
||||
|
||||
boolean added = delegate.make(call);
|
||||
logger.info("{} with UUID {} was {} added to current {} : {}",
|
||||
Facet.NAME, uuid, added ? "successfully": "NOT",
|
||||
Context.NAME, context);
|
||||
Facet.NAME, uuid, added ? "successfully" : "NOT",
|
||||
Context.NAME, context);
|
||||
return added;
|
||||
} catch (Exception e) {
|
||||
logger.error("Error Adding {} with UUID {} to current {} : {}",
|
||||
|
@ -676,4 +681,93 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
return addFacetToContext(facet.getHeader().getUUID());
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
@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);
|
||||
stringWriter.append(EntityPath.ENTITY_PATH_PART);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(EntityPath.REMOVE_PATH_PART);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(EntityPath.RESOURCE_PATH_PART);
|
||||
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);
|
||||
stringWriter.append(EntityPath.ENTITY_PATH_PART);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(EntityPath.REMOVE_PATH_PART);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(EntityPath.FACET_PATH_PART);
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue