Added support to specify Context implementation to GCubeContext

This commit is contained in:
Luca Frosini 2024-07-01 17:43:30 +02:00
parent 2d5c9247cc
commit e8ade3d3ea
2 changed files with 17 additions and 0 deletions

View File

@ -4,7 +4,11 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.discovery.RegistrationProvider;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.resourcemanagement.contexts.impl.entities.GCubeContext;
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
@ -18,8 +22,17 @@ public class GCubeModelRegistrationProvider implements RegistrationProvider {
public static final String GCUBE_MODEL_NAME = "gCube Model";
public <E extends Element, EImpl extends E> void registerContextOverride() {
@SuppressWarnings("unchecked")
Class<E> clz = (Class<E>) Context.class;
@SuppressWarnings("unchecked")
Class<EImpl> implClz = (Class<EImpl>) GCubeContext.class;
ElementMapper.addDynamicAssociation(clz, implClz);
}
@Override
public Collection<Package> getPackagesToRegister() {
registerContextOverride();
Set<Package> packages = new HashSet<>();
packages.add(ValueSchema.class.getPackage());
packages.add(SoftwareFacet.class.getPackage());

View File

@ -124,6 +124,10 @@ public class PolymorphismTest {
Context c = new ContextImpl("test");
c.setID(UUID.randomUUID());
c.setState("created");
String s = c.toString();
logger.debug(s);
c = ElementMapper.unmarshal(Context.class, s);
logger.debug(c.toString());
GCubeContext gcubeContext = new GCubeContext(c);