Skip to content

Commit

Permalink
Serialize the data as found on entities rather than read it into prot…
Browse files Browse the repository at this point in the history
…ocol classes
  • Loading branch information
rafaelbey committed Dec 13, 2024
1 parent 6f650e6 commit 900483d
Showing 1 changed file with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -76,7 +80,7 @@ public PureModelContextData getPureModelContextData(String groupId, String artif
public PureModelContextData getPureModelContextData(List<ProjectVersion> projectDependencies, String clientVersion, boolean transitive)
{
String resolvedClientVersion = resolveAndValidateClientVersion(clientVersion);
List<ProjectVersionEntities> dependenciesEntities = (List<ProjectVersionEntities>) entitiesService.getDependenciesEntities(projectDependencies, transitive, true);
List<ProjectVersionEntities> dependenciesEntities = entitiesService.getDependenciesEntities(projectDependencies, transitive, true);
return buildPureModelContextData(dependenciesEntities.stream().flatMap(dep -> dep.getEntities().stream()), new AlloySDLC(), resolvedClientVersion);
}

Expand Down Expand Up @@ -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<PackageableElement> 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<EntityToRawPureConverter.EntityPackageableElement, Map<String, ?>>
{
@Override
public Map<String, ?> convert(EntityToRawPureConverter.EntityPackageableElement value)
{
return value.entity.getContent();
}
}
}

0 comments on commit 900483d

Please sign in to comment.