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); + } } }