Skip to content

Commit a4ff7a8

Browse files
committed
System enhancements
1. Reformat all records and Event class to use same datetime. 1. Create a GlobalConfiguration class. 1. Removed custom Jakson properties from HttpErrorInfo.
1 parent 3331bb4 commit a4ff7a8

File tree

11 files changed

+142
-62
lines changed

11 files changed

+142
-62
lines changed
-109 KB
Binary file not shown.

store-common/store-api/src/main/java/com/siriusxi/ms/store/api/composite/dto/ProductAggregate.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
package com.siriusxi.ms.store.api.composite.dto;
22

33
import java.util.List;
4-
4+
/**
5+
* Record <code>ProductAggregate</code> that hold all the product aggregate information.
6+
*
7+
* @implNote Since it is a record and not normal POJO, so it needs some customizations
8+
* to be serialized to JSON and this is done with method
9+
* <code>GlobalConfiguration.jacksonCustomizer()</code>.
10+
*
11+
* @see java.lang.Record
12+
* @see com.siriusxi.ms.store.util.config.GlobalConfiguration
13+
* @author mohamed.taman
14+
* @version v4.6
15+
* @since v0.1
16+
*/
517
public record ProductAggregate (int productId,
618
String name,
719
int weight,

store-common/store-api/src/main/java/com/siriusxi/ms/store/api/composite/dto/RecommendationSummary.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
package com.siriusxi.ms.store.api.composite.dto;
22

3+
/**
4+
* Record <code>RecommendationSummary</code> that hold all the product recommendations.
5+
*
6+
* @implNote Since it is a record and not normal POJO, so it needs some customizations
7+
* to be serialized to JSON and this is done with method
8+
* <code>GlobalConfiguration.jacksonCustomizer()</code>.
9+
*
10+
* @see java.lang.Record
11+
* @see com.siriusxi.ms.store.util.config.GlobalConfiguration
12+
* @author mohamed.taman
13+
* @version v4.6
14+
* @since v0.1
15+
*/
316
public record RecommendationSummary(int recommendationId,
417
String author,
518
int rate,

store-common/store-api/src/main/java/com/siriusxi/ms/store/api/composite/dto/ReviewSummary.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
package com.siriusxi.ms.store.api.composite.dto;
22

3+
/**
4+
* Record <code>ReviewSummary</code> that hold all product reviews.
5+
*
6+
* @implNote Since it is a record and not normal POJO, so it needs some customizations
7+
* to be serialized to JSON and this is done with method
8+
* <code>GlobalConfiguration.jacksonCustomizer()</code>.
9+
*
10+
* @see java.lang.Record
11+
* @see com.siriusxi.ms.store.util.config.GlobalConfiguration
12+
* @author mohamed.taman
13+
* @version v4.6
14+
* @since v0.1
15+
*/
316
public record ReviewSummary(int reviewId,
417
String author,
518
String subject,

store-common/store-api/src/main/java/com/siriusxi/ms/store/api/composite/dto/ServiceAddresses.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
package com.siriusxi.ms.store.api.composite.dto;
22

3+
/**
4+
* Record <code>ServiceAddresses</code> that hold all services addresses involved in the product
5+
* call.
6+
*
7+
* @implNote Since it is a record and not normal POJO, so it needs some customizations
8+
* to be serialized to JSON and this is done with method
9+
* <code>GlobalConfiguration.jacksonCustomizer()</code>.
10+
*
11+
* @see java.lang.Record
12+
* @see com.siriusxi.ms.store.util.config.GlobalConfiguration
13+
* @author mohamed.taman
14+
* @version v4.6
15+
* @since v0.1
16+
*/
317
public record ServiceAddresses( String storeService,
418
String productService,
519
String reviewService,
Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package com.siriusxi.ms.store.api.event;
22

3-
import lombok.*;
3+
import com.fasterxml.jackson.annotation.JsonFormat;
4+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
5+
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Data;
8+
import lombok.NoArgsConstructor;
9+
import lombok.Setter;
410

511
import java.time.LocalDateTime;
612

@@ -13,17 +19,22 @@
1319
@Setter(NONE)
1420
public class Event<K, T> {
1521

16-
public enum Type {CREATE, DELETE}
22+
private Event.Type eventType;
23+
private K key;
24+
private T data;
25+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd@HH:mm:ss.SSS")
26+
@JsonSerialize(using = LocalDateTimeSerializer.class)
27+
private LocalDateTime eventCreatedAt;
1728

18-
private Event.Type eventType;
19-
private K key;
20-
private T data;
21-
private LocalDateTime eventCreatedAt;
29+
public Event(Type eventType, K key, T data) {
30+
this.eventType = eventType;
31+
this.key = key;
32+
this.data = data;
33+
this.eventCreatedAt = now();
34+
}
2235

23-
public Event(Type eventType, K key, T data) {
24-
this.eventType = eventType;
25-
this.key = key;
26-
this.data = data;
27-
this.eventCreatedAt = now();
28-
}
29-
}
36+
public enum Type {
37+
CREATE,
38+
DELETE
39+
}
40+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.siriusxi.ms.store.util.config;
2+
3+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
4+
import com.fasterxml.jackson.annotation.PropertyAccessor;
5+
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
/**
9+
* Class <code>GlobalConfiguration</code> holds all configurations that used by all the system
10+
* services.
11+
*
12+
* @author mohamed.taman
13+
* @version v4.6
14+
* @since v0.1
15+
*/
16+
@Configuration
17+
public class GlobalConfiguration {
18+
19+
/**
20+
* This bean is for Java 14 record to be serialized as JSON
21+
*
22+
* @return Jackson2ObjectMapperBuilderCustomizer builder
23+
*/
24+
@Bean
25+
public Jackson2ObjectMapperBuilderCustomizer jacksonCustomizer() {
26+
return builder ->
27+
builder
28+
.visibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
29+
// human readable
30+
.indentOutput(true);
31+
}
32+
}
Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.siriusxi.ms.store.util.http;
22

33
import com.fasterxml.jackson.annotation.JsonFormat;
4-
import com.fasterxml.jackson.annotation.JsonProperty;
5-
import com.fasterxml.jackson.core.JsonProcessingException;
6-
import com.fasterxml.jackson.databind.ObjectMapper;
74
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
85
import com.fasterxml.jackson.datatype.jsr310.ser.ZonedDateTimeSerializer;
96
import org.springframework.http.HttpStatus;
@@ -14,21 +11,22 @@
1411
* Record <code>HttpErrorInfo</code> which encapsulate all HTTP errors sent to client.
1512
*
1613
* @implNote Since it is a record and not normal POJO, so it needs some customizations
17-
* to be serialized to JSON.
18-
* @see java.lang.Record
14+
* to be serialized to JSON and this is done with method
15+
* <code>GlobalConfiguration.jacksonCustomizer()</code>.
16+
*
17+
* @see java.lang.Record
18+
* @see com.siriusxi.ms.store.util.config.GlobalConfiguration
1919
* @author mohamed.taman
20-
* @version v0.4
20+
* @version v4.6
2121
* @since v0.1
2222
*/
2323
public record HttpErrorInfo(
24-
@JsonProperty("httpStatus")HttpStatus httpStatus,
25-
@JsonProperty("message")String message,
26-
@JsonProperty("path")String path,
27-
@JsonProperty("time")
24+
HttpStatus httpStatus,
25+
String message,
26+
String path,
2827
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd@HH:mm:ss.SSSZ")
2928
@JsonSerialize(using = ZonedDateTimeSerializer.class)
30-
ZonedDateTime timestamp
31-
) {
29+
ZonedDateTime timestamp) {
3230

3331
/**
3432
* Instantiates a new Http error info.
@@ -40,14 +38,4 @@ public record HttpErrorInfo(
4038
public HttpErrorInfo(HttpStatus httpStatus, String path, String message) {
4139
this(httpStatus, message, path, ZonedDateTime.now());
4240
}
43-
44-
45-
public static void main(String[] args) throws JsonProcessingException {
46-
HttpErrorInfo err = new HttpErrorInfo(HttpStatus.BAD_REQUEST, "/path", "Error man");
47-
HttpErrorInfo err1 = new HttpErrorInfo(HttpStatus.UNPROCESSABLE_ENTITY, "Error message man",
48-
"/path1234", ZonedDateTime.now());
49-
ObjectMapper mapper = new ObjectMapper();
50-
System.out.println(mapper.writeValueAsString(err));
51-
System.out.println(mapper.writeValueAsString(err1));
52-
}
5341
}
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package com.siriusxi.ms.store.pcs;
22

3-
import com.fasterxml.jackson.annotation.JsonAutoDetect;
4-
import com.fasterxml.jackson.annotation.PropertyAccessor;
53
import org.springframework.boot.SpringApplication;
64
import org.springframework.boot.autoconfigure.SpringBootApplication;
75
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
86
import org.springframework.context.annotation.Bean;
97
import org.springframework.context.annotation.ComponentScan;
108
import org.springframework.web.reactive.function.client.WebClient;
11-
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
129
import springfox.documentation.swagger2.annotations.EnableSwagger2WebFlux;
1310

1411
@SpringBootApplication
@@ -24,10 +21,4 @@ public static void main(String[] args) {
2421
public WebClient.Builder loadBalancedWebClientBuilder() {
2522
return WebClient.builder();
2623
}
27-
28-
@Bean
29-
public Jackson2ObjectMapperBuilderCustomizer jacksonCustomizer() {
30-
return builder -> builder.visibility( PropertyAccessor.FIELD,
31-
JsonAutoDetect.Visibility.ANY);
32-
}
3324
}

store-services/store-service/src/main/java/com/siriusxi/ms/store/pcs/config/StoreServiceConfiguration.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ public StoreServiceConfiguration(StoreIntegration integration) {
5757
this.integration = integration;
5858
}
5959

60-
@Bean(name = "Core System Microservices")
60+
/**
61+
* This method is to check all the services health status, and store service health will be only
62+
* in up health state if and only if all of the core services and dependencies are up and running.
63+
*
64+
* @return ReactiveHealthContributor information about all the core microservices.
65+
*/
66+
@Bean(name = "Core Microservices")
6167
ReactiveHealthContributor coreServices() {
6268

6369
ReactiveHealthIndicator productHealthIndicator = integration::getProductHealth;

0 commit comments

Comments
 (0)