/quarkus-utils

Utility classes to have standard base in quarkus projects

Primary LanguageJavaApache License 2.0Apache-2.0

DrWolf Quarkus Utils

Add repository:

<repositories>
    <repository>
        <id>drwolf maven public</id>
        <url>https://maven.drwolf.it</url>
    </repository>
</repositories>

Add dependency:

<dependency>
    <groupId>com.github.drwolf-oss</groupId>
    <artifactId>quarkus-utils</artifactId>
    <!-- check available tags: https://github.com/DrWolf-OSS/quarkus-utils/tags -->
    <version>${quarkus.platform.version}.3</version>
</dependency>

Exception Handling

The library provides CustomExceptionHandler which will catch and log any Exception, if you throw subclasses of WebApplicationException the handler will return the proper status code

(the stack trace is limited at 20 rows by default, see options below)

JWT in queryParam

The library provides QueryFilter which will let you pass the JWT as as the queryParam token in requests (?token=babecafedeadbeef)

(you can disable the filter, see options below)

Default configuration options

You can override the options in your application

quarkus-utils.timezone=UTC
quarkus-utils.locale=en
quarkus-utils.stack-trace-limit=20
quarkus-utils.disable-query-filter=false

GIT info

Add git-info plugin to pom.xml

<plugin>
    <groupId>io.github.git-commit-id</groupId>
    <artifactId>git-commit-id-maven-plugin</artifactId>
    <version>5.0.0</version>
    <executions>
        <execution>
            <id>get-the-git-infos</id>
            <goals>
                <goal>revision</goal>
            </goals>
            <phase>initialize</phase>
        </execution>
    </executions>
    <configuration>
        <generateGitPropertiesFile>true</generateGitPropertiesFile>
        <generateGitPropertiesFilename>${project.build.outputDirectory}/git.json
        </generateGitPropertiesFilename>
        <excludeProperties>
            <excludeProperty>git.commit.user.*</excludeProperty>
            <excludeProperty>git.build.user.*</excludeProperty>
        </excludeProperties>
        <format>json</format>
        <commitIdGenerationMode>full</commitIdGenerationMode>
    </configuration>
</plugin>

@ Startup do

GitResource.loadInfo(this.getClass().

getClassLoader().

getResourceAsStream("git.json"));

Entities:

@Entity
public class YourEntity extends BaseEntity<Long> {
 ...
}

Repository:

@ApplicationScoped
@Unremovable // As repository is injected via reflection in the resource this annotation is needed
public class YourRepository extends PanacheRepositoryBase<User, Long> {
  ...
}}

Resources:

Don't use @Transactional annotation when calling super.add(...), super.update(...) and super.delete(...)

@Path("/your-resource")
public class YourResource extends CrudResource<YourRepository, YourEntity, Long> {
  ...
}}

DateUtils

Useful to parse ISO strings from requests (optional or mandatory)

  • Optional<Date> DateUtils.parseOptional(String isoDate)
  • Date DateUtils.parse(String isoDate)