Search in sources :

Example 1 with EntityToPureConverter

use of org.finos.legend.sdlc.protocol.pure.v1.EntityToPureConverter in project legend-sdlc by finos.

the class ServicesGenerationMojo method resolveServicesSpecification.

private static ResolvedServicesSpecification resolveServicesSpecification(ServicesSpecification servicesSpec) throws Exception {
    Set<String> servicePaths = null;
    if (servicesSpec.directories != null) {
        try (EntityLoader directoriesLoader = EntityLoader.newEntityLoader(servicesSpec.directories)) {
            EntityToPureConverter converter = new EntityToPureConverter();
            servicePaths = directoriesLoader.getAllEntities().filter(e -> converter.fromEntityIfPossible(e).filter(s -> s instanceof Service).isPresent()).map(Entity::getPath).collect(Collectors.toSet());
        }
    }
    if (servicesSpec.servicePaths != null) {
        if (servicePaths == null) {
            servicePaths = servicesSpec.servicePaths;
        } else {
            servicePaths.addAll(servicesSpec.servicePaths);
        }
    }
    return new ResolvedServicesSpecification(servicePaths, servicesSpec.packages);
}
Also used : Arrays(java.util.Arrays) PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) Lists(org.eclipse.collections.api.factory.Lists) Parameter(org.apache.maven.plugins.annotations.Parameter) MutableList(org.eclipse.collections.api.list.MutableList) EntityToPureConverter(org.finos.legend.sdlc.protocol.pure.v1.EntityToPureConverter) ArrayList(java.util.ArrayList) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) Mojo(org.apache.maven.plugins.annotations.Mojo) RichIterable(org.eclipse.collections.api.RichIterable) EntityLoader(org.finos.legend.sdlc.serialization.EntityLoader) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Entity(org.finos.legend.sdlc.domain.model.entity.Entity) Map(java.util.Map) LifecyclePhase(org.apache.maven.plugins.annotations.LifecyclePhase) PlanTransformer(org.finos.legend.engine.plan.generation.transformers.PlanTransformer) PureModelBuilder(org.finos.legend.sdlc.language.pure.compiler.toPureGraph.PureModelBuilder) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) StreamWriteFeature(com.fasterxml.jackson.core.StreamWriteFeature) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) StreamReadFeature(com.fasterxml.jackson.core.StreamReadFeature) JsonMapper(com.fasterxml.jackson.databind.json.JsonMapper) Collectors(java.util.stream.Collectors) Root_meta_pure_router_extension_RouterExtension(org.finos.legend.pure.generated.Root_meta_pure_router_extension_RouterExtension) File(java.io.File) SourceVersion(javax.lang.model.SourceVersion) List(java.util.List) Service(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) PureProtocolObjectMapperFactory(org.finos.legend.engine.protocol.pure.v1.PureProtocolObjectMapperFactory) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) Comparator(java.util.Comparator) AbstractMojo(org.apache.maven.plugin.AbstractMojo) PlanGeneratorExtension(org.finos.legend.engine.plan.generation.extension.PlanGeneratorExtension) Entity(org.finos.legend.sdlc.domain.model.entity.Entity) EntityLoader(org.finos.legend.sdlc.serialization.EntityLoader) EntityToPureConverter(org.finos.legend.sdlc.protocol.pure.v1.EntityToPureConverter) Service(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service)

Example 2 with EntityToPureConverter

use of org.finos.legend.sdlc.protocol.pure.v1.EntityToPureConverter in project legend-sdlc by finos.

the class LegendSDLCTestSuiteBuilder method buildSuite.

public TestSuite buildSuite(String name, Collection<? extends Entity> entitiesForTesting, ClassLoader classLoader) {
    Map<Class<? extends PackageableElement>, TestSuiteBuilder> testSuiteBuilders = getTestSuiteBuilderByTypeMap(MappingTestCase.class, ServiceTestCase.class);
    TestSuite suite = new TestSuite();
    suite.setName(name);
    Set<String> entitiesForTestingPaths = entitiesForTesting.stream().map(Entity::getPath).collect(Collectors.toSet());
    PureModelContextData pureModelContextData;
    PureModel pureModel;
    try (EntityLoader entityLoader = EntityLoader.newEntityLoader((classLoader == null) ? LegendSDLCTestSuiteBuilder.class.getClassLoader() : classLoader)) {
        PureModelBuilder.PureModelWithContextData pureModelWithContextData = PureModelBuilder.newBuilder().withEntitiesIfPossible(entitiesForTesting).withEntitiesIfPossible(entityLoader.getAllEntities().filter(e -> !entitiesForTestingPaths.contains(e.getPath()))).build(classLoader);
        pureModelContextData = pureModelWithContextData.getPureModelContextData();
        pureModel = pureModelWithContextData.getPureModel();
    } catch (Exception e) {
        LOGGER.error("Error loading entities", e);
        throw (e instanceof RuntimeException) ? (RuntimeException) e : new RuntimeException("Error loading entities", e);
    }
    EntityToPureConverter converter = new EntityToPureConverter();
    entitiesForTesting.stream().map(e -> {
        Optional<TestSuiteBuilder> optionalBuilder = converter.fromEntityIfPossible(e).map(element -> testSuiteBuilders.get(element.getClass()));
        if (!optionalBuilder.isPresent()) {
            return null;
        }
        TestSuiteBuilder builder = optionalBuilder.get();
        LOGGER.debug("Building test suite for {} (classifier: {})", e.getPath(), e.getClassifierPath());
        TestSuite eSuite = builder.build(pureModel, pureModelContextData, e);
        LOGGER.debug("Test count for {}: {}", e.getPath(), (eSuite == null) ? 0 : eSuite.testCount());
        return eSuite;
    }).filter(Objects::nonNull).forEach(suite::addTest);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Entity test suite count: {}", suite.testCount());
        LOGGER.debug("Entity test case count: {}", suite.countTestCases());
    }
    return suite;
}
Also used : PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) EntityLoader(org.finos.legend.sdlc.serialization.EntityLoader) EntityToPureConverter(org.finos.legend.sdlc.protocol.pure.v1.EntityToPureConverter) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) TestSuite(junit.framework.TestSuite) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) PureModelBuilder(org.finos.legend.sdlc.language.pure.compiler.toPureGraph.PureModelBuilder)

Aggregations

PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)2 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)2 PackageableElement (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement)2 PureModelBuilder (org.finos.legend.sdlc.language.pure.compiler.toPureGraph.PureModelBuilder)2 EntityToPureConverter (org.finos.legend.sdlc.protocol.pure.v1.EntityToPureConverter)2 EntityLoader (org.finos.legend.sdlc.serialization.EntityLoader)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 StreamReadFeature (com.fasterxml.jackson.core.StreamReadFeature)1 StreamWriteFeature (com.fasterxml.jackson.core.StreamWriteFeature)1 MapperFeature (com.fasterxml.jackson.databind.MapperFeature)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 JsonMapper (com.fasterxml.jackson.databind.json.JsonMapper)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 ServiceLoader (java.util.ServiceLoader)1 Set (java.util.Set)1