Skip to content

Commit

Permalink
Artifactory collector changes (hygieia#2808)
Browse files Browse the repository at this point in the history
  • Loading branch information
nireeshT authored Apr 1, 2019
1 parent be79c51 commit 1173ec7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion collectors/artifact/artifactory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<dependency>
<groupId>com.capitalone.dashboard</groupId>
<artifactId>core</artifactId>
<version>3.0.4</version>
<version>[3.1.0-SNAPSHOT,)</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ private void addNewArtifactsItems(List<BaseArtifact> baseArtifacts, List<Artifac
}
}
if(!binaryArtifacts.isEmpty()){
binaryArtifactRepository.save(binaryArtifacts);
}
binaryArtifacts.forEach(binaryArtifact->binaryArtifactRepository.save(binaryArtifact));
}
log("New artifacts", start, count);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public List<BinaryArtifact> 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:
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

}
Expand Down

0 comments on commit 1173ec7

Please sign in to comment.