Domain validation

A simple framework to write domain validation.

License

License

Categories

Categories

Doma Data ORM
GroupId

GroupId

com.github.thiagogarbazza
ArtifactId

ArtifactId

domain-validation
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Domain validation
A simple framework to write domain validation.
Project URL

Project URL

https://github.com/thiagogarbazza/domain-validation
Source Code Management

Source Code Management

https://github.com/thiagogarbazza/domain-validation

Download domain-validation

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.thiagogarbazza/domain-validation/ -->
<dependency>
    <groupId>com.github.thiagogarbazza</groupId>
    <artifactId>domain-validation</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.thiagogarbazza/domain-validation/
implementation 'com.github.thiagogarbazza:domain-validation:0.1.0'
// https://jarcasting.com/artifacts/com.github.thiagogarbazza/domain-validation/
implementation ("com.github.thiagogarbazza:domain-validation:0.1.0")
'com.github.thiagogarbazza:domain-validation:jar:0.1.0'
<dependency org="com.github.thiagogarbazza" name="domain-validation" rev="0.1.0">
  <artifact name="domain-validation" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.thiagogarbazza', module='domain-validation', version='0.1.0')
)
libraryDependencies += "com.github.thiagogarbazza" % "domain-validation" % "0.1.0"
[com.github.thiagogarbazza/domain-validation "0.1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.hamcrest : hamcrest-core jar 1.3
org.projectlombok : lombok jar 1.16.18

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

domain-validation

A simple framework to write domain validation.

Build Status Quality Gate

Install

Available in the Maven Central repository.

Add a dependency to com.github.thiagogarbazza:domain-validation in compile scope.

Example using maven:

<dependency>
  <groupId>com.github.thiagogarbazza</groupId>
  <artifactId>domain-validation</artifactId>
  <version>0.1.0</version>
</dependency>

Usage

Informing message text on failure

Simple usage:

public void methodValidationNotifyMessage(Domain domain) throws ViolationException {
    ViolationContextMessage context = ViolationContextFactory.newViolationContext();

    context.error(domain.getPropertyA() == null, "ERROR_CODE", "ERROR_MESSAGE");
    context.warning("".equals(domain.getPropertyB()), "WARNING_CODE", "WARNING_MESSAGE");

    context.toProcess();
}

Usage with org.hamcrest:

public void methodValidationNotifyMessageUsingHamcrest(Domain domain) throws ViolationException {
    ViolationContextMessage context = ViolationContextFactory.newViolationContext();

    context.error(domain.getPropertyA(), nullValue(), "ERROR_CODE", "ERROR_MESSAGE");
    context.warning(domain.getPropertyB(), equalTo(""), "WARNING_CODE", "WARNING_MESSAGE");

    context.toProcess();
}

Using resource-bundle to retrieve the text of the failure message

Create a property file in the project resource, example domain-violation-massage.properties

Simple usage:

public void methodValidationNotifyResourceBundle(Domain domain) throws ViolationException {
    ViolationContextResource context = ViolationContextFactory.newViolationContext(getBundle("domain-violation-massage"));

    context.error(domain.getPropertyA() == null, "ERROR_CODE");
    context.warning("".equals(domain.getPropertyB()), "WARNING_CODE");

    context.toProcess();
}

Usage with org.hamcrest:

public void methodValidationNotifyResourceBundleUsingHamcrest(Domain domain) throws ViolationException {
    ViolationContextResource context = ViolationContextFactory.newViolationContext(getBundle("domain-violation-massage"));

    context.error(domain.getPropertyA(), nullValue(), "ERROR_CODE");
    context.warning(domain.getPropertyB(), equalTo(""), "WARNING_CODE");

    context.toProcess();
}

Versions

Version
0.1.0
0.0.2
0.0.1