Search in sources :

Example 1 with Service

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service in project legend-sdlc by finos.

the class ServicesGenerationMojo method filterServicesByIncludes.

private void filterServicesByIncludes(Map<String, Service> servicesByPath) throws MojoExecutionException {
    if (this.inclusions != null) {
        ResolvedServicesSpecification resolvedIncluded;
        try {
            resolvedIncluded = resolveServicesSpecification(this.inclusions);
        } catch (Exception e) {
            throw new MojoExecutionException("Error resolving included services", e);
        }
        servicesByPath.keySet().removeIf(resolvedIncluded::notMatches);
        if ((resolvedIncluded.servicePaths != null) && resolvedIncluded.servicePaths.stream().anyMatch(p -> !servicesByPath.containsKey(p))) {
            throw new MojoExecutionException(resolvedIncluded.servicePaths.stream().filter(p -> !servicesByPath.containsKey(p)).sorted().collect(Collectors.joining(", ", "Could not find included services: ", "")));
        }
    }
}
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) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 2 with Service

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service 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 3 with Service

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service in project legend-sdlc by finos.

the class TestServiceExecutionGenerator method testSimpleRelational.

@Test
public void testSimpleRelational() throws Exception {
    String packagePrefix = "org.finos";
    Service service = getService("service::RelationalService");
    ClassLoader classLoader = generateAndCompile(packagePrefix, service);
    assertExecuteMethods(classLoader, "org.finos.service.RelationalService");
}
Also used : Service(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service) URLClassLoader(java.net.URLClassLoader) Test(org.junit.Test)

Example 4 with Service

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service in project legend-sdlc by finos.

the class TestServiceExecutionGenerator method testServiceExecutionUsingServiceRunnerAPI.

@Test
public void testServiceExecutionUsingServiceRunnerAPI() throws Exception {
    ClassLoader classLoader = generateAndCompile("org.finos", getAllServices());
    try (JavaHelper.ThreadContextClassLoaderScope ignored = JavaHelper.withCurrentThreadContextClassLoader(classLoader)) {
        // No Param Model To Model Service
        ServiceRunner noParamServiceRunner = findServiceRunnerByPath("service::ModelToModelService");
        assertServiceVariables(noParamServiceRunner);
        IllegalArgumentException e = Assert.assertThrows(IllegalArgumentException.class, () -> noParamServiceRunner.run(ServiceRunnerInput.newInstance().withArgs(Collections.singletonList("a"))));
        Assert.assertEquals("Unexpected number of parameters. Expected parameter size: 0, Passed parameter size: 1", e.getMessage());
        String expectedOutput = "{\"builder\":{\"_type\":\"json\"},\"values\":{\"defects\":[],\"source\":{\"defects\":[],\"source\":{\"number\":1,\"record\":\"{\\\"firstName\\\":\\\"firstName 73\\\",\\\"lastName\\\":\\\"lastName 79\\\",\\\"age\\\":27}\"}," + "\"value\":{\"age\":27,\"firstName\":\"firstName 73\",\"lastName\":\"lastName 79\"}},\"value\":{\"age\":27,\"fullName\":\"firstName 73 lastName 79\"}}}";
        Assert.assertEquals(OBJECT_MAPPER.readTree(expectedOutput), OBJECT_MAPPER.readTree(noParamServiceRunner.run(ServiceRunnerInput.newInstance())));
        // Multi Param Model To Model Service
        ServiceRunner multiParamServiceRunner = findServiceRunnerByPath("service::ModelToModelServiceWithMultipleParams");
        assertServiceVariables(multiParamServiceRunner, new ServiceVariable("i_s", String.class, new Multiplicity(1, 1)), new ServiceVariable("i_i", Long.class, new Multiplicity(1, 1)), new ServiceVariable("i_f", Double.class, new Multiplicity(1, 1)), new ServiceVariable("i_dec", BigDecimal.class, new Multiplicity(1, 1)), new ServiceVariable("i_b", Boolean.class, new Multiplicity(1, 1)), new ServiceVariable("i_sd", LocalDate.class, new Multiplicity(1, 1)), new ServiceVariable("i_dt", ZonedDateTime.class, new Multiplicity(1, 1)), new ServiceVariable("i_d", Temporal.class, new Multiplicity(1, 1)), new ServiceVariable("i_oi", Long.class, new Multiplicity(0, 1)), new ServiceVariable("i_li", Long.class, new Multiplicity(0, null)));
        IllegalArgumentException e1 = Assert.assertThrows(IllegalArgumentException.class, () -> multiParamServiceRunner.run(ServiceRunnerInput.newInstance()));
        Assert.assertEquals("Unexpected number of parameters. Expected parameter size: 10, Passed parameter size: 0", e1.getMessage());
        IllegalArgumentException e2 = Assert.assertThrows(IllegalArgumentException.class, () -> multiParamServiceRunner.run(ServiceRunnerInput.newInstance().withArgs(Arrays.asList("1", 2, 3.0))));
        Assert.assertEquals("Unexpected number of parameters. Expected parameter size: 10, Passed parameter size: 3", e2.getMessage());
        List<Object> args1 = Arrays.asList(1, 2, 3.0, new BigDecimal("4.0"), true, LocalDate.now(), ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("UTC")), LocalDateTime.now(), 5, Arrays.asList(6, 7));
        IllegalArgumentException e3 = Assert.assertThrows(IllegalArgumentException.class, () -> multiParamServiceRunner.run(ServiceRunnerInput.newInstance().withArgs(args1)));
        Assert.assertEquals("Invalid provided parameter(s): [Unable to process 'String' parameter, value: 1.]", e3.getMessage());
        List<Object> args2 = Arrays.asList("1", null, 3.0, new BigDecimal("4.0"), true, LocalDate.now(), ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("UTC")), LocalDateTime.now(), 5, Arrays.asList(6, 7));
        IllegalArgumentException e4 = Assert.assertThrows(IllegalArgumentException.class, () -> multiParamServiceRunner.run(ServiceRunnerInput.newInstance().withArgs(args2)));
        Assert.assertEquals("Missing external parameter(s): i_i:Integer[1]", e4.getMessage());
        List<Object> arg3 = Arrays.asList("1", 2, 3.0, new BigDecimal("4.0"), true, LocalDate.now(), ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("UTC")), LocalDateTime.now(), 5, Arrays.asList(1, "hello"));
        IllegalArgumentException e5 = Assert.assertThrows(IllegalArgumentException.class, () -> multiParamServiceRunner.run(ServiceRunnerInput.newInstance().withArgs(arg3).withSerializationFormat(SerializationFormat.PURE)));
        Assert.assertEquals("Invalid provided parameter(s): [Unable to process 'Integer' parameter, value: 'hello' is not parsable.]", e5.getMessage());
        JsonNode expected = OBJECT_MAPPER.readTree("[{\"age\":22,\"fullName\":\"Peter Smith\"},{\"age\":23,\"fullName\":\"John Johnson\"}]");
        Assert.assertEquals(expected, OBJECT_MAPPER.readTree(multiParamServiceRunner.run(ServiceRunnerInput.newInstance().withArgs(Arrays.asList("1", 2, 3.0, new BigDecimal("4.0"), true, LocalDate.now(), ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("UTC")), LocalDateTime.now(), 5, Arrays.asList(6, 7))).withSerializationFormat(SerializationFormat.PURE))));
        Assert.assertEquals(expected, OBJECT_MAPPER.readTree(multiParamServiceRunner.run(ServiceRunnerInput.newInstance().withArgs(Arrays.asList("1", 2L, 3.0D, new BigDecimal("4.0"), true, LocalDate.now(), ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("UTC")), LocalDateTime.now(), null, Arrays.asList(6, 7))).withSerializationFormat(SerializationFormat.PURE))));
        Assert.assertEquals(expected, OBJECT_MAPPER.readTree(multiParamServiceRunner.run(ServiceRunnerInput.newInstance().withArgs(Arrays.asList("1", 2L, 3.0f, new BigDecimal("4.0"), true, LocalDate.now(), ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("UTC")), LocalDateTime.now(), null, Arrays.asList(6, 7))).withSerializationFormat(SerializationFormat.PURE))));
        int x = 2;
        float y = 2.0f;
        Assert.assertEquals(expected, OBJECT_MAPPER.readTree(multiParamServiceRunner.run(ServiceRunnerInput.newInstance().withArgs(Arrays.asList("1", x, y, new BigDecimal("4.0"), true, LocalDate.now(), ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("UTC")), LocalDateTime.now(), null, Arrays.asList(6, 7))).withSerializationFormat(SerializationFormat.PURE))));
        Assert.assertEquals(expected, OBJECT_MAPPER.readTree(multiParamServiceRunner.run(ServiceRunnerInput.newInstance().withArgs(Arrays.asList("1", x, x, new BigDecimal("4.0"), true, LocalDate.now(), ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("UTC")), LocalDateTime.now(), null, 7)).withSerializationFormat(SerializationFormat.PURE))));
        Assert.assertEquals(expected, OBJECT_MAPPER.readTree(multiParamServiceRunner.run(ServiceRunnerInput.newInstance().withArgs(Arrays.asList("1", x, x, new BigDecimal("4.0"), true, LocalDate.now(), ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("UTC")), LocalDateTime.now(), null, null)).withSerializationFormat(SerializationFormat.PURE))));
    }
}
Also used : ServiceVariable(org.finos.legend.engine.language.pure.dsl.service.execution.ServiceVariable) JsonNode(com.fasterxml.jackson.databind.JsonNode) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Temporal(java.time.temporal.Temporal) ServiceRunner(org.finos.legend.engine.language.pure.dsl.service.execution.ServiceRunner) ZonedDateTime(java.time.ZonedDateTime) Multiplicity(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity) URLClassLoader(java.net.URLClassLoader) SimpleJavaFileObject(javax.tools.SimpleJavaFileObject) JavaFileObject(javax.tools.JavaFileObject) JavaHelper(org.finos.legend.engine.plan.execution.nodes.helpers.platform.JavaHelper) Test(org.junit.Test)

Example 5 with Service

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service in project legend-sdlc by finos.

the class TestServiceExecutionGenerator method testSimpleMultiService.

@Test
public void testSimpleMultiService() throws Exception {
    String packagePrefix = "org.finos";
    Service service = getService("service::ModelToModelServiceMulti");
    ClassLoader classLoader = generateAndCompile(packagePrefix, service);
    assertExecuteMethods(classLoader, "org.finos.service.ModelToModelServiceMulti", String.class);
}
Also used : Service(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service) URLClassLoader(java.net.URLClassLoader) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)55 SingleExecutionPlan (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan)45 Service (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service)24 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)22 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)18 Scope (io.opentracing.Scope)16 List (java.util.List)15 CommonProfile (org.pac4j.core.profile.CommonProfile)15 ApiOperation (io.swagger.annotations.ApiOperation)13 MutableList (org.eclipse.collections.api.list.MutableList)13 RichIterable (org.eclipse.collections.api.RichIterable)11 Map (java.util.Map)10 ListIterate (org.eclipse.collections.impl.utility.ListIterate)9 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)9 URLClassLoader (java.net.URLClassLoader)8 ServiceLoader (java.util.ServiceLoader)8 PureSingleExecution (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution)8 Consumes (javax.ws.rs.Consumes)7 POST (javax.ws.rs.POST)7 Path (javax.ws.rs.Path)7