use of org.jboss.pnc.model.ArtifactAudited in project pnc by project-ncl.
the class ArtifactProviderTest method testGetRevisions.
@Test
public void testGetRevisions() {
// With
final Integer revision = 1;
ArtifactAudited aa1 = ArtifactAudited.fromArtifact(artifact1, revision);
ArtifactAudited aa2 = ArtifactAudited.fromArtifact(artifact1, revision + 1);
List<org.jboss.pnc.model.ArtifactAudited> artifactRevisions = new ArrayList<>();
artifactRevisions.add(aa1);
artifactRevisions.add(aa2);
when(artifactAuditedRepository.findAllByIdOrderByRevDesc(artifact1.getId())).thenReturn(artifactRevisions);
// When
Page<ArtifactRevision> pagedAr = provider.getRevisions(0, 20, artifact1.getId().toString());
// Then
assertEquals(pagedAr.getContent().size(), 2);
Iterator<ArtifactRevision> itARev = pagedAr.getContent().iterator();
ArtifactRevision aRev1 = itARev.next();
assertThat(aRev1.getId()).isEqualTo(artifact1.getId().toString());
assertThat(aRev1.getRev()).isEqualTo(revision);
ArtifactRevision aRev2 = itARev.next();
assertThat(aRev2.getId()).isEqualTo(artifact1.getId().toString());
assertThat(aRev2.getRev()).isEqualTo(revision + 1);
}
use of org.jboss.pnc.model.ArtifactAudited in project pnc by project-ncl.
the class ArtifactProviderImpl method createQualityLevelRevision.
@Override
public ArtifactRevision createQualityLevelRevision(String id, String quality, String reason) throws DTOValidationException {
boolean isLoggedInUserSystemUser = userService.hasLoggedInUserRole(SYSTEM_USER);
ArtifactQuality newQuality = validateProvidedArtifactQuality(quality, isLoggedInUserSystemUser);
org.jboss.pnc.dto.Artifact artifact = getSpecific(id);
if (artifact == null) {
throw new InvalidEntityException("Artifact with id: " + id + " does not exist.");
}
validateIfArtifactQualityIsModifiable(artifact, newQuality);
update(id, artifact.toBuilder().artifactQuality(newQuality).qualityLevelReason(reason).build());
ArtifactAudited latestRevision = artifactAuditedRepository.findLatestById(Integer.parseInt(id));
if (latestRevision == null) {
throw new RepositoryViolationException("Entity should exist in the DB");
}
if (DA_SYNCRONIZED_ARTIFACT_QUALITIES.contains(newQuality)) {
String jsonPayload = createBlacklistJSONPayload(artifact);
blacklistAsyncInvoker.notifyBlacklistToDA(jsonPayload);
}
return artifactRevisionMapper.toDTO(latestRevision);
}
use of org.jboss.pnc.model.ArtifactAudited in project pnc by project-ncl.
the class ArtifactProviderTest method testGetRevision.
@Test
public void testGetRevision() {
// With
final Integer revision = 1;
ArtifactAudited aa = ArtifactAudited.fromArtifact(artifact1, revision);
when(artifactAuditedRepository.queryById(new IdRev(artifact1.getId(), revision))).thenReturn(aa);
// When
ArtifactRevision ar = provider.getRevision(artifact1.getId().toString(), revision);
// Then
assertThat(ar).isNotNull();
assertThat(ar.getId()).isEqualTo(artifact1.getId().toString());
assertThat(ar.getRev()).isEqualTo(revision);
}
use of org.jboss.pnc.model.ArtifactAudited in project pnc by project-ncl.
the class ArtifactProviderImpl method getRevision.
@Override
public ArtifactRevision getRevision(String id, Integer rev) {
IdRev idRev = new IdRev(Integer.valueOf(id), rev);
ArtifactAudited auditedArtifact = artifactAuditedRepository.queryById(idRev);
return artifactRevisionMapper.toDTO(auditedArtifact);
}
Aggregations