Skip to content

Commit

Permalink
Merge branch 'release/5.0.1.RELEASE.20231011'
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusHdez960717 committed Oct 11, 2023
2 parents 36e9d6d + eb6ad12 commit 4242015
Show file tree
Hide file tree
Showing 60 changed files with 222 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* 5.0.1.RELEASE.20231011:
* **GENERAL** :
* **FIX** :raised: : Rename `clean-core` to `commons`.

* 5.0.0.RELEASE.20231011:
* **NEW VERSION** :
* **REMOVED** :x: : Removed `Repo` layer, use basic Spring Boot architecture from now on.
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Multilanguage:

This library aims to provide standards and utilities that make work easier when creating microservices.

Docs updated for version: `4.8.1.RELEASE.20230919`
Docs updated for version: `5.0.1.RELEASE.20231011`

## Table of Contents
- [1 - Validations](#1)
Expand All @@ -36,13 +36,13 @@ Docs updated for version: `4.8.1.RELEASE.20230919`

## Validations <a name="1"></a>
- All native validations are loaded from the [`jakarta.validations.*` framework](https://mvnrepository.com/artifact/jakarta.validation/jakarta.validation-api).
- To validate an object, the `dev.root101.clean.core.utils.validation.ValidationService` class and its static methods are used. Example: `ValidationService.validateAndThrow(some_object);`.
- To validate an object, the `dev.root101.commons.utils.validation.ValidationService` class and its static methods are used. Example: `ValidationService.validateAndThrow(some_object);`.
- If all validations passed correctly, the code runs normally. If at least one validation fails, a `ValidationException` will be thrown or **a `List` in case of need** (`ValidationService.validate(some_object);`, without `andThrow`).
- ALL validation examples are located in the examples folder `dev.root101.clean.core.examples.validation...`.
- ALL validation examples are located in the examples folder `dev.root101.commons.examples.validation...`.
- **NOTE**: ALL the objects used are `record` to reduce the example code, but everything explained here works EXACTLY the same with standard Java classes.

### 1.1 - Validation Exception <a name="1.1"></a>
Once validations are executed on an object, and some fail, an exception of type `dev.root101.clean.core.exceptions.ValidationException` will be thrown.
Once validations are executed on an object, and some fail, an exception of type `dev.root101.commons.exceptions.ValidationException` will be thrown.

This exception has the:
- `status_code`, which represents the http response code, ALWAYS being `422: UNPROCESSABLE_ENTITY`. AND,
Expand Down Expand Up @@ -577,7 +577,7 @@ For writing (Convert Object to String):
String converted = Jackson.toString(object);
```

**NOTE**: This class has some other functionalities for further read/write customization, as well as to convert/parse objects from one type to another. For more details consult the source code in `dev.root101.clean.core.utils.Jackson`.
**NOTE**: This class has some other functionalities for further read/write customization, as well as to convert/parse objects from one type to another. For more details consult the source code in `dev.root101.commons.utils.Jackson`.

### 4.2 - Enum mappeable <a name="4.2"></a>
When you want to map an Enum to its list of elements without so much code at hand:
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ plugins {
id 'java'
}

group = 'dev.root101.clean'
group = 'dev.root101.commons'

version = '5.0.0.RELEASE.20231011'
version = '5.0.1.RELEASE.20231011'

repositories {
jcenter()
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'clean-core'
rootProject.name = 'commons'
50 changes: 50 additions & 0 deletions src/main/java/dev/root101/commons/test/Child.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package dev.root101.clean.core.test;

import dev.root101.clean.core.utils.validation.ValidationFieldName;
import java.util.List;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

/**
*
* @author Yo
*/
public class Child {

@NotNull
@Size(max = 5)
@ValidationFieldName("child_name")
private String childName;

@NotNull
@NotEmpty
@ValidationFieldName("toys")
private List<Toy> toys;

public Child(String childName, List<Toy> toys) {
this.childName = childName;
this.toys = toys;
}

public String getChildName() {
return childName;
}

public void setChildName(String childName) {
this.childName = childName;
}

public List<Toy> getToys() {
return toys;
}

public void setToys(List<Toy> toys) {
this.toys = toys;
}

}
13 changes: 13 additions & 0 deletions src/main/java/dev/root101/commons/test/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.root101.clean.core.test;

import dev.root101.clean.core.utils.validation.ValidationService;
import java.util.List;

class Main {

public static void main(String[] args) throws Exception {
Parent parent = new Parent("name111", ParentType.ACTIVE, List.of(new Toy("toy name 1")));
ValidationService.validateRecursiveAndThrow(parent);
}

}
51 changes: 51 additions & 0 deletions src/main/java/dev/root101/commons/test/Parent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package dev.root101.clean.core.test;

import dev.root101.clean.core.utils.validation.ValidationFieldName;
import java.util.List;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

/**
*
* @author Yo
*/
public class Parent {

@Size(max = 5)
@ValidationFieldName("parent_name")
private String parentName;

@ValidationFieldName("type")
@NotNull
private ParentType type;

@ValidationFieldName("parent_toys")
private List<Toy> parentToys;

public Parent(String parentName, ParentType type, List<Toy> parentToys) {
this.parentName = parentName;
this.type = type;
this.parentToys = parentToys;
}

public String getParentName() {
return parentName;
}

public void setParentName(String parentName) {
this.parentName = parentName;
}

public List<Toy> getParentToys() {
return parentToys;
}

public void setParentToys(List<Toy> parentToys) {
this.parentToys = parentToys;
}

}
65 changes: 65 additions & 0 deletions src/main/java/dev/root101/commons/test/ParentType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package dev.root101.clean.core.test;

import com.fasterxml.jackson.annotation.JsonProperty;
import dev.root101.clean.core.exceptions.NotFoundException;
import dev.root101.clean.core.test.ParentType.PlatformResponse;
import dev.root101.clean.core.utils.EnumMappeable;
import jakarta.validation.constraints.Size;

/**
*
* @author Yo
*/
public enum ParentType implements EnumMappeable<PlatformResponse> {
ACTIVE(1, "Active"),
ON_HOLD(2, "on Hold"),
CLOSED(3, "Closed");

public record PlatformResponse(
@JsonProperty("id")
int id,
@JsonProperty("name")
String name) {

}
private final int id;

@Size(max = 3)
private final String name;

private ParentType(int id, String name) {
this.id = id;
this.name = name;
}

public int getId() {
return id;
}

public String getName() {
return name;
}

@Override
public PlatformResponse map() {
return new PlatformResponse(id, name);
}

@Override
public String toString() {
return getName();
}

public static ParentType resolve(int id) {
for (ParentType value : ParentType.values()) {
if (value.getId() == id) {
return value;
}
}
throw new NotFoundException("No Parent Type found with id '%s'.".formatted(id));
}
}
31 changes: 31 additions & 0 deletions src/main/java/dev/root101/commons/test/Toy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package dev.root101.clean.core.test;

import jakarta.validation.constraints.Size;

/**
*
* @author Yo
*/
public class Toy {

@Size(max = 5)
//@ValidationFieldName("toy_name")
private String toyName;

public Toy(String toyName) {
this.toyName = toyName;
}

public String getToyName() {
return toyName;
}

public void setToyName(String toyName) {
this.toyName = toyName;
}

}

0 comments on commit 4242015

Please sign in to comment.