use of org.jboss.pnc.model.BuildConfigurationAudited in project pnc by project-ncl.
the class BuildConfigProviderTest method testRestoreRevision.
@Test
public void testRestoreRevision() {
// With
final Integer revision = 1;
final String restoredName = "Old guy";
BuildConfigurationAudited bca = BuildConfigurationAudited.fromBuildConfiguration(bc, revision);
bca.setName(restoredName);
when(buildConfigurationAuditedRepository.queryById(new IdRev(bc.getId(), revision))).thenReturn(bca);
// When
provider.restoreRevision(bc.getId().toString(), revision);
// Then
org.jboss.pnc.dto.BuildConfiguration restored = provider.getSpecific(bc.getId().toString());
assertThat(restored).isNotNull();
assertThat(restored.getName()).isEqualTo(restoredName);
}
use of org.jboss.pnc.model.BuildConfigurationAudited in project pnc by project-ncl.
the class BuildProviderImpl method getSpecific.
@Override
public Build getSpecific(String buildId) {
List<BuildTask> runningBuilds = buildCoordinator.getSubmittedBuildTasks();
Build build = runningBuilds.stream().filter(buildTask -> buildId.equals(buildTask.getId())).findAny().map(buildMapper::fromBuildTask).orElse(null);
// if build not in runningBuilds, check the database
if (build == null) {
// use findByIdFetchProperties instead of super.getSpecific to get 'BuildConfigurationAudited' object
build = mapper.toDTO(buildRecordRepository.findByIdFetchProperties(parseId(buildId)));
}
return build;
}
use of org.jboss.pnc.model.BuildConfigurationAudited in project pnc by project-ncl.
the class BuildConfigurationProviderImpl method restoreRevision.
@Override
public Optional<BuildConfiguration> restoreRevision(String id, int rev) {
IdRev idRev = new IdRev(Integer.valueOf(id), rev);
BuildConfigurationAudited buildConfigurationAudited = buildConfigurationAuditedRepository.queryById(idRev);
org.jboss.pnc.model.BuildConfiguration originalBC = repository.queryById(Integer.valueOf(id));
org.jboss.pnc.model.User user = userService.currentUser();
if (buildConfigurationAudited == null || originalBC == null) {
return Optional.empty();
}
originalBC.setName(buildConfigurationAudited.getName());
originalBC.setBuildScript(buildConfigurationAudited.getBuildScript());
originalBC.setRepositoryConfiguration(buildConfigurationAudited.getRepositoryConfiguration());
originalBC.setScmRevision(buildConfigurationAudited.getScmRevision());
originalBC.setBuildType(buildConfigurationAudited.getBuildType());
originalBC.setBuildEnvironment(buildConfigurationAudited.getBuildEnvironment());
originalBC.setGenericParameters(buildConfigurationAudited.getGenericParameters());
originalBC.setLastModificationUser(user);
org.jboss.pnc.model.BuildConfiguration newBc = repository.save(originalBC);
newBc.getBuildConfigurationSets().forEach(BuildConfigurationSet::getId);
newBc.getDependencies().forEach(org.jboss.pnc.model.BuildConfiguration::getId);
repository.flushAndRefresh(newBc);
return Optional.of(mapper.toDTO(newBc));
}
use of org.jboss.pnc.model.BuildConfigurationAudited in project pnc by project-ncl.
the class BuildTriggererImpl method loadAuditedsFromDB.
private Map<Integer, BuildConfigurationAudited> loadAuditedsFromDB(BuildConfigurationSet buildConfigurationSet, List<BuildConfigurationRevisionRef> buildConfigurationAuditedRests) throws InvalidEntityException {
Map<Integer, BuildConfigurationAudited> buildConfigurationAuditedsMap = new HashMap<>();
Set<IdRev> buildConfigurationAuditedRevs = nullableStreamOf(buildConfigurationAuditedRests).map(bcrRef -> new IdRev(Integer.valueOf(bcrRef.getId()), bcrRef.getRev())).collect(Collectors.toSet());
if (!buildConfigurationAuditedRevs.isEmpty()) {
Map<IdRev, BuildConfigurationAudited> buildConfigurationsAuditedMap = buildConfigurationAuditedRepository.queryById(buildConfigurationAuditedRevs);
for (BuildConfigurationRevisionRef bc : buildConfigurationAuditedRests) {
BuildConfigurationAudited buildConfigurationAudited = buildConfigurationsAuditedMap.get(new IdRev(Integer.valueOf(bc.getId()), bc.getRev()));
Preconditions.checkArgument(buildConfigurationAudited != null, "Can't find Build Configuration with id=" + bc.getId() + ", rev=" + bc.getRev());
buildConfigurationAudited = hibernateLazyInitializer.initializeBuildConfigurationAuditedBeforeTriggeringIt(buildConfigurationAudited);
if (!buildConfigurationSet.getBuildConfigurations().contains(buildConfigurationAudited.getBuildConfiguration())) {
throw new InvalidEntityException("BuildConfigurationSet " + buildConfigurationSet + " doesn't contain this BuildConfigurationAudited entity " + buildConfigurationAudited);
}
buildConfigurationAuditedsMap.put(buildConfigurationAudited.getId(), buildConfigurationAudited);
}
}
return buildConfigurationAuditedsMap;
}
use of org.jboss.pnc.model.BuildConfigurationAudited in project pnc by project-ncl.
the class DatastoreAdapterTest method shouldStoreRepourResult.
@Test
public void shouldStoreRepourResult() throws DatastoreException {
// given
DatastoreMock datastore = new DatastoreMock();
DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
RepourResult repourResult = RepourResultMock.mock();
// when
BuildConfiguration buildConfiguration = BuildConfiguration.Builder.newBuilder().name("Configuration.").build();
BuildConfigurationAudited buildConfigurationAudited = BuildConfigurationAudited.Builder.newBuilder().buildConfiguration(buildConfiguration).build();
BuildTask buildTask = mockBuildTask();
BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
BuildResult buildResult = new BuildResult(CompletionStatus.SUCCESS, Optional.empty(), "", Optional.of(buildExecutionConfiguration), Optional.of(BuildDriverResultMock.mockResult(BuildStatus.SUCCESS)), Optional.of(RepositoryManagerResultMock.mockResult()), Optional.of(EnvironmentDriverResultMock.mock()), Optional.of(repourResult));
datastoreAdapter.storeResult(buildTask, buildResult);
// then
List<BuildRecord> buildRecords = datastore.getBuildRecords();
Assert.assertEquals(1, buildRecords.size());
BuildRecord buildRecord = buildRecords.get(0);
Assert.assertEquals(buildRecord.getStatus(), BuildStatus.SUCCESS);
Assert.assertEquals(repourResult.getExecutionRootName(), buildRecord.getExecutionRootName());
Assert.assertEquals(repourResult.getExecutionRootVersion(), buildRecord.getExecutionRootVersion());
Assert.assertEquals(repourResult.getLog(), buildRecord.getRepourLog());
}
Aggregations