Search in sources :

Example 1 with InvalidEntityException

use of org.jboss.pnc.facade.validation.InvalidEntityException in project pnc by project-ncl.

the class ProductVersionProviderImpl method validateBeforeSaving.

@Override
protected void validateBeforeSaving(ProductVersion restEntity) {
    super.validateBeforeSaving(restEntity);
    Product product = productRepository.queryById(Integer.valueOf(restEntity.getProduct().getId()));
    if (product == null) {
        throw new InvalidEntityException("Product with id: " + restEntity.getProduct().getId() + " does not exist.");
    }
    Set<org.jboss.pnc.model.ProductVersion> productVersionList = product.getProductVersions();
    if (productVersionList == null) {
        return;
    }
    productVersionList.stream().filter(pv -> pv.getVersion().equals(restEntity.getVersion())).findFirst().ifPresent(pv -> {
        throw new ConflictedEntryException("Product version with version " + restEntity.getVersion() + " already exists", org.jboss.pnc.model.ProductVersion.class, pv.getId().toString());
    });
}
Also used : Product(org.jboss.pnc.model.Product) ProductVersion(org.jboss.pnc.dto.ProductVersion) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException)

Example 2 with InvalidEntityException

use of org.jboss.pnc.facade.validation.InvalidEntityException in project pnc by project-ncl.

the class ProductVersionProviderImpl method validateMilestone.

private void validateMilestone(Integer id, ProductVersion entity) {
    if (entity.getCurrentProductMilestone() != null) {
        Integer newMilestoneId = milestoneMapper.getIdMapper().toEntity(entity.getCurrentProductMilestone().getId());
        org.jboss.pnc.model.ProductVersion productVersion = repository.queryById(id);
        ProductMilestone currentMilestone = productVersion.getCurrentProductMilestone();
        if (currentMilestone == null || currentMilestone.getId() != newMilestoneId) {
            ProductMilestone newMilestone = milestoneRepository.queryById(newMilestoneId);
            if (newMilestone == null) {
                throw new InvalidEntityException("Milestone with id: " + newMilestoneId + " does not exist.");
            } else if (newMilestone.getEndDate() != null) {
                throw new InvalidEntityException("Milestone with id: " + newMilestoneId + " is closed, so cannot be set as current.");
            }
        }
    }
}
Also used : ProductMilestone(org.jboss.pnc.model.ProductMilestone) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException)

Example 3 with InvalidEntityException

use of org.jboss.pnc.facade.validation.InvalidEntityException in project pnc by project-ncl.

the class SCMRepositoryProviderImpl method validateBeforeUpdating.

@Override
public void validateBeforeUpdating(Integer id, SCMRepository restEntity) {
    super.validateBeforeUpdating(id, restEntity);
    RepositoryConfiguration entityInDb = findInDB(id);
    if (!entityInDb.getInternalUrl().equals(restEntity.getInternalUrl())) {
        throw new InvalidEntityException("Updating internal URL is prohibited. SCMRepo: " + id);
    }
    if (restEntity.getExternalUrl() != null && !restEntity.getExternalUrl().equals(entityInDb.getExternalUrl())) {
        validateRepositoryWithExternalURLDoesNotExist(restEntity.getExternalUrl(), id);
    }
}
Also used : RepositoryConfiguration(org.jboss.pnc.model.RepositoryConfiguration) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException)

Example 4 with InvalidEntityException

use of org.jboss.pnc.facade.validation.InvalidEntityException 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));
}
Also used : BigInteger(java.math.BigInteger) PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Vertex(org.jboss.util.graph.Vertex) Arrays(java.util.Arrays) RolesAllowed(javax.annotation.security.RolesAllowed) ArtifactRepository(org.jboss.pnc.spi.datastore.repositories.ArtifactRepository) SYSTEM_USER(org.jboss.pnc.facade.providers.api.UserRoles.SYSTEM_USER) StringUtils(org.jboss.pnc.common.util.StringUtils) BuildConfigSetRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigSetRecordRepository) Map(java.util.Map) RunningBuildCount(org.jboss.pnc.dto.response.RunningBuildCount) BigInteger(java.math.BigInteger) EJBAccessException(javax.ejb.EJBAccessException) BuildConfigurationRevision(org.jboss.pnc.dto.BuildConfigurationRevision) BuildConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationRepository) User(org.jboss.pnc.model.User) BuildRef(org.jboss.pnc.dto.BuildRef) SortInfoProducer(org.jboss.pnc.spi.datastore.repositories.SortInfoProducer) Gerrit(org.jboss.pnc.common.gerrit.Gerrit) BuildProvider(org.jboss.pnc.facade.providers.api.BuildProvider) Set(java.util.Set) BuildRecordPredicates.withArtifactProduced(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withArtifactProduced) IdRev(org.jboss.pnc.model.IdRev) BuildRecordPredicates.withPerformedInMilestone(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withPerformedInMilestone) Base32LongID(org.jboss.pnc.model.Base32LongID) BuildRecordPredicates.withBuildConfigurationId(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withBuildConfigurationId) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) HttpUtils(org.jboss.pnc.common.util.HttpUtils) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) BuildRecordPredicates.withoutImplicitDependants(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withoutImplicitDependants) DTOValidationException(org.jboss.pnc.facade.validation.DTOValidationException) StreamSupport(java.util.stream.StreamSupport) CorruptedDataException(org.jboss.pnc.facade.validation.CorruptedDataException) ResultMapper(org.jboss.pnc.mapper.api.ResultMapper) ValidationException(org.jboss.pnc.spi.exception.ValidationException) BuildRecordPredicates.withoutLinkedNRRRecordOlderThanTimestamp(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withoutLinkedNRRRecordOlderThanTimestamp) BuildRecord(org.jboss.pnc.model.BuildRecord) TemporaryBuildsCleanerAsyncInvoker(org.jboss.pnc.coordinator.maintenance.TemporaryBuildsCleanerAsyncInvoker) Page(org.jboss.pnc.dto.response.Page) BuildRecordPredicates(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates) BuildRecordPredicates.withBuildConfigSetId(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withBuildConfigSetId) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) StreamHelper.nullableStreamOf(org.jboss.pnc.common.util.StreamHelper.nullableStreamOf) BuildRecordPredicates.buildFinishedBefore(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.buildFinishedBefore) LongBase32IdConverter(org.jboss.pnc.common.pnc.LongBase32IdConverter) Date(java.util.Date) Spliterators(java.util.Spliterators) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) GraphUtils(org.jboss.pnc.common.graph.GraphUtils) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) UserService(org.jboss.pnc.facade.util.UserService) Graph(org.jboss.pnc.dto.response.Graph) BuildRecordPredicates.withUserId(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withUserId) BuildConfigurationRevisionMapper(org.jboss.pnc.mapper.api.BuildConfigurationRevisionMapper) URI(java.net.URI) Stateless(javax.ejb.Stateless) PermitAll(javax.annotation.security.PermitAll) Collection(java.util.Collection) Artifact(org.jboss.pnc.model.Artifact) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Result(org.jboss.pnc.spi.coordinator.Result) BuildRecordInsights(org.jboss.pnc.dto.insights.BuildRecordInsights) RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) Math.min(java.lang.Math.min) Collectors(java.util.stream.Collectors) BuildStatus(org.jboss.pnc.enums.BuildStatus) Objects(java.util.Objects) BuildRecordPredicates.withBuildConfigSetRecordId(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withBuildConfigSetRecordId) List(java.util.List) GerritException(org.jboss.pnc.common.gerrit.GerritException) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) Optional(java.util.Optional) BuildRecordPredicates.withAttribute(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withAttribute) Spliterator(java.util.Spliterator) BuildRecordPredicates.withoutAttribute(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withoutAttribute) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Getter(lombok.Getter) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) Function(java.util.function.Function) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) HashSet(java.util.HashSet) Inject(javax.inject.Inject) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) GraphBuilder(org.jboss.pnc.common.graph.GraphBuilder) Attributes(org.jboss.pnc.constants.Attributes) MergeIterator(org.jboss.pnc.facade.util.MergeIterator) NoSuchElementException(java.util.NoSuchElementException) SSHCredentials(org.jboss.pnc.dto.response.SSHCredentials) ArtifactPredicates.withIds(org.jboss.pnc.spi.datastore.predicates.ArtifactPredicates.withIds) TimeUtils(org.jboss.pnc.common.util.TimeUtils) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) BuildRecordPredicates.withArtifactDependency(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withArtifactDependency) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) BuildConfigurationPredicates.withProjectId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withProjectId) Consumer(java.util.function.Consumer) BuildRecordPredicates.temporaryBuild(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild) GraphDtoBuilder(org.jboss.pnc.facade.util.GraphDtoBuilder) Build(org.jboss.pnc.dto.Build) BuildRecordPredicates.withBuildConfigurationIds(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withBuildConfigurationIds) Comparator(java.util.Comparator) Collections(java.util.Collections) Base32LongID(org.jboss.pnc.model.Base32LongID) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) Artifact(org.jboss.pnc.model.Artifact) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) BuildRecord(org.jboss.pnc.model.BuildRecord) HashSet(java.util.HashSet) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 5 with InvalidEntityException

use of org.jboss.pnc.facade.validation.InvalidEntityException in project pnc by project-ncl.

the class ArtifactProviderImpl method validateProvidedArtifactQuality.

private ArtifactQuality validateProvidedArtifactQuality(String quality, boolean isLoggedInUserSystemUser) {
    ArtifactQuality newQuality;
    try {
        newQuality = ArtifactQuality.valueOf(quality.toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new InvalidEntityException("Artifact quality: " + quality + " does not exist.");
    }
    // User can specify NEW, TESTED, VERIFIED, DEPRECATED quality levels; admins can also specify DELETED and
    // BLACKLISTED
    EnumSet<ArtifactQuality> allowedQualities = isLoggedInUserSystemUser ? ADMIN_ALLOWED_ARTIFACT_QUALITIES : USER_ALLOWED_ARTIFACT_QUALITIES;
    if (!allowedQualities.contains(newQuality)) {
        throw new InvalidEntityException("Artifact quality level can be changed only to " + allowedQualities);
    }
    return newQuality;
}
Also used : ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException)

Aggregations

InvalidEntityException (org.jboss.pnc.facade.validation.InvalidEntityException)13 List (java.util.List)3 RepositoryViolationException (org.jboss.pnc.facade.validation.RepositoryViolationException)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Stateless (javax.ejb.Stateless)2 Inject (javax.inject.Inject)2 ProgressStatus (org.jboss.pnc.api.enums.ProgressStatus)2 StreamHelper.nullableStreamOf (org.jboss.pnc.common.util.StreamHelper.nullableStreamOf)2 ArtifactQuality (org.jboss.pnc.enums.ArtifactQuality)2 UserService (org.jboss.pnc.facade.util.UserService)2 ConflictedEntryException (org.jboss.pnc.facade.validation.ConflictedEntryException)2 BuildMapper (org.jboss.pnc.mapper.api.BuildMapper)2 Artifact (org.jboss.pnc.model.Artifact)2 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)2 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)2