Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Changes related to support of old and new Service Offering VC #193

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import eu.gaiax.wizard.api.model.setting.ContextConfig;
import eu.gaiax.wizard.api.utils.CommonUtils;
import eu.gaiax.wizard.api.utils.S3Utils;
import eu.gaiax.wizard.api.utils.StringPool;
import eu.gaiax.wizard.api.utils.Validate;
import eu.gaiax.wizard.core.service.InvokeService;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -114,13 +113,29 @@ private JsonNode getPolicyArrayFromServiceOffer(JsonNode serviceOffer) {
log.info("Error encountered while parsing service for policy");
}

Optional<JsonNode> policyVcOptional = list.stream()
.filter(vc -> vc.get(StringPool.CREDENTIAL_SUBJECT).get("type").asText().equals("gx:ServiceOffering"))
.findFirst();
if (policyVcOptional.isPresent() && policyVcOptional.get().get(StringPool.CREDENTIAL_SUBJECT).has(StringPool.GX_POLICY)) {
return policyVcOptional.get().get(StringPool.CREDENTIAL_SUBJECT).get(StringPool.GX_POLICY);
for (JsonNode vc : list) {
JsonNode credentialSubject = vc.get(CREDENTIAL_SUBJECT);
if (credentialSubject.isArray()){
for (JsonNode cs : credentialSubject) {
JsonNode serviceOfferingPolicy = getServiceOfferingPolicy(vc, cs);
if (Objects.nonNull(serviceOfferingPolicy)){
return serviceOfferingPolicy;
}
}
} else {
JsonNode serviceOfferingPolicy = getServiceOfferingPolicy(vc, credentialSubject);
if (Objects.nonNull(serviceOfferingPolicy)){
return serviceOfferingPolicy;
}
}
}
return null;
}

private JsonNode getServiceOfferingPolicy(JsonNode vc, JsonNode cs) {
if (cs.get("type").asText().equals("gx:ServiceOffering") && cs.has(GX_POLICY)) {
return cs.get(GX_POLICY);
}
return null;
}

Expand Down
Loading