From 900483d111bc8390d9477e97f7aced87f4d1bef8 Mon Sep 17 00:00:00 2001 From: Rafael Bey Date: Fri, 13 Dec 2024 10:59:44 -0500 Subject: [PATCH] Serialize the data as found on entities rather than read it into protocol classes --- .../context/PureModelContextServiceImpl.java | 59 +++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/legend-depot-pure-model-context/src/main/java/org/finos/legend/depot/services/pure/model/context/PureModelContextServiceImpl.java b/legend-depot-pure-model-context/src/main/java/org/finos/legend/depot/services/pure/model/context/PureModelContextServiceImpl.java index ef38ba297..6950085a7 100644 --- a/legend-depot-pure-model-context/src/main/java/org/finos/legend/depot/services/pure/model/context/PureModelContextServiceImpl.java +++ b/legend-depot-pure-model-context/src/main/java/org/finos/legend/depot/services/pure/model/context/PureModelContextServiceImpl.java @@ -15,6 +15,14 @@ package org.finos.legend.depot.services.pure.model.context; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.util.StdConverter; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Stream; +import javax.inject.Inject; import org.finos.legend.depot.core.services.tracing.TracerFactory; import org.finos.legend.depot.domain.entity.ProjectVersionEntities; import org.finos.legend.depot.domain.project.ProjectVersion; @@ -24,27 +32,23 @@ import org.finos.legend.engine.protocol.pure.PureClientVersions; import org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC; import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; +import static org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData.newBuilder; +import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement; import org.finos.legend.sdlc.domain.model.entity.Entity; +import org.finos.legend.sdlc.protocol.pure.v1.EntityToPureConverter; import org.finos.legend.sdlc.protocol.pure.v1.PureModelContextDataBuilder; -import javax.inject.Inject; -import java.util.List; -import java.util.Objects; -import java.util.stream.Stream; - -import static org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData.newBuilder; - public class PureModelContextServiceImpl implements PureModelContextService { private static final String PURE = "pure"; private static final String CALCULATE_COMBINED_PMCD = "calculate combined PMCD"; private static final String GA_SEPARATOR = ":"; private static final TracerFactory tracer = TracerFactory.get(); - private final EntitiesService entitiesService; + private final EntitiesService entitiesService; private final ProjectsService projectsService; @Inject - public PureModelContextServiceImpl(EntitiesService entitiesService, ProjectsService projectsService) + public PureModelContextServiceImpl(EntitiesService entitiesService, ProjectsService projectsService) { this.entitiesService = entitiesService; this.projectsService = projectsService; @@ -76,7 +80,7 @@ public PureModelContextData getPureModelContextData(String groupId, String artif public PureModelContextData getPureModelContextData(List projectDependencies, String clientVersion, boolean transitive) { String resolvedClientVersion = resolveAndValidateClientVersion(clientVersion); - List dependenciesEntities = (List) entitiesService.getDependenciesEntities(projectDependencies, transitive, true); + List dependenciesEntities = entitiesService.getDependenciesEntities(projectDependencies, transitive, true); return buildPureModelContextData(dependenciesEntities.stream().flatMap(dep -> dep.getEntities().stream()), new AlloySDLC(), resolvedClientVersion); } @@ -119,4 +123,39 @@ protected AlloySDLC buildAlloySDLC(String groupId, String artifactId, String ver sdlc.baseVersion = versionId; return sdlc; } + + private static class EntityToRawPureConverter extends EntityToPureConverter + { + @Override + public PackageableElement fromEntity(Entity entity) + { + return new EntityPackageableElement(entity); + } + + @Override + public Optional fromEntityIfPossible(Entity entity) + { + return Optional.of(this.fromEntity(entity)); + } + + @JsonSerialize(converter = EntityPackageableElementConverter.class) + private static class EntityPackageableElement extends PackageableElement + { + private final Entity entity; + + public EntityPackageableElement(Entity entity) + { + this.entity = entity; + } + } + } + + private static final class EntityPackageableElementConverter extends StdConverter> + { + @Override + public Map convert(EntityToRawPureConverter.EntityPackageableElement value) + { + return value.entity.getContent(); + } + } }