From f7b5daf95f9de31c87f5c5960ae95072ab894488 Mon Sep 17 00:00:00 2001 From: iadgovuser29 <33426478+iadgovuser29@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:48:57 -0400 Subject: [PATCH] Lookup here needed summary id from device object --- .../service/SupplyChainValidationService.java | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/service/SupplyChainValidationService.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/service/SupplyChainValidationService.java index adc9e557..7fec11b8 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/service/SupplyChainValidationService.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/service/SupplyChainValidationService.java @@ -35,6 +35,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.UUID; import static hirs.attestationca.persist.enums.AppraisalStatus.Status.FAIL; @@ -359,26 +360,30 @@ public class SupplyChainValidationService { // Generate validation summary, save it, and return it. List validations = new ArrayList<>(); - SupplyChainValidationSummary previous + Optional previousOpt //= this.supplyChainValidationSummaryRepository.findByDevice(deviceName); - = this.supplyChainValidationSummaryRepository.findByDevice(device); - for (SupplyChainValidation scv : previous.getValidations()) { - if (scv.getValidationType() != SupplyChainValidation.ValidationType.FIRMWARE) { - validations.add(ValidationService.buildValidationRecord(scv.getValidationType(), - scv.getValidationResult(), scv.getMessage(), - scv.getCertificatesUsed().get(0), Level.INFO)); + //= this.supplyChainValidationSummaryRepository.findByDevice(device); + = this.supplyChainValidationSummaryRepository.findById(UUID.fromString(device.getSummaryId())); + if (previousOpt.isPresent()) { + SupplyChainValidationSummary previous = previousOpt.get(); + for (SupplyChainValidation scv : previous.getValidations()) { + if (scv.getValidationType() != SupplyChainValidation.ValidationType.FIRMWARE) { + validations.add(ValidationService.buildValidationRecord(scv.getValidationType(), + scv.getValidationResult(), scv.getMessage(), + scv.getCertificatesUsed().get(0), Level.INFO)); + } } - } - validations.add(quoteScv); - previous.archive(); - supplyChainValidationSummaryRepository.save(previous); - summary = new SupplyChainValidationSummary(device, validations); + validations.add(quoteScv); + previous.archive(); + supplyChainValidationSummaryRepository.save(previous); + summary = new SupplyChainValidationSummary(device, validations); - // try removing the supply chain validation as well and resaving that - try { - supplyChainValidationSummaryRepository.save(summary); - } catch (DBManagerException dbEx) { - log.error("Failed to save Supply Chain Summary", dbEx); + // try removing the supply chain validation as well and resaving that + try { + supplyChainValidationSummaryRepository.save(summary); + } catch (DBManagerException dbEx) { + log.error("Failed to save Supply Chain Summary", dbEx); + } } }