Skip to content

Commit 013b32d

Browse files
authored
Merge pull request #14 from mcanoy/get-allowed-user-roles
add ability to query for participant role key / values
2 parents b901912 + ac4e048 commit 013b32d

10 files changed

Lines changed: 121 additions & 11 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1717
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
1818
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
19-
<quarkus.platform.version>2.1.3.Final</quarkus.platform.version>
19+
<quarkus.platform.version>2.9.2.Final</quarkus.platform.version>
2020
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
2121
<lombok.version>1.18.20</lombok.version>
2222
<sonar.host.url>https://sonarcloud.io</sonar.host.url>

src/main/java/com/redhat/labs/lodestar/resource/RuntimeConfigResource.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public Map<String, String> getEngagementOptions() {
4444
public Map<String, String> getRegionOptions() {
4545
return configService.getEngagementRegionOptions();
4646
}
47+
48+
@GET
49+
@Path("participant/options")
50+
public Map<Object, Object> getParticipantOptions(@QueryParam("engagementType") String type) {
51+
return configService.getParticipantRoleOptions(type);
52+
}
4753

4854
@GET
4955
@Path("rbac")

src/main/java/com/redhat/labs/lodestar/service/RuntimeConfigService.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ void createRuntimeConfigurations() {
7272

7373
}
7474

75+
@SuppressWarnings("unchecked")
76+
public Map<Object, Object> getParticipantRoleOptions(String engagementType) {
77+
Map<String, Object> runtime = mapRuntimeConfigurationTypeRequired(engagementType);
78+
List<Map<String, Object>> typesList = Optional.of(runtime)
79+
.map(m -> (Map<String, Object>) m.get("user_options"))
80+
.map(m -> (Map<String, Object>) m.get("user_roles"))
81+
.map(m -> (List<Map<String, Object>>) m.get("options")).orElse(new ArrayList<>());
82+
83+
return typesList.stream().collect(Collectors.toMap(s -> s.get("value"), s -> s.get("label")));
84+
}
85+
7586
@SuppressWarnings("unchecked")
7687
public Map<Object, Object> getArtifactOptions() {
7788
Map<String, Object> configuration = baseConfiguration.getConfiguration();
@@ -136,12 +147,22 @@ void createOverrideConfig(String engagementType) {
136147
*/
137148
public Map<String, Object> mapRuntimeConfiguration(Optional<String> engagementType) {
138149

150+
if (engagementType.isPresent()) {
151+
return mapRuntimeConfigurationTypeRequired(engagementType.get());
152+
}
153+
154+
return baseConfiguration.getConfiguration();
155+
156+
}
157+
158+
public Map<String, Object> mapRuntimeConfigurationTypeRequired(String engagementType) {
159+
139160
// get map for base configuration
140161
Map<String, Object> base = baseConfiguration.getConfiguration();
141162

142-
if (engagementType.isPresent() && overrideConfigurations.containsKey(engagementType.get())) {
163+
if (overrideConfigurations.containsKey(engagementType)) {
143164

144-
Map<String, Object> override = overrideConfigurations.get(engagementType.get()).getConfiguration();
165+
Map<String, Object> override = overrideConfigurations.get(engagementType).getConfiguration();
145166
base = MarshalUtils.merge(base, override);
146167

147168
}

src/test/java/com/redhat/labs/lodestar/resource/RuntimeConfigResourceTest.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
import java.util.List;
1010
import java.util.Map;
1111

12-
import com.fasterxml.jackson.databind.JsonNode;
13-
import com.fasterxml.jackson.databind.ObjectMapper;
14-
import io.restassured.path.json.JsonPath;
15-
import org.junit.jupiter.api.Assertions;
1612
import org.junit.jupiter.api.Test;
1713

1814
import com.redhat.labs.lodestar.utils.ResourceLoader;
@@ -51,7 +47,7 @@ void testGetRuntimeConfigurationNoType() {
5147
String response = given().when().contentType(ContentType.JSON).get()
5248
.then().statusCode(200).extract().asString();
5349

54-
Assertions.assertEquals(expectedResponse, response);
50+
assertEquals(expectedResponse, response);
5551

5652
}
5753

@@ -61,7 +57,7 @@ void testGetRuntimeConfigurationTypeOne() throws Exception {
6157
String response = given().when().contentType(ContentType.JSON).queryParam("type", "TypeOne").get()
6258
.then().statusCode(200).extract().asString();
6359

64-
Assertions.assertEquals(expectedResponse, response);
60+
assertEquals(expectedResponse, response);
6561

6662
}
6763

@@ -71,7 +67,7 @@ void testGetRuntimeConfigurationTypeTwo() {
7167
String response = given().when().contentType(ContentType.JSON).queryParam("type", "TypeTwo").get()
7268
.then().statusCode(200).extract().asString();
7369

74-
Assertions.assertEquals(expectedResponse, response);
70+
assertEquals(expectedResponse, response);
7571

7672
}
7773

@@ -106,4 +102,20 @@ void testGetEngagementOptions() {
106102

107103
}
108104

105+
@Test
106+
void testGetParticipantOptions() {
107+
given().when().contentType(ContentType.JSON).get("participant/options")
108+
.then().statusCode(200).body("size()", equalTo(2))
109+
.body("jurist", equalTo("Jurist")).body("judge", equalTo("Judge"));
110+
111+
}
112+
113+
@Test
114+
void testGetParticipantOptionsTyped() {
115+
given().queryParam("engagementType", "TypeTwo").when().contentType(ContentType.JSON).get("participant/options")
116+
.then().statusCode(200).body("size()", equalTo(2))
117+
.body("plaintiff", equalTo("Plaintiff")).body("defendant", equalTo("Defendant"));
118+
119+
}
120+
109121
}

src/test/resources/expected/service-base-config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,19 @@
6767
}
6868
]
6969
}
70+
},
71+
"user_options": {
72+
"user_roles": {
73+
"options": [
74+
{
75+
"value": "jurist",
76+
"label": "Jurist"
77+
},
78+
{
79+
"value": "judge",
80+
"label": "Judge"
81+
}
82+
]
83+
}
7084
}
7185
}

src/test/resources/expected/service-get-type-one-config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@
5454
]
5555
}
5656
},
57+
"user_options": {
58+
"user_roles": {
59+
"options": [
60+
{
61+
"value": "jurist",
62+
"label": "Jurist"
63+
},
64+
{
65+
"value": "judge",
66+
"label": "Judge"
67+
}
68+
]
69+
}
70+
},
5771
"other_options": {
5872
"types": {
5973
"options": [

src/test/resources/expected/service-get-type-three-config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@
3636
]
3737
}
3838
},
39+
"user_options": {
40+
"user_roles": {
41+
"options": [
42+
{
43+
"value": "jurist",
44+
"label": "Jurist"
45+
},
46+
{
47+
"value": "judge",
48+
"label": "Judge"
49+
}
50+
]
51+
}
52+
},
3953
"other_options": {
4054
"types": {
4155
"options": [

src/test/resources/expected/service-get-type-two-config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@
5454
]
5555
}
5656
},
57+
"user_options": {
58+
"user_roles": {
59+
"options": [
60+
{
61+
"value": "defendant",
62+
"label": "Defendant"
63+
},
64+
{
65+
"value": "plaintiff",
66+
"label": "Plaintiff"
67+
}
68+
]
69+
}
70+
},
5771
"other_options": {
5872
"types": {
5973
"options": [

src/test/resources/runtime-config-TypeTwo.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@ other_options:
66
types:
77
options:
88
- label: OptionTwo
9-
value: option2
9+
value: option2
10+
user_options:
11+
user_roles:
12+
options:
13+
- value: defendant
14+
label: Defendant
15+
- value: plaintiff
16+
label: Plaintiff

src/test/resources/runtime-config-base.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ artifact_options:
3737
options:
3838
- value: flyer
3939
label: Flyer
40+
user_options:
41+
user_roles:
42+
options:
43+
- value: jurist
44+
label: Jurist
45+
- value: judge
46+
label: Judge
47+

0 commit comments

Comments
 (0)