Porting code to redesigned E/R format

This commit is contained in:
Luca Frosini 2023-04-19 11:37:22 +02:00
parent cab174141a
commit cda204abcb
3 changed files with 33 additions and 34 deletions

View File

@ -13,8 +13,6 @@ import org.gcube.common.gxhttp.reference.GXConnection;
import org.gcube.common.gxhttp.request.GXHTTPStringRequest; import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
import org.gcube.common.http.GXHTTPUtility; import org.gcube.common.http.GXHTTPUtility;
import org.gcube.informationsystem.contexts.reference.entities.Context; import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache; import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal; import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
@ -24,6 +22,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.Cont
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath; import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility; import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
import org.gcube.informationsystem.serialization.ElementMapper; import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.utils.UUIDManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -119,12 +118,12 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
protected String internalCreate(Context context) throws ContextAlreadyPresentException, ResourceRegistryException { protected String internalCreate(Context context) throws ContextAlreadyPresentException, ResourceRegistryException {
try { try {
Header header = context.getHeader(); UUID uuid = context.getUUID();
if(header == null) { if(uuid == null) {
header = new HeaderImpl(UUID.randomUUID()); uuid = UUIDManager.getInstance().generateValidRandomUUID();
context.setHeader(header); context.setUUID(uuid);
} }
UUID uuid = context.getHeader().getUUID();
String contextString = ElementMapper.marshal(context); String contextString = ElementMapper.marshal(context);
@ -221,7 +220,7 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
@Override @Override
public Context read(Context context) throws ContextNotFoundException, ResourceRegistryException { public Context read(Context context) throws ContextNotFoundException, ResourceRegistryException {
return read(context.getHeader().getUUID()); return read(context.getUUID());
} }
@Override @Override
@ -235,7 +234,7 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
throw new RuntimeException(e); throw new RuntimeException(e);
} }
forceCacheRefresh(); forceCacheRefresh();
Context c = contextCache.getContextByUUID(context.getHeader().getUUID()); Context c = contextCache.getContextByUUID(context.getUUID());
if(c!=null){ if(c!=null){
context = c; context = c;
}else { }else {
@ -292,7 +291,7 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
String contextString = ElementMapper.marshal(context); String contextString = ElementMapper.marshal(context);
logger.trace("Going to update {}", contextString); logger.trace("Going to update {}", contextString);
UUID uuid = context.getHeader().getUUID(); UUID uuid = context.getUUID();
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest(); GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8); gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
@ -347,7 +346,7 @@ public class ResourceRegistryContextClientImpl implements ResourceRegistryContex
@Override @Override
public boolean delete(Context context) throws ContextNotFoundException, ResourceRegistryException { public boolean delete(Context context) throws ContextNotFoundException, ResourceRegistryException {
return delete(context.getHeader().getUUID()); return delete(context.getUUID());
} }
@Override @Override

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.KeycloakClientFactory;
import org.gcube.common.keycloak.model.TokenResponse; import org.gcube.common.keycloak.model.TokenResponse;
import org.gcube.common.scope.api.ScopeProvider; 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.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -117,7 +117,7 @@ public class ContextTest {
} }
public static String getUser() { public static String getUser() {
String user = Header.UNKNOWN_USER; String user = Metadata.UNKNOWN_USER;
try { try {
user = SecretManagerProvider.instance.get().getUser().getUsername(); user = SecretManagerProvider.instance.get().getUser().getUsername();
} catch(Exception e) { } catch(Exception e) {

View File

@ -40,32 +40,32 @@ public class ResourceRegistryContextClientTest extends ContextTest {
public static final String CTX_NAME_B = "B"; public static final String CTX_NAME_B = "B";
public static final String CTX_NAME_C = "C"; public static final String CTX_NAME_C = "C";
public static void checkHeader(IdentifiableElement er, UUID uuid, boolean create) { public static void checkUUIDAndMetadata(IdentifiableElement er, UUID uuid, boolean create) {
Assert.assertTrue(er.getHeader() != null); Assert.assertTrue(er.getMetadata() != null);
Assert.assertTrue(er.getHeader().getUUID() != null); Assert.assertTrue(er.getUUID() != null);
if(uuid != null) { if(uuid != null) {
Assert.assertTrue(er.getHeader().getUUID().compareTo(uuid) == 0); Assert.assertTrue(er.getUUID().compareTo(uuid) == 0);
} }
String user = getUser(); String user = getUser();
Assert.assertTrue(er.getHeader().getLastUpdateBy().compareTo(user) == 0); Assert.assertTrue(er.getMetadata().getLastUpdateBy().compareTo(user) == 0);
if(create) { if(create) {
Assert.assertTrue(er.getHeader().getCreatedBy().compareTo(user) == 0); Assert.assertTrue(er.getMetadata().getCreatedBy().compareTo(user) == 0);
Assert.assertTrue(er.getHeader().getCreationTime().compareTo(er.getHeader().getLastUpdateTime()) == 0); Assert.assertTrue(er.getMetadata().getCreationTime().compareTo(er.getMetadata().getLastUpdateTime()) == 0);
} else { } else {
Assert.assertTrue(er.getHeader().getCreationTime().before(er.getHeader().getLastUpdateTime())); Assert.assertTrue(er.getMetadata().getCreationTime().before(er.getMetadata().getLastUpdateTime()));
} }
} }
protected void assertions(Context pre, Context post, boolean checkParent, boolean create) { protected void assertions(Context pre, Context post, boolean checkParent, boolean create) {
if(checkParent) { if(checkParent) {
if(pre.getHeader() != null) { if(pre.getMetadata() != null) {
checkHeader(post, pre.getHeader().getUUID(), create); checkUUIDAndMetadata(post, pre.getUUID(), create);
} else { } else {
checkHeader(post, null, create); checkUUIDAndMetadata(post, null, create);
} }
} }
@ -79,9 +79,9 @@ public class ResourceRegistryContextClientTest extends ContextTest {
protected Context read(UUID uuid) throws ResourceRegistryException, IOException { protected Context read(UUID uuid) throws ResourceRegistryException, IOException {
Context c = resourceRegistryContextClient.read(uuid); Context c = resourceRegistryContextClient.read(uuid);
Assert.assertTrue(c.getHeader() != null); Assert.assertTrue(c.getMetadata() != null);
Assert.assertTrue(c.getHeader().getUUID() != null); Assert.assertTrue(c.getUUID() != null);
Assert.assertTrue(c.getHeader().getUUID().compareTo(uuid) == 0); Assert.assertTrue(c.getUUID().compareTo(uuid) == 0);
return c; return c;
} }
@ -105,7 +105,7 @@ public class ResourceRegistryContextClientTest extends ContextTest {
} }
protected boolean delete(Context context) throws ResourceRegistryException { protected boolean delete(Context context) throws ResourceRegistryException {
return delete(context.getHeader().getUUID()); return delete(context.getUUID());
} }
protected void invalidCreate(Context context) throws ResourceRegistryException, IOException { protected void invalidCreate(Context context) throws ResourceRegistryException, IOException {
@ -317,7 +317,7 @@ public class ResourceRegistryContextClientTest extends ContextTest {
delete(contextA5); delete(contextA5);
} catch(ContextNotFoundException e) { } catch(ContextNotFoundException e) {
logger.debug("The context with uuid {} was not found. (Was already deleted)", logger.debug("The context with uuid {} was not found. (Was already deleted)",
contextA5.getHeader().getUUID()); contextA5.getUUID());
} }
delete(contextB3); delete(contextB3);
@ -441,11 +441,11 @@ public class ResourceRegistryContextClientTest extends ContextTest {
for(Context c : contexts) { for(Context c : contexts) {
UUID uuid = c.getHeader().getUUID(); UUID uuid = c.getUUID();
if(c.getParent()!=null) { if(c.getParent()!=null) {
IsParentOf isParentOf = c.getParent(); IsParentOf isParentOf = c.getParent();
Context parentContext = isParentOf.getSource(); Context parentContext = isParentOf.getSource();
UUID parentUUID = parentContext.getHeader().getUUID(); UUID parentUUID = parentContext.getUUID();
Assert.assertEquals(parentContext, contextCache.getContextByUUID(parentUUID)); Assert.assertEquals(parentContext, contextCache.getContextByUUID(parentUUID));
List<IsParentOf> children = parentContext.getChildren(); List<IsParentOf> children = parentContext.getChildren();
boolean found = false; boolean found = false;
@ -456,9 +456,9 @@ public class ResourceRegistryContextClientTest extends ContextTest {
} }
} }
Assert.assertTrue(found); 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 { }else {
logger.debug("{} : {}", c.getHeader().getUUID(), contextCache.getContextFullNameByUUID(uuid)); logger.debug("{} : {}", c.getUUID(), contextCache.getContextFullNameByUUID(uuid));
} }
} }
@ -466,7 +466,7 @@ public class ResourceRegistryContextClientTest extends ContextTest {
logger.debug("Current context : {}", currentContext); logger.debug("Current context : {}", currentContext);
for(Context c : contexts) { for(Context c : contexts) {
UUID uuid = c.getHeader().getUUID(); UUID uuid = c.getUUID();
Context context = resourceRegistryContextClient.read(uuid); Context context = resourceRegistryContextClient.read(uuid);
String fullName = ContextCache.getInstance().getContextFullNameByUUID(uuid); String fullName = ContextCache.getInstance().getContextFullNameByUUID(uuid);
logger.debug("{} - {} : {}", uuid, fullName, context); logger.debug("{} - {} : {}", uuid, fullName, context);