Search in sources :

Example 6 with EmptyEntityException

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

the class OperationsManagerImpl method newDeliverableAnalyzerOperation.

@Override
public DeliverableAnalyzerOperation newDeliverableAnalyzerOperation(String milestoneId, Map<String, String> inputParams) {
    ProductMilestone milestone = productMilestoneRepository.queryById(ProductMilestoneMapper.idMapper.toEntity(milestoneId));
    if (milestone == null) {
        throw new EmptyEntityException("Milestone with id " + milestoneId + " doesn't exist");
    }
    String operationId = Sequence.nextBase32Id();
    MDCUtils.addProcessContext(operationId);
    org.jboss.pnc.model.DeliverableAnalyzerOperation operation = org.jboss.pnc.model.DeliverableAnalyzerOperation.Builder.newBuilder().progressStatus(ProgressStatus.NEW).submitTime(Date.from(Instant.now())).productMilestone(milestone).operationParameters(inputParams).user(userService.currentUser()).id(operationId).build();
    repository.save(operation);
    analysisStatusChangedEventNotifier.fire(new OperationChangedEvent(operation, null));
    return operation;
}
Also used : EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) DeliverableAnalyzerOperation(org.jboss.pnc.model.DeliverableAnalyzerOperation) ProductMilestone(org.jboss.pnc.model.ProductMilestone)

Example 7 with EmptyEntityException

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

the class BrewPusherImpl method getLatestSuccessfullyExecutedBuildRecord.

/**
 * @param buildRecordId
 * @return Latest build record with status success or null if the build record does not exist.
 * @throws InconsistentDataException when there is no SUCCESS status before NO_REBUILD_REQUIRED
 * @throws InvalidEntityException when the status is not SUCCESS or NO_REBUILD_REQUIRED
 */
private BuildRecord getLatestSuccessfullyExecutedBuildRecord(Base32LongID buildRecordId) {
    BuildRecord buildRecord = buildRecordRepository.findByIdFetchProperties(buildRecordId);
    if (buildRecord == null) {
        throw new EmptyEntityException("Build record not found.");
    }
    switch(buildRecord.getStatus()) {
        case SUCCESS:
            return buildRecord;
        case NO_REBUILD_REQUIRED:
            // if status is NO_REBUILD_REQUIRED, find the associated BuildRecord which was linked as the no rebuild
            // cause
            BuildRecord noRebuildCause = buildRecord.getNoRebuildCause();
            if (noRebuildCause != null) {
                return noRebuildCause;
            } else {
                String message = "There is no SUCCESS build before NO_REBUILD_REQUIRED.";
                log.error(message);
                throw new InconsistentDataException(message);
            }
        default:
            // Build status is not SUCCESS or NO_REBUILD_REQUIRED.
            throw new OperationNotAllowedException("Not allowed to push failed build.");
    }
}
Also used : EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) InconsistentDataException(org.jboss.pnc.spi.datastore.InconsistentDataException) OperationNotAllowedException(org.jboss.pnc.facade.validation.OperationNotAllowedException) BuildRecord(org.jboss.pnc.model.BuildRecord)

Aggregations

EmptyEntityException (org.jboss.pnc.facade.validation.EmptyEntityException)7 Build (org.jboss.pnc.dto.Build)2 GraphDtoBuilder (org.jboss.pnc.facade.util.GraphDtoBuilder)2 BuildRecordPredicates.temporaryBuild (org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 BpmEventType (org.jboss.pnc.bpm.BpmEventType)1 NoEntityException (org.jboss.pnc.bpm.NoEntityException)1 BpmEvent (org.jboss.pnc.bpm.model.BpmEvent)1 Graph (org.jboss.pnc.dto.response.Graph)1 OperationNotAllowedException (org.jboss.pnc.facade.validation.OperationNotAllowedException)1 Base32LongID (org.jboss.pnc.model.Base32LongID)1 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)1 BuildEnvironment (org.jboss.pnc.model.BuildEnvironment)1 BuildRecord (org.jboss.pnc.model.BuildRecord)1 DeliverableAnalyzerOperation (org.jboss.pnc.model.DeliverableAnalyzerOperation)1 ProductMilestone (org.jboss.pnc.model.ProductMilestone)1 InconsistentDataException (org.jboss.pnc.spi.datastore.InconsistentDataException)1