Search in sources :

Example 11 with GeneratedFile

use of io.automatiko.engine.codegen.GeneratedFile in project automatiko-engine by automatiko-io.

the class PersistenceGenerator method dbBasedPersistence.

protected void dbBasedPersistence(List<GeneratedFile> generatedFiles) {
    ClassOrInterfaceDeclaration persistenceProviderClazz = new ClassOrInterfaceDeclaration().setName("ProcessInstancesFactoryImpl").setModifiers(Modifier.Keyword.PUBLIC).addExtendedType("io.automatiko.engine.addons.persistence.AbstractProcessInstancesFactory");
    CompilationUnit compilationUnit = new CompilationUnit("io.automatiko.engine.addons.persistence.impl");
    compilationUnit.getTypes().add(persistenceProviderClazz);
    if (useInjection()) {
        annotator.withApplicationComponent(persistenceProviderClazz);
        addCodecComponents(persistenceProviderClazz);
    }
    String packageName = compilationUnit.getPackageDeclaration().map(pd -> pd.getName().toString()).orElse("");
    String clazzName = packageName + "." + persistenceProviderClazz.findFirst(ClassOrInterfaceDeclaration.class).map(c -> c.getName().toString()).get();
    generatedFiles.add(new GeneratedFile(GeneratedFile.Type.CLASS, clazzName.replace('.', '/') + ".java", compilationUnit.toString().getBytes(StandardCharsets.UTF_8)));
    persistenceProviderClazz.getMembers().sort(new BodyDeclarationComparator());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) ApplicationSection(io.automatiko.engine.codegen.ApplicationSection) ArrayList(java.util.ArrayList) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Keyword(com.github.javaparser.ast.Modifier.Keyword) DependencyInjectionAnnotator(io.automatiko.engine.codegen.di.DependencyInjectionAnnotator) ConfigGenerator(io.automatiko.engine.codegen.ConfigGenerator) NodeList(com.github.javaparser.ast.NodeList) SimpleName(com.github.javaparser.ast.expr.SimpleName) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) Collection(java.util.Collection) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) StoredDataCodec(io.automatiko.engine.api.workflow.encrypt.StoredDataCodec) BodyDeclarationComparator(io.automatiko.engine.codegen.BodyDeclarationComparator) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) Modifier(com.github.javaparser.ast.Modifier) List(java.util.List) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) AbstractGenerator(io.automatiko.engine.codegen.AbstractGenerator) Optional(java.util.Optional) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) BodyDeclarationComparator(io.automatiko.engine.codegen.BodyDeclarationComparator) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile)

Example 12 with GeneratedFile

use of io.automatiko.engine.codegen.GeneratedFile in project automatiko-engine by automatiko-io.

the class JsonSchemaGeneratorTest method testJsonSchemaGenerator.

@Test
public void testJsonSchemaGenerator() throws IOException {
    Collection<GeneratedFile> files = new JsonSchemaGenerator.Builder(Stream.of(PersonInputParams.class, PersonOutputParams.class, IgnoredClass.class)).build().generate();
    assertEquals(1, files.size());
    GeneratedFile file = files.iterator().next();
    assertEquals("test_test.json", file.relativePath());
    assertSchema(file, SchemaVersion.DRAFT_7);
}
Also used : GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) Test(org.junit.jupiter.api.Test)

Aggregations

GeneratedFile (io.automatiko.engine.codegen.GeneratedFile)12 File (java.io.File)8 ArrayList (java.util.ArrayList)7 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)6 AbstractGenerator (io.automatiko.engine.codegen.AbstractGenerator)6 ApplicationSection (io.automatiko.engine.codegen.ApplicationSection)6 ConfigGenerator (io.automatiko.engine.codegen.ConfigGenerator)6 DependencyInjectionAnnotator (io.automatiko.engine.codegen.di.DependencyInjectionAnnotator)6 StandardCharsets (java.nio.charset.StandardCharsets)6 Collection (java.util.Collection)6 List (java.util.List)6 Optional (java.util.Optional)6 CompilationUnit (com.github.javaparser.ast.CompilationUnit)5 Modifier (com.github.javaparser.ast.Modifier)5 Keyword (com.github.javaparser.ast.Modifier.Keyword)5 NodeList (com.github.javaparser.ast.NodeList)5 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)5 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)5 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)5 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)5