Skip to content

Commit

Permalink
if pub date unparseable, fall back to created date
Browse files Browse the repository at this point in the history
  • Loading branch information
memeeerit authored and ctevse committed Nov 9, 2023
1 parent 98e6f07 commit aa6c86e
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ public int insertRawVulnerability(RawVulnerability vuln) {

pstmt.setString(1, vuln.getDescription());
pstmt.setString(2, vuln.getCveId());
pstmt.setTimestamp(3, Timestamp.valueOf(vuln.getCreatedDateAsDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));
pstmt.setTimestamp(4, Timestamp.valueOf(vuln.getPublishDateAsDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));
Timestamp cdate = Timestamp.valueOf(vuln.getCreatedDateAsDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
pstmt.setTimestamp(3, cdate);
try {
pstmt.setTimestamp(4, Timestamp.valueOf(vuln.getPublishDateAsDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));
} catch (DateTimeParseException e) {
log.error("Failed to parse publish date for {}. Insertion will proceed using the created date as the publish date.", vuln.getCveId());
pstmt.setTimestamp(4, cdate);
}
try {
pstmt.setTimestamp(5, Timestamp.valueOf(vuln.getLastModifiedDateAsDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));
} catch (DateTimeParseException e) {
Expand Down Expand Up @@ -84,8 +90,14 @@ public List<RawVulnerability> batchInsertRawVulnerability(List<RawVulnerability>
try {
pstmt.setString(1, vuln.getDescription());
pstmt.setString(2, vuln.getCveId());
pstmt.setTimestamp(3, Timestamp.valueOf(vuln.getCreatedDateAsDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));
pstmt.setTimestamp(4, Timestamp.valueOf(vuln.getPublishDateAsDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));
Timestamp cdate = Timestamp.valueOf(vuln.getCreatedDateAsDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
pstmt.setTimestamp(3, cdate);
try {
pstmt.setTimestamp(4, Timestamp.valueOf(vuln.getPublishDateAsDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));
} catch (DateTimeParseException e) {
log.error("Failed to parse publish date for {}. Insertion will proceed using the created date as the publish date.", vuln.getCveId());
pstmt.setTimestamp(4, cdate);
}
try {
pstmt.setTimestamp(5, Timestamp.valueOf(vuln.getLastModifiedDateAsDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));
} catch (DateTimeParseException e) {
Expand Down Expand Up @@ -192,10 +204,10 @@ public static void main(String[] args) {
singleList.add(new RawVulnerability("http://url.gov/page/0", "CVE-1234", "01/01/2023", null, "description", "generic"));
singleList.forEach(r->r.setSourceType("cna"));

list.add(new RawVulnerability("http://url.gov/page/1", "CVE-6666", "01/01/2023", null, "description", "generic"));
list.add(new RawVulnerability("http://url.gov/page/2", "CVE-7777", "01/01/2023", null, "description", "generic"));
list.add(new RawVulnerability("http://url.gov/page/1", "CVE-8888", "01/01/2023", null, "description", "generic"));
list.add(new RawVulnerability("http://url.gov/page/1", "CVE-9999", "01/01/2023", null, "description", "generic"));
list.add(new RawVulnerability("http://url.gov/page/1", "CVE-6666", "not a date", null, "description", "generic"));
list.add(new RawVulnerability("http://url.gov/page/2", "CVE-7777", "not a date", null, "description", "generic"));
list.add(new RawVulnerability("http://url.gov/page/1", "CVE-8888", "not a date", null, "description", "generic"));
list.add(new RawVulnerability("http://url.gov/page/1", "CVE-9999", "not a date", null, "description", "generic"));
list.forEach(r->r.setSourceType("cna"));

List<RawVulnerability> singleInsert = repo.batchInsertRawVulnerability(singleList);
Expand Down

0 comments on commit aa6c86e

Please sign in to comment.