use of org.finos.legend.sdlc.domain.model.entity.Entity in project legend-sdlc by finos.
the class ModelGenerationMojo method serializePureModelContextData.
private void serializePureModelContextData(PureModelContextData pureModelContextData) throws Exception {
PureToEntityConverter converter = new PureToEntityConverter();
List<Entity> entities = ListIterate.collect(pureModelContextData.getAllElements(), converter::toEntity);
this.serializeEntities(entities);
}
use of org.finos.legend.sdlc.domain.model.entity.Entity in project legend-sdlc by finos.
the class ModelGenerationMojo method serializeEntities.
private void serializeEntities(List<Entity> entities) throws IOException {
long serializeStart = System.nanoTime();
getLog().info(String.format("Serializing %,d entities to %s", entities.size(), this.outputDirectory));
Path outputDirPath = this.outputDirectory.toPath();
Path entitiesDir = outputDirPath.resolve("entities");
Pattern pkgSepPattern = Pattern.compile("::", Pattern.LITERAL);
String replacement = Matcher.quoteReplacement(outputDirPath.getFileSystem().getSeparator());
EntitySerializer entitySerializer = EntitySerializers.getDefaultJsonSerializer();
for (Entity entity : entities) {
Path entityFilePath = entitiesDir.resolve(pkgSepPattern.matcher(entity.getPath()).replaceAll(replacement) + "." + entitySerializer.getDefaultFileExtension());
Files.createDirectories(entityFilePath.getParent());
try (OutputStream stream = Files.newOutputStream(entityFilePath)) {
entitySerializer.serialize(entity, stream);
}
}
getLog().info(String.format("Done serializing %,d entities to %s (%.9fs)", entities.size(), this.outputDirectory, (System.nanoTime() - serializeStart) / 1_000_000_000.0));
}
use of org.finos.legend.sdlc.domain.model.entity.Entity 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.sdlc.domain.model.entity.Entity in project legend-sdlc by finos.
the class TestEntityToPureConverter method testFromEntity.
@Test
public void testFromEntity() {
Entity entity = TestTools.newClassEntity("EmptyClass", "model::test");
PackageableElement result = this.converter.fromEntity(entity);
Assert.assertTrue(result instanceof Class);
Class resultClass = (Class) result;
Assert.assertEquals("EmptyClass", resultClass.name);
Assert.assertEquals("model::test", resultClass._package);
Assert.assertEquals(Collections.singletonList("meta::pure::metamodel::type::Any"), resultClass.superTypes);
Assert.assertEquals(Collections.emptyList(), resultClass.properties);
IllegalArgumentException e = Assert.assertThrows(IllegalArgumentException.class, () -> this.converter.fromEntity(Entity.newEntity("not::a::real::PureEntity", "meta::unknown::NotAClassifier", Collections.emptyMap())));
String message = e.getMessage();
Assert.assertNotNull(message);
String expectedPrefix = "Could not convert entity not::a::real::PureEntity with classifier meta::unknown::NotAClassifier to class PackageableElement";
if (!message.startsWith(expectedPrefix)) {
Assert.assertEquals(expectedPrefix, message);
}
}
use of org.finos.legend.sdlc.domain.model.entity.Entity in project legend-sdlc by finos.
the class TestPureEntitySerializer method testNonPureEntity.
@Test
public void testNonPureEntity() {
Entity entity = readEntityFromJsonResource(buildResourceName("invalid", "TestNonPureEntity.json"));
Assert.assertFalse(this.pureSerializer.canSerialize(entity));
IllegalArgumentException e = Assert.assertThrows(IllegalArgumentException.class, () -> this.pureSerializer.serializeToString(entity));
String message = e.getMessage();
String expectedStart = "Could not convert entity model::otherthings::AnotherThing with classifier meta::notpure::something::SomeType to class PackageableElement";
if (!message.startsWith(expectedStart)) {
// We don't really want these to be equal, this is just to produce a decent failure message
Assert.assertEquals(expectedStart, message);
}
}
Aggregations