GithubHelp home page GithubHelp logo

roymanigley / ggq Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 22.13 MB

GGQ is a code generator for Quarkus which generates REST APIs incl Swagger, Unit and Integration Tests. Supportet technologies: JPA_REST, HIBERNATE_PANACHE_REST, JPA_SPRING_REST, MONGO_PANACHE_REST, MONGO_PANACHE_REST_OIDC, HIBERNATE_PANACHE_REST_KAFKA

License: Apache License 2.0

Java 24.84% XSLT 74.05% HTML 1.11%
quarkus code-generation code-generator generator quarkus-maven quarkus-example quarkus-kafka quarkus-mongo quarkus-panache quarkus-hibernate-orm

ggq's Introduction

GGQ - go go Quarkus

As part of the study at the HFTM Grenchen in the module XML processing, an example project was developed which is to illuminate specific XML technologies.

Chosen technology:

  • XSLT
  • xStream as an alternative to JAXB

TOC

What is GGQ

GGQ is a code generator for Quarkus which was implemented as a CLI. The input is an XML file which contains the entities (see example below).

The transformation of the individual entities into the respective output files is implemented using XSL templates.

The following types can be generated:

  • JPA_REST → REST Application incl. Swagger using EntityManager (100% test coverage)
  • HIBERNATE_PANACHE_REST → REST Application with pagination incl. Swagger using PanacheRepository (100% test coverage)
  • JPA_SPRING_REST → REST Application with pagination incl. Swagger using Spring (data, di, web) (100% test coverage)
  • MONGO_PANACHE_REST → REST Application incl. Swagger using ReactiveMongoPanacheRepository (~80% test coverage)
  • MONGO_PANACHE_REST_OIDC → REST Application with OIDC (KeyCloak) incl. Swagger using ReactiveMongoPanacheRepository (~80% test coverage)
  • HIBERNATE_PANACHE_REST_KAFKA → Application with pagination incl. Swagger using PanacheRepository every UPDATE, CREATE or DELETE of an Entity is published to Kafka (~75% test coverage)

The following content is generated based on the entities

  • JPA or Mongo Entities
  • DTOs
  • Mapper (DTO <-> Entity)
  • Repository (interface & implementation)
  • Service (interface & implementation)
  • REST Resource (incl. swagger)
  • UnitTests
  • IntegrationTests
  • TestUtil per Entity

The following files are generated once

  • pom.xml
  • basic index.html page
  • application.propperties (test, dev, und prod)
  • Exception Handling
  • RandomGenerator.java (for tests)
  • README.md
  • docker-compose.xml

Example XML

This is the simple example XML try the command printXml --extended or create your own

<entities>
    <entity name="Movie">
        <variables>
            <variable name="name" type="String" required="true" />
            <variable name="date" type="java.time.LocalDate" required="true" />
        </variables>
        <relations>
            <relation name="genre" type="Genre" mapping="ManyToOne" required="true" />
        </relations>
    </entity>
    <entity name="Genre">
        <variables>
            <variable name="name" type="String" required="true" />
        </variables>
    </entity>
</entities>

Getting started

Building

  • build
    ./mvnw clean package
  • run all tests (integration tests will build a generated Application from the extended XML example)
    ./mvnw -Pintegration-tests test

Running

$ java -jar target/ggq-1.0.0-SNAPSHOT-runner.jar -h

Usage: <main class> [-hV] [COMMAND]
  -h, --help      Show this help message and exit.
  -V, --version   Print version information and exit.
Commands:
  codeGenerator   Generate boilerplate code for Entities
  printXml        Print an example XML for the Code Generator
  xslTransformer  Transform XML by using a XSL stylesheet
  xmlWizzard      CLI Wizzard for creating and updating a XML for the Code Generator → better edit the XML  manualy ;)

codeGenerator

How does is the project name chosen?
→ it is taken by the project dirs las folder (to lowercase) Which variable types are allowed?

  • String
  • Integer
  • Double
  • java.time.LocalDate
  • java.time.LocalDateTime

Those types are tested
→ you can still try other types but you may have to adapt the RandomGenerator for the tests, and to avoid adding the imports define the type incl. package name

$ java -jar target/ggq-1.0.0-SNAPSHOT-runner.jar codeGenerator -h
Usage: <main class> codeGenerator [-hV] [--basePackage=<basePackage>]
                                  --input=<input> --projectDir=<projectDir>
                                  [--type=<templateType>]
Generate boilerplate code for Entities
      --basePackage=<basePackage>
                        Base package
  -h, --help            Show this help message and exit.
      --input=<input>   XML File containing entities
      --projectDir=<projectDir>
                        Quarkus project directory
      --type=<templateType>
                        template types (valid values: JPA_REST,
                          HIBERNATE_PANACHE_REST, JPA_SPRING_REST, MONGO_PANACHE_REST,
                          MONGO_PANACHE_REST_OIDC, HIBERNATE_PANACHE_REST_KAFKA)
  -V, --version         Print version information and exit.

Tutorial

  1. Generate an entities.xml

     # Simple example with Movie and Genre
     java -jar target/ggq-1.0.0-SNAPSHOT-runner.jar printXml > entities.xml
     # More complex example Brewery
     java -jar target/ggq-1.0.0-SNAPSHOT-runner.jar printXml --extended > entities.xml
    

  2. Generate Quarkus Application form entities.xml

     java -jar target/ggq-1.0.0-SNAPSHOT-runner.jar codeGenerator \
         --input entities.xml \
         --projectDir experiment \
         --type HIBERNATE_PANACHE_REST \
         --basePackage com.experiment
    

  3. Navigate to the projectDir and run the tests

     ./mvnw -Pintegration-tests test
    

  4. Check the test coverage target/site/jacoco/index.html

  5. Start the generated Application in dev mode

     ./mvnw quarkus:dev
    

  6. Access the Application

     http://localhost:8080 
    

ggq's People

Contributors

roymanigley avatar

Watchers

 avatar

ggq's Issues

feature/support-enum

Beside an entity we should also have the possibility to define Enums and use them in the variables.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.