mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-01-22 04:18:20 +00:00
Reverted some changes after a lot of bugs
This commit is contained in:
parent
29ef08e5e9
commit
1cdb07ae20
@ -337,7 +337,6 @@ public class CertificateAttributeScvValidator extends SupplyChainCredentialValid
|
||||
remainingComponentResults.add(componentResult);
|
||||
}
|
||||
}
|
||||
List<UUID> failedComponents = new ArrayList<>();
|
||||
if (!remainingComponentResults.isEmpty()) {
|
||||
// continue down the options, move to a different method.
|
||||
// create component class mapping to component info
|
||||
@ -370,23 +369,23 @@ public class CertificateAttributeScvValidator extends SupplyChainCredentialValid
|
||||
componentAttributeResult.setProvisionSessionId(provisionSessionId);
|
||||
componentAttributeRepository.save(componentAttributeResult);
|
||||
fieldValidation &= componentAttributeResult.checkMatchedStatus();
|
||||
if (!componentAttributeResult.checkMatchedStatus()) {
|
||||
numOfAttributes++;
|
||||
failedComponents.add(componentAttributeResult.getComponentId());
|
||||
}
|
||||
}
|
||||
numOfAttributes = attributeResults.size();
|
||||
}
|
||||
|
||||
StringBuilder additionalInfo = new StringBuilder();
|
||||
if (!remainingComponentResults.isEmpty()) {
|
||||
resultMessage.append(String.format("There are %d components not matched%n",
|
||||
remainingComponentResults.size()));
|
||||
resultMessage.append(String.format("\twith %d total attributes mismatched.",
|
||||
numOfAttributes));
|
||||
}
|
||||
|
||||
passesValidation &= fieldValidation;
|
||||
|
||||
if (passesValidation) {
|
||||
return new AppraisalStatus(PASS, PLATFORM_ATTRIBUTES_VALID);
|
||||
} else {
|
||||
resultMessage.append(String.format("There are %d components not matched%n",
|
||||
failedComponents.size()));
|
||||
resultMessage.append(String.format("\twith %d total attributes mismatched.",
|
||||
numOfAttributes));
|
||||
return new AppraisalStatus(FAIL, resultMessage.toString(), additionalInfo.toString());
|
||||
}
|
||||
}
|
||||
@ -403,17 +402,25 @@ public class CertificateAttributeScvValidator extends SupplyChainCredentialValid
|
||||
final ComponentResult componentResult) {
|
||||
// there are instances of components with the same class (ie hard disks, memory)
|
||||
List<ComponentAttributeResult> attributeResults = new ArrayList<>();
|
||||
attributeResults.add(new ComponentAttributeResult(componentResult.getId(), componentInfo.getId(),
|
||||
componentResult.getManufacturer(), componentInfo.getComponentManufacturer()));
|
||||
if (!componentInfo.getComponentManufacturer().equals(componentResult.getManufacturer())) {
|
||||
attributeResults.add(new ComponentAttributeResult(componentResult.getId(), componentInfo.getId(),
|
||||
componentResult.getManufacturer(), componentInfo.getComponentManufacturer()));
|
||||
}
|
||||
|
||||
attributeResults.add(new ComponentAttributeResult(componentResult.getId(), componentInfo.getId(),
|
||||
componentResult.getModel(), componentInfo.getComponentModel()));
|
||||
if (!componentInfo.getComponentModel().equals(componentResult.getModel())) {
|
||||
attributeResults.add(new ComponentAttributeResult(componentResult.getId(), componentInfo.getId(),
|
||||
componentResult.getModel(), componentInfo.getComponentModel()));
|
||||
}
|
||||
|
||||
attributeResults.add(new ComponentAttributeResult(componentResult.getId(), componentInfo.getId(),
|
||||
componentResult.getSerialNumber(), componentInfo.getComponentSerial()));
|
||||
if (!componentInfo.getComponentSerial().equals(componentResult.getSerialNumber())) {
|
||||
attributeResults.add(new ComponentAttributeResult(componentResult.getId(), componentInfo.getId(),
|
||||
componentResult.getSerialNumber(), componentInfo.getComponentSerial()));
|
||||
}
|
||||
|
||||
attributeResults.add(new ComponentAttributeResult(componentResult.getId(), componentInfo.getId(),
|
||||
componentResult.getRevisionNumber(), componentInfo.getComponentRevision()));
|
||||
if (!componentInfo.getComponentRevision().equals(componentResult.getRevisionNumber())) {
|
||||
attributeResults.add(new ComponentAttributeResult(componentResult.getId(), componentInfo.getId(),
|
||||
componentResult.getRevisionNumber(), componentInfo.getComponentRevision()));
|
||||
}
|
||||
|
||||
return attributeResults;
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Log4j2
|
||||
@ -93,7 +94,7 @@ public class ComponentComparisonPageController extends PageController<Certificat
|
||||
}
|
||||
|
||||
if (data.isEmpty()) {
|
||||
String notFoundMessage = "Unable to find RIM with ID: " + params.getId();
|
||||
String notFoundMessage = "Unable to find session with ID: " + params.getId();
|
||||
messages.addError(notFoundMessage);
|
||||
log.warn(notFoundMessage);
|
||||
mav.addObject(MESSAGES_ATTRIBUTE, messages);
|
||||
@ -146,19 +147,17 @@ public class ComponentComparisonPageController extends PageController<Certificat
|
||||
+ componentResults.get(0).getBoardSerialNumber());
|
||||
return data;
|
||||
}
|
||||
|
||||
List<ComponentResult> matchedResults = new LinkedList<>();
|
||||
List<ComponentInfo> matchedDeviceComps = new LinkedList<>();
|
||||
List<ComponentInfo> componentInfos = componentInfoRepository
|
||||
.findByDeviceNameOrderByComponentClassAsc(deviceName);
|
||||
Map<ComponentResult, ComponentInfo> componentInfoHashMap = findMatchedComponents(componentResults, componentInfos);
|
||||
List<ComponentResult> matchedResults = new LinkedList<>(componentInfoHashMap.keySet());
|
||||
List<ComponentInfo> matchedDeviceComps = new LinkedList<>(componentInfoHashMap.values());
|
||||
List<ComponentResult> mismatchedResults = new LinkedList<>();
|
||||
List<ComponentInfo> mismatchedDeviceComps = new LinkedList<>();
|
||||
for(ComponentAttributeResult dbObject : attributeResults) {
|
||||
if (dbObject.checkMatchedStatus()) {
|
||||
matchedResults.add(componentResultRepository.getReferenceById(dbObject.getComponentId()));
|
||||
matchedDeviceComps.add(componentInfoRepository.getReferenceById(dbObject.getDeviceComponentId()));
|
||||
} else {
|
||||
mismatchedResults.add(componentResultRepository.getReferenceById(dbObject.getComponentId()));
|
||||
mismatchedDeviceComps.add(componentInfoRepository.getReferenceById(dbObject.getDeviceComponentId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// componentResults.clear();
|
||||
@ -213,6 +212,31 @@ public class ComponentComparisonPageController extends PageController<Certificat
|
||||
|
||||
return tempList;
|
||||
}
|
||||
|
||||
private static Map<ComponentResult, ComponentInfo> findMatchedComponents(
|
||||
final List<ComponentResult> componentResults, final List<ComponentInfo> componentInfos) {
|
||||
// first create hash map based on hashCode
|
||||
Map<ComponentResult, ComponentInfo> resultComponentInfoMap = new HashMap<>();
|
||||
Map<Integer, ComponentInfo> deviceHashMap = new HashMap<>();
|
||||
componentInfos.stream().forEach((componentInfo) -> {
|
||||
deviceHashMap.put(componentInfo.hashCommonElements(), componentInfo);
|
||||
});
|
||||
|
||||
// Look for hash code in device mapping
|
||||
// if it exists, don't save the component
|
||||
List<ComponentResult> remainingComponentResults = new ArrayList<>();
|
||||
int numOfAttributes = 0;
|
||||
for (ComponentResult componentResult : componentResults) {
|
||||
if (!deviceHashMap.containsKey(componentResult.hashCommonElements())) {
|
||||
// didn't find the component result in the hashed mapping
|
||||
remainingComponentResults.add(componentResult);
|
||||
} else {
|
||||
resultComponentInfoMap.put(componentResult, deviceHashMap.get(componentResult.hashCommonElements()));
|
||||
}
|
||||
}
|
||||
|
||||
return resultComponentInfoMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user