diff --git a/productnameextractor/src/main/java/messenger/Messenger.java b/productnameextractor/src/main/java/messenger/Messenger.java index 9a9693ad0..bffd9e950 100644 --- a/productnameextractor/src/main/java/messenger/Messenger.java +++ b/productnameextractor/src/main/java/messenger/Messenger.java @@ -88,29 +88,31 @@ public void run() { String message = new String(delivery.getBody(), StandardCharsets.UTF_8); List cveIds = parseIds(message); - logger.info("Received job with CVE(s) {}", cveIds); - - // Pull specific cve information from database for each CVE ID passed from reconciler - List vulnList = databaseHelper.getSpecificCompositeVulnerabilities(cveIds); - - // Identify affected products from the CVEs - final long getProdStart = System.currentTimeMillis(); - List affectedProducts = affectedProductIdentifier.identifyAffectedProducts(vulnList); - - // Insert the affected products found into the database - databaseHelper.insertAffectedProductsToDB(affectedProducts); - logger.info("Product Name Extractor found and inserted {} affected products to the database in {} seconds", affectedProducts.size(), Math.floor(((double) (System.currentTimeMillis() - getProdStart) / 1000) * 100) / 100); - - // Clear cveIds, extract only the cveIds for which affected products were found to be sent to the Patchfinder - cveIds.clear(); - for (AffectedProduct affectedProduct : affectedProducts) { - if (!cveIds.contains(affectedProduct.getCveId())) cveIds.add(affectedProduct.getCveId()); + if(!cveIds.isEmpty()){ + logger.info("Received job with CVE(s) {}", cveIds); + + // Pull specific cve information from database for each CVE ID passed from reconciler + List vulnList = databaseHelper.getSpecificCompositeVulnerabilities(cveIds); + + // Identify affected products from the CVEs + final long getProdStart = System.currentTimeMillis(); + List affectedProducts = affectedProductIdentifier.identifyAffectedProducts(vulnList); + + // Insert the affected products found into the database + databaseHelper.insertAffectedProductsToDB(affectedProducts); + logger.info("Product Name Extractor found and inserted {} affected products to the database in {} seconds", affectedProducts.size(), Math.floor(((double) (System.currentTimeMillis() - getProdStart) / 1000) * 100) / 100); + + // Clear cveIds, extract only the cveIds for which affected products were found to be sent to the Patchfinder + cveIds.clear(); + for (AffectedProduct affectedProduct : affectedProducts) { + if (!cveIds.contains(affectedProduct.getCveId())) cveIds.add(affectedProduct.getCveId()); + } + + logger.info("Sending jobs to patchfinder..."); + String response = genJson(cveIds); + channel.basicPublish("", outputQueue, null, response.getBytes(StandardCharsets.UTF_8)); + logger.info("Jobs have been sent!\n\n"); } - - logger.info("Sending jobs to patchfinder..."); - String response = genJson(cveIds); - channel.basicPublish("", outputQueue, null, response.getBytes(StandardCharsets.UTF_8)); - logger.info("Jobs have been sent!\n\n"); }; channel.basicConsume(inputQueue, true, deliverCallback, consumerTag -> {}); diff --git a/productnameextractor/src/test/resources/data/test_product_dict_creation.json b/productnameextractor/src/test/resources/data/test_product_dict_creation.json new file mode 100644 index 000000000..b7ff88420 --- /dev/null +++ b/productnameextractor/src/test/resources/data/test_product_dict_creation.json @@ -0,0 +1 @@ +{"compTime":"2023-06-13T19:58:32.350096800Z","refreshTime":"2023-11-21T21:49:50.367428501Z","products":{"Key1":{"vendor":"Vendor1","product":"Product1","groupID":"Vendor1:Product1","commonTitle":"CommonTitle1","versions":{"1.0":{"title":"Title1","version":"1.0","update":"Update1","cpeID":"CpeID1","platform":"Platform1"}}},"Key2":{"vendor":"Vendor2","product":"Product2","groupID":"Vendor2:Product2","commonTitle":"CommonTitle2","versions":{"2.0":{"title":"Title2","version":"2.0","update":"Update2","cpeID":"CpeID2","platform":"Platform2"},"2.1":{"title":"Title2","version":"2.1","update":"Update2","cpeID":"CpeID2","platform":"Platform2"}}},"Key3":{"vendor":"Vendor3","product":"Product3","groupID":"Vendor3:Product3","commonTitle":"CommonTitle3","versions":{"3.0":{"title":"Title3","version":"3.0","update":"Update3","cpeID":"CpeID3","platform":"Platform3"}}}}} \ No newline at end of file diff --git a/productnameextractor/test_ids.txt b/productnameextractor/test_ids.txt new file mode 100644 index 000000000..e69de29bb