use of org.jboss.pnc.facade.validation.InvalidEntityException 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.InvalidEntityException in project pnc by project-ncl.
the class BrewPusherImpl method doPushBuild.
private BuildPushResult doPushBuild(Base32LongID buildId, BuildPushParameters buildPushParameters, Long buildPushResultId) throws ProcessException {
// TODO START timing event
userLog.info("Push started.");
// collect and validate input data
BuildRecord buildRecord = getLatestSuccessfullyExecutedBuildRecord(buildId);
if (buildRecord.getExecutionRootName() == null && !buildRecord.getBuildConfigurationAudited().getGenericParameters().containsKey(BREW_BUILD_NAME.name())) {
throw new InvalidEntityException("Build " + buildId + " cannot be pushed to brew, because it is missing " + Attributes.BUILD_BREW_NAME + " attribute with brew name.");
}
List<Artifact> artifacts = artifactRepository.queryWithPredicates(ArtifactPredicates.withBuildRecordId(buildRecord.getId()));
if (hasBadArtifactQuality(artifacts)) {
String message = "Build contains artifacts of insufficient quality: BLACKLISTED/DELETED.";
log.debug(message);
BuildPushResult pushResult = BuildPushResult.builder().buildId(BuildMapper.idMapper.toDto(buildId)).status(BuildPushStatus.REJECTED).id(buildPushResultId.toString()).logContext(buildPushResultId.toString()).message(message).build();
throw new OperationNotAllowedException(message, pushResult);
}
log.debug("Pushing Build.id {}.", buildRecord.getId());
BuildPushOperation buildPushOperation = new BuildPushOperation(buildRecord, buildPushResultId, buildPushParameters.getTagPrefix(), buildPushParameters.isReimport(), getCompleteCallbackUrlTemplate());
Result pushResult = buildResultPushManager.push(buildPushOperation, userService.currentUserToken());
log.info("Push Result {}.", pushResult);
BuildPushResult result = BuildPushResult.builder().id(pushResult.getId()).buildId(pushResult.getBuildId()).status(pushResult.getStatus()).logContext(pushResult.getId()).message(pushResult.getMessage()).build();
// verify operation status
switch(pushResult.getStatus()) {
case ACCEPTED:
userLog.info("Push ACCEPTED.");
return result;
case REJECTED:
userLog.warn("Push REJECTED.");
throw new AlreadyRunningException(pushResult.getMessage(), result);
case SYSTEM_ERROR:
userLog.error("Brew push failed: " + pushResult.getMessage());
throw new ProcessException(pushResult.getMessage());
default:
userLog.error("Invalid push result status.");
throw new ProcessException("Invalid push result status.");
}
}
use of org.jboss.pnc.facade.validation.InvalidEntityException in project pnc by project-ncl.
the class BuildTriggererImpl method loadAuditedsFromDB.
private Map<Integer, BuildConfigurationAudited> loadAuditedsFromDB(BuildConfigurationSet buildConfigurationSet, List<BuildConfigurationRevisionRef> buildConfigurationAuditedRests) throws InvalidEntityException {
Map<Integer, BuildConfigurationAudited> buildConfigurationAuditedsMap = new HashMap<>();
Set<IdRev> buildConfigurationAuditedRevs = nullableStreamOf(buildConfigurationAuditedRests).map(bcrRef -> new IdRev(Integer.valueOf(bcrRef.getId()), bcrRef.getRev())).collect(Collectors.toSet());
if (!buildConfigurationAuditedRevs.isEmpty()) {
Map<IdRev, BuildConfigurationAudited> buildConfigurationsAuditedMap = buildConfigurationAuditedRepository.queryById(buildConfigurationAuditedRevs);
for (BuildConfigurationRevisionRef bc : buildConfigurationAuditedRests) {
BuildConfigurationAudited buildConfigurationAudited = buildConfigurationsAuditedMap.get(new IdRev(Integer.valueOf(bc.getId()), bc.getRev()));
Preconditions.checkArgument(buildConfigurationAudited != null, "Can't find Build Configuration with id=" + bc.getId() + ", rev=" + bc.getRev());
buildConfigurationAudited = hibernateLazyInitializer.initializeBuildConfigurationAuditedBeforeTriggeringIt(buildConfigurationAudited);
if (!buildConfigurationSet.getBuildConfigurations().contains(buildConfigurationAudited.getBuildConfiguration())) {
throw new InvalidEntityException("BuildConfigurationSet " + buildConfigurationSet + " doesn't contain this BuildConfigurationAudited entity " + buildConfigurationAudited);
}
buildConfigurationAuditedsMap.put(buildConfigurationAudited.getId(), buildConfigurationAudited);
}
}
return buildConfigurationAuditedsMap;
}
use of org.jboss.pnc.facade.validation.InvalidEntityException in project pnc by project-ncl.
the class BuildConfigurationEndpointImpl method validate.
private void validate(BuildConfiguration buildConfiguration) {
if (buildConfiguration != null) {
Map<String, String> parameters = buildConfiguration.getParameters();
String buildCategoryKey = BuildConfigurationParameterKeys.BUILD_CATEGORY.name();
if (parameters != null && parameters.containsKey(buildCategoryKey)) {
String buildCategoryStr = parameters.get(buildCategoryKey);
try {
BuildCategory.valueOf(buildCategoryStr.toUpperCase());
} catch (Exception ex) {
List<String> categories = Stream.of(BuildCategory.values()).map(BuildCategory::name).collect(Collectors.toList());
throw new InvalidEntityException(buildCategoryKey + " value '" + buildCategoryStr + "' is invalid. Valid values are: " + String.join(", ", categories) + '.');
}
}
}
}
use of org.jboss.pnc.facade.validation.InvalidEntityException in project pnc by project-ncl.
the class OperationsManagerImpl method setResult.
@Override
public Operation setResult(Base32LongID id, OperationResult result) {
Operation operation = repository.queryById(id);
if (operation.getEndTime() != null) {
throw new InvalidEntityException("Operation " + operation + " is already finished!");
}
log.debug("Updating result of operation " + operation + " to " + result);
ProgressStatus previousProgress = operation.getProgressStatus();
operation.setResult(result);
operation.setEndTime(Date.from(Instant.now()));
analysisStatusChangedEventNotifier.fire(new OperationChangedEvent(operation, previousProgress));
return operation;
}
Aggregations