Search in sources :

Example 1 with ArtifactAudited

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);
}
Also used : ArrayList(java.util.ArrayList) ArtifactAudited(org.jboss.pnc.model.ArtifactAudited) ArtifactRevision(org.jboss.pnc.dto.ArtifactRevision) Test(org.junit.Test)

Example 2 with ArtifactAudited

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);
}
Also used : RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) ArtifactAudited(org.jboss.pnc.model.ArtifactAudited)

Example 3 with ArtifactAudited

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);
}
Also used : IdRev(org.jboss.pnc.model.IdRev) ArtifactAudited(org.jboss.pnc.model.ArtifactAudited) ArtifactRevision(org.jboss.pnc.dto.ArtifactRevision) Test(org.junit.Test)

Example 4 with ArtifactAudited

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);
}
Also used : IdRev(org.jboss.pnc.model.IdRev) ArtifactAudited(org.jboss.pnc.model.ArtifactAudited)

Aggregations

ArtifactAudited (org.jboss.pnc.model.ArtifactAudited)4 ArtifactRevision (org.jboss.pnc.dto.ArtifactRevision)2 IdRev (org.jboss.pnc.model.IdRev)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 ArtifactQuality (org.jboss.pnc.enums.ArtifactQuality)1 InvalidEntityException (org.jboss.pnc.facade.validation.InvalidEntityException)1 RepositoryViolationException (org.jboss.pnc.facade.validation.RepositoryViolationException)1