diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/context/ContextCreator.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/context/ContextCreator.java index 1e90597..d50d6bf 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/context/ContextCreator.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/context/ContextCreator.java @@ -12,9 +12,9 @@ import org.gcube.informationsystem.context.reference.entities.Context; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException; -import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility; import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement; import org.gcube.informationsystem.utils.ISMapper; +import org.gcube.resourcemanagement.support.shared.types.datamodel.D4SEnvironment; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,6 +58,46 @@ public class ContextCreator extends ContextElaborator { return null; } + protected void elaborateContext(D4SEnvironment d4sEnvironment) throws Exception { + UUID uuid = null; + ScopeBean scopeBean = d4sEnvironment.getContext(); + + UUID oldISResourceUUID = null; + try { + oldISResourceUUID = UUID.fromString(d4sEnvironment.getUuid()); + } catch (Exception e) { + + } + try { + uuid = getContextUUID(scopeBean); + }catch (ContextNotFoundException e) { + // The context has to be created + logger.info("{} not found", scopeBean.toString()); + } + if(uuid==null) { + logger.info("Parent Context of {} is {}", scopeBean, scopeBean.enclosingScope()); + UUID parentUUID = getContextUUID(scopeBean.enclosingScope()); + Context context; + if(oldISResourceUUID==null) { + context = new ContextImpl(scopeBean.name()); + }else { + context = new ContextImpl(scopeBean.name(), oldISResourceUUID); + } + if(parentUUID!=null) { + context.setParent(parentUUID); + } + context = create(context); + contexts.put(scopeBean.toString(), context.getHeader().getUUID()); + }else { + logger.info("Context {} is already present with UUID {}", scopeBean, uuid.toString()); + if(oldISResourceUUID==null || uuid.compareTo(oldISResourceUUID)!=0) { + String warn = "Context " + scopeBean.toString() + " has in Resource Registry UUID " + uuid.toString() + " which does not match with UUID " + oldISResourceUUID + " of the resource in the OLD Information System"; + logger.warn(warn); + } + } + + } + @Override protected void elaborateContext(ScopeBean scopeBean) throws Exception { diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java index f5cd31f..a1a898e 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java @@ -14,5 +14,4 @@ public class ContextManagementTest extends ContextTest { contextCreator.all(); } - }