Added apis to avoid to pass the type

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@154771 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-10-03 13:49:47 +00:00
parent 82cd0aa78a
commit 90ca8549b9
4 changed files with 551 additions and 415 deletions

View File

@ -17,86 +17,97 @@ 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 <F extends Facet> F createFacet(Class<F> facetClass, F facet)
throws FacetAlreadyPresentException, ResourceRegistryException;
public String createFacet(String facetType, String facet)
throws FacetAlreadyPresentException, ResourceRegistryException;
public String createFacet(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 String updateFacet(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 String createResource(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 String updateResource(String resource)
throws ResourceNotFoundException, 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 <R extends Resource> boolean deleteResource(R resource)
throws ResourceNotFoundException, ResourceRegistryException;
public boolean deleteResource(UUID uuid) throws ResourceNotFoundException, ResourceRegistryException;
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>> 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;
public String createConsistsOf(String consistsOf)
throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException;
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(C consistsOf)
throws ResourceRegistryException;
public boolean deleteConsistsOf(UUID uuid) throws ResourceRegistryException;
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 String createIsRelatedTo(String 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;
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(I isRelatedTo)
throws ResourceRegistryException;
public boolean deleteIsRelatedTo(UUID uuid) throws ResourceRegistryException;
public boolean addResourceToContext(UUID uuid)
throws ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <R extends Resource> boolean addResourceToContext(R resource)
throws ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public boolean addFacetToContext(UUID uuid) throws FacetNotFoundException,
ContextNotFoundException, ResourceRegistryException;
public boolean addFacetToContext(UUID uuid)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <F extends Facet> boolean addFacetToContext(F facet)
throws FacetNotFoundException, ContextNotFoundException,
ResourceRegistryException;
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public boolean removeResourceFromContext(UUID uuid)
throws ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <R extends Resource> boolean removeResourceFromContext(R resource)
throws ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public boolean removeFacetFromContext(UUID uuid) throws FacetNotFoundException,
ContextNotFoundException, ResourceRegistryException;
public boolean removeFacetFromContext(UUID uuid)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <F extends Facet> boolean removeFacetFromContext(F facet)
throws FacetNotFoundException, ContextNotFoundException,
ResourceRegistryException;
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
}

View File

@ -72,7 +72,7 @@ public class ERManagementTest extends ScopedTest {
}
@Test
public void testCreateEService() throws Exception {
public void testCreateDeleteEService() throws Exception {
EService eService = new EServiceImpl();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
@ -111,6 +111,145 @@ public class ERManagementTest extends ScopedTest {
Assert.assertTrue(deleted);
}
@Test
public void testCreateUpdateDeleteEService() throws Exception {
EService eService = new EServiceImpl();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(
eService, softwareFacet, null);
eService.addFacet(isIdentifiedBy);
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
accessPointFacet.setEndpoint(new URI("http://localhost"));
accessPointFacet.setEntryName("port1");
eService.addFacet(accessPointFacet);
EventFacet eventFacet = new EventFacetImpl();
eventFacet.setDate(Calendar.getInstance().getTime());
eventFacet.setValue("Created");
eService.addFacet(eventFacet);
ServiceStateFacet serviceStateFacet = new ServiceStateFacetImpl();
serviceStateFacet.setValue("ready");
eService.addFacet(serviceStateFacet);
LicenseFacet licenseFacet = new LicenseFacetImpl();
licenseFacet.setName("EUPL");
licenseFacet
.setTextURL(new URL(
"https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
eService.addFacet(licenseFacet);
eService = resourceRegistryPublisher.createResource(EService.class,
eService);
eService.getFacets(SoftwareFacet.class).get(0).setVersion("1.2.0");
eService = resourceRegistryPublisher.updateResource(EService.class,
eService);
Assert.assertTrue(eService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo("1.2.0")==0);
boolean deleted = resourceRegistryPublisher.deleteResource(eService);
Assert.assertTrue(deleted);
}
@Test
public void testCreateEServiceAsJsonString() throws Exception {
EService eService = new EServiceImpl();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(
eService, softwareFacet, null);
eService.addFacet(isIdentifiedBy);
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
accessPointFacet.setEndpoint(new URI("http://localhost"));
accessPointFacet.setEntryName("port1");
eService.addFacet(accessPointFacet);
EventFacet eventFacet = new EventFacetImpl();
eventFacet.setDate(Calendar.getInstance().getTime());
eventFacet.setValue("Created");
eService.addFacet(eventFacet);
ServiceStateFacet serviceStateFacet = new ServiceStateFacetImpl();
serviceStateFacet.setValue("ready");
eService.addFacet(serviceStateFacet);
LicenseFacet licenseFacet = new LicenseFacetImpl();
licenseFacet.setName("EUPL");
licenseFacet
.setTextURL(new URL(
"https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
eService.addFacet(licenseFacet);
String json = ISMapper.marshal(eService);
String createdString = resourceRegistryPublisher.createResource(json);
EService created = ISMapper.unmarshal(EService.class, createdString);
boolean deleted = resourceRegistryPublisher.deleteResource(created);
Assert.assertTrue(deleted);
}
@Test
public void testCreateUpdateDeleteEServiceAsJsonString() throws Exception {
EService eService = new EServiceImpl();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(
eService, softwareFacet, null);
eService.addFacet(isIdentifiedBy);
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
accessPointFacet.setEndpoint(new URI("http://localhost"));
accessPointFacet.setEntryName("port1");
eService.addFacet(accessPointFacet);
EventFacet eventFacet = new EventFacetImpl();
eventFacet.setDate(Calendar.getInstance().getTime());
eventFacet.setValue("Created");
eService.addFacet(eventFacet);
ServiceStateFacet serviceStateFacet = new ServiceStateFacetImpl();
serviceStateFacet.setValue("ready");
eService.addFacet(serviceStateFacet);
LicenseFacet licenseFacet = new LicenseFacetImpl();
licenseFacet.setName("EUPL");
licenseFacet
.setTextURL(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.getFacets(SoftwareFacet.class).get(0).setVersion("1.2.0");
eServiceString = resourceRegistryPublisher.updateResource(eService.getHeader().getUUID(), ISMapper.marshal(eService));
eService = ISMapper.unmarshal(EService.class, eServiceString);
Assert.assertTrue(eService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo("1.2.0")==0);
boolean deleted = resourceRegistryPublisher.deleteResource(eService);
Assert.assertTrue(deleted);
}
@Test
public void testCreateReadDeleteFacet() throws Exception {
CPUFacet cpuFacet = new CPUFacetImpl();

View File

@ -13,6 +13,7 @@ import org.gcube.informationsystem.impl.entity.resource.EServiceImpl;
import org.gcube.informationsystem.impl.entity.resource.HostingNodeImpl;
import org.gcube.informationsystem.impl.relation.IsIdentifiedByImpl;
import org.gcube.informationsystem.impl.relation.isrelatedto.HostsImpl;
import org.gcube.informationsystem.impl.utils.ISMapper;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.entity.facet.CPUFacet;
@ -77,6 +78,45 @@ public class EntityManagementTest extends ScopedTest {
boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet);
Assert.assertTrue(deleted);
}
@Test
public void testCreateUpdateDeleteFacetStringAPI() throws Exception {
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
String createdCpuFacetString = resourceRegistryPublisher.createFacet(ISMapper.marshal(cpuFacet));
CPUFacet createdCpuFacet = ISMapper.unmarshal(CPUFacet.class, createdCpuFacetString);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0);
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
createdCpuFacet.setVendor(newVendor);
createdCpuFacet.setClockSpeed(newClockSpeed);
String additionPropertyKey = "My";
String additionPropertyValue = "Test";
createdCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
String updatedCpuFacetString = resourceRegistryPublisher.updateFacet(createdCpuFacet.getHeader().getUUID(), ISMapper.marshal(createdCpuFacet));
CPUFacet updatedCpuFacet = ISMapper.unmarshal(CPUFacet.class, updatedCpuFacetString);
Assert.assertTrue(createdCpuFacet.getClockSpeed().compareTo(updatedCpuFacet.getClockSpeed())==0);
Assert.assertTrue(createdCpuFacet.getModel().compareTo(updatedCpuFacet.getModel())==0);
Assert.assertTrue(createdCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor())==0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)).compareTo((String) createdCpuFacet.getAdditionalProperty(additionPropertyKey))==0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID())==0);
boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet);
Assert.assertTrue(deleted);
}
@Test
public void testCreateDeleteResources() throws Exception {