use of org.jboss.pnc.facade.validation.RepositoryViolationException in project pnc by project-ncl.
the class ArtifactProviderImpl method createQualityLevelRevision.
@Override
public ArtifactRevision createQualityLevelRevision(String id, String quality, String reason) throws DTOValidationException {
boolean isLoggedInUserSystemUser = userService.hasLoggedInUserRole(SYSTEM_USER);
ArtifactQuality newQuality = validateProvidedArtifactQuality(quality, isLoggedInUserSystemUser);
org.jboss.pnc.dto.Artifact artifact = getSpecific(id);
if (artifact == null) {
throw new InvalidEntityException("Artifact with id: " + id + " does not exist.");
}
validateIfArtifactQualityIsModifiable(artifact, newQuality);
update(id, artifact.toBuilder().artifactQuality(newQuality).qualityLevelReason(reason).build());
ArtifactAudited latestRevision = artifactAuditedRepository.findLatestById(Integer.parseInt(id));
if (latestRevision == null) {
throw new RepositoryViolationException("Entity should exist in the DB");
}
if (DA_SYNCRONIZED_ARTIFACT_QUALITIES.contains(newQuality)) {
String jsonPayload = createBlacklistJSONPayload(artifact);
blacklistAsyncInvoker.notifyBlacklistToDA(jsonPayload);
}
return artifactRevisionMapper.toDTO(latestRevision);
}
use of org.jboss.pnc.facade.validation.RepositoryViolationException in project pnc by project-ncl.
the class BuildConfigurationProviderImpl method createBuildConfigurationWithRepository.
public void createBuildConfigurationWithRepository(String taskId, int scmRepositoryId, BuildConfiguration configuration) {
RepositoryConfiguration repositoryConfiguration = repositoryConfigurationRepository.queryById(scmRepositoryId);
final boolean sendMessage = taskId != null;
if (repositoryConfiguration == null) {
String errorMessage = "Repository Configuration was not found in database.";
logger.error(errorMessage);
if (sendMessage) {
sendErrorMessage(SCMRepository.builder().id(Integer.toString(scmRepositoryId)).build(), null, errorMessage, taskId);
return;
}
throw new RepositoryViolationException("Repository Configuration was not found in database.");
}
org.jboss.pnc.model.BuildConfiguration buildConfiguration = mapper.toEntity(configuration);
buildConfiguration.setRepositoryConfiguration(repositoryConfiguration);
org.jboss.pnc.model.BuildConfiguration buildConfigurationSaved = repository.save(buildConfiguration);
Set<Integer> bcSetIds;
if (configuration.getGroupConfigs() == null) {
bcSetIds = Collections.emptySet();
} else {
bcSetIds = configuration.getGroupConfigs().keySet().stream().map(Integer::valueOf).collect(Collectors.toSet());
}
SCMRepository scmRepository = scmRepositoryMapper.toDTO(repositoryConfiguration);
BuildConfiguration buildConfig = mapper.toDTO(buildConfigurationSaved);
try {
addBuildConfigurationToSet(buildConfigurationSaved, bcSetIds);
} catch (Exception e) {
logger.error(e.getMessage());
if (sendMessage) {
sendErrorMessage(scmRepository, buildConfig, e.getMessage(), taskId);
return;
}
throw new RepositoryViolationException("Failed to add BuildConfig to BuildConfigSets.");
}
logger.info("Created Build Configuration with Repository: {}.", buildConfig);
if (sendMessage) {
BuildConfigurationCreation successMessage = BuildConfigurationCreation.success(scmRepository, buildConfig, taskId);
notifier.sendMessage(successMessage);
}
}
use of org.jboss.pnc.facade.validation.RepositoryViolationException in project pnc by project-ncl.
the class GroupConfigurationProviderImpl method validateBeforeUpdating.
@Override
protected void validateBeforeUpdating(Integer id, GroupConfiguration restEntity) {
super.validateBeforeUpdating(id, restEntity);
BuildConfigurationSet dbEntity = findInDB(id);
if (dbEntity.isArchived()) {
throw new RepositoryViolationException("The Group Config " + id + " is already deleted.");
}
}
use of org.jboss.pnc.facade.validation.RepositoryViolationException 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