Skip to content

Commit 0d4d5d2

Browse files
committed
Documentation
1 parent c30bda8 commit 0d4d5d2

File tree

10 files changed

+151
-2
lines changed

10 files changed

+151
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## Refer to subproject's changelog for details :
99

1010
- [emp-service-model](https://github.com/fugerit-org/fj-service-helper-bom/blob/main/emp-service-model/CHANGELOG.md)
11+
- [emp-exception-mapper](https://github.com/fugerit-org/fj-service-helper-bom/blob/main/emp-exception-mapper/CHANGELOG.md)
1112
- [data-service-base](https://github.com/fugerit-org/fj-service-helper-bom/blob/main/data-service-base/CHANGELOG.md)
1213
- [data-service-jvfs](https://github.com/fugerit-org/fj-service-helper-bom/blob/main/data-service-jvfs/CHANGELOG.md)
1314

1415
## [Unreleased]
1516

17+
## [1.1.0 - 2024-04-05]
18+
1619
### Added
1720

1821
- WAExHelper to build WebApplicationException
22+
- module emp-exception-mapper [incubator]
1923

2024
### Changed
2125

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ This project is a wrapper for some service components abstraction modules :
1919

2020
Collections of model for services.
2121

22+
## [emp-exception-mapper](emp-exception-mapper/README.md)
23+
24+
Collection of MicroProfile ExceptionMappers.
25+
2226
## [data-service-base](data-service-base/README.md)
2327

2428
Simple data resources load/save interface layer.

emp-exception-mapper/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [1.1.0 - 2024-04-05]
11+
12+
### Added
13+
14+
- GenericExceptionMapper (incubator)

emp-exception-mapper/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Eclipse MicroProfile Exception Mappers
2+
3+
[![Keep a Changelog v1.1.0 badge](https://img.shields.io/badge/changelog-Keep%20a%20Changelog%20v1.1.0-%23E05735)](https://github.com/fugerit-org/fj-service-helper-bom/blob/main/emp-exception-mapper/CHANGELOG.md)
4+
5+
Collection of MicroProfile ExceptionMappers.

emp-service-model/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.1.0 - 2024-04-05]
11+
1012
### Added
1113

14+
- WAExHelper to build WebApplicationException
1215
- [emp-service-model] native support : relfect-config.json
1316

1417
## [0.1.0 - 2023-11-12]

emp-service-model/README.md

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,81 @@
22

33
[![Keep a Changelog v1.1.0 badge](https://img.shields.io/badge/changelog-Keep%20a%20Changelog%20v1.1.0-%23E05735)](https://github.com/fugerit-org/fj-service-helper-bom/blob/main/emp-service-model/CHANGELOG.md)
44

5-
This project contains a collection of model object (like beans or POJOS) to be used in service implementation.
5+
This project contains a collection of model object (like beans or POJOS) to be used in service implementation.
6+
7+
## 1. ServiceMessage
8+
9+
Sample usage :
10+
11+
```java
12+
ServiceResponse response = new ServiceResponse()
13+
.addAllBySeverity( ServiceMessage.newMessage( "400001", ServiceMessage.Severity.ERROR, "Test bad request message" ),
14+
ServiceMessage.newMessage( ServiceMessage.Severity.INFO, "Test info message" ),
15+
ServiceMessage.newMessage( ServiceMessage.Severity.WARNING, "Test warning message" ) );
16+
```
17+
18+
Json output :
19+
20+
```json
21+
{
22+
"errors" : [ {
23+
"code" : "400001",
24+
"severity" : "E",
25+
"text" : "Test bad request message"
26+
} ],
27+
"warnings" : [ {
28+
"code" : "W",
29+
"severity" : "W",
30+
"text" : "Test warning message"
31+
} ],
32+
"infos" : [ {
33+
"code" : "I",
34+
"severity" : "I",
35+
"text" : "Test info message"
36+
} ]
37+
}
38+
```
39+
40+
## 2. WAExHelper
41+
42+
Sample usage :
43+
44+
```java
45+
throw WAExHelper.newEx( Response.Status.BAD_REQUEST, "Test bad request message" );
46+
```
47+
json output :
48+
49+
```json
50+
{
51+
"status" : 400,
52+
"entity" : {
53+
"errors" : [ {
54+
"code" : "E",
55+
"severity" : "E",
56+
"text" : "Test bad request message"
57+
} ]
58+
},
59+
"headers" : { },
60+
"entityStream" : null,
61+
"stringHeaders" : { },
62+
"entityAnnotations" : null,
63+
"closed" : false,
64+
"length" : -1,
65+
"location" : null,
66+
"language" : null,
67+
"date" : null,
68+
"lastModified" : null,
69+
"statusInfo" : {
70+
"reasonPhrase" : "Bad Request",
71+
"family" : "CLIENT_ERROR",
72+
"statusCode" : 400
73+
},
74+
"mediaType" : null,
75+
"cookies" : { },
76+
"entityTag" : null,
77+
"links" : [ ],
78+
"metadata" : { },
79+
"allowedMethods" : [ ]
80+
}
81+
82+
```

emp-service-model/src/main/java/org/fugerit/java/emp/sm/service/ServiceMessage.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,12 @@ public enum Severity {
8484
@Schema(description = "Message test", example = "User not authorized to access the resource." , required = false, type = SchemaType.STRING )
8585
@Getter @Setter private String text;
8686

87+
public static ServiceMessage newMessage( Severity severity, String message ) {
88+
return newMessage( severity.getLevel(), severity, message );
89+
}
90+
91+
public static ServiceMessage newMessage( String code, Severity severity, String message ) {
92+
return ServiceResponseHelper.newMessage( code, severity.getLevel(), message );
93+
}
94+
8795
}

emp-service-model/src/main/java/org/fugerit/java/emp/sm/service/ServiceResponseHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ private ServiceResponseHelper() {}
1313
private static List<ServiceMessage> addHelper( List<ServiceMessage> currentMessages, List<ServiceMessage> messages ) {
1414
List<ServiceMessage> result = currentMessages == null ? new ArrayList<>() : currentMessages;
1515
result.addAll( messages );
16-
return result;
16+
return result.isEmpty() ? null : result;
1717
}
1818

1919
public static void addErrors(ServiceResponse response, List<ServiceMessage> messages) {

emp-service-model/src/test/java/test/org/fugerit/java/emp/ex/TestWAExHelper.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package test.org.fugerit.java.emp.ex;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
34
import jakarta.ws.rs.WebApplicationException;
45
import jakarta.ws.rs.core.Response;
6+
import lombok.extern.slf4j.Slf4j;
57
import org.fugerit.java.emp.ex.WAExHelper;
68
import org.fugerit.java.emp.sm.service.ServiceMessage;
79
import org.fugerit.java.emp.sm.service.ServiceResponse;
810
import org.fugerit.java.emp.sm.service.ServiceResponseHelper;
911
import org.junit.jupiter.api.Assertions;
1012
import org.junit.jupiter.api.Test;
1113

14+
import java.io.IOException;
15+
import java.io.StringWriter;
16+
17+
@Slf4j
1218
class TestWAExHelper {
1319

1420
private static final String TEST_MESSAGE = "My Message";
@@ -29,4 +35,14 @@ void test() {
2935
Assertions.assertEquals( TEST_MESSAGE, this.getFirstError( WAExHelper.newEx(Response.Status.INTERNAL_SERVER_ERROR, new ServiceResponse().addAllBySeverity( ServiceResponseHelper.newDefaultErrorMessage( TEST_MESSAGE ) ) ) ) );
3036
}
3137

38+
@Test
39+
void testSampleUsage() throws IOException {
40+
WebApplicationException wae = WAExHelper.newEx( Response.Status.BAD_REQUEST, "Test bad request message" );
41+
try (StringWriter writer = new StringWriter()) {
42+
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValue( writer, wae.getResponse() );
43+
log.info( "test response : \n{}", writer );
44+
}
45+
Assertions.assertEquals( Response.Status.BAD_REQUEST.getStatusCode(), wae.getResponse().getStatus() );
46+
}
47+
3248
}

emp-service-model/src/test/java/test/org/fugerit/java/emp/sm/service/TestServiceResponse.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package test.org.fugerit.java.emp.sm.service;
22

3+
import java.io.IOException;
4+
import java.io.StringWriter;
35
import java.util.Arrays;
46
import java.util.stream.Collectors;
57

8+
import com.fasterxml.jackson.databind.ObjectMapper;
9+
import lombok.extern.slf4j.Slf4j;
610
import org.fugerit.java.emp.sm.service.ServiceMessage;
711
import org.fugerit.java.emp.sm.service.ServiceResponse;
812
import org.fugerit.java.emp.sm.service.ServiceResponseHelper;
913
import org.junit.jupiter.api.Assertions;
1014
import org.junit.jupiter.api.Test;
1115

16+
@Slf4j
1217
class TestServiceResponse {
1318

1419
@Test
@@ -26,5 +31,18 @@ void testServiceResponse() {
2631
Assertions.assertNotNull( response.getInfos() );
2732
Assertions.assertNotNull( response.getSuccess() );
2833
}
34+
35+
@Test
36+
void testSampleUsage() throws IOException {
37+
ServiceResponse response = new ServiceResponse()
38+
.addAllBySeverity( ServiceMessage.newMessage( "400001", ServiceMessage.Severity.ERROR, "Test bad request message" ),
39+
ServiceMessage.newMessage( ServiceMessage.Severity.INFO, "Test info message" ),
40+
ServiceMessage.newMessage( ServiceMessage.Severity.WARNING, "Test warning message" ) );
41+
try (StringWriter writer = new StringWriter()) {
42+
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValue( writer, response );
43+
log.info( "test response : \n{}", writer );
44+
}
45+
Assertions.assertEquals( 1, response.getErrors().size() );
46+
}
2947

3048
}

0 commit comments

Comments
 (0)