Migrated context creation to new version of APIs which provides uuids

This commit is contained in:
Luca Frosini 2019-11-15 11:56:53 +01:00
parent a4ee7d0812
commit 44f3d2d84c
2 changed files with 41 additions and 2 deletions

View File

@ -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 {

View File

@ -14,5 +14,4 @@ public class ContextManagementTest extends ContextTest {
contextCreator.all();
}
}