Merge pull request #319 from nsacyber/rim-update-error

[#318] RIM upload error
This commit is contained in:
iadgovuser26 2020-11-23 13:05:41 -05:00 committed by GitHub
commit e3b8ce25d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -188,7 +188,7 @@ public class ReferenceManifestPageController
Map<String, Object> model = new HashMap<>(); Map<String, Object> model = new HashMap<>();
PageMessages messages = new PageMessages(); PageMessages messages = new PageMessages();
String fileName; String fileName;
Pattern pattern; Pattern logPattern = Pattern.compile(LOG_FILE_PATTERN);
Matcher matcher; Matcher matcher;
boolean supportRIM = false; boolean supportRIM = false;
BaseReferenceManifest base; BaseReferenceManifest base;
@ -197,64 +197,63 @@ public class ReferenceManifestPageController
// loop through the files // loop through the files
for (MultipartFile file : files) { for (MultipartFile file : files) {
fileName = file.getOriginalFilename(); fileName = file.getOriginalFilename();
pattern = Pattern.compile(LOG_FILE_PATTERN); matcher = logPattern.matcher(fileName);
matcher = pattern.matcher(fileName);
supportRIM = matcher.matches(); supportRIM = matcher.matches();
//Parse reference manifests //Parse reference manifests
ReferenceManifest rim = parseRIM(file, supportRIM, messages); ReferenceManifest rim = parseRIM(file, supportRIM, messages);
if (supportRIM) { //Store only if it was parsed
// look for associated base/support if (rim != null) {
Set<BaseReferenceManifest> rims = BaseReferenceManifest if (supportRIM) {
.select(referenceManifestManager).getRIMs(); // look for associated base/support
support = (SupportReferenceManifest) rim; Set<BaseReferenceManifest> rims = BaseReferenceManifest
// update information for associated support rim .select(referenceManifestManager).getRIMs();
for (BaseReferenceManifest dbRim : rims) { support = (SupportReferenceManifest) rim;
for (SwidResource swid : dbRim.parseResource()) { // update information for associated support rim
if (swid.getName().equals(rim.getFileName())) { for (BaseReferenceManifest dbRim : rims) {
support.setSwidTagVersion(dbRim.getSwidTagVersion()); for (SwidResource swid : dbRim.parseResource()) {
support.setPlatformManufacturer(dbRim.getPlatformManufacturer()); if (swid.getName().equals(rim.getFileName())) {
support.setPlatformModel(dbRim.getPlatformModel()); support.setSwidTagVersion(dbRim.getSwidTagVersion());
support.setTagId(dbRim.getTagId()); support.setPlatformManufacturer(dbRim.getPlatformManufacturer());
support.setAssociatedRim(dbRim.getId()); support.setPlatformModel(dbRim.getPlatformModel());
support.setUpdated(true); support.setTagId(dbRim.getTagId());
break; support.setAssociatedRim(dbRim.getId());
support.setUpdated(true);
break;
}
} }
} }
} } else {
} else { base = (BaseReferenceManifest) rim;
base = (BaseReferenceManifest) rim;
for (SwidResource swid : base.parseResource()) { for (SwidResource swid : base.parseResource()) {
support = SupportReferenceManifest.select(referenceManifestManager) support = SupportReferenceManifest.select(referenceManifestManager)
.byFileName(swid.getName()).getRIM(); .byFileName(swid.getName()).getRIM();
if (support != null) { if (support != null) {
base.setAssociatedRim(support.getId()); base.setAssociatedRim(support.getId());
if (support.isUpdated()) { if (support.isUpdated()) {
// this is separate because I want to break if we found it // this is separate because I want to break if we found it
// instead of finding it, it is uptodate but still search // instead of finding it, it is uptodate but still search
break; break;
} else { } else {
support.setSwidTagVersion(base.getSwidTagVersion()); support.setSwidTagVersion(base.getSwidTagVersion());
support.setPlatformManufacturer(base.getPlatformManufacturer()); support.setPlatformManufacturer(base.getPlatformManufacturer());
support.setPlatformModel(base.getPlatformModel()); support.setPlatformModel(base.getPlatformModel());
support.setTagId(base.getTagId()); support.setTagId(base.getTagId());
support.setUpdated(true); support.setUpdated(true);
try { try {
referenceManifestManager.update(support); referenceManifestManager.update(support);
} catch (DBManagerException dbmEx) { } catch (DBManagerException dbmEx) {
LOGGER.error(String.format("Couldn't update Support RIM " LOGGER.error(String.format("Couldn't update Support RIM "
+ "%s with associated UUID %s", rim.getTagId(), + "%s with associated UUID %s", rim.getTagId(),
support.getId()), dbmEx); support.getId()), dbmEx);
}
} }
} }
} }
} }
}
//Store only if it was parsed
if (rim != null) {
storeManifest(file.getOriginalFilename(), storeManifest(file.getOriginalFilename(),
messages, messages,
rim, rim,