From 1173ec7a9b9cfdb99ed2493ad5689d08e76d0841 Mon Sep 17 00:00:00 2001 From: nireeshT Date: Mon, 1 Apr 2019 16:21:04 -0400 Subject: [PATCH] Artifactory collector changes (#2808) --- collectors/artifact/artifactory/pom.xml | 2 +- .../collector/ArtifactoryCollectorTask.java | 4 ++-- .../collector/DefaultArtifactoryClient.java | 20 ++++++++++++++++--- .../DefaultArtifactoryClientTest.java | 4 ++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/collectors/artifact/artifactory/pom.xml b/collectors/artifact/artifactory/pom.xml index 682957bf59..3e7b5fa8b7 100644 --- a/collectors/artifact/artifactory/pom.xml +++ b/collectors/artifact/artifactory/pom.xml @@ -85,7 +85,7 @@ com.capitalone.dashboard core - 3.0.4 + [3.1.0-SNAPSHOT,) com.google.guava diff --git a/collectors/artifact/artifactory/src/main/java/com/capitalone/dashboard/collector/ArtifactoryCollectorTask.java b/collectors/artifact/artifactory/src/main/java/com/capitalone/dashboard/collector/ArtifactoryCollectorTask.java index 1945bcd26f..6a7f2c81d0 100644 --- a/collectors/artifact/artifactory/src/main/java/com/capitalone/dashboard/collector/ArtifactoryCollectorTask.java +++ b/collectors/artifact/artifactory/src/main/java/com/capitalone/dashboard/collector/ArtifactoryCollectorTask.java @@ -284,8 +284,8 @@ private void addNewArtifactsItems(List baseArtifacts, ListbinaryArtifactRepository.save(binaryArtifact)); + } log("New artifacts", start, count); } diff --git a/collectors/artifact/artifactory/src/main/java/com/capitalone/dashboard/collector/DefaultArtifactoryClient.java b/collectors/artifact/artifactory/src/main/java/com/capitalone/dashboard/collector/DefaultArtifactoryClient.java index ff8cf85f02..2ee87e1841 100644 --- a/collectors/artifact/artifactory/src/main/java/com/capitalone/dashboard/collector/DefaultArtifactoryClient.java +++ b/collectors/artifact/artifactory/src/main/java/com/capitalone/dashboard/collector/DefaultArtifactoryClient.java @@ -234,6 +234,7 @@ public List getArtifacts(String instanceUrl, String repoName, lo return result; } + /** * Creates an artifact given its canonical name and path. * Artifacts are created by supplied pattern configurations. By default three are supplied: @@ -265,11 +266,11 @@ private BinaryArtifact createArtifact(String artifactCanonicalName, String artif } result.setType(getString(jsonArtifact, "type")); - result.setCreatedTimeStamp(getString(jsonArtifact, "created")); + result.setCreatedTimeStamp(convertTimestamp(getString(jsonArtifact, "created"))); result.setCreatedBy(getString(jsonArtifact, "created_by")); - result.setModifiedTimeStamp(getString(jsonArtifact, "modified")); + result.setModifiedTimeStamp(convertTimestamp(getString(jsonArtifact, "modified"))); result.setModifiedBy(getString(jsonArtifact, "modified_by")); - result.setActual_md5(getString(jsonArtifact, "actual_md5")); + result.setActual_md5(getString(jsonArtifact, "actual_md5")); result.setActual_sha1(getString(jsonArtifact, "actual_sha1")); result.setCanonicalName(artifactCanonicalName); result.setTimestamp(timestamp); @@ -288,6 +289,19 @@ private BinaryArtifact createArtifact(String artifactCanonicalName, String artif return null; } + + private long convertTimestamp(String sTimestamp){ + long timestamp = 0; + if (sTimestamp != null) { + try { + Date date = FULL_DATE.parse(sTimestamp); + timestamp = date.getTime(); + } catch (java.text.ParseException e) { + LOGGER.error("Parsing artifact timestamp: " + sTimestamp, e); + } + } + return timestamp; + } @SuppressWarnings("PMD.AvoidDeeplyNestedIfStmts") private void addMetadataToArtifact(BinaryArtifact ba, JSONObject jsonArtifact) { if (ba != null && jsonArtifact != null) { diff --git a/collectors/artifact/artifactory/src/test/java/com/capitalone/dashboard/collector/DefaultArtifactoryClientTest.java b/collectors/artifact/artifactory/src/test/java/com/capitalone/dashboard/collector/DefaultArtifactoryClientTest.java index b4958f2470..c4ed35f252 100644 --- a/collectors/artifact/artifactory/src/test/java/com/capitalone/dashboard/collector/DefaultArtifactoryClientTest.java +++ b/collectors/artifact/artifactory/src/test/java/com/capitalone/dashboard/collector/DefaultArtifactoryClientTest.java @@ -112,9 +112,9 @@ public void testGetArtifactItems() throws Exception { assertThat(baseArtifacts.get(0).getBinaryArtifact().getArtifactName(),is("test-dev")); assertThat(baseArtifacts.get(0).getBinaryArtifact().getType(),is("file")); assertThat(baseArtifacts.get(0).getBinaryArtifact().getModifiedBy(),is("robot")); - assertThat(baseArtifacts.get(0).getBinaryArtifact().getModifiedTimeStamp(),is("2018-10-11T14:38:56.471Z")); + assertThat(baseArtifacts.get(0).getBinaryArtifact().getModifiedTimeStamp(),is(new Long("1539268736471"))); assertThat(baseArtifacts.get(0).getBinaryArtifact().getCreatedBy(),is("robot")); - assertThat(baseArtifacts.get(0).getBinaryArtifact().getCreatedTimeStamp(),is("2018-10-11T14:27:16.031Z")); + assertThat(baseArtifacts.get(0).getBinaryArtifact().getCreatedTimeStamp(),is(new Long("1539268036031"))); assertThat(baseArtifacts.get(0).getBinaryArtifact().getArtifactVersion(),is("1")); }