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: ", "")));
}
}
}
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);
}
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");
}
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))));
}
}
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);
}
Aggregations