Added getInstanceContexts() APIs

This commit is contained in:
Luca Frosini 2020-11-11 14:18:43 +01:00
parent a2f7d15768
commit e1c0bf70f1
2 changed files with 202 additions and 118 deletions

View File

@ -1,6 +1,7 @@
package org.gcube.informationsystem.resourceregistry.publisher;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
@ -36,26 +37,26 @@ public interface ResourceRegistryPublisher {
public <IE extends IdentifiableElement> boolean exists(IE identifiableElement)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
public boolean exists(String identifiableElementTypeName, UUID uuid)
public boolean exists(String type, UUID uuid)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
public <IE extends IdentifiableElement> IE read(IE identifiableElement) throws NotFoundException, ResourceRegistryException;
public String read(String identifiableElementTypeName, UUID uuid) throws NotFoundException, ResourceRegistryException;
public String read(String type, UUID uuid) throws NotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> IE update(IE identifiableElement)
throws NotFoundException, ResourceRegistryException;
public String update(String identifiableElementTypeName, String json) throws NotFoundException, ResourceRegistryException;
public String update(String type, String json) throws NotFoundException, ResourceRegistryException;
public String update(String json) throws NotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> boolean delete(IE identifiableElement) throws NotFoundException, ResourceRegistryException;
public boolean delete(String identifiableElementTypeName, UUID uuid) throws NotFoundException, ResourceRegistryException;
public boolean delete(String type, UUID uuid) throws NotFoundException, ResourceRegistryException;
/* ----- */
@ -69,7 +70,7 @@ public interface ResourceRegistryPublisher {
public <F extends Facet> F readFacet(F facet) throws FacetNotFoundException, ResourceRegistryException;
public String readFacet(String facetTypeName, UUID uuid) throws FacetNotFoundException, ResourceRegistryException;
public String readFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException;
public <F extends Facet> F updateFacet(F facet)
@ -80,7 +81,7 @@ public interface ResourceRegistryPublisher {
public <F extends Facet> boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException;
public boolean deleteFacet(String facetTypeName, UUID uuid) throws FacetNotFoundException, ResourceRegistryException;
public boolean deleteFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException;
/* ----- */
@ -95,7 +96,7 @@ public interface ResourceRegistryPublisher {
public <R extends Resource> R readResource(R resource)
throws ResourceNotFoundException, ResourceRegistryException;
public String readResource(String resourceTypeName, UUID uuid) throws ResourceNotFoundException, ResourceRegistryException;
public String readResource(String resourceType, UUID uuid) throws ResourceNotFoundException, ResourceRegistryException;
public <R extends Resource> R updateResource(R resource)
@ -108,7 +109,7 @@ public interface ResourceRegistryPublisher {
public <R extends Resource> boolean deleteResource(R resource)
throws ResourceNotFoundException, ResourceRegistryException;
public boolean deleteResource(String resourceTypeName, UUID uuid) throws ResourceNotFoundException, ResourceRegistryException;
public boolean deleteResource(String resourceType, UUID uuid) throws ResourceNotFoundException, ResourceRegistryException;
/* ----- */
@ -124,7 +125,7 @@ public interface ResourceRegistryPublisher {
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C readConsistsOf(
C consistsOf) throws NotFoundException, ResourceRegistryException;
public String readConsistsOf(String consistsOfTypeName, UUID uuid) throws NotFoundException, ResourceRegistryException;
public String readConsistsOf(String consistsOfType, UUID uuid) throws NotFoundException, ResourceRegistryException;
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C updateConsistsOf(C consistsOf)
@ -137,7 +138,7 @@ public interface ResourceRegistryPublisher {
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(C consistsOf)
throws ResourceRegistryException;
public boolean deleteConsistsOf(String consistsOfTypeName, UUID uuid) throws ResourceRegistryException;
public boolean deleteConsistsOf(String consistsOfType, UUID uuid) throws ResourceRegistryException;
/* ----- */
@ -153,7 +154,7 @@ public interface ResourceRegistryPublisher {
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I readIsRelatedTo(
I isRelatedTo) throws NotFoundException, ResourceRegistryException;
public String readIsRelatedTo(String isRelatedToTypeName, UUID uuid) throws NotFoundException, ResourceRegistryException;
public String readIsRelatedTo(String isRelatedToType, UUID uuid) throws NotFoundException, ResourceRegistryException;
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I updateIsRelatedTo(I isRelatedTo)
@ -166,44 +167,50 @@ public interface ResourceRegistryPublisher {
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(I isRelatedTo)
throws ResourceRegistryException;
public boolean deleteIsRelatedTo(String isRelatedToTypeName, UUID uuid) throws ResourceRegistryException;
public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid) throws ResourceRegistryException;
/* ----- */
public boolean addToContext(UUID contextUUID, String identifiableElementTypeName, UUID instanceUUID)
public boolean addToContext(String type, UUID instanceUUID, UUID contextUUID)
throws NotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> boolean addToContext(UUID contextUUID, IE identifiableElement)
public <IE extends IdentifiableElement> boolean addToContext(IE identifiableElement, UUID contextUUID)
throws NotFoundException, ResourceRegistryException;
public boolean addToCurrentContext(String identifiableElementTypeName, UUID instanceUUID)
public boolean addToCurrentContext(String type, UUID instanceUUID)
throws NotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> boolean addToCurrentContext(IE identifiableElement)
throws NotFoundException, ResourceRegistryException;
public boolean removeFromContext(UUID contextUUID, String identifiableElementTypeName, UUID instanceUUID)
public boolean removeFromContext(String type, UUID instanceUUID, UUID contextUUID)
throws NotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> boolean removeFromContext(UUID contextUUID, IE identifiableElement)
public <IE extends IdentifiableElement> boolean removeFromContext(IE identifiableElement, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public boolean removeFromCurrentContext(String identifiableElementTypeName, UUID instanceUUID)
public boolean removeFromCurrentContext(String type, UUID instanceUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> boolean removeFromCurrentContext(IE identifiableElement)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public Set<UUID> getElementContexts(String type, UUID instanceUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> Set<UUID> getElementContexts(IE identifiableElement)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
/* ----- */
public boolean addResourceToContext(UUID contextUUID, String resourceTypeName, UUID resourceUUID)
public boolean addResourceToContext(String resourceType, UUID resourceUUID, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <R extends Resource> boolean addResourceToContext(UUID contextUUID, R resource)
public <R extends Resource> boolean addResourceToContext(R resource, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID)
@ -212,10 +219,10 @@ public interface ResourceRegistryPublisher {
public <R extends Resource> boolean addResourceToCurrentContext(R resource)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public boolean removeResourceFromContext(UUID contextUUID, String resourceTypeName, UUID resourceUUID)
public boolean removeResourceFromContext(String resourceType, UUID resourceUUID, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <R extends Resource> boolean removeResourceFromContext(UUID contextUUID, R resource)
public <R extends Resource> boolean removeResourceFromContext(R resource, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public boolean removeResourceFromCurrentContext(String resourceType, UUID resourceUUID)
@ -224,35 +231,48 @@ public interface ResourceRegistryPublisher {
public <R extends Resource> boolean removeResourceFromCurrentContext(R resource)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public Set<UUID> getResourceContexts(String resourceType, UUID resourceUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <R extends Resource> Set<UUID> getResourceContexts(R resource)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
/* ----- */
public boolean addFacetToContext(UUID contextUUID, String facetTypeName, UUID facetUUID)
public boolean addFacetToContext(String facetType, UUID facetUUID, UUID contextUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <F extends Facet> boolean addFacetToContext(UUID contextUUID, F facet)
public <F extends Facet> boolean addFacetToContext(F facet, UUID contextUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public boolean addFacetToCurrentContext(String facetTypeName, UUID facetUUID)
public boolean addFacetToCurrentContext(String facetType, UUID facetUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <F extends Facet> boolean addFacetToCurrentContext(F facet)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public boolean removeFacetFromContext(UUID contextUUID, String facetTypeName, UUID facetUUID)
public boolean removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <F extends Facet> boolean removeFacetFromContext(UUID contextUUID, F facet)
public <F extends Facet> boolean removeFacetFromContext(F facet, UUID contextUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public boolean removeFacetFromCurrentContext(String facetTypeName, UUID facetUUID)
public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <F extends Facet> boolean removeFacetFromCurrentContext(F facet)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
/* ---- */
public Set<UUID> getFacetContexts(String facetType, UUID facetUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <F extends Facet> Set<UUID> getFacetContexts(F facet)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
/* ----- */
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException;

View File

@ -5,6 +5,7 @@ import java.net.HttpURLConnection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.gcube.common.gxhttp.reference.GXConnection;
@ -20,6 +21,7 @@ import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
@ -196,16 +198,16 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
return getCurrentContext().getHeader().getUUID();
}
protected String create(String identifiableElementTypeName, String json, UUID uuid)
protected String create(String type, String json, UUID uuid)
throws AlreadyPresentException, ResourceRegistryException {
try {
logger.trace("Going to create {} : {}", identifiableElementTypeName, json);
logger.trace("Going to create {} : {}", type, json);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.header("Content-type", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(identifiableElementTypeName);
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString());
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json);
@ -225,7 +227,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public <IE extends IdentifiableElement> String internalCreate(IE identifiableElement) throws AlreadyPresentException, ResourceRegistryException {
try {
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
String json = ElementMapper.marshal(identifiableElement);
Header header = identifiableElement.getHeader();
if(header==null) {
@ -233,7 +235,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
identifiableElement.setHeader(header);
}
UUID uuid = identifiableElement.getHeader().getUUID();
return create(identifiableElementTypeName, json, uuid);
return create(type, json, uuid);
} catch(ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
throw e;
@ -260,9 +262,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public String create(String identifiableElement) throws AlreadyPresentException, ResourceRegistryException {
public String create(String json) throws AlreadyPresentException, ResourceRegistryException {
try {
IdentifiableElement e = ElementMapper.unmarshal(IdentifiableElement.class, identifiableElement);
IdentifiableElement e = ElementMapper.unmarshal(IdentifiableElement.class, json);
return internalCreate(e);
} catch(ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
@ -323,9 +325,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <IE extends IdentifiableElement> IE read(IE identifiableElement) throws NotFoundException, ResourceRegistryException {
try {
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
UUID uuid = identifiableElement.getHeader().getUUID();
String ret = read(identifiableElementTypeName, uuid);
String ret = read(type, uuid);
return (IE) ElementMapper.unmarshal(IdentifiableElement.class, ret);
} catch(ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
@ -337,14 +339,14 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public String read(String identifiableElementTypeName, UUID uuid) throws NotFoundException, ResourceRegistryException {
public String read(String type, UUID uuid) throws NotFoundException, ResourceRegistryException {
try {
logger.trace("Going to read {} with UUID {}", identifiableElementTypeName, uuid);
logger.trace("Going to read {} with UUID {}", type, uuid);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(identifiableElementTypeName);
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString());
includeAdditionalQueryParameters(gxHTTPStringRequest);
@ -352,7 +354,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
logger.debug("Got {} with UUID {} is {}", identifiableElementTypeName, uuid, ret);
logger.debug("Got {} with UUID {} is {}", type, uuid, ret);
return ret;
} catch(ResourceRegistryException e) {
@ -364,22 +366,22 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
}
protected String update(String identifiableElementTypeName, String json, UUID uuid)
protected String update(String type, String json, UUID uuid)
throws AlreadyPresentException, ResourceRegistryException {
try {
logger.trace("Going to create {} : {}", identifiableElementTypeName, json);
logger.trace("Going to create {} : {}", type, json);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.header("Content-type", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(identifiableElementTypeName);
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString());
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json);
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
logger.trace("{} with UUID {} successfully created : {}", identifiableElementTypeName, uuid, ret);
logger.trace("{} with UUID {} successfully created : {}", type, uuid, ret);
return ret;
} catch(ResourceRegistryException e) {
@ -395,10 +397,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <IE extends IdentifiableElement> IE update(IE identifiableElement) throws NotFoundException, ResourceRegistryException {
try {
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
String type = 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);
String ret = update(type, json, uuid);
return (IE) ElementMapper.unmarshal(Element.class, ret);
} catch(ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
@ -410,10 +412,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public String update(String identifiableElementTypeName, String json) throws NotFoundException, ResourceRegistryException {
public String update(String type, String json) throws NotFoundException, ResourceRegistryException {
try {
UUID uuid = Utility.getUUIDFromJSONString(json);
return update(identifiableElementTypeName, json, uuid);
return update(type, json, uuid);
} catch(ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
throw e;
@ -426,8 +428,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public String update(String json) throws NotFoundException, ResourceRegistryException {
try {
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(json);
return update(identifiableElementTypeName, json);
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(json);
return update(type, json);
} catch(ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
throw e;
@ -440,9 +442,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <IE extends IdentifiableElement> boolean delete(IE identifiableElement) throws NotFoundException, ResourceRegistryException {
try {
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
UUID uuid = identifiableElement.getHeader().getUUID();
return delete(identifiableElementTypeName, uuid);
return delete(type, uuid);
} catch(ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
throw e;
@ -453,14 +455,14 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public boolean delete(String identifiableElementTypeName, UUID uuid) throws NotFoundException, ResourceRegistryException {
public boolean delete(String type, UUID uuid) throws NotFoundException, ResourceRegistryException {
try {
logger.trace("Going to delete {} with UUID {}", identifiableElementTypeName, uuid);
logger.trace("Going to delete {} with UUID {}", type, uuid);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(identifiableElementTypeName);
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString());
HttpURLConnection httpURLConnection = gxHTTPStringRequest.delete();
@ -468,7 +470,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
boolean deleted = true;
logger.info("{} with UUID {} {}", identifiableElementTypeName, uuid, deleted ? " successfully deleted" : "was NOT deleted");
logger.info("{} with UUID {} {}", type, uuid, deleted ? " successfully deleted" : "was NOT deleted");
return deleted;
} catch(ResourceRegistryException e) {
@ -496,8 +498,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public String readFacet(String facetTypeName, UUID uuid) throws FacetNotFoundException, ResourceRegistryException {
return read(facetTypeName, uuid);
public String readFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException {
return read(facetType, uuid);
}
@Override
@ -516,8 +518,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public boolean deleteFacet(String facetTypeName, UUID uuid) throws FacetNotFoundException, ResourceRegistryException {
return delete(facetTypeName, uuid);
public boolean deleteFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException {
return delete(facetType, uuid);
}
@Override
@ -537,9 +539,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public String readResource(String resourceTypeName, UUID uuid)
public String readResource(String resourceType, UUID uuid)
throws ResourceNotFoundException, ResourceRegistryException {
return read(resourceTypeName, uuid);
return read(resourceType, uuid);
}
@Override
@ -560,9 +562,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public boolean deleteResource(String resourceTypeName, UUID uuid)
public boolean deleteResource(String resourceType, UUID uuid)
throws ResourceNotFoundException, ResourceRegistryException {
return delete(resourceTypeName, uuid);
return delete(resourceType, uuid);
}
@Override
@ -583,8 +585,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public String readConsistsOf(String consistsOfTypeName, UUID uuid) throws NotFoundException, ResourceRegistryException {
return read(consistsOfTypeName, uuid);
public String readConsistsOf(String consistsOfType, UUID uuid) throws NotFoundException, ResourceRegistryException {
return read(consistsOfType, uuid);
}
@Override
@ -605,8 +607,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public boolean deleteConsistsOf(String consistsOfTypeName, UUID uuid) throws ResourceRegistryException {
return delete(consistsOfTypeName, uuid);
public boolean deleteConsistsOf(String consistsOfType, UUID uuid) throws ResourceRegistryException {
return delete(consistsOfType, uuid);
}
@Override
@ -627,9 +629,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public String readIsRelatedTo(String isRelatedToTypeName, UUID uuid)
public String readIsRelatedTo(String isRelatedToType, UUID uuid)
throws NotFoundException, ResourceRegistryException {
return read(isRelatedToTypeName, uuid);
return read(isRelatedToType, uuid);
}
@Override
@ -650,20 +652,20 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public boolean deleteIsRelatedTo(String isRelatedToTypeName, UUID uuid) throws ResourceRegistryException {
return delete(isRelatedToTypeName, uuid);
public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid) throws ResourceRegistryException {
return delete(isRelatedToType, uuid);
}
@Override
public boolean addToContext(UUID contextUUID, String identifiableElementTypeName, UUID instanceUUID)
public boolean addToContext(String type, UUID instanceUUID, UUID contextUUID)
throws NotFoundException, ResourceRegistryException {
try {
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", identifiableElementTypeName, instanceUUID, Context.NAME,
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME,
contextUUID);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.path(SharingPath.SHARING_PATH_PART);
gxHTTPStringRequest.path(identifiableElementTypeName);
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(instanceUUID.toString());
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
gxHTTPStringRequest.path(contextUUID.toString());
@ -671,7 +673,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put();
boolean added = HTTPUtility.getResponse(Boolean.class, httpURLConnection);
logger.info("{} with UUID {} {} to {} with UUID {}", identifiableElementTypeName, instanceUUID,
logger.info("{} with UUID {} {} to {} with UUID {}", type, instanceUUID,
added ? " successfully added" : "was NOT added", Context.NAME, contextUUID);
return added;
@ -685,12 +687,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public <IE extends IdentifiableElement> boolean addToContext(UUID contextUUID, IE identifiableElement)
public <IE extends IdentifiableElement> boolean addToContext(IE identifiableElement, UUID contextUUID)
throws NotFoundException, ResourceRegistryException {
try {
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
UUID instanceUUID = identifiableElement.getHeader().getUUID();
return addToContext(contextUUID, identifiableElementTypeName, instanceUUID);
return addToContext(type, instanceUUID, contextUUID);
} catch(ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
throw e;
@ -701,28 +703,28 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public boolean addToCurrentContext(String identifiableElementTypeName, UUID instanceUUID)
public boolean addToCurrentContext(String type, UUID instanceUUID)
throws NotFoundException, ResourceRegistryException {
UUID contextUUID = getCurrentContextUUID();
return addToContext(contextUUID, identifiableElementTypeName, instanceUUID);
return addToContext(type, instanceUUID, contextUUID);
}
@Override
public <IE extends IdentifiableElement> boolean addToCurrentContext(IE identifiableElement) throws NotFoundException, ResourceRegistryException {
UUID contextUUID = getCurrentContextUUID();
return addToContext(contextUUID, identifiableElement);
return addToContext(identifiableElement, contextUUID);
}
@Override
public boolean removeFromContext(UUID contextUUID, String identifiableElementTypeName, UUID instanceUUID)
public boolean removeFromContext(String type, UUID instanceUUID, UUID contextUUID)
throws NotFoundException, ResourceRegistryException {
try {
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", identifiableElementTypeName, instanceUUID, Context.NAME,
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME,
contextUUID);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.path(SharingPath.SHARING_PATH_PART);
gxHTTPStringRequest.path(identifiableElementTypeName);
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(instanceUUID.toString());
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
gxHTTPStringRequest.path(contextUUID.toString());
@ -730,7 +732,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
HttpURLConnection httpURLConnection = gxHTTPStringRequest.delete();
boolean removed = HTTPUtility.getResponse(Boolean.class, httpURLConnection);
logger.info("{} with UUID {} {} to {} with UUID {}", identifiableElementTypeName, instanceUUID,
logger.info("{} with UUID {} {} to {} with UUID {}", type, instanceUUID,
removed ? " successfully removed" : "was NOT removed", Context.NAME, contextUUID);
return removed;
@ -744,12 +746,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public <IE extends IdentifiableElement> boolean removeFromContext(UUID contextUUID, IE identifiableElement)
public <IE extends IdentifiableElement> boolean removeFromContext(IE identifiableElement, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
try {
String identifiableElementTypeName = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
UUID instanceUUID = identifiableElement.getHeader().getUUID();
return removeFromContext(contextUUID, identifiableElementTypeName, instanceUUID);
return removeFromContext(type, instanceUUID, contextUUID);
} catch(ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
throw e;
@ -760,35 +762,73 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public boolean removeFromCurrentContext(String identifiableElementTypeName, UUID instanceUUID)
public boolean removeFromCurrentContext(String type, UUID instanceUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
UUID contextUUID = getCurrentContextUUID();
return removeFromContext(contextUUID, identifiableElementTypeName, instanceUUID);
return removeFromContext(type, instanceUUID, contextUUID);
}
@Override
public <IE extends IdentifiableElement> boolean removeFromCurrentContext(IE identifiableElement)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
UUID contextUUID = getCurrentContextUUID();
return removeFromContext(contextUUID, identifiableElement);
return removeFromContext(identifiableElement, contextUUID);
}
@Override
public boolean addResourceToContext(UUID contextUUID, String resourceTypeName, UUID resourceUUID)
public Set<UUID> getElementContexts(String type, UUID instanceUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
return addToContext(contextUUID, resourceTypeName, resourceUUID);
try {
logger.trace("Going to get contexts of {} with UUID {}", type, instanceUUID);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
gxHTTPStringRequest.path(SharingPath.SHARING_PATH_PART);
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(instanceUUID.toString());
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
String jsonArray = HTTPUtility.getResponse(String.class, httpURLConnection);
Set<UUID> contexts = ContextUtility.getContextUUIDSet(jsonArray);
logger.info("Contexts of {} with UUID {} are {}", type, instanceUUID, contexts);
return contexts;
} 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
public <IE extends IdentifiableElement> Set<UUID> getElementContexts(IE identifiableElement)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement);
UUID instanceUUID = identifiableElement.getHeader().getUUID();
return getElementContexts(type, instanceUUID);
}
@Override
public boolean addResourceToContext(String resourceType, UUID resourceUUID, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
return addToContext(resourceType, resourceUUID, contextUUID);
}
@Override
public <R extends Resource> boolean addResourceToContext(UUID contextUUID, R resource)
public <R extends Resource> boolean addResourceToContext(R resource, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
return addToContext(contextUUID, resource);
return addToContext(resource, contextUUID);
}
@Override
public boolean addResourceToCurrentContext(String resourceTypeName, UUID resourceUUID)
public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
return addToCurrentContext(resourceTypeName, resourceUUID);
return addToCurrentContext(resourceType, resourceUUID);
}
@Override
@ -798,21 +838,21 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public boolean removeResourceFromContext(UUID contextUUID, String resourceTypeName, UUID resourceUUID)
public boolean removeResourceFromContext(String resourceType, UUID resourceUUID, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
return removeFromContext(contextUUID, resourceTypeName, resourceUUID);
return removeFromContext(resourceType, resourceUUID, contextUUID);
}
@Override
public <R extends Resource> boolean removeResourceFromContext(UUID contextUUID, R resource)
public <R extends Resource> boolean removeResourceFromContext(R resource, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
return removeFromContext(contextUUID, resource);
return removeFromContext(resource, contextUUID);
}
@Override
public boolean removeResourceFromCurrentContext(String resourceTypeName, UUID resourceUUID)
public boolean removeResourceFromCurrentContext(String resourceType, UUID resourceUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
return removeFromCurrentContext(resourceTypeName, resourceUUID);
return removeFromCurrentContext(resourceType, resourceUUID);
}
@Override
@ -822,21 +862,21 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public boolean addFacetToContext(UUID contextUUID, String facetTypeName, UUID facetUUID)
public boolean addFacetToContext(String facetType, UUID facetUUID, UUID contextUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
return addToContext(contextUUID, facetTypeName, facetUUID);
return addToContext(facetType, facetUUID, contextUUID);
}
@Override
public <F extends Facet> boolean addFacetToContext(UUID contextUUID, F facet)
public <F extends Facet> boolean addFacetToContext(F facet, UUID contextUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
return addToContext(contextUUID, facet);
return addToContext(facet, contextUUID);
}
@Override
public boolean addFacetToCurrentContext(String facetTypeName, UUID facetUUID)
public boolean addFacetToCurrentContext(String facetType, UUID facetUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
return addToCurrentContext(facetTypeName, facetUUID);
return addToCurrentContext(facetType, facetUUID);
}
@Override
@ -846,21 +886,21 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public boolean removeFacetFromContext(UUID contextUUID, String facetTypeName, UUID facetUUID)
public boolean removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
return removeFromContext(contextUUID, facetTypeName, facetUUID);
return removeFromContext(facetType, facetUUID, contextUUID);
}
@Override
public <F extends Facet> boolean removeFacetFromContext(UUID contextUUID, F facet)
public <F extends Facet> boolean removeFacetFromContext(F facet, UUID contextUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
return removeFromContext(contextUUID, facet);
return removeFromContext(facet, contextUUID);
}
@Override
public boolean removeFacetFromCurrentContext(String facetTypeName, UUID facetUUID)
public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
return removeFromCurrentContext(facetTypeName, facetUUID);
return removeFromCurrentContext(facetType, facetUUID);
}
@Override
@ -868,5 +908,29 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
return removeFromCurrentContext(facet);
}
@Override
public Set<UUID> getResourceContexts(String resourceType, UUID resourceUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
return getElementContexts(resourceType, resourceUUID);
}
@Override
public <R extends Resource> Set<UUID> getResourceContexts(R resource)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
return getElementContexts(resource);
}
@Override
public Set<UUID> getFacetContexts(String facetType, UUID facetUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
return getElementContexts(facetType, facetUUID);
}
@Override
public <F extends Facet> Set<UUID> getFacetContexts(F facet)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
return getElementContexts(facet);
}
}