use of org.jboss.pnc.facade.validation.ConflictedEntryException 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.ConflictedEntryException in project pnc by project-ncl.
the class SCMRepositoryProviderImpl method validateRepositoryWithExternalURLDoesNotExist.
private void validateRepositoryWithExternalURLDoesNotExist(String externalUrl, Integer ignoreId) throws ConflictedEntryException {
RepositoryConfiguration repositoryConfiguration = repositoryConfigurationRepository.queryByExternalScm(externalUrl);
if (repositoryConfiguration != null && !repositoryConfiguration.getId().equals(ignoreId)) {
String message = "SCM Repository already exists (id: " + repositoryConfiguration.getId() + ")";
throw new ConflictedEntryException(message, RepositoryConfiguration.class, repositoryConfiguration.getId().toString());
}
String internalUrl = repour.translateExternalUrl(externalUrl);
validateRepositoryWithInternalURLDoesNotExist(internalUrl, ignoreId);
}
use of org.jboss.pnc.facade.validation.ConflictedEntryException 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));
}
Aggregations