Search in sources :

Example 1 with RepositoryViolationException

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);
}
Also used : RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) ArtifactAudited(org.jboss.pnc.model.ArtifactAudited)

Example 2 with RepositoryViolationException

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);
    }
}
Also used : BuildConfigurationCreation(org.jboss.pnc.dto.notification.BuildConfigurationCreation) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) DTOValidationException(org.jboss.pnc.facade.validation.DTOValidationException) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) RepositoryConfiguration(org.jboss.pnc.model.RepositoryConfiguration) SCMRepository(org.jboss.pnc.dto.SCMRepository)

Example 3 with RepositoryViolationException

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.");
    }
}
Also used : BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException)

Example 4 with RepositoryViolationException

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;
        }
    }
}
Also used : RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) ProductMilestoneCloseResult(org.jboss.pnc.dto.ProductMilestoneCloseResult) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) ProductMilestoneRelease(org.jboss.pnc.model.ProductMilestoneRelease)

Aggregations

RepositoryViolationException (org.jboss.pnc.facade.validation.RepositoryViolationException)4 InvalidEntityException (org.jboss.pnc.facade.validation.InvalidEntityException)3 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)1 ProductMilestoneCloseResult (org.jboss.pnc.dto.ProductMilestoneCloseResult)1 SCMRepository (org.jboss.pnc.dto.SCMRepository)1 BuildConfigurationCreation (org.jboss.pnc.dto.notification.BuildConfigurationCreation)1 ArtifactQuality (org.jboss.pnc.enums.ArtifactQuality)1 ConflictedEntryException (org.jboss.pnc.facade.validation.ConflictedEntryException)1 DTOValidationException (org.jboss.pnc.facade.validation.DTOValidationException)1 EmptyEntityException (org.jboss.pnc.facade.validation.EmptyEntityException)1 ArtifactAudited (org.jboss.pnc.model.ArtifactAudited)1 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)1 ProductMilestoneRelease (org.jboss.pnc.model.ProductMilestoneRelease)1 RepositoryConfiguration (org.jboss.pnc.model.RepositoryConfiguration)1