Added create/update methods using string containing the json of the entity instead of the java instance. refs #9877
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@154758 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a9e284580c
commit
82cd0aa78a
|
@ -17,21 +17,29 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resour
|
|||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public interface ResourceRegistryPublisher {
|
||||
|
||||
|
||||
public <F extends Facet> F createFacet(Class<F> facetClass, F facet) throws FacetAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String createFacet(String facetType, String facet) throws FacetAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public <F extends Facet> F updateFacet(Class<F> facetClass, F facet) throws FacetNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String updateFacet(UUID uuid, String facet) throws FacetNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <F extends Facet> boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean deleteFacet(UUID uuid) throws FacetNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
public <R extends Resource> R createResource(Class<R> resourceClass,
|
||||
R resource) throws ResourceAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String createResource(String resourceType, String resource) throws ResourceAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> R updateResource(Class<R> resourceClass, R resource) throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String updateResource(UUID uuid, String resource) throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <R extends Resource> boolean deleteResource(R resource) throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public boolean deleteResource(UUID uuid) throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
@ -40,6 +48,8 @@ public interface ResourceRegistryPublisher {
|
|||
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(
|
||||
Class<C> consistsOfClass, C consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String createConsistsOf(String consistsOfType, String consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(
|
||||
C consistsOf) throws ResourceRegistryException;
|
||||
|
||||
|
@ -48,7 +58,9 @@ public interface ResourceRegistryPublisher {
|
|||
|
||||
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo(
|
||||
Class<I> isRelatedToClass, I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
|
||||
public String createIsRelatedTo(String isRelatedToType, String isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(
|
||||
I isRelatedTo) throws ResourceRegistryException;
|
||||
|
||||
|
|
|
@ -76,10 +76,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
stringWriter.append(facetClass.getSimpleName());
|
||||
|
||||
String body = ISMapper.marshal(facet);
|
||||
|
||||
|
||||
HTTPCall httpCall = getHTTPCall();
|
||||
F f= httpCall.call(facetClass, stringWriter.toString(),
|
||||
F f = httpCall.call(facetClass, stringWriter.toString(),
|
||||
HTTPMETHOD.PUT, body);
|
||||
|
||||
logger.info("{} successfully created", f);
|
||||
|
@ -93,7 +92,35 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String createFacet(String facetType, String facet) throws FacetAlreadyPresentException, ResourceRegistryException {
|
||||
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);
|
||||
|
||||
HTTPCall httpCall = getHTTPCall();
|
||||
String f = httpCall.call(String.class, stringWriter.toString(),
|
||||
HTTPMETHOD.PUT, facet);
|
||||
|
||||
logger.info("{} successfully created", f);
|
||||
return f;
|
||||
|
||||
} 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 <F extends Facet> F updateFacet(Class<F> facetClass, F facet) throws FacetNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
|
@ -123,7 +150,35 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@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());
|
||||
|
||||
HTTPCall httpCall = getHTTPCall();
|
||||
String f = httpCall.call(String.class, stringWriter.toString(),
|
||||
HTTPMETHOD.POST, facet);
|
||||
|
||||
logger.info("{} successfully updated", f);
|
||||
return f;
|
||||
|
||||
} catch (ResourceRegistryException e) {
|
||||
//logger.trace("Error Updating {}", facet, e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
//logger.trace("Error Updating {}", facet, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends Facet> boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException {
|
||||
logger.info("Going to delete : {}", facet);
|
||||
|
@ -191,6 +246,35 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createResource(String resourceType, String resource) throws ResourceAlreadyPresentException, ResourceRegistryException {
|
||||
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();
|
||||
String r = httpCall.call(String.class, stringWriter.toString(),
|
||||
HTTPMETHOD.PUT, resource);
|
||||
|
||||
logger.info("{} successfully created", r);
|
||||
return r;
|
||||
|
||||
} catch (ResourceRegistryException e) {
|
||||
//logger.trace("Error Creating {}", resource, e);
|
||||
throw e;
|
||||
|
||||
} catch (Exception e) {
|
||||
//logger.trace("Error Creating {}", resource, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends Resource> R updateResource(Class<R> resourceClass,
|
||||
R resource) throws ResourceNotFoundException, ResourceRegistryException {
|
||||
|
@ -222,6 +306,35 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String updateResource(UUID uuid, String resource) throws ResourceNotFoundException, ResourceRegistryException {
|
||||
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();
|
||||
String r = httpCall.call(String.class, stringWriter.toString(),
|
||||
HTTPMETHOD.POST, resource);
|
||||
|
||||
logger.info("{} successfully updated", r);
|
||||
return r;
|
||||
|
||||
} catch (ResourceRegistryException e) {
|
||||
//logger.trace("Error Creating {}", resource, e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
//logger.trace("Error Creating {}", resource, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends Resource> boolean deleteResource(R resource) throws ResourceNotFoundException, ResourceRegistryException {
|
||||
logger.info("Going to delete {}", resource);
|
||||
|
@ -301,6 +414,46 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String createConsistsOf(String consistsOfType, String consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException {
|
||||
try {
|
||||
logger.info("Going to create: {}", consistsOf);
|
||||
|
||||
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);
|
||||
/*
|
||||
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());
|
||||
*/
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(consistsOfType);
|
||||
|
||||
HTTPCall httpCall = getHTTPCall();
|
||||
String c = httpCall.call(String.class, stringWriter.toString(),
|
||||
HTTPMETHOD.PUT, consistsOf);
|
||||
|
||||
logger.info("{} successfully created", c);
|
||||
return c;
|
||||
|
||||
} catch (ResourceRegistryException e) {
|
||||
//logger.trace("Error Creating {}", consistsOf, e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
//logger.trace("Error Creating {}", consistsOf, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(
|
||||
|
@ -382,6 +535,45 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String createIsRelatedTo(String isRelatedToType, String isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException {
|
||||
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);
|
||||
/*
|
||||
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());
|
||||
*/
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(isRelatedToType);
|
||||
|
||||
HTTPCall httpCall = getHTTPCall();
|
||||
String i = httpCall.call(String.class, stringWriter.toString(),
|
||||
HTTPMETHOD.PUT, isRelatedTo);
|
||||
|
||||
logger.info("{} successfully created", i);
|
||||
return i;
|
||||
|
||||
} 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 <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(
|
||||
|
|
Loading…
Reference in New Issue