/violation-builder

A small java library for building violations.

Primary LanguageJavaMIT LicenseMIT

violation-builder

A small java library for building violations.

Build Status Coverage Status Coverage Status

Usage samples

void example() throws ViolationException {
  boolean condition = true;

  ViolationBuilder.builder()
    .error(condition,"error-key", () -> "some error message.")
    .warning(condition,"waring-key", () -> "some warning message.")
    .buildIgnoreWarnings();
}

Appends to the builder a violations of error type.

void example() throws ViolationException {
  boolean condition = true;

  ViolationBuilder.builder()
    .error(condition, "error-key-01", "some error-01 message.")
    .error("error-key-02", "some error-02 message.")
    .error(condition,"error-key-03", () -> "some error-03 message.")
    .error("error-key-04", () -> "some error-04 message.")
    .build();
}

Appends to the builder a violations of warning type.

void example() throws ViolationException {
  boolean condition = true;

  ViolationBuilder.builder()
    .warning(condition, "waring-key-01", "some waring-01 message.")
    .warning("waring-key-02", "some waring-02 message.")
    .warning(condition,"waring-key-03", () -> "some warning-03 message.")
    .warning("waring-key-04", () -> "some warning-04 message.")
    .build();
}

Executing a collection of validation rules

final Collection<ValidationRule<Object>> rules = Arrays.asList(
  new ValidationRuleContinueFlow<Object>() {
    @Override
    public void runContinueFlow(ViolationBuilder violationBuilder, Object data) {
      violationBuilder.warning(/* validation on the data */, "waring-key-01", "some waring-01 message.");
    }
  },
  new ValidationRuleStopFlow<Object>() {
    @Override
    public void runStopFlow(ViolationBuilder violationBuilder, Object data) {
      violationBuilder.error(/* validation on the data */, "error-key-01", "some error-01 message.");
    }
  },
  new ValidationRuleContinueFlow<Object>() {
    @Override
    public void runContinueFlow(ViolationBuilder violationBuilder, Object data) {
      violationBuilder.error(/* validation on the data */, "error-key-02", "some error-02 message.");
    }
  },
  new ValidationRule<Object>() {
    @Override
    public Rulesflow run(ViolationBuilder violationBuilder, Object data) {
      violationBuilder.error(/* validation on the data */, "error-key-03", "some error-03 message.");
      return Rulesflow.CONTINUE;
    }
  }
);

RulesExecutor.rulesExecutor(rules, data);

Installing

Available in the Maven Central repository.

Add a dependency to com.github.thiagogarbazza:violation-builder in your project.

Example using maven:

<dependency>
  <groupId>com.github.thiagogarbazza</groupId>
  <artifactId>violation-builder</artifactId>
  <version>1.2.0</version>
</dependency>

Built With

  • Java - The lang used
  • Junit - The framework test used
  • Maven - Dependency Management

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments

  • Java 8+
  • Junit jupter