use of org.jboss.pnc.model.ProductMilestoneRelease in project pnc by project-ncl.
the class ProductMilestoneReleaseManager method cancel.
public void cancel(ProductMilestone milestoneInDb, String accessToken, boolean useRHPAM) {
if (!useRHPAM) {
Collection<BpmTask> activeTasks = bpmManager.getActiveTasks();
Optional<MilestoneReleaseTask> milestoneReleaseTask = activeTasks.stream().map(task -> (MilestoneReleaseTask) task).filter(task -> task.getMilestone().getId().equals(milestoneInDb.getId())).findAny();
if (milestoneReleaseTask.isPresent()) {
bpmManager.cancelTask(milestoneReleaseTask.get());
}
} else {
RestConnector restConnector = new RestConnector(bpmConfig);
restConnector.cancelByCorrelation(Numbers.decimalToBase32(milestoneInDb.getId()), accessToken);
}
ProductMilestoneRelease milestoneRelease = productMilestoneReleaseRepository.findLatestByMilestone(milestoneInDb);
milestoneRelease.setStatus(MilestoneCloseStatus.CANCELED);
productMilestoneReleaseRepository.save(milestoneRelease);
}
use of org.jboss.pnc.model.ProductMilestoneRelease in project pnc by project-ncl.
the class ProductMilestoneReleaseManager method updateRelease.
/**
* @param milestone
* @param status
* @return null if ProductMilestoneRelease is not found
*/
private Optional<ProductMilestoneRelease> updateRelease(ProductMilestone milestone, MilestoneCloseStatus status) {
ProductMilestoneRelease release = productMilestoneReleaseRepository.findLatestByMilestone(milestone);
if (release == null) {
log.error("No milestone release found for milestone {}", milestone.getId());
return Optional.empty();
}
if (status != MilestoneCloseStatus.IN_PROGRESS) {
release.setEndDate(new Date());
}
release.setStatus(status);
return Optional.of(productMilestoneReleaseRepository.save(release));
}
use of org.jboss.pnc.model.ProductMilestoneRelease in project pnc by project-ncl.
the class ProductMilestoneProviderImpl method doCloseMilestone.
private ProductMilestoneCloseResult doCloseMilestone(String id, Long milestoneReleaseId) {
org.jboss.pnc.model.ProductMilestone milestoneInDb = repository.queryById(Integer.valueOf(id));
if (milestoneInDb.getEndDate() != null) {
userLog.info("Milestone is already closed: no more modifications allowed");
throw new RepositoryViolationException("Milestone is already closed! No more modifications allowed");
}
if (milestoneInDb.getPerformedBuilds().size() == 0) {
throw new InvalidEntityException("No builds were performed in milestone!");
} else {
Optional<ProductMilestoneRelease> inProgress = releaseManager.getInProgress(milestoneInDb);
if (inProgress.isPresent()) {
userLog.warn("Milestone close is already in progress.");
return milestoneReleaseMapper.toDTO(inProgress.get());
} else {
log.debug("Milestone's 'end date' set; no release of the milestone in progress: will start release");
boolean useRHPAM = bpmConfig.isNewBpmForced() || userService.hasLoggedInUserRole(WORK_WITH_TECH_PREVIEW);
log.debug("Using RHPAM server: {}", useRHPAM);
ProductMilestoneRelease milestoneReleaseDb = releaseManager.startRelease(milestoneInDb, userService.currentUserToken(), useRHPAM, milestoneReleaseId);
ProductMilestoneCloseResult milestoneCloseResult = milestoneReleaseMapper.toDTO(milestoneReleaseDb);
return milestoneCloseResult;
}
}
}
Aggregations