/** * */ package org.gcube.resourcemanagement.model.reference.entities.facets; import java.util.List; import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.model.impl.properties.MetadataImpl; import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.properties.Metadata; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.serialization.ElementMapper; import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl; import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl; import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl; import org.gcube.resourcemanagement.model.reference.entities.resources.EService; import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode; import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) */ public class PolymorphismTest { private static Logger logger = LoggerFactory .getLogger(PolymorphismTest.class); public static final String NYESERVICE = "{\"" + Element.TYPE_PROPERTY + "\":\"EService\",\"" + IdentifiableElement.ID_PROPERTY + "\":\"3ace4bd0-e5cd-49a3-97a8-a0a9468ce6d4\",\"metadata\":{\"" + Element.TYPE_PROPERTY + "\":\"Metadata\",\"creator\":null, \"creationTime\":null, \"lastUpdateTime\":null},\"consistsOf\":[{\"" + Element.TYPE_PROPERTY + "\":\"IsIdentifiedBy\",\"metadata\":null,\"target\":{\""+ Element.SUPERTYPES_PROPERTY + "\":[\"SoftwareFacet\", \"Facet\", \"Entity\"],\"" + Element.TYPE_PROPERTY + "\":\"MySoftwareFacet\",\"metadata\":null,\"name\":\"WhnManager\",\"group\":\"VREManagement\",\"version\":\"2.0.0-SNAPSHOT\",\"description\":\"Web Hosting Node Service\",\"qualifier\":null,\"optional\":false}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\"metadata\":null,\"entryName\":\"whnmanager\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/vremanagement/ws/whnmanager\",\"protocol\":null,\"description\":null,\"authorization\": {\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\"metadata\":null,\"entryName\":\"WhnManager-remote-management\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/resource\",\"protocol\":null,\"description\":null,\"authorization\":{\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}}],\"isRelatedTo\":[]}"; public static final String MYESERVICE = "{\"" + Element.TYPE_PROPERTY + "\":\"EService\",\"" + IdentifiableElement.ID_PROPERTY + "\":\"3ace4bd0-e5cd-49a3-97a8-a0a9468ce6d4\",\"metadata\":{\"" + Element.TYPE_PROPERTY + "\":\"Metadata\",\"creator\":null, \"creationTime\":null, \"lastUpdateTime\":null},\"consistsOf\":[{\"" + Element.TYPE_PROPERTY + "\":\"IsIdentifiedBy\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"MySoftwareFacet\",\""+ Element.SUPERTYPES_PROPERTY + "\":[\"SoftwareFacet\", \"Facet\", \"Entity\"],\"metadata\":null,\"name\":\"WhnManager\",\"group\":\"VREManagement\",\"version\":\"2.0.0-SNAPSHOT\",\"description\":\"Web Hosting Node Service\",\"qualifier\":null,\"optional\":false}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\""+ Element.SUPERTYPES_PROPERTY + "\":[\"Facet\", \"Entity\"],\"metadata\":null,\"entryName\":\"whnmanager\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/vremanagement/ws/whnmanager\",\"protocol\":null,\"description\":null,\"authorization\": {\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\"metadata\":null,\"entryName\":\"WhnManager-remote-management\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/resource\",\"protocol\":null,\"description\":null,\"authorization\":{\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}}],\"isRelatedTo\":[]}"; public static final String MYOTHERESERVICE = "{\"" + Element.TYPE_PROPERTY + "\":\"EService\",\"" + IdentifiableElement.ID_PROPERTY + "\":\"3ace4bd0-e5cd-49a3-97a8-a0a9468ce6d4\",\"metadata\":{\"" + Element.TYPE_PROPERTY + "\":\"Metadata\",\"creator\":null, \"creationTime\":null, \"lastUpdateTime\":null},\"consistsOf\":[{\"" + Element.TYPE_PROPERTY + "\":\"IsIdentifiedBy\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"MySoftwareFacet\",\"metadata\":null,\""+ Element.SUPERTYPES_PROPERTY + "\":[\"SoftwareFacet\", \"Facet\", \"Entity\"],\"name\":\"WhnManager\",\"group\":\"VREManagement\",\"version\":\"2.0.0-SNAPSHOT\",\"description\":\"Web Hosting Node Service\",\"qualifier\":null,\"optional\":false}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\"metadata\":null,\"entryName\":\"whnmanager\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/vremanagement/ws/whnmanager\",\"protocol\":null,\"description\":null,\"authorization\": {\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\"metadata\":null,\"entryName\":\"WhnManager-remote-management\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/resource\",\"protocol\":null,\"description\":null,\"authorization\":{\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}}],\"isRelatedTo\":[]}"; public static final String MYANOTHERESERVICE = "{\"" + Element.TYPE_PROPERTY + "\":\"EService\",\"" + IdentifiableElement.ID_PROPERTY + "\":\"3ace4bd0-e5cd-49a3-97a8-a0a9468ce6d4\",\"metadata\":{\"" + Element.TYPE_PROPERTY + "\":\"Metadata\",\"creator\":null, \"creationTime\":null, \"lastUpdateTime\":null},\"consistsOf\":[{\"" + Element.TYPE_PROPERTY + "\":\"IsIdentifiedBy\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"MySoftwareFacet\",\"metadata\":null,\""+ Element.SUPERTYPES_PROPERTY + "\":[\"SoftwareFacet\", \"Facet\", \"Entity\"],\"name\":\"WhnManager\",\"group\":\"VREManagement\",\"version\":\"2.0.0-SNAPSHOT\",\"description\":\"Web Hosting Node Service\",\"qualifier\":null,\"optional\":false}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\"metadata\":null,\"entryName\":\"whnmanager\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/vremanagement/ws/whnmanager\",\"protocol\":null,\"description\":null,\"authorization\": {\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\"metadata\":null,\"entryName\":\"WhnManager-remote-management\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/resource\",\"protocol\":null,\"description\":null,\"authorization\":{\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}}],\"isRelatedTo\":[]}"; public static final String NYESERVICE2 = "{\"" + Element.TYPE_PROPERTY + "\":\"MyEService\",\""+ Element.SUPERTYPES_PROPERTY + "\":[\"EService\",\"Service\",\"Resource\"],\"" + IdentifiableElement.ID_PROPERTY + "\":\"3ace4bd0-e5cd-49a3-97a8-a0a9468ce6d4\",\"metadata\":{\"" + Element.TYPE_PROPERTY + "\":\"Metadata\",\"creator\":null, \"creationTime\":null, \"lastUpdateTime\":null},\"consistsOf\":[{\"" + Element.TYPE_PROPERTY + "\":\"IsIdentifiedBy\",\"metadata\":null,\"target\":{\""+ Element.SUPERTYPES_PROPERTY + "\":[\"SoftwareFacet\", \"Facet\", \"Entity\"],\"" + Element.TYPE_PROPERTY + "\":\"MySoftwareFacet\",\""+ Element.SUPERTYPES_PROPERTY + "\":[\"SoftwareFacet\", \"Facet\", \"Entity\"],\"metadata\":null,\"name\":\"WhnManager\",\"group\":\"VREManagement\",\"version\":\"2.0.0-SNAPSHOT\",\"description\":\"Web Hosting Node Service\",\"qualifier\":null,\"optional\":false}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\"metadata\":null,\"entryName\":\"whnmanager\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/vremanagement/ws/whnmanager\",\"protocol\":null,\"description\":null,\"authorization\": {\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\"metadata\":null,\"entryName\":\"WhnManager-remote-management\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/resource\",\"protocol\":null,\"description\":null,\"authorization\":{\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}}],\"isRelatedTo\":[]}"; public static final String MYANOTHERESERVICE2 = "{\"" + Element.TYPE_PROPERTY + "\":\"MyEService\",\""+ Element.SUPERTYPES_PROPERTY + "\":[\"EService\",\"Service\",\"Resource\"],\"" + IdentifiableElement.ID_PROPERTY + "\":\"3ace4bd0-e5cd-49a3-97a8-a0a9468ce6d4\",\"metadata\":{\"" + Element.TYPE_PROPERTY + "\":\"Metadata\",\"creator\":null, \"creationTime\":null, \"lastUpdateTime\":null},\"consistsOf\":[{\"" + Element.TYPE_PROPERTY + "\":\"IsIdentifiedBy\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"MySoftwareFacet\",\""+ Element.SUPERTYPES_PROPERTY + "\":[\"SoftwareFacet\", \"Facet\", \"Entity\"],\"metadata\":null,\"name\":\"WhnManager\",\"group\":\"VREManagement\",\"version\":\"2.0.0-SNAPSHOT\",\"description\":\"Web Hosting Node Service\",\"qualifier\":null,\"optional\":false}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\"metadata\":null,\"entryName\":\"whnmanager\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/vremanagement/ws/whnmanager\",\"protocol\":null,\"description\":null,\"authorization\": {\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"metadata\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\"metadata\":null,\"entryName\":\"WhnManager-remote-management\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/resource\",\"protocol\":null,\"description\":null,\"authorization\":{\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}}],\"isRelatedTo\":[]}"; public static final String MY_CONSISTS_OF = "{\""+ Element.SUPERTYPES_PROPERTY + "\":[\"IsIdentifiedBy\", \"ConsistsOf\", \"Relation\"],\"" + Element.TYPE_PROPERTY + "\":\"MyIsIdentifiedBy\",\"target\":{\""+ Element.SUPERTYPES_PROPERTY + "\":[\"SoftwareFacet\", \"Facet\", \"Entity\"],\"" + Element.TYPE_PROPERTY + "\":\"MySoftwareFacet\",\"metadata\":null,\"name\":\"WhnManager\",\"group\":\"VREManagement\",\"version\":\"2.0.0-SNAPSHOT\",\"description\":\"Web Hosting Node Service\",\"qualifier\":null,\"optional\":false}}"; public static final String MY_TEST_FACET = "{\""+ Element.SUPERTYPES_PROPERTY + "\":[\"SoftwareFacet\", \"Facet\", \"Entity\"],\"" + Element.TYPE_PROPERTY + "\":\"MySoftwareFacet\",\"name\":\"WhnManager\",\"group\":\"VREManagement\",\"version\":\"2.0.0-SNAPSHOT\",\"description\":\"Web Hosting Node Service\",\"qualifier\":null,\"optional\":false}"; @Test public void testER() throws Exception { Facet f = ElementMapper.unmarshal(Facet.class, MY_TEST_FACET); logger.debug("{} {}", f.getClass().getSimpleName(), f); ConsistsOf c = ElementMapper.unmarshal(ConsistsOf.class, MY_CONSISTS_OF); logger.debug("{} {}", c.getClass().getSimpleName(), c); String[] eServices = new String[]{NYESERVICE, MYESERVICE, MYOTHERESERVICE, MYANOTHERESERVICE, NYESERVICE2, MYANOTHERESERVICE2}; //String[] eServices = new String[]{NYESERVICE2, MYANOTHERESERVICE2}; //String[] eServices = new String[]{ESERVICE}; for(String eService : eServices){ logger.debug("Going to unmarshal {}", eService); Resource resource = ElementMapper.unmarshal(Resource.class, eService); logger.debug("{} {}", resource.getClass().getSimpleName(), resource); List> consistsOfs = resource.getConsistsOf(); for(ConsistsOf consistsOf : consistsOfs){ logger.debug("{}", consistsOf); Facet facet = consistsOf.getTarget(); logger.debug("{} {}", facet.getClass().getSimpleName(), facet); } } } @Test public void testRelation() throws Exception { HostingNode hostingNode = new HostingNodeImpl(); Metadata metadataHn = new MetadataImpl(); hostingNode.setMetadata(metadataHn); EService eService = new EServiceImpl(); Metadata metadataES = new MetadataImpl(); eService.setMetadata(metadataES); Activates activates = new ActivatesImpl(hostingNode, eService, null); hostingNode.attachResource(activates); String string = ElementMapper.marshal(activates); logger.debug(string); } }