infrastructure-tests/src/test/java/org/gcube/resourceregistry/ContextCreator.java

54 lines
1.4 KiB
Java

package org.gcube.resourceregistry;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.context.ContextElaborator;
import org.gcube.informationsystem.impl.utils.ISMapper;
import org.gcube.informationsystem.model.entity.Context;
import org.gcube.informationsystem.resourceregistry.context.ContextManagement;
import org.gcube.informationsystem.resourceregistry.context.ContextManagementImpl;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ContextCreator extends ContextElaborator {
protected Map<String, UUID> contexts;
protected ContextManagement contextManagement;
public ContextCreator() {
super();
contexts = new HashMap<>();
contextManagement = new ContextManagementImpl();
}
@Override
protected void elaborateContext(ScopeBean scopeBean) throws Exception {
UUID parentUUID = null;
switch(scopeBean.type()) {
case INFRASTRUCTURE:
parentUUID = null;
break;
default:
parentUUID = getParentUUID(scopeBean);
break;
}
String created = contextManagement.create(parentUUID, scopeBean.name());
Context context = ISMapper.unmarshal(Context.class, created);
contexts.put(scopeBean.toString(), context.getHeader().getUUID());
}
private UUID getParentUUID(ScopeBean scopeBean) {
String parent = scopeBean.toString().replace("/" + scopeBean.name(), "");
return contexts.get(parent);
}
}