Search in sources :

Example 26 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method createServerErrorTest.

@Test
public void createServerErrorTest() throws Exception {
    Mockito.doThrow(new AlertException("Exception for test")).when(mockedFieldModelProcessor).performBeforeSaveAction(Mockito.any());
    ActionResponse<JobFieldModel> jobFieldModelActionResponse = defaultJobConfigActions.create(jobFieldModel);
    assertTrue(jobFieldModelActionResponse.isError());
    assertFalse(jobFieldModelActionResponse.hasContent());
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, jobFieldModelActionResponse.getHttpStatus());
}
Also used : JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 27 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method getOneErrorTest.

@Test
public void getOneErrorTest() throws Exception {
    Mockito.doThrow(new AlertException("Exception for Alert")).when(mockedFieldModelProcessor).performAfterReadAction(Mockito.any());
    ActionResponse<JobFieldModel> jobFieldModelActionResponse = defaultJobConfigActions.getOne(jobId);
    assertTrue(jobFieldModelActionResponse.isError());
    assertFalse(jobFieldModelActionResponse.hasContent());
    assertEquals(HttpStatus.NOT_FOUND, jobFieldModelActionResponse.getHttpStatus());
}
Also used : JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 28 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class ConfigActions method convertConfigurationModelList.

private List<FieldModel> convertConfigurationModelList(String descriptorName, String context, List<ConfigurationModel> configurationModels) {
    List<FieldModel> responseFieldModels = new LinkedList<>();
    List<FieldModel> fieldModelList = new LinkedList<>();
    if (null != configurationModels) {
        for (ConfigurationModel configurationModel : configurationModels) {
            FieldModel fieldModel = modelConverter.convertToFieldModel(configurationModel);
            fieldModelList.add(fieldModel);
        }
    }
    if (fieldModelList.isEmpty()) {
        fieldModelList.add(new FieldModel(descriptorName, context, new HashMap<>()));
    }
    for (FieldModel fieldModel : fieldModelList) {
        try {
            responseFieldModels.add(fieldModelProcessor.performAfterReadAction(fieldModel));
        } catch (AlertException ex) {
            logger.error("Error performing after read action", ex);
        }
    }
    return responseFieldModels;
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) HashMap(java.util.HashMap) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) LinkedList(java.util.LinkedList) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 29 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class JobConfigActions method updateWithoutChecks.

@Override
protected ActionResponse<JobFieldModel> updateWithoutChecks(UUID id, JobFieldModel resource) {
    try {
        Optional<DistributionJobModel> jobModel = jobAccessor.getJobById(id);
        if (jobModel.isPresent()) {
            DistributionJobModel previousJob = jobModel.get();
            JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(previousJob);
            Map<String, FieldModel> descriptorAndContextToPreviousFieldModel = new HashMap<>();
            for (FieldModel previousJobFieldModel : jobFieldModel.getFieldModels()) {
                descriptorAndContextToPreviousFieldModel.put(previousJobFieldModel.getDescriptorName() + previousJobFieldModel.getContext(), previousJobFieldModel);
            }
            Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
            for (FieldModel fieldModel : resource.getFieldModels()) {
                FieldModel beforeUpdateEventFieldModel = fieldModelProcessor.performBeforeUpdateAction(fieldModel);
                String beforeFieldModelId = beforeUpdateEventFieldModel.getId();
                Long fieldModelId = (StringUtils.isNotBlank(beforeFieldModelId)) ? Long.parseLong(beforeFieldModelId) : null;
                Collection<ConfigurationFieldModel> updatedFieldModels = fieldModelProcessor.fillFieldModelWithExistingData(fieldModelId, beforeUpdateEventFieldModel);
                configurationFieldModels.addAll(updatedFieldModels);
            }
            List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
            DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, previousJob.getCreatedAt(), DateUtils.createCurrentDateTimestamp());
            DistributionJobModel savedJob = jobAccessor.updateJob(previousJob.getJobId(), jobRequestModel);
            JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
            Set<FieldModel> updatedFieldModels = new HashSet<>();
            for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
                FieldModel previousFieldModel = descriptorAndContextToPreviousFieldModel.get(fieldModel.getDescriptorName() + fieldModel.getContext());
                FieldModel updatedModel = fieldModelProcessor.performAfterUpdateAction(previousFieldModel, fieldModel);
                updatedFieldModels.add(updatedModel);
            }
            savedJobFieldModel.setFieldModels(updatedFieldModels);
            return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
        } else {
            return new ActionResponse<>(HttpStatus.NOT_FOUND);
        }
    } catch (AlertException ex) {
        logger.error("Error creating job", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) HashSet(java.util.HashSet)

Example 30 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class IssueTrackerTransitionTestAction method transitionTestIssueOrReturnFailureResult.

public Optional<MessageResult> transitionTestIssueOrReturnFailureResult(IssueOperation operation, ExistingIssueDetails<T> existingIssueDetails, ProjectIssueModel testProjectIssueModel) {
    String postTransitionComment = String.format("Successfully tested the %s operation", operation.name());
    IssueTransitionModel<T> resolveRequest = new IssueTransitionModel<>(existingIssueDetails, operation, List.of(postTransitionComment), testProjectIssueModel);
    IssueTrackerModelHolder<T> resolveRequestModelHolder = new IssueTrackerModelHolder<>(List.of(), List.of(resolveRequest), List.of());
    List<IssueTrackerIssueResponseModel<T>> transitionedIssues;
    try {
        transitionedIssues = messageSender.sendMessages(resolveRequestModelHolder);
    } catch (IssueMissingTransitionException e) {
        MessageResult issueMissingResult = handleIssueMessingTransitionException(e);
        return Optional.of(issueMissingResult);
    } catch (AlertException e) {
        MessageResult alertExceptionResult = handleAlertException(e, operation);
        return Optional.of(alertExceptionResult);
    }
    int transitionedIssuesSize = transitionedIssues.size();
    if (transitionedIssuesSize != 1) {
        String errorMessage = String.format("Expected [1] issue to be transitioned, but there were actually [%d]", transitionedIssuesSize);
        return Optional.of(new MessageResult(errorMessage, fieldStatusCreator.createWithoutField(errorMessage)));
    }
    return Optional.empty();
}
Also used : IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) IssueMissingTransitionException(com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Aggregations

AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)101 Test (org.junit.jupiter.api.Test)35 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)22 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)18 List (java.util.List)18 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)17 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)16 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)16 Optional (java.util.Optional)13 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)12 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)12 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)11 HashMap (java.util.HashMap)11 IntegrationException (com.synopsys.integration.exception.IntegrationException)10 ArrayList (java.util.ArrayList)9 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)8 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)8 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)8 UUID (java.util.UUID)8 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)7