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());
});
}
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.");
}
}
}
}
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);
}
}
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));
}
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;
}
Aggregations