Refs #11903: Use new REST interface in Resource Registry Publisher
Task-Url: https://support.d4science.org/issues/11903 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@169062 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d12e35f225
commit
e0b3cee45b
|
@ -24,9 +24,6 @@ public interface ResourceRegistryPublisher {
|
|||
public <E extends ER> E create(E er)
|
||||
throws AlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String create(String erType, String er)
|
||||
throws AlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String create(String er) throws AlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
|
||||
|
@ -54,9 +51,6 @@ public interface ResourceRegistryPublisher {
|
|||
public <F extends Facet> F createFacet(F facet)
|
||||
throws FacetAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String createFacet(String facetType, String facet)
|
||||
throws FacetAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
|
||||
|
@ -81,9 +75,6 @@ public interface ResourceRegistryPublisher {
|
|||
|
||||
public <R extends Resource> R createResource(R resource)
|
||||
throws ResourceAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String createResource(String resourceType, String resource)
|
||||
throws ResourceAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException;
|
||||
|
||||
|
@ -113,9 +104,6 @@ public interface ResourceRegistryPublisher {
|
|||
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(
|
||||
C consistsOf) throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public String createConsistsOf(String consistsOfType, String consistsOf)
|
||||
throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
public String createConsistsOf(String consistsOf)
|
||||
throws NotFoundException, ResourceRegistryException;
|
||||
|
||||
|
@ -144,9 +132,6 @@ public interface ResourceRegistryPublisher {
|
|||
|
||||
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo(
|
||||
I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String createIsRelatedTo(String isRelatedToType, String isRelatedTo)
|
||||
throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
||||
public String createIsRelatedTo(String isRelatedTo)
|
||||
throws ResourceNotFoundException, ResourceRegistryException;
|
||||
|
|
|
@ -8,9 +8,11 @@ import org.gcube.common.authorization.client.Constants;
|
|||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.impl.embedded.HeaderImpl;
|
||||
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||
import org.gcube.informationsystem.impl.utils.Utility;
|
||||
import org.gcube.informationsystem.model.ER;
|
||||
import org.gcube.informationsystem.model.embedded.Header;
|
||||
import org.gcube.informationsystem.model.entity.Context;
|
||||
import org.gcube.informationsystem.model.entity.Facet;
|
||||
import org.gcube.informationsystem.model.entity.Resource;
|
||||
|
@ -120,14 +122,32 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
}
|
||||
}
|
||||
|
||||
public <E extends ER> String internalCreate(E er) throws AlreadyPresentException, ResourceRegistryException {
|
||||
try {
|
||||
String erType = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getType(er);
|
||||
String erString = ISMapper.marshal(er);
|
||||
Header header = er.getHeader();
|
||||
if(header==null) {
|
||||
header = new HeaderImpl(UUID.randomUUID());
|
||||
er.setHeader(header);
|
||||
}
|
||||
UUID uuid = er.getHeader().getUUID();
|
||||
return create(erType, erString, uuid);
|
||||
} catch(ResourceRegistryException e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <E extends ER> E create(E er) throws AlreadyPresentException, ResourceRegistryException {
|
||||
try {
|
||||
String erType = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getType(er);
|
||||
String erString = ISMapper.marshal(er);
|
||||
UUID uuid = er.getHeader().getUUID();
|
||||
String ret = create(erType, erString, uuid);
|
||||
String ret = internalCreate(er);
|
||||
return (E) ISMapper.unmarshal(ER.class, ret);
|
||||
} catch(ResourceRegistryException e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
|
@ -138,26 +158,11 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String create(String erType, String er) throws AlreadyPresentException, ResourceRegistryException {
|
||||
try {
|
||||
UUID uuid = Utility.getUUIDFromJSONString(er);
|
||||
return create(erType, er, uuid);
|
||||
} 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 String create(String er) throws AlreadyPresentException, ResourceRegistryException {
|
||||
try {
|
||||
String erType = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(er);
|
||||
return create(erType, er);
|
||||
ER e = ISMapper.unmarshal(ER.class, er);
|
||||
return internalCreate(e);
|
||||
} catch(ResourceRegistryException e) {
|
||||
// logger.trace("Error Creating {}", facet, e);
|
||||
throw e;
|
||||
|
@ -331,12 +336,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
return create(facet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createFacet(String facetType, String facet)
|
||||
throws FacetAlreadyPresentException, ResourceRegistryException {
|
||||
return create(facetType, facet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException {
|
||||
return create(facet);
|
||||
|
@ -378,12 +377,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
return create(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createResource(String resourceType, String resource)
|
||||
throws ResourceAlreadyPresentException, ResourceRegistryException {
|
||||
return create(resourceType, resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException {
|
||||
return create(resource);
|
||||
|
@ -429,12 +422,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
return create(consistsOf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createConsistsOf(String consistsOfType, String consistsOf)
|
||||
throws NotFoundException, ResourceRegistryException {
|
||||
return create(consistsOfType, consistsOf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createConsistsOf(String consistsOf) throws NotFoundException, ResourceRegistryException {
|
||||
return create(consistsOf);
|
||||
|
@ -479,12 +466,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
return create(isRelatedTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createIsRelatedTo(String isRelatedToType, String isRelatedTo)
|
||||
throws ResourceNotFoundException, ResourceRegistryException {
|
||||
return create(isRelatedToType, isRelatedTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createIsRelatedTo(String isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException {
|
||||
return create(isRelatedTo);
|
||||
|
|
|
@ -225,13 +225,11 @@ public class ERManagementTest extends ScopedTest {
|
|||
new URL("https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
|
||||
eService.addFacet(licenseFacet);
|
||||
|
||||
String eServiceString = resourceRegistryPublisher.createResource(EService.NAME, ISMapper.marshal(eService));
|
||||
eService = ISMapper.unmarshal(EService.class, eServiceString);
|
||||
eService = resourceRegistryPublisher.createResource(eService);
|
||||
|
||||
eService.getFacets(SoftwareFacet.class).get(0).setVersion("1.2.0");
|
||||
|
||||
eServiceString = resourceRegistryPublisher.updateResource(ISMapper.marshal(eService));
|
||||
eService = ISMapper.unmarshal(EService.class, eServiceString);
|
||||
eService = resourceRegistryPublisher.updateResource(eService);
|
||||
|
||||
Assert.assertTrue(eService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo("1.2.0") == 0);
|
||||
|
||||
|
@ -494,18 +492,14 @@ public class ERManagementTest extends ScopedTest {
|
|||
List<Resource> resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, EService.class, eServiceUUID, Direction.both, true);
|
||||
Assert.assertTrue(resourceList.size() == 1);
|
||||
Resource sourceResource = resourceList.get(0);
|
||||
Resource targetResource = sourceResource.getIsRelatedTo().get(0).getTarget();
|
||||
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
|
||||
Assert.assertTrue(targetResource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
|
||||
Resource resource = resourceList.get(0);
|
||||
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, EService.class, eServiceUUID, Direction.out, true);
|
||||
Assert.assertTrue(resourceList.size() == 1);
|
||||
sourceResource = resourceList.get(0);
|
||||
targetResource = sourceResource.getIsRelatedTo().get(0).getTarget();
|
||||
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
|
||||
Assert.assertTrue(targetResource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
|
||||
resource = resourceList.get(0);
|
||||
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, EService.class, eServiceUUID, Direction.in, true);
|
||||
|
@ -528,10 +522,8 @@ public class ERManagementTest extends ScopedTest {
|
|||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.both, true);
|
||||
Assert.assertTrue(resourceList.size() == 1);
|
||||
sourceResource = resourceList.get(0);
|
||||
targetResource = sourceResource.getIsRelatedTo().get(0).getTarget();
|
||||
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
|
||||
Assert.assertTrue(targetResource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
|
||||
resource = resourceList.get(0);
|
||||
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.out, true);
|
||||
|
@ -540,10 +532,8 @@ public class ERManagementTest extends ScopedTest {
|
|||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.in, true);
|
||||
Assert.assertTrue(resourceList.size() == 1);
|
||||
sourceResource = resourceList.get(0);
|
||||
targetResource = sourceResource.getIsRelatedTo().get(0).getTarget();
|
||||
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
|
||||
Assert.assertTrue(targetResource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
|
||||
resource = resourceList.get(0);
|
||||
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
|
||||
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.both, false);
|
||||
|
@ -566,9 +556,9 @@ public class ERManagementTest extends ScopedTest {
|
|||
/* Eservice with Software Facet as Identification Facet */
|
||||
resourceList = resourceRegistryClient.getResourcesFromReferenceFacet(Resource.class, ConsistsOf.class, SoftwareFacet.class, identificationFacetUUID, true);
|
||||
Assert.assertTrue(resourceList.size() == 1);
|
||||
sourceResource = resourceList.get(0);
|
||||
Facet targetIdentificationFacet = sourceResource.getIdentificationFacets().get(0);
|
||||
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
|
||||
resource = resourceList.get(0);
|
||||
Facet targetIdentificationFacet = resource.getIdentificationFacets().get(0);
|
||||
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
|
||||
Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID().compareTo(identificationFacetUUID) == 0);
|
||||
|
||||
resourceList = resourceRegistryClient.getResourcesFromReferenceFacet(Resource.class, ConsistsOf.class, SoftwareFacet.class, identificationFacetUUID, false);
|
||||
|
@ -578,7 +568,7 @@ public class ERManagementTest extends ScopedTest {
|
|||
|
||||
|
||||
/* END SoftwareFacet of Eservice */
|
||||
|
||||
/* Support removed
|
||||
List<Facet> facets = resourceRegistryClient.getRelated(Facet.class, ConsistsOf.class, EService.class, eServiceUUID, Direction.in, true);
|
||||
Assert.assertTrue(resourceList.size() == 1);
|
||||
Facet facet = facets.get(0);
|
||||
|
@ -586,7 +576,7 @@ public class ERManagementTest extends ScopedTest {
|
|||
|
||||
facets = resourceRegistryClient.getRelated(Facet.class, ConsistsOf.class, EService.class, eServiceUUID, Direction.in, false);
|
||||
Assert.assertTrue(resourceList.size() == 0);
|
||||
|
||||
*/
|
||||
/* END SoftwareFacet of Eservice */
|
||||
|
||||
/* Removing created Entity and Relation to have a clean DB */
|
||||
|
|
|
@ -41,7 +41,6 @@ import org.gcube.informationsystem.model.relation.isrelatedto.Hosts;
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
||||
import org.junit.Assert;
|
||||
|
@ -185,8 +184,8 @@ public class MultiContextTest extends ScopedTest {
|
|||
|
||||
try {
|
||||
resourceRegistryClient.exists(EService.class, eServiceUUID);
|
||||
}catch(ResourceAvailableInAnotherContextException e){
|
||||
logger.debug("Resource with {} Not Found as Expected", eServiceUUID.toString());
|
||||
}catch(AvailableInAnotherContextException e){
|
||||
logger.debug("Resource with {} Available in another Context as Expected", eServiceUUID.toString());
|
||||
}
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(createdHN);
|
||||
|
|
Loading…
Reference in New Issue