Skip to content

Commit 9bc08dc

Browse files
committed
SDK-2531: Update SessionSpec to use strongly typed object for Identity Profile requirements
1 parent efb45c3 commit 9bc08dc

File tree

4 files changed

+146
-30
lines changed

4 files changed

+146
-30
lines changed

yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SessionSpec.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.yoti.api.client.docs.session.create.check.RequestedCheck;
99
import com.yoti.api.client.docs.session.create.filters.RequiredDocument;
1010
import com.yoti.api.client.docs.session.create.identityprofile.advanced.AdvancedIdentityProfileRequirementsPayload;
11+
import com.yoti.api.client.docs.session.create.identityprofile.simple.IdentityProfileRequirementsPayload;
1112
import com.yoti.api.client.docs.session.create.resources.ResourceCreationContainer;
1213
import com.yoti.api.client.docs.session.create.task.RequestedTask;
1314

@@ -55,7 +56,7 @@ public class SessionSpec {
5556
private final IbvOptions ibvOptions;
5657

5758
@JsonProperty(Property.IDENTITY_PROFILE_REQUIREMENTS)
58-
private final Map<String, Object> identityProfile;
59+
private final IdentityProfileRequirementsPayload identityProfile;
5960

6061
@JsonProperty(Property.ADVANCED_IDENTITY_PROFILE_REQUIREMENTS)
6162
private final AdvancedIdentityProfileRequirementsPayload advancedIdentityProfileRequirements;
@@ -81,7 +82,7 @@ public class SessionSpec {
8182
Boolean blockBiometricConsent,
8283
IbvOptions ibvOptions,
8384
ZonedDateTime sessionDeadline,
84-
Map<String, Object> identityProfile,
85+
IdentityProfileRequirementsPayload identityProfile,
8586
Map<String, Object> subject,
8687
ResourceCreationContainer resources,
8788
Boolean createIdentityProfilePreview,
@@ -223,7 +224,7 @@ public ZonedDateTime getSessionDeadline() {
223224
*
224225
* @return Identity Profile
225226
*/
226-
public Object getIdentityProfile() {
227+
public IdentityProfileRequirementsPayload getIdentityProfile() {
227228
return identityProfile;
228229
}
229230

@@ -277,7 +278,7 @@ public static class Builder {
277278
private Boolean blockBiometricConsent;
278279
private IbvOptions ibvOptions;
279280
private ZonedDateTime sessionDeadline;
280-
private Map<String, Object> identityProfile;
281+
private IdentityProfileRequirementsPayload identityProfile;
281282
private AdvancedIdentityProfileRequirementsPayload advancedIdentityProfileRequirementsPayload;
282283
private Map<String, Object> subject;
283284
private ResourceCreationContainer resources;
@@ -428,7 +429,7 @@ public Builder withSessionDeadline(ZonedDateTime sessionDeadline) {
428429
* @param identityProfile the Identity Profile
429430
* @return the Builder
430431
*/
431-
public Builder withIdentityProfile(Map<String, Object> identityProfile) {
432+
public Builder withIdentityProfile(IdentityProfileRequirementsPayload identityProfile) {
432433
this.identityProfile = identityProfile;
433434
return this;
434435
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.yoti.api.client.docs.session.create.identityprofile.simple;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
@JsonInclude(JsonInclude.Include.NON_NULL)
7+
public class IdentityProfileRequirementsPayload {
8+
9+
@JsonProperty("trust_framework")
10+
private final String trustFramework;
11+
12+
@JsonProperty("scheme")
13+
private final IdentityProfileSchemePayload scheme;
14+
15+
IdentityProfileRequirementsPayload(String trustFramework, IdentityProfileSchemePayload scheme) {
16+
this.trustFramework = trustFramework;
17+
this.scheme = scheme;
18+
}
19+
20+
public static Builder builder() {
21+
return new Builder();
22+
}
23+
24+
public String getTrustFramework() {
25+
return trustFramework;
26+
}
27+
28+
public IdentityProfileSchemePayload getScheme() {
29+
return scheme;
30+
}
31+
32+
public static class Builder {
33+
34+
private String trustFramework;
35+
private IdentityProfileSchemePayload scheme;
36+
37+
Builder() {}
38+
39+
/**
40+
* Sets the trust framework name for the Identity Profile requirement
41+
*
42+
* @param trustFramework the name of the trust framework
43+
* @return the builder
44+
*/
45+
public Builder withTrustFramework(String trustFramework) {
46+
this.trustFramework = trustFramework;
47+
return this;
48+
}
49+
50+
/**
51+
* Sets the scheme for the Identity Profile requirement
52+
*
53+
* @param scheme the scheme
54+
* @return the builder
55+
*/
56+
public Builder withScheme(IdentityProfileSchemePayload scheme) {
57+
this.scheme = scheme;
58+
return this;
59+
}
60+
61+
public IdentityProfileRequirementsPayload build() {
62+
return new IdentityProfileRequirementsPayload(trustFramework, scheme);
63+
}
64+
65+
}
66+
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.yoti.api.client.docs.session.create.identityprofile.simple;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
@JsonInclude(JsonInclude.Include.NON_NULL)
7+
public class IdentityProfileSchemePayload {
8+
9+
@JsonProperty("type")
10+
private final String type;
11+
12+
@JsonProperty("objective")
13+
private final String objective;
14+
15+
IdentityProfileSchemePayload(String type, String objective) {
16+
this.type = type;
17+
this.objective = objective;
18+
}
19+
20+
public static Builder builder() {
21+
return new Builder();
22+
}
23+
24+
public String getType() {
25+
return type;
26+
}
27+
28+
public String getObjective() {
29+
return objective;
30+
}
31+
32+
public static class Builder {
33+
34+
private String type;
35+
private String objective;
36+
37+
Builder() {}
38+
39+
/**
40+
* Sets the type of the scheme for the Identity Profile
41+
*
42+
* @param type the type of scheme
43+
* @return the builder
44+
*/
45+
public Builder withType(String type) {
46+
this.type = type;
47+
return this;
48+
}
49+
50+
/**
51+
* Sets the objective of the scheme for the Identity Profile
52+
*
53+
* @param objective the objective of the scheme
54+
* @return the builder
55+
*/
56+
public Builder withObjective(String objective) {
57+
this.objective = objective;
58+
return this;
59+
}
60+
61+
public IdentityProfileSchemePayload build() {
62+
return new IdentityProfileSchemePayload(type, objective);
63+
}
64+
65+
}
66+
67+
}

yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SessionSpecTest.java

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.yoti.api.client.docs.session.create.check.RequestedDocumentAuthenticityCheck;
2121
import com.yoti.api.client.docs.session.create.check.RequestedLivenessCheck;
2222
import com.yoti.api.client.docs.session.create.filters.RequiredDocument;
23+
import com.yoti.api.client.docs.session.create.identityprofile.simple.IdentityProfileRequirementsPayload;
2324
import com.yoti.api.client.docs.session.create.resources.ResourceCreationContainer;
2425
import com.yoti.api.client.docs.session.create.task.RequestedIdDocTextExtractionTask;
2526

@@ -57,6 +58,7 @@ public class SessionSpecTest {
5758
@Mock ZonedDateTime sessionDeadlineMock;
5859
@Mock ResourceCreationContainer resourceCreationContainerMock;
5960
@Mock ImportTokenPayload importTokenMock;
61+
@Mock IdentityProfileRequirementsPayload identityProfileRequirementsPayloadMock;
6062

6163
@Test
6264
public void shouldBuildWithMinimalConfiguration() {
@@ -215,33 +217,12 @@ public void withSessionDeadline_shouldSetTheSessionDeadline() {
215217
}
216218

217219
@Test
218-
public void shouldBuildWithIdentityProfileRequirements() throws IOException {
219-
Map<String, Object> scheme = new HashMap<>();
220-
scheme.put(IdentityProperty.TYPE, "A_TYPE");
221-
scheme.put(IdentityProperty.OBJECTIVE, "AN_OBJECTIVE");
222-
223-
Map<String, Object> identityProfile = new HashMap<>();
224-
identityProfile.put(IdentityProperty.TRUST_FRAMEWORK, "A_FRAMEWORK");
225-
identityProfile.put(IdentityProperty.SCHEME, scheme);
226-
227-
JsonNode json = toSessionSpecJson(identityProfile);
228-
229-
assertThat(
230-
json.get(IdentityProperty.TRUST_FRAMEWORK).asText(),
231-
is(equalTo(identityProfile.get(IdentityProperty.TRUST_FRAMEWORK)))
232-
);
233-
234-
JsonNode schemeJsonNode = json.get(IdentityProperty.SCHEME);
235-
assertThat(schemeJsonNode.get(IdentityProperty.TYPE).asText(), is(equalTo(scheme.get(IdentityProperty.TYPE))));
236-
assertThat(schemeJsonNode.get(IdentityProperty.OBJECTIVE).asText(), is(equalTo(scheme.get(IdentityProperty.OBJECTIVE))));
237-
}
238-
239-
private static JsonNode toSessionSpecJson(Map<String, Object> obj) throws IOException {
240-
SessionSpec session = SessionSpec.builder()
241-
.withIdentityProfile(obj)
220+
public void withIdentityProfile_shouldSetTheIdentityProfile() {
221+
SessionSpec result = SessionSpec.builder()
222+
.withIdentityProfile(identityProfileRequirementsPayloadMock)
242223
.build();
243224

244-
return MAPPER.readTree(MAPPER.writeValueAsString(session.getIdentityProfile()).getBytes(DEFAULT_CHARSET));
225+
assertThat(result.getIdentityProfile(), is(identityProfileRequirementsPayloadMock));
245226
}
246227

247228
@Test

0 commit comments

Comments
 (0)