use of org.jboss.pnc.model.Base32LongID in project pnc by project-ncl.
the class DeliverableAnalyzerOperationProviderImplTest method prepareRepositoryMock.
@Before
@Override
public void prepareRepositoryMock() {
when(em.getReference(any(), any())).thenAnswer(inv -> {
Class<GenericEntity> type = inv.getArgument(0, Class.class);
Serializable id = inv.getArgument(1, Serializable.class);
GenericEntity mock = mock(type);
when(mock.getId()).thenReturn(id);
return mock;
});
when(repository().queryWithPredicates(any(), any(), any())).thenAnswer(new ListAnswer(repositoryList));
when(repository().count(any())).thenAnswer(inv -> repositoryList.size());
when(repository().queryById(any())).thenAnswer(inv -> {
Base32LongID id = inv.getArgument(0);
return repositoryList.stream().filter(a -> id.equals(a.getId())).findFirst().orElse(null);
});
when(repository().save(any())).thenAnswer(inv -> {
DeliverableAnalyzerOperation entity = inv.getArgument(0);
if (entity.getId() == null) {
entity.setId(getNextId());
repositoryList.add(entity);
return entity;
} else {
boolean found = false;
for (int i = 0; i < repositoryList.size(); i++) {
if (repositoryList.get(i).getId().equals(entity.getId())) {
repositoryList.set(i, entity);
return entity;
}
}
if (!found) {
repositoryList.add(entity);
return entity;
}
}
throw new IllegalArgumentException("Provided entity has ID but is not in the repository.");
});
doAnswer(inv -> {
Base32LongID id = inv.getArgument(0);
DeliverableAnalyzerOperation object = repositoryList.stream().filter(a -> id.equals(a.getId())).findFirst().orElse(null);
repositoryList.remove(object);
return null;
}).when(repository()).delete(any());
}
use of org.jboss.pnc.model.Base32LongID in project pnc by project-ncl.
the class BuildProviderImpl method setBuiltArtifacts.
@RolesAllowed(SYSTEM_USER)
@Override
public void setBuiltArtifacts(String buildId, List<String> artifactIds) {
Set<Integer> ids = artifactIds.stream().map(Integer::valueOf).collect(Collectors.toSet());
List<Artifact> artifacts = artifactRepository.queryWithPredicates(withIds(ids));
if (ids.size() != artifacts.size()) {
artifacts.stream().map(Artifact::getId).forEach(ids::remove);
throw new InvalidEntityException("Artifacts not found, missing ids: " + ids);
}
final Base32LongID id = parseId(buildId);
BuildRecord buildRecord = repository.queryById(id);
for (Artifact artifact : artifacts) {
if (artifact.getBuildRecord() != null && !id.equals(artifact.getBuildRecord().getId())) {
throw new ConflictedEntryException("Artifact " + artifact.getId() + " is already marked as built by different build.", BuildRecord.class, BuildMapper.idMapper.toDto(artifact.getBuildRecord().getId()));
}
artifact.setBuildRecord(buildRecord);
}
HashSet<Artifact> oldBuiltArtifacts = new HashSet<>(buildRecord.getBuiltArtifacts());
oldBuiltArtifacts.stream().filter(a -> !ids.contains(a.getId())).forEach(a -> a.setBuildRecord(null));
}
use of org.jboss.pnc.model.Base32LongID in project pnc by project-ncl.
the class BuildProviderImpl method update.
@RolesAllowed(SYSTEM_USER)
@Override
public Build update(String buildId, Build restEntity) {
Base32LongID id = parseId(buildId);
validateBeforeUpdating(id, restEntity);
logger.debug("Updating build: " + restEntity.toString());
BuildRecord entityInDB = repository.queryById(id);
entityInDB.setStatus(restEntity.getStatus());
return mapper.toDTO(entityInDB);
}
use of org.jboss.pnc.model.Base32LongID in project pnc by project-ncl.
the class BrewPusherImpl method brewPushCancel.
@Override
public boolean brewPushCancel(String buildId) {
Base32LongID id = BuildMapper.idMapper.toEntity(buildId);
Optional<InProgress.Context> pushContext = buildResultPushManager.getContext(id);
if (pushContext.isPresent()) {
MDCUtils.addProcessContext(pushContext.get().getPushResultId());
MDCUtils.addCustomContext(BUILD_ID_KEY, id.getId());
userLog.info("Build push cancel requested.");
try {
return buildResultPushManager.cancelInProgressPush(id);
} finally {
MDCUtils.removeProcessContext();
MDCUtils.removeCustomContext(BUILD_ID_KEY);
}
} else {
throw new EmptyEntityException("There is no running push operation for build id: " + buildId);
}
}
use of org.jboss.pnc.model.Base32LongID in project pnc by project-ncl.
the class BrewPusherImpl method brewPushComplete.
@Override
public BuildPushResult brewPushComplete(String buildId, BuildPushResult buildPushResult) {
Base32LongID id = BuildMapper.idMapper.toEntity(buildId);
MDCUtils.addProcessContext(buildPushResult.getId());
MDCUtils.addCustomContext(BUILD_ID_KEY, id.getId());
try {
log.info("Received completion notification for BuildRecord.id: {}. Object received: {}.", buildId, buildPushResult);
buildResultPushManager.complete(id, buildPushResultMapper.toEntity(buildPushResult));
// TODO END timing event
userLog.info("Brew push completed.");
return buildPushResult;
} finally {
MDCUtils.removeProcessContext();
MDCUtils.removeCustomContext(BUILD_ID_KEY);
}
}
Aggregations