Skip to content

Commit 04e8d32

Browse files
committed
release: 1.2.2
- logback version upgrade - enhancement in execution context
1 parent 45aa0b8 commit 04e8d32

File tree

5 files changed

+114
-15
lines changed

5 files changed

+114
-15
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ framework and objects.
4949
<dependency>
5050
<groupId>com.javaquery</groupId>
5151
<artifactId>util</artifactId>
52-
<version>1.2.1</version>
52+
<version>1.2.2</version>
5353
</dependency>
5454
```
5555

5656
# Gradle
5757

5858
```
59-
implementation 'com.javaquery:util:1.2.1'
59+
implementation 'com.javaquery:util:1.2.2'
6060
```

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66

77
sourceCompatibility = 1.8
88
group 'com.javaquery'
9-
version '1.2.1'
9+
version '1.2.2'
1010

1111
repositories {
1212
mavenCentral()
@@ -17,8 +17,8 @@ dependencies {
1717
implementation('org.json:json:+')
1818
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.13.2'
1919

20-
testImplementation 'net.logstash.logback:logstash-logback-encoder:6.6'
21-
testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '+'
20+
testImplementation 'net.logstash.logback:logstash-logback-encoder:7.4'
21+
testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.7'
2222
testImplementation('org.junit.jupiter:junit-jupiter:5.7.0')
2323
}
2424

src/main/java/com/javaquery/util/ExecutionContext.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import com.javaquery.util.logging.Action;
5+
import com.javaquery.util.logging.ActivityStatus;
56
import com.javaquery.util.time.Dates;
67

78
import java.util.Date;
@@ -12,14 +13,22 @@
1213
* @author vicky.thakor
1314
* @since 1.2.0
1415
*/
15-
public class ExecutionContext<T> {
16+
public class ExecutionContext<T, V> {
1617

1718
@JsonProperty("request_id")
18-
private final String requestId;
19+
private String requestId;
1920

2021
@JsonProperty("reference_id")
2122
private T referenceId;
22-
private final Action action;
23+
24+
@JsonProperty("user")
25+
private V userContext;
26+
27+
private Action action;
28+
29+
@JsonProperty("activity_status")
30+
private ActivityStatus activityStatus;
31+
2332
private Map<String, Object> meta;
2433

2534
@JsonProperty("max_retries")
@@ -31,6 +40,15 @@ public class ExecutionContext<T> {
3140
@JsonProperty("created_at")
3241
private final Date createdAt;
3342

43+
public ExecutionContext() {
44+
this.createdAt = Dates.current();
45+
}
46+
47+
public ExecutionContext(String requestId){
48+
this.requestId = requestId;
49+
this.createdAt = Dates.current();
50+
}
51+
3452
public ExecutionContext(String requestId, T referenceId, Action action) {
3553
this.requestId = requestId;
3654
this.referenceId = referenceId;
@@ -75,6 +93,18 @@ public String getRequestId() {
7593
return requestId;
7694
}
7795

96+
public void setRequestId(String requestId) {
97+
this.requestId = requestId;
98+
}
99+
100+
public V getUserContext() {
101+
return userContext;
102+
}
103+
104+
public void setUserContext(V userContext) {
105+
this.userContext = userContext;
106+
}
107+
78108
public T getReferenceId() {
79109
return referenceId;
80110
}
@@ -83,6 +113,18 @@ public Action getAction() {
83113
return action;
84114
}
85115

116+
public void setAction(Action action) {
117+
this.action = action;
118+
}
119+
120+
public ActivityStatus getActivityStatus() {
121+
return activityStatus;
122+
}
123+
124+
public void setActivityStatus(ActivityStatus activityStatus) {
125+
this.activityStatus = activityStatus;
126+
}
127+
86128
public Map<String, Object> getMeta() {
87129
return meta;
88130
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.javaquery.util.logging;
2+
3+
/**
4+
* @author vicky.thakor
5+
* @since 1.2.2
6+
*
7+
* Represents current activity status
8+
*/
9+
public enum ActivityStatus {
10+
STARTED, PROCESSING, COMPLETED, FAILED, PROCESSING_WITH_ERROR, COMPLETED_WITH_ERROR;
11+
}
12+

src/test/java/com/javaquery/util/TestExecutionContext.java

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.javaquery.util;
22

33
import com.javaquery.util.logging.Action;
4+
import com.javaquery.util.logging.ActivityStatus;
45
import org.junit.jupiter.api.Assertions;
56
import org.junit.jupiter.api.Test;
67

@@ -16,19 +17,63 @@ public enum ExecutionContextAction implements Action{
1617
ONE
1718
}
1819

20+
public class UserContext{
21+
22+
private Long userId;
23+
24+
private Long tenantId;
25+
26+
public UserContext(Long userId, Long tenantId) {
27+
this.userId = userId;
28+
this.tenantId = tenantId;
29+
}
30+
31+
public Long getUserId() {
32+
return userId;
33+
}
34+
35+
public Long getTenantId() {
36+
return tenantId;
37+
}
38+
}
39+
40+
@Test
41+
public void defaultConstructor(){
42+
ExecutionContext<Object, Object> executionContext = new ExecutionContext<>();
43+
executionContext.setUserContext(new UserContext(50L, 20L));
44+
executionContext.setRequestId(UniqueIdGenerator.generate());
45+
46+
UserContext userContext = (UserContext) executionContext.getUserContext();
47+
Assertions.assertEquals(50L, userContext.getUserId());
48+
Assertions.assertNotNull(executionContext.getCreatedAt());
49+
Assertions.assertNotNull(executionContext.getRequestId());
50+
}
51+
52+
@Test
53+
public void constructorWithRequestId(){
54+
ExecutionContext<Long, Long> executionContext = new ExecutionContext<>(UniqueIdGenerator.generate());
55+
Assertions.assertNotNull(executionContext.getRequestId());
56+
}
57+
1958
@Test
2059
public void constructorWithRequestIdReferenceIdAction(){
21-
ExecutionContext<Long> executionContext = new ExecutionContext<>(UniqueIdGenerator.generate(), 1L, ExecutionContextAction.ONE);
60+
ExecutionContext<Long, Long> executionContext = new ExecutionContext<>(UniqueIdGenerator.generate(), 1L, ExecutionContextAction.ONE);
61+
executionContext.setUserContext(50L);
62+
executionContext.setActivityStatus(ActivityStatus.STARTED);
2263
Assertions.assertNotNull(executionContext.getRequestId());
2364
Assertions.assertEquals(ExecutionContextAction.ONE, executionContext.getAction());
2465
Assertions.assertEquals(1L, executionContext.getReferenceId());
2566
Assertions.assertNotNull(executionContext.getMeta());
2667
Assertions.assertNotNull(executionContext.getCreatedAt());
68+
69+
Assertions.assertEquals(50L, executionContext.getUserContext());
70+
Assertions.assertEquals(ActivityStatus.STARTED, executionContext.getActivityStatus());
71+
Assertions.assertNotNull(executionContext.getCreatedAt());
2772
}
2873

2974
@Test
3075
public void constructorWithReferenceIdAction(){
31-
ExecutionContext<String> executionContext = new ExecutionContext<>("test", ExecutionContextAction.ONE);
76+
ExecutionContext<String, Void> executionContext = new ExecutionContext<>("test", ExecutionContextAction.ONE);
3277
Assertions.assertNotNull(executionContext.getRequestId());
3378
Assertions.assertEquals(ExecutionContextAction.ONE, executionContext.getAction());
3479
Assertions.assertEquals("test", executionContext.getReferenceId());
@@ -38,7 +83,7 @@ public void constructorWithReferenceIdAction(){
3883

3984
@Test
4085
public void constructorWithAction(){
41-
ExecutionContext<String> executionContext = new ExecutionContext<>(ExecutionContextAction.ONE);
86+
ExecutionContext<String, Void> executionContext = new ExecutionContext<>(ExecutionContextAction.ONE);
4287
Assertions.assertNotNull(executionContext.getRequestId());
4388
Assertions.assertEquals(ExecutionContextAction.ONE, executionContext.getAction());
4489
Assertions.assertNull(executionContext.getReferenceId());
@@ -48,7 +93,7 @@ public void constructorWithAction(){
4893

4994
@Test
5095
public void constructorWithActionAndMeta(){
51-
ExecutionContext<String> executionContext = new ExecutionContext<>(ExecutionContextAction.ONE);
96+
ExecutionContext<String, Void> executionContext = new ExecutionContext<>(ExecutionContextAction.ONE);
5297
executionContext.addMeta("key", "value");
5398
Assertions.assertNotNull(executionContext.getRequestId());
5499
Assertions.assertEquals(ExecutionContextAction.ONE, executionContext.getAction());
@@ -63,7 +108,7 @@ public void constructorWithActionAndMeta(){
63108

64109
@Test
65110
public void constructorWithActionAndRetriesAttempted(){
66-
ExecutionContext<String> executionContext = new ExecutionContext<>(ExecutionContextAction.ONE);
111+
ExecutionContext<String, Void> executionContext = new ExecutionContext<>(ExecutionContextAction.ONE);
67112
executionContext.addRetriesAttempted(1);
68113
Assertions.assertNotNull(executionContext.getRequestId());
69114
Assertions.assertEquals(ExecutionContextAction.ONE, executionContext.getAction());
@@ -75,7 +120,7 @@ public void constructorWithActionAndRetriesAttempted(){
75120

76121
@Test
77122
public void constructorWithReferenceIdActionMaxRetries(){
78-
ExecutionContext<Long> executionContext = new ExecutionContext<>(1L, ExecutionContextAction.ONE, 3);
123+
ExecutionContext<Long, Void> executionContext = new ExecutionContext<>(1L, ExecutionContextAction.ONE, 3);
79124
Assertions.assertNotNull(executionContext.getRequestId());
80125
Assertions.assertEquals(ExecutionContextAction.ONE, executionContext.getAction());
81126
Assertions.assertEquals(1L, executionContext.getReferenceId());
@@ -86,7 +131,7 @@ public void constructorWithReferenceIdActionMaxRetries(){
86131

87132
@Test
88133
public void constructorWithActionMaxRetries(){
89-
ExecutionContext<Long> executionContext = new ExecutionContext<>(ExecutionContextAction.ONE, 3);
134+
ExecutionContext<Long, Void> executionContext = new ExecutionContext<>(ExecutionContextAction.ONE, 3);
90135
Assertions.assertNotNull(executionContext.getRequestId());
91136
Assertions.assertEquals(ExecutionContextAction.ONE, executionContext.getAction());
92137
Assertions.assertNull(executionContext.getReferenceId());

0 commit comments

Comments
 (0)