use of org.jboss.pnc.model.BuildConfiguration 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.BuildConfiguration in project pnc by project-ncl.
the class DatastoreMock method storeCompletedBuild.
@Override
public BuildRecord storeCompletedBuild(BuildRecord.Builder buildRecordBuilder, List<Artifact> builtArtifacts, List<Artifact> dependencies) {
buildRecordBuilder.dependencies(dependencies);
BuildRecord buildRecord = Mockito.spy(buildRecordBuilder.build());
Mockito.when(buildRecord.getBuiltArtifacts()).thenReturn(new HashSet<>(builtArtifacts));
BuildConfiguration buildConfiguration = buildRecord.getBuildConfigurationAudited().getBuildConfiguration();
log.info("Storing build " + buildConfiguration);
synchronized (this) {
boolean exists = getBuildRecords().stream().anyMatch(br -> br.equals(buildRecord));
if (exists) {
throw new PersistenceException("Unique constraint violation, the record with id [" + buildRecord.getId() + "] already exists.");
}
buildRecords.add(buildRecord);
}
return buildRecord;
}
use of org.jboss.pnc.model.BuildConfiguration in project pnc by project-ncl.
the class DatastoreMock method getLatestBuildConfigurationAuditedLoadBCDependencies.
@Override
public BuildConfigurationAudited getLatestBuildConfigurationAuditedLoadBCDependencies(Integer buildConfigurationId) {
BuildConfiguration buildConfig = buildConfigurations.get(buildConfigurationId);
int rev = buildConfigAuditedRevSequence.incrementAndGet();
BuildConfigurationAudited buildConfigurationAudited = BuildConfigurationAudited.Builder.newBuilder().buildConfiguration(buildConfig).rev(rev).build();
return buildConfigurationAudited;
}
use of org.jboss.pnc.model.BuildConfiguration in project pnc by project-ncl.
the class DefaultDatastore method hasARebuiltExplicitDependency.
/**
* Check is some of the dependencies defined on BuildConfiguration has newer version.
*/
private boolean hasARebuiltExplicitDependency(BuildRecord latestSuccessfulBuildRecord, Set<BuildConfiguration> dependencies, boolean temporaryBuild, AlignmentPreference alignmentPreference) {
for (BuildConfiguration dependencyBuildConfiguration : dependencies) {
BuildRecord dependencyLatestSuccessfulBuildRecord = buildRecordRepository.getPreferredLatestSuccessfulBuildRecordWithBuildConfig(dependencyBuildConfiguration.getId(), temporaryBuild, alignmentPreference);
if (dependencyLatestSuccessfulBuildRecord == null) {
return true;
}
boolean newer = dependencyLatestSuccessfulBuildRecord.getEndTime().after(latestSuccessfulBuildRecord.getEndTime());
if (newer) {
return true;
}
}
return false;
}
use of org.jboss.pnc.model.BuildConfiguration 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));
}
Aggregations