use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.
the class DefaultBuildCoordinatorTest method shouldCreateNoRebuildRequiredRecords.
@Test
public void shouldCreateNoRebuildRequiredRecords() throws CoreException, TimeoutException, InterruptedException {
when(datastore.requiresRebuild(any(BuildConfigurationAudited.class), any(Boolean.class), any(Boolean.class), nullable(AlignmentPreference.class), anySet())).thenReturn(false);
BuildConfigurationAudited bca1 = new BuildConfigurationAudited();
IdRev idRev1 = new IdRev(BC_1.getId(), BC_1.getId() * 1000 + 1);
bca1.setIdRev(idRev1);
bca1.setId(idRev1.getId());
bca1.setRev(idRev1.getRev());
bca1.setProject(PROJECT);
when(datastore.getLatestBuildConfigurationAuditedLoadBCDependencies(BC_1.getId())).thenReturn(bca1);
BuildConfigurationAudited bca3 = new BuildConfigurationAudited();
IdRev idRev3 = new IdRev(BC_3.getId(), BC_3.getId() * 1000 + 1);
bca3.setIdRev(idRev3);
bca3.setId(idRev3.getId());
bca3.setRev(idRev3.getRev());
bca3.setProject(PROJECT);
when(datastore.getLatestBuildConfigurationAuditedLoadBCDependencies(BC_3.getId())).thenReturn(bca3);
Set<BuildConfiguration> buildConfigs = new HashSet<>();
buildConfigs.add(BC_1);
buildConfigs.add(BC_3);
when(datastore.getBuildConfigurations(any())).thenReturn(buildConfigs);
Set<BuildRecord> storedRecords = new HashSet<>();
when(datastore.storeRecordForNoRebuild(any())).thenAnswer(new SaveRecordForNoRebuildAnswer(storedRecords));
BuildSetTask bsTask = coordinator.build(BCS, USER, BUILD_OPTIONS);
coordinator.start();
assertThat(bsTask.getBuildConfigSetRecord().get().getStatus()).isEqualTo(BuildStatus.NO_REBUILD_REQUIRED);
Wait.forCondition(() -> storedRecords.size() == 2, 3, ChronoUnit.SECONDS);
assertThat(storedRecords.size()).isEqualTo(2);
}
use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.
the class BuildConfigurationAuditedRepositoryMock method save.
public BuildConfigurationAudited save(BuildConfigurationAudited entity) {
IdRev idRev = entity.getIdRev();
if (idRev == null) {
throw new IllegalStateException("auto-setting " + this.getClass().getSimpleName() + " entity id is not supported");
}
BuildConfiguration buildConfiguration = entity.getBuildConfiguration();
Integer newRev = idSequence.getAndIncrement();
BuildConfigurationAudited.fromBuildConfiguration(buildConfiguration, newRev);
getOptionalById(idRev).ifPresent(data::remove);
data.add(entity);
return entity;
}
use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.
the class BuildRecordRepositoryImpl method fetchBuildConfigurationAudited.
private void fetchBuildConfigurationAudited(BuildRecord buildRecord) {
Integer revision = buildRecord.getBuildConfigurationRev();
BuildConfigurationAudited buildConfigurationAudited = buildConfigurationAuditedRepository.queryById(new IdRev(buildRecord.getBuildConfigurationId(), revision));
buildRecord.setBuildConfigurationAudited(buildConfigurationAudited);
}
use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.
the class BuildConfigurationAuditedRepositoryImpl method queryById.
@Override
public Map<IdRev, BuildConfigurationAudited> queryById(Set<IdRev> idRevs) {
logger.trace("Querying for BuildConfigurationAudited.idRevs: {}.", idRevs);
List<String> idRevConcatenated = idRevs.stream().map(idRev -> idRev.getId() + "-" + idRev.getRev()).collect(Collectors.toList());
// WORKAROUND: as I cannot concatenate AuditEntity property to match
// `AuditEntity.property("id")-AuditEntity.property("rev")` in idRevConcatenated list
// I can query all BuildConfigurationAudited with the only id and later on filter id and rev
List<Integer> bcaRevIds = idRevs.stream().map(IdRev::getRev).collect(Collectors.toList());
// Getting all revisions of BuildConfiguration with specified list of IDs
List<Object[]> result = AuditReaderFactory.get(entityManager).createQuery().forRevisionsOfEntity(BuildConfiguration.class, false, false).add(AuditEntity.revisionNumber().in(bcaRevIds)).addOrder(AuditEntity.revisionNumber().desc()).getResultList();
return result.stream().filter(res -> {
BuildConfiguration buildConfiguration = (BuildConfiguration) res[0];
DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) res[1];
return idRevConcatenated.contains(buildConfiguration.getId() + "-" + revisionEntity.getId());
}).peek(res -> {
BuildConfiguration buildConfiguration = (BuildConfiguration) res[0];
// preload generic parameters
buildConfiguration.getGenericParameters().forEach((k, v) -> k.equals(null));
}).map(res -> {
BuildConfiguration buildConfiguration = (BuildConfiguration) res[0];
DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) res[1];
return BuildConfigurationAudited.fromBuildConfiguration(buildConfiguration, revisionEntity.getId());
}).collect(Collectors.toMap(BuildConfigurationAudited::getIdRev, bca -> bca));
}
use of org.jboss.pnc.model.IdRev in project pnc by project-ncl.
the class BuildConfigurationAuditedRepositoryImpl method getBuildRecords.
/**
* @param idRev
* @return List of BuildRecords where only id is fetched
*/
private List<BuildRecord> getBuildRecords(IdRev idRev) {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Base32LongID> query = cb.createQuery(Base32LongID.class);
Root<BuildRecord> root = query.from(BuildRecord.class);
query.select(root.get(BuildRecord_.id));
query.where(cb.and(cb.equal(root.get(BuildRecord_.buildConfigurationId), idRev.getId()), cb.equal(root.get(BuildRecord_.buildConfigurationRev), idRev.getRev())));
List<Base32LongID> buildRecordIds = entityManager.createQuery(query).getResultList();
return buildRecordIds.stream().map(id -> BuildRecord.Builder.newBuilder().id(id).build()).collect(Collectors.toList());
}
Aggregations