Skip to content

Commit

Permalink
SDK-2528: Helper method for finding the Resources that belong to a Check
Browse files Browse the repository at this point in the history
  • Loading branch information
bucky-boy committed Sep 24, 2024
1 parent bddc4a5 commit 2c90ecb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public ImportTokenResponse getImportToken() {
return importToken;
}

public ResourceContainer getResourcesForCheck(String checkId) {
CheckResponse checkResponse = this.checks.stream()
.filter(check -> check.getId().equals(checkId))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Check not found"));
return resources.filterForCheckId(checkResponse.getResourcesUsed());
}

public List<AuthenticityCheckResponse> getAuthenticityChecks() {
return filterChecksByType(AuthenticityCheckResponse.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.yoti.api.client.docs.session.retrieve;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonProperty;

Expand Down Expand Up @@ -72,7 +73,20 @@ public List<ZoomLivenessResourceResponse> getZoomLivenessResources() {
*
* @return the list of static liveness resources
*/
public List<StaticLivenessResourceResponse> getStaticLivenessResources() { return filterLivenessResourcesByType(StaticLivenessResourceResponse.class); }
public List<StaticLivenessResourceResponse> getStaticLivenessResources() {
return filterLivenessResourcesByType(StaticLivenessResourceResponse.class);
}

private <T extends LivenessResourceResponse> List<T> filterLivenessResourcesByType(Class<T> clazz) {
if (livenessCapture == null) {
return Collections.emptyList();
} else {
return livenessCapture.stream()
.filter(clazz::isInstance)
.map(clazz::cast)
.collect(Collectors.toList());
}
}

/**
* Returns ApplicantProfile resources uploaded by the user/relying business
Expand All @@ -83,14 +97,23 @@ public List<ApplicantProfileResourceResponse> getApplicantProfiles() {
return applicantProfiles;
}

private <T extends LivenessResourceResponse> List<T> filterLivenessResourcesByType(Class<T> clazz) {
List<T> filteredList = new ArrayList<>();
for (LivenessResourceResponse livenessResourceResponse : livenessCapture) {
if (clazz.isInstance(livenessResourceResponse)) {
filteredList.add(clazz.cast(livenessResourceResponse));
}
ResourceContainer filterForCheckId(List<String> checkIds) {
ResourceContainer newResourceContainer = new ResourceContainer();
newResourceContainer.idDocuments = filterResources(this.idDocuments, checkIds);
newResourceContainer.supplementaryDocuments = filterResources(this.supplementaryDocuments, checkIds);
newResourceContainer.livenessCapture = filterResources(this.livenessCapture, checkIds);
newResourceContainer.faceCapture = filterResources(this.faceCapture, checkIds);
newResourceContainer.applicantProfiles = filterResources(this.applicantProfiles, checkIds);
return newResourceContainer;
}

private <T extends ResourceResponse> List<T> filterResources(List<T> resources, List<String> checkIds) {
if (resources == null) {
return Collections.emptyList();
}
return filteredList;
return resources.stream()
.filter(resource -> checkIds.contains(resource.getId()))
.collect(Collectors.toList());
}

}

0 comments on commit 2c90ecb

Please sign in to comment.