Porting code to redesigned E/R format

This commit is contained in:
Luca Frosini 2023-04-19 11:38:22 +02:00
parent bef7068964
commit 9a465edb19
11 changed files with 121 additions and 131 deletions

View File

@ -38,9 +38,9 @@ public interface ResourceRegistryPublisher {
public void setHierarchicalMode(boolean hierarchicalMode);
public boolean isIncludeContextsInHeader();
public boolean isIncludeContexts();
public void setIncludeContextsInHeader(boolean includeContextsInHeader);
public void setIncludeContexts(boolean includeContexts);
public void addHeader(String name, String value);

View File

@ -11,11 +11,9 @@ import org.gcube.common.gxhttp.reference.GXConnection;
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
import org.gcube.common.http.GXHTTPUtility;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.reference.ERElement;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
@ -62,7 +60,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
protected Map<String, String> headers;
protected boolean hierarchicalMode;
protected boolean includeContextsInHeader;
protected boolean includeContexts;
protected ContextCache contextCache;
@ -77,13 +75,13 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public boolean isIncludeContextsInHeader() {
return includeContextsInHeader;
public boolean isIncludeContexts() {
return includeContexts;
}
@Override
public void setIncludeContextsInHeader(boolean includeContextsInHeader) {
this.includeContextsInHeader = includeContextsInHeader;
public void setIncludeContexts(boolean includeContexts) {
this.includeContexts = includeContexts;
}
@ -95,7 +93,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest,
Map<String, String> queryParams) throws UnsupportedEncodingException {
gxHTTPStringRequest = checkHierarchicalMode(gxHTTPStringRequest, queryParams);
return checkIncludeContextsInInstanceHeader(gxHTTPStringRequest, queryParams);
return checkIncludeContextsInInstance(gxHTTPStringRequest, queryParams);
}
private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest,
@ -109,13 +107,13 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
return gxHTTPStringRequest.queryParams(queryParams);
}
private GXHTTPStringRequest checkIncludeContextsInInstanceHeader(GXHTTPStringRequest gxHTTPStringRequest,
private GXHTTPStringRequest checkIncludeContextsInInstance(GXHTTPStringRequest gxHTTPStringRequest,
Map<String, String> queryParams) throws UnsupportedEncodingException {
if(includeContextsInHeader) {
if(includeContexts) {
if(queryParams==null) {
queryParams = new HashMap<>();
}
queryParams.put(AccessPath.INCLUDE_CONTEXTS_IN_HEADER_QUERY_PARAMETER, Boolean.toString(includeContextsInHeader));
queryParams.put(AccessPath.INCLUDE_CONTEXTS_QUERY_PARAMETER, Boolean.toString(includeContexts));
}
return gxHTTPStringRequest.queryParams(queryParams);
}
@ -224,7 +222,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
context = getContextFromServer(uuid.toString());
contextCache.cleanCache();
contextCache.refreshContextsIfNeeded();
Context c = contextCache.getContextByUUID(context.getHeader().getUUID());
Context c = contextCache.getContextByUUID(context.getUUID());
if (c != null) {
context = c;
} else {
@ -244,7 +242,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
private UUID getCurrentContextUUID() throws ResourceRegistryException {
return getCurrentContext().getHeader().getUUID();
return getCurrentContext().getUUID();
}
@SuppressWarnings("unchecked")
@ -320,13 +318,11 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(er);
String json = ElementMapper.marshal(er);
Header header = er.getHeader();
if (header == null) {
UUID randomUUID = UUIDManager.generateValidRandomUUID();
header = new HeaderImpl(randomUUID);
er.setHeader(header);
UUID uuid = er.getUUID();
if (uuid == null) {
uuid = UUIDManager.getInstance().generateValidRandomUUID();
er.setUUID(uuid);
}
UUID uuid = er.getHeader().getUUID();
return create(type, json, uuid);
} catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
@ -372,7 +368,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public <ERElem extends ERElement> boolean exist(ERElem er)
throws AvailableInAnotherContextException, ResourceRegistryException {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(er);
UUID uuid = er.getHeader().getUUID();
UUID uuid = er.getUUID();
return exist(type, uuid);
}
@ -422,7 +418,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(er);
UUID uuid = er.getHeader().getUUID();
UUID uuid = er.getUUID();
String ret = read(type, uuid);
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
} catch (ResourceRegistryException e) {
@ -484,7 +480,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(er);
String json = ElementMapper.marshal(er);
UUID uuid = er.getHeader().getUUID();
UUID uuid = er.getUUID();
String ret = update(type, json, uuid);
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
} catch (ResourceRegistryException e) {
@ -560,7 +556,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(er);
UUID uuid = er.getHeader().getUUID();
UUID uuid = er.getUUID();
return delete(type, uuid);
} catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
@ -837,7 +833,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(er);
UUID instanceUUID = er.getHeader().getUUID();
UUID instanceUUID = er.getUUID();
return addToContext(type, instanceUUID, contextUUID, dryRun);
} catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
@ -905,7 +901,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(er);
UUID instanceUUID = er.getHeader().getUUID();
UUID instanceUUID = er.getUUID();
return removeFromContext(type, instanceUUID, contextUUID, dryRun);
} catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
@ -964,7 +960,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public <ERElem extends ERElement> Map<UUID, String> getElementContexts(ERElem er)
throws NotFoundException, ResourceRegistryException {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(er);
UUID instanceUUID = er.getHeader().getUUID();
UUID instanceUUID = er.getUUID();
return getElementContexts(type, instanceUUID);
}

View File

@ -15,7 +15,7 @@ import org.gcube.common.authorization.utils.secret.SecretUtility;
import org.gcube.common.keycloak.KeycloakClientFactory;
import org.gcube.common.keycloak.model.TokenResponse;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
@ -117,7 +117,7 @@ public class ContextTest {
}
public static String getUser() {
String user = Header.UNKNOWN_USER;
String user = Metadata.UNKNOWN_USER;
try {
user = SecretManagerProvider.instance.get().getUser().getUsername();
} catch(Exception e) {

View File

@ -15,16 +15,16 @@ import java.util.UUID;
import org.gcube.common.encryption.encrypter.StringEncrypter;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.impl.properties.VaultImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.properties.Vault;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceNotFoundException;
import org.gcube.informationsystem.serialization.ElementMapper;
@ -218,46 +218,46 @@ public class ERManagementTest extends ContextTest {
return hostingNode;
}
public static void checkHeader(IdentifiableElement identifiableElement, IdentifiableElement createdIdentifiableElement) {
Header createdHeader = createdIdentifiableElement.getHeader();
Assert.assertTrue(createdHeader!=null);
UUID createdUUID = createdHeader.getUUID();
public static void checkUUIDAndMetadata(IdentifiableElement identifiableElement, IdentifiableElement createdIdentifiableElement) {
UUID createdUUID = createdIdentifiableElement.getUUID();
Assert.assertTrue(createdUUID!=null);
String createdBy = createdHeader.getCreatedBy();
if(identifiableElement.getUUID()!=null) {
Assert.assertTrue(createdUUID.compareTo(identifiableElement.getUUID())==0);
}
Metadata createdMetadata = createdIdentifiableElement.getMetadata();
Assert.assertTrue(createdMetadata!=null);
String createdBy = createdMetadata.getCreatedBy();
Assert.assertTrue(createdBy!=null);
String lastUpdateBy = createdHeader.getLastUpdateBy();
String lastUpdateBy = createdMetadata.getLastUpdateBy();
Assert.assertTrue(lastUpdateBy!=null);
Date creationTime = createdHeader.getCreationTime();
Date creationTime = createdMetadata.getCreationTime();
Assert.assertTrue(creationTime!=null);
Date lastUpdateTime = createdHeader.getLastUpdateTime();
Date lastUpdateTime = createdMetadata.getLastUpdateTime();
Assert.assertTrue(lastUpdateTime!=null);
Assert.assertTrue(lastUpdateTime.equals(creationTime) || lastUpdateTime.equals(lastUpdateTime));
Header header = identifiableElement.getHeader();
if(header!=null) {
if(header.getUUID()!=null) {
Assert.assertTrue(createdUUID.compareTo(header.getUUID())==0);
}
if(header.getCreatedBy()!=null) {
Assert.assertTrue(createdBy.compareTo(header.getCreatedBy())==0);
Metadata metadata = identifiableElement.getMetadata();
if(metadata!=null) {
if(metadata.getCreatedBy()!=null) {
Assert.assertTrue(createdBy.compareTo(metadata.getCreatedBy())==0);
}else {
Assert.assertTrue(createdBy.compareTo(ContextTest.getUser())==0);
}
if(header.getLastUpdateBy()!=null) {
Assert.assertTrue(lastUpdateBy.compareTo(header.getLastUpdateBy())==0);
if(metadata.getLastUpdateBy()!=null) {
Assert.assertTrue(lastUpdateBy.compareTo(metadata.getLastUpdateBy())==0);
}else {
Assert.assertTrue(lastUpdateBy.compareTo(ContextTest.getUser())==0);
}
if(header.getLastUpdateTime()!=null) {
Assert.assertTrue(lastUpdateTime.after(header.getLastUpdateTime()));
if(metadata.getLastUpdateTime()!=null) {
Assert.assertTrue(lastUpdateTime.after(metadata.getLastUpdateTime()));
}
}
@ -269,7 +269,7 @@ public class ERManagementTest extends ContextTest {
}
public static void checkConsistOf(ConsistsOf<? extends Resource, ? extends Facet> consistsOf, ConsistsOf<? extends Resource, ? extends Facet> gotConsistsOf) {
checkHeader(consistsOf, gotConsistsOf);
checkUUIDAndMetadata(consistsOf, gotConsistsOf);
if(consistsOf.getPropagationConstraint()==null) {
PropagationConstraint propagationConstraint = gotConsistsOf.getPropagationConstraint();
@ -295,7 +295,7 @@ public class ERManagementTest extends ContextTest {
}
public static void checkFacet(Facet facet, Facet gotFacet) throws Exception {
checkHeader(facet, gotFacet);
checkUUIDAndMetadata(facet, gotFacet);
Class<? extends Facet> clz = facet.getClass();
Class<? extends Facet> gotClz = gotFacet.getClass();
Assert.assertTrue(clz==gotClz);
@ -307,7 +307,7 @@ public class ERManagementTest extends ContextTest {
protected static <R extends Resource> void checkResource(R resource, R gotResource) throws Exception {
Assert.assertTrue(resource.getClass() == gotResource.getClass());
checkHeader(resource, gotResource);
checkUUIDAndMetadata(resource, gotResource);
List<ConsistsOf<? extends Resource, ? extends Facet>> resourceConsistsOf = resource.getConsistsOf();
List<ConsistsOf<? extends Resource, ? extends Facet>> gotResourceConsistsOf = gotResource.getConsistsOf();
@ -450,13 +450,13 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
UUID uuid = createdCpuFacet.getUUID();
CPUFacet readCpuFacet = resourceRegistryPublisher.read(createdCpuFacet.getClass(), uuid);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(readCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(readCpuFacet.getVendor()) == 0);
Assert.assertTrue(uuid.compareTo(readCpuFacet.getHeader().getUUID()) == 0);
Assert.assertTrue(uuid.compareTo(readCpuFacet.getUUID()) == 0);
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
@ -473,9 +473,9 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(newVendor) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getUUID()) == 0);
String user = ContextTest.getUser();
Assert.assertTrue(updatedCpuFacet.getHeader().getLastUpdateBy().compareTo(user) == 0);
Assert.assertTrue(updatedCpuFacet.getMetadata().getLastUpdateBy().compareTo(user) == 0);
CPUFacet readUpdatedCpuFacet = resourceRegistryPublisher.read(updatedCpuFacet);
@ -484,7 +484,7 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getUUID()) == 0);
resourceRegistryPublisher.delete(readCpuFacet);
} finally {
@ -514,12 +514,12 @@ public class ERManagementTest extends ContextTest {
String additionlaPropertyValue = "MyTest";
accessPointFacet.setAdditionalProperty(additionlaPropertyKey, additionlaPropertyValue);
Vault vault = new VaultImpl();
Encrypted encrypted = new EncryptedImpl();
String plainValue = "my plain value";
String encryptedValue = StringEncrypter.getEncrypter().encrypt(plainValue);
vault.setValue(encryptedValue);
encrypted.setValue(encryptedValue);
String encryptedKey = "Enc";
accessPointFacet.setAdditionalProperty(encryptedKey, vault);
accessPointFacet.setAdditionalProperty(encryptedKey, encrypted);
configuration.addFacet(accessPointFacet);
@ -531,8 +531,8 @@ public class ERManagementTest extends ContextTest {
AccessPointFacet apf = configuration.getFacets(AccessPointFacet.class).get(0);
Assert.assertTrue(apf.getAuthorization() instanceof ValueSchema);
Assert.assertTrue(apf.getAdditionalProperty(encryptedKey) instanceof Vault);
Vault enc = (Vault) apf.getAdditionalProperty(encryptedKey);
Assert.assertTrue(apf.getAdditionalProperty(encryptedKey) instanceof Encrypted);
Encrypted enc = (Encrypted) apf.getAdditionalProperty(encryptedKey);
String encValue = enc.getValue();
Assert.assertTrue(encValue.compareTo(encryptedValue) == 0);
String decryptedValue = StringEncrypter.getEncrypter().decrypt(encValue);
@ -577,7 +577,7 @@ public class ERManagementTest extends ContextTest {
// EService eService = ElementMapper.unmarshal(EService.class, fileInputStream);
//
// ResourceManagement resourceManagement = new ResourceManagement();
// resourceManagement.setUUID(eService.getHeader().getUUID());
// resourceManagement.setUUID(eService.getUUID());
// resourceManagement.setJson(ElementMapper.marshal(eService));
//
// resourceManagement.update();

View File

@ -3,7 +3,6 @@ package org.gcube.informationsystem.resourceregistry.publisher;
import java.util.Map;
import java.util.UUID;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
@ -54,8 +53,8 @@ public class InvalidOperationTest extends ERManagementTest {
* Here we want to test how the service behave if a client does not behave properly
*/
String json = ACTIVATES.replace("CONFIGURATION_UUID", configuration.getHeader().getUUID().toString());
json = json.replace("ESERVICE_UUID", eService.getHeader().getUUID().toString());
String json = ACTIVATES.replace("CONFIGURATION_UUID", configuration.getUUID().toString());
json = json.replace("ESERVICE_UUID", eService.getUUID().toString());
resourceRegistryPublisher.create(json);
@ -168,14 +167,14 @@ public class InvalidOperationTest extends ERManagementTest {
ERManagementTest erManagementTest = new ERManagementTest();
Map<String, Resource> map = erManagementTest.createHostingNodeAndEService();
UUID hostingNodeUUID = map.get(HostingNode.NAME).getHeader().getUUID();
UUID eServiceUUID = map.get(EService.NAME).getHeader().getUUID();
UUID hostingNodeUUID = map.get(HostingNode.NAME).getUUID();
UUID eServiceUUID = map.get(EService.NAME).getUUID();
HostingNode hostingNode = new HostingNodeImpl();
hostingNode.setHeader(new HeaderImpl(hostingNodeUUID));
hostingNode.setUUID(hostingNodeUUID);
SimpleFacet fakeEServiceAsSimpleFacet = new SimpleFacetImpl();
fakeEServiceAsSimpleFacet.setHeader(new HeaderImpl(eServiceUUID));
fakeEServiceAsSimpleFacet.setUUID(eServiceUUID);
ConsistsOf<HostingNode, SimpleFacet> consistsOf = new ConsistsOfImpl<HostingNode, SimpleFacet>(hostingNode, fakeEServiceAsSimpleFacet);

View File

@ -32,16 +32,15 @@ import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.utils.UUIDManager;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl;
@ -96,11 +95,10 @@ public class SmartgearResourcesTest extends ERManagementTest {
@Test
public void testHostingNodeOperations() throws ResourceRegistryException,
IOException, URISyntaxException {
UUID uuid = UUID.randomUUID();
UUID uuid = UUIDManager.getInstance().generateValidRandomUUID();
HostingNode hostingNode = new HostingNodeImpl();
Header header = new HeaderImpl(uuid);
hostingNode.setHeader(header);
hostingNode.setUUID(uuid);
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
try {

View File

@ -14,16 +14,16 @@ import java.util.UUID;
import org.gcube.common.encryption.encrypter.StringEncrypter;
import org.gcube.informationsystem.base.reference.Direction;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.impl.properties.VaultImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.DeleteConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.properties.Vault;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation;
@ -92,7 +92,7 @@ public class ERManagementTest extends ContextTest {
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
URL endpoint = new URL("https://d4science.org:443");
accessPointFacet.setEndpoint(endpoint.toURI());
Vault encrypted = new VaultImpl();
Encrypted encrypted = new EncryptedImpl();
encrypted.setValue(StringEncrypter.getEncrypter().encrypt("1"));
accessPointFacet.setAdditionalProperty(PASSWORD, encrypted);
eService.addFacet(accessPointFacet);
@ -100,8 +100,8 @@ public class ERManagementTest extends ContextTest {
ResourceRegistryPublisher resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
EService receivedEservice = resourceRegistryPublisher.create(eService);
AccessPointFacet receivedFacet = (AccessPointFacet) receivedEservice.getFacets().get(0);
UUID eServiceUUID = receivedEservice.getHeader().getUUID();
UUID facetUUID = receivedFacet.getHeader().getUUID();
UUID eServiceUUID = receivedEservice.getUUID();
UUID facetUUID = receivedFacet.getUUID();
logger.debug("Created {} : {}", EService.NAME, ElementMapper.marshal(receivedEservice));
@ -114,14 +114,14 @@ public class ERManagementTest extends ContextTest {
receivedEservice = resourceRegistryPublisher.read(receivedEservice);
logger.debug("Read {} : {}", EService.NAME, ElementMapper.marshal(receivedEservice));
}
UUID receivedEServiceUUID = receivedEservice.getHeader().getUUID();
UUID receivedEServiceUUID = receivedEservice.getUUID();
Assert.assertTrue(eServiceUUID.compareTo(receivedEServiceUUID)==0);
receivedFacet = (AccessPointFacet) receivedEservice.getFacets().get(0);
UUID receivedFacetUUID = receivedFacet.getHeader().getUUID();
UUID receivedFacetUUID = receivedFacet.getUUID();
Assert.assertTrue(facetUUID.compareTo(receivedFacetUUID)==0);
Vault receivedEncrypted = (Vault) receivedFacet.getAdditionalProperty(PASSWORD);
Encrypted receivedEncrypted = (Encrypted) receivedFacet.getAdditionalProperty(PASSWORD);
Assert.assertTrue(encrypted.getValue().compareTo(receivedEncrypted.getValue())==0);
} catch(ResourceRegistryException e) {
logger.error("", e);
@ -313,13 +313,13 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
UUID uuid = createdCpuFacet.getUUID();
CPUFacet readCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(readCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(readCpuFacet.getVendor()) == 0);
Assert.assertTrue(uuid.compareTo(readCpuFacet.getHeader().getUUID()) == 0);
Assert.assertTrue(uuid.compareTo(readCpuFacet.getUUID()) == 0);
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
@ -336,7 +336,7 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(readCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor()) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getUUID()) == 0);
CPUFacet readUpdatedCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid);
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(readUpdatedCpuFacet.getClockSpeed()) == 0);
@ -344,7 +344,7 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getUUID()) == 0);
boolean deleted = resourceRegistryPublisher.deleteFacet(readUpdatedCpuFacet);
Assert.assertTrue(deleted);
@ -423,7 +423,7 @@ public class ERManagementTest extends ContextTest {
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
Facet shared = hostingNode.getConsistsOf().get(0).getTarget();
UUID sharedFacetUUID = shared.getHeader().getUUID();
UUID sharedFacetUUID = shared.getUUID();
ConsistsOf<EService,Facet> consistsOf = new ConsistsOfImpl<EService,Facet>(eService, shared, null);
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
@ -459,7 +459,7 @@ public class ERManagementTest extends ContextTest {
null);
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
UUID consistOfUUID = consistsOf.getHeader().getUUID();
UUID consistOfUUID = consistsOf.getUUID();
boolean detached = resourceRegistryPublisher.deleteConsistsOf(consistsOf);
@ -550,23 +550,23 @@ public class ERManagementTest extends ContextTest {
Map<String,Resource> map = createHostingNodeAndEService();
EService eService = (EService) map.get(EService.NAME);
UUID eServiceUUID = eService.getHeader().getUUID();
UUID eServiceUUID = eService.getUUID();
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
UUID hostingNodeUUID = hostingNode.getHeader().getUUID();
UUID hostingNodeUUID = hostingNode.getUUID();
/* EService */
List<Resource> resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.BOTH, true);
Assert.assertTrue(resourceList.size() == 1);
Resource resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
Assert.assertTrue(resource.getUUID().compareTo(hostingNodeUUID) == 0);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.OUT, true);
Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
Assert.assertTrue(resource.getUUID().compareTo(hostingNodeUUID) == 0);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.IN, true);
@ -590,7 +590,7 @@ public class ERManagementTest extends ContextTest {
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.BOTH, true);
Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
Assert.assertTrue(resource.getUUID().compareTo(eServiceUUID) == 0);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.OUT, true);
@ -600,7 +600,7 @@ public class ERManagementTest extends ContextTest {
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.IN, true);
Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
Assert.assertTrue(resource.getUUID().compareTo(eServiceUUID) == 0);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.BOTH, false);
@ -616,8 +616,7 @@ public class ERManagementTest extends ContextTest {
/* END HostingNode */
Facet identificationFacet = eService.getIdentificationFacets().get(0);
UUID identificationFacetUUID = identificationFacet.getHeader().getUUID();
UUID identificationFacetUUID = identificationFacet.getUUID();
/* Eservice with Software Facet as Identification Facet */
@ -625,8 +624,8 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0);
Facet targetIdentificationFacet = ((GCubeResource) resource).getIdentificationFacets().get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID().compareTo(identificationFacetUUID) == 0);
Assert.assertTrue(resource.getUUID().compareTo(eServiceUUID) == 0);
Assert.assertTrue(targetIdentificationFacet.getUUID().compareTo(identificationFacetUUID) == 0);
resourceList = resourceRegistryClient.getResourcesFromReferenceFacet(Resource.class, ConsistsOf.class, SoftwareFacet.class, identificationFacetUUID, false);
Assert.assertTrue(resourceList.size() == 0);
@ -639,7 +638,7 @@ public class ERManagementTest extends ContextTest {
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);
Assert.assertTrue(facet.getHeader().getUUID().compareTo(identificationFacetUUID) == 0);
Assert.assertTrue(facet.getUUID().compareTo(identificationFacetUUID) == 0);
facets = resourceRegistryClient.getRelated(Facet.class, ConsistsOf.class, EService.class, eServiceUUID, Direction.in, false);
Assert.assertTrue(resourceList.size() == 0);

View File

@ -62,7 +62,7 @@ public class EntityManagementTest extends ContextTest {
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
UUID uuid = createdCpuFacet.getUUID();
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
@ -78,7 +78,7 @@ public class EntityManagementTest extends ContextTest {
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);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getUUID())==0);
boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet);
Assert.assertTrue(deleted);
@ -99,7 +99,7 @@ public class EntityManagementTest extends ContextTest {
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
UUID uuid = createdCpuFacet.getUUID();
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
@ -117,7 +117,7 @@ public class EntityManagementTest extends ContextTest {
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);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getUUID())==0);
boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet);
Assert.assertTrue(deleted);

View File

@ -168,8 +168,8 @@ public class MultiContextTest extends ContextTest {
ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE);
UUID hostingNodeUUID = createdHN.getHeader().getUUID();
UUID eServiceUUID = createdEService.getHeader().getUUID();
UUID hostingNodeUUID = createdHN.getUUID();
UUID eServiceUUID = createdEService.getUUID();
logger.debug("Changing token to test add to scope");
ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE);
@ -229,11 +229,11 @@ public class MultiContextTest extends ContextTest {
for(Context c : contexts) {
UUID uuid = c.getHeader().getUUID();
UUID uuid = c.getUUID();
if(c.getParent()!=null) {
IsParentOf isParentOf = c.getParent();
Context parentContext = isParentOf.getSource();
UUID parentUUID = parentContext.getHeader().getUUID();
UUID parentUUID = parentContext.getUUID();
Assert.assertEquals(parentContext, contextCache.getContextByUUID(parentUUID));
List<IsParentOf> children = parentContext.getChildren();
boolean found = false;
@ -244,9 +244,9 @@ public class MultiContextTest extends ContextTest {
}
}
Assert.assertTrue(found);
logger.debug("{} : {} (parent {} : {})", c.getHeader().getUUID(), contextCache.getContextFullNameByUUID(uuid), parentUUID, contextCache.getContextFullNameByUUID(parentUUID));
logger.debug("{} : {} (parent {} : {})", c.getUUID(), contextCache.getContextFullNameByUUID(uuid), parentUUID, contextCache.getContextFullNameByUUID(parentUUID));
}else {
logger.debug("{} : {}", c.getHeader().getUUID(), contextCache.getContextFullNameByUUID(uuid));
logger.debug("{} : {}", c.getUUID(), contextCache.getContextFullNameByUUID(uuid));
}
}
@ -254,7 +254,7 @@ public class MultiContextTest extends ContextTest {
logger.debug("Current context : {}", currentContext);
for(Context c : contexts) {
UUID uuid = c.getHeader().getUUID();
UUID uuid = c.getUUID();
Context context = resourceRegistryPublisher.getContext(uuid);
String fullName = ContextCache.getInstance().getContextFullNameByUUID(uuid);
logger.debug("{} - {} : {}", uuid, fullName, context);

View File

@ -68,7 +68,7 @@ public class RRClientTest extends ContextTest {
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
UUID uuid = createdCpuFacet.getUUID();
Facet f = resourceRegistryClient.getInstance(Facet.class, uuid);
Assert.assertTrue(f instanceof CPUFacet);
@ -115,12 +115,12 @@ public class RRClientTest extends ContextTest {
Assert.assertTrue(createdSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion())==0);
Resource resource = resourceRegistryClient.getInstance(Resource.class, createdEService.getHeader().getUUID());
Assert.assertTrue(resource.getHeader().getUUID().compareTo(createdEService.getHeader().getUUID())==0);
Resource resource = resourceRegistryClient.getInstance(Resource.class, createdEService.getUUID());
Assert.assertTrue(resource.getUUID().compareTo(createdEService.getUUID())==0);
Assert.assertTrue(resource instanceof EService);
EService readEService = resourceRegistryClient.getInstance(EService.class, createdEService.getHeader().getUUID());
Assert.assertTrue(readEService.getHeader().getUUID().compareTo(createdEService.getHeader().getUUID())==0);
EService readEService = resourceRegistryClient.getInstance(EService.class, createdEService.getUUID());
Assert.assertTrue(readEService.getUUID().compareTo(createdEService.getUUID())==0);
List<? extends Facet> idFacets = readEService.getIdentificationFacets();
Assert.assertTrue(idFacets!=null);
Assert.assertTrue(idFacets.size()==1);
@ -131,7 +131,7 @@ public class RRClientTest extends ContextTest {
Assert.assertTrue(readSoftwareFacet.getGroup().compareTo(softwareFacet.getGroup())==0);
Assert.assertTrue(readSoftwareFacet.getName().compareTo(softwareFacet.getName())==0);
Assert.assertTrue(readSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion())==0);
Assert.assertTrue(readSoftwareFacet.getHeader().getUUID().compareTo(createdSoftwareFacet.getHeader().getUUID())==0);
Assert.assertTrue(readSoftwareFacet.getUUID().compareTo(createdSoftwareFacet.getUUID())==0);
boolean deleted = resourceRegistryPublisher.deleteResource(createdEService);

View File

@ -32,10 +32,8 @@ import javax.management.ReflectionException;
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.publisher.ContextTest;
@ -43,6 +41,7 @@ import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPu
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherImpl;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.utils.UUIDManager;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl;
@ -99,8 +98,8 @@ public class SmartgearResourcesTest extends ContextTest {
logger.debug("Created : {}", hostingNode);
Assert.assertTrue(hostingNode!=null);
Assert.assertTrue(hostingNode.getHeader()!=null);
Assert.assertTrue(hostingNode.getHeader().getUUID()!=null);
Assert.assertTrue(hostingNode.getMetadata()!=null);
Assert.assertTrue(hostingNode.getUUID()!=null);
boolean deleted = resourceRegistryPublisher.deleteResource(hostingNode);
Assert.assertTrue(deleted);
@ -115,8 +114,8 @@ public class SmartgearResourcesTest extends ContextTest {
logger.debug("Created : {}", eService);
Assert.assertTrue(eService!=null);
Assert.assertTrue(eService.getHeader()!=null);
Assert.assertTrue(eService.getHeader().getUUID()!=null);
Assert.assertTrue(eService.getMetadata()!=null);
Assert.assertTrue(eService.getUUID()!=null);
boolean deleted = resourceRegistryPublisher.deleteResource(eService);
Assert.assertTrue(deleted);
@ -131,11 +130,10 @@ public class SmartgearResourcesTest extends ContextTest {
@Test
public void testHostingNodeOperations() throws ResourceRegistryException, IOException{
UUID uuid = UUID.randomUUID();
UUID uuid = UUIDManager.getInstance().generateValidRandomUUID();
HostingNode hostingNode = new HostingNodeImpl();
Header header = new HeaderImpl(uuid);
hostingNode.setHeader(header);
hostingNode.setUUID(uuid);
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
try {