Search in sources :

Example 1 with GeneratedFile

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

the class JsonSchemaGeneratorTest method testJsonSchemaGeneratorInputOutput.

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

Example 2 with GeneratedFile

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

the class JsonSchemaGeneratorTest method testJsonSchemaGeneratorDraft2019.

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

Example 3 with GeneratedFile

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

the class AutomatikoQuarkusProcessor method generatePersistenceInfo.

private void generatePersistenceInfo(AutomatikoBuildTimeConfig config, PackageConfig pconfig, AppPaths appPaths, BuildProducer<GeneratedBeanBuildItem> generatedBeans, BuildProducer<AdditionalIndexedClassesBuildItem> additionalIndexClass, IndexView index, LaunchModeBuildItem launchMode, BuildProducer<NativeImageResourceBuildItem> resource, CurateOutcomeBuildItem curateOutcomeBuildItem) throws Exception, BootstrapDependencyProcessingException {
    ClassInfo persistenceClass = index.getClassByName(createDotName(persistenceFactoryClass));
    boolean usePersistence = persistenceClass != null;
    List<String> parameters = new ArrayList<>();
    if (usePersistence) {
        for (MethodInfo mi : persistenceClass.methods()) {
            if (mi.name().equals("<init>") && !mi.parameters().isEmpty()) {
                parameters = mi.parameters().stream().map(p -> p.name().toString()).collect(Collectors.toList());
                break;
            }
        }
    }
    Collection<GeneratedFile> generatedFiles = getGeneratedPersistenceFiles(config, appPaths, index, usePersistence, parameters);
    if (!generatedFiles.isEmpty()) {
        writeGeneratedFiles(appPaths, generatedFiles);
        compile(appPaths, curateOutcomeBuildItem.getApplicationModel(), generatedFiles, launchMode.getLaunchMode(), generatedBeans, additionalIndexClass, GeneratedBeanBuildItem::new, pconfig);
    }
}
Also used : GeneratedBeanBuildItem(io.quarkus.arc.deployment.GeneratedBeanBuildItem) ArrayList(java.util.ArrayList) MethodInfo(org.jboss.jandex.MethodInfo) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) ClassInfo(org.jboss.jandex.ClassInfo)

Example 4 with GeneratedFile

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

the class PersistenceGenerator method mongodbBasedPersistence.

protected void mongodbBasedPersistence(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);
    persistenceProviderClazz.addConstructor(Keyword.PUBLIC);
    ConstructorDeclaration constructor = persistenceProviderClazz.addConstructor(Keyword.PUBLIC).addParameter("com.mongodb.client.MongoClient", "mongoClient").addParameter("io.automatiko.engine.api.config.MongodbPersistenceConfig", "config");
    BlockStmt body = new BlockStmt();
    ExplicitConstructorInvocationStmt superExp = new ExplicitConstructorInvocationStmt(false, null, NodeList.nodeList(new NameExpr("mongoClient"), new NameExpr("config")));
    body.addStatement(superExp);
    constructor.setBody(body);
    if (useInjection()) {
        annotator.withApplicationComponent(persistenceProviderClazz);
        annotator.withInjection(constructor);
        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) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) BodyDeclarationComparator(io.automatiko.engine.codegen.BodyDeclarationComparator) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile)

Example 5 with GeneratedFile

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

the class PersistenceGenerator method fileSystemBasedPersistence.

protected void fileSystemBasedPersistence(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);
        FieldDeclaration pathField = new FieldDeclaration().addVariable(new VariableDeclarator().setType(new ClassOrInterfaceType(null, new SimpleName(Optional.class.getCanonicalName()), NodeList.nodeList(new ClassOrInterfaceType(null, String.class.getCanonicalName())))).setName(PATH_NAME));
        annotator.withConfigInjection(pathField, PERSISTENCE_FS_PATH_PROP);
        // allow to inject path for the file system storage
        BlockStmt pathMethodBody = new BlockStmt();
        pathMethodBody.addStatement(new ReturnStmt(new MethodCallExpr(new NameExpr(PATH_NAME), "orElse").addArgument(new StringLiteralExpr("/tmp"))));
        MethodDeclaration pathMethod = new MethodDeclaration().addModifier(Keyword.PUBLIC).setName(PATH_NAME).setType(String.class).setBody(pathMethodBody);
        persistenceProviderClazz.addMember(pathField);
        persistenceProviderClazz.addMember(pathMethod);
        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) Optional(java.util.Optional) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) SimpleName(com.github.javaparser.ast.expr.SimpleName) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) BodyDeclarationComparator(io.automatiko.engine.codegen.BodyDeclarationComparator) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

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