Search in sources :

Example 61 with AlertException

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

the class ConfigActions method findFieldModel.

@Override
protected Optional<FieldModel> findFieldModel(Long id) {
    Optional<FieldModel> optionalModel = Optional.empty();
    Optional<ConfigurationModel> configurationModel = configurationModelConfigurationAccessor.getConfigurationById(id);
    if (configurationModel.isPresent()) {
        try {
            FieldModel configurationFieldModel = modelConverter.convertToFieldModel(configurationModel.get());
            FieldModel fieldModel = fieldModelProcessor.performAfterReadAction(configurationFieldModel);
            optionalModel = Optional.of(fieldModel);
        } catch (AlertException ex) {
            logger.error(String.format("Error finding configuration for id: %d", id), ex);
        }
    }
    return optionalModel;
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) 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) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 62 with AlertException

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

the class ConfigActions method createWithoutChecks.

@Override
protected ActionResponse<FieldModel> createWithoutChecks(FieldModel resource) {
    Optional<DescriptorKey> descriptorKey = descriptorMap.getDescriptorKey(resource.getDescriptorName());
    if (descriptorKey.isPresent()) {
        try {
            FieldModel modifiedFieldModel = fieldModelProcessor.performBeforeSaveAction(resource);
            String context = modifiedFieldModel.getContext();
            Map<String, ConfigurationFieldModel> configurationFieldModelMap = modelConverter.convertToConfigurationFieldModelMap(modifiedFieldModel);
            ConfigurationModel configuration = configurationModelConfigurationAccessor.createConfiguration(descriptorKey.get(), EnumUtils.getEnum(ConfigContextEnum.class, context), configurationFieldModelMap.values());
            globalConfigurationModelToConcreteConversionService.createDefaultConcreteModel(modifiedFieldModel.getDescriptorName(), configuration);
            FieldModel dbSavedModel = modelConverter.convertToFieldModel(configuration);
            FieldModel afterSaveAction = fieldModelProcessor.performAfterSaveAction(dbSavedModel);
            FieldModel responseModel = dbSavedModel.fill(afterSaveAction);
            return new ActionResponse<>(HttpStatus.OK, responseModel);
        } catch (AlertException ex) {
            logger.error("Error creating configuration", ex);
            return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error creating config: %s", ex.getMessage()));
        }
    }
    return new ActionResponse<>(HttpStatus.BAD_REQUEST, "descriptorName is missing or invalid");
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) 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) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 63 with AlertException

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

the class ConfigActions method deleteWithoutChecks.

@Override
protected ActionResponse<FieldModel> deleteWithoutChecks(Long id) {
    Optional<ConfigurationModel> configuration = configurationModelConfigurationAccessor.getConfigurationById(id);
    if (configuration.isPresent()) {
        try {
            ConfigurationModel configurationModel = configuration.get();
            FieldModel convertedFieldModel = modelConverter.convertToFieldModel(configurationModel);
            FieldModel fieldModel = fieldModelProcessor.performBeforeDeleteAction(convertedFieldModel);
            configurationModelConfigurationAccessor.deleteConfiguration(Long.parseLong(fieldModel.getId()));
            globalConfigurationModelToConcreteConversionService.deleteDefaultConcreteModel(fieldModel.getDescriptorName(), configurationModel);
            fieldModelProcessor.performAfterDeleteAction(fieldModel);
        } catch (AlertException ex) {
            logger.error(String.format("Error deleting config id: %d", id), ex);
            return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
        }
    }
    return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) 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) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 64 with AlertException

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

the class IssueTrackerTestAction method testConfig.

@Override
public MessageResult testConfig(DistributionJobModel testJobModel, String jobName, @Nullable String customTopic, @Nullable String customMessage) throws AlertException {
    D distributionDetails = (D) testJobModel.getDistributionJobDetails();
    IssueTrackerMessageSender<T> messageSender = messageSenderFactory.createMessageSender(distributionDetails);
    String topicString = Optional.ofNullable(customTopic).orElse("Alert Test Topic");
    String messageString = Optional.ofNullable(customMessage).orElse("Alert Test Message");
    // TODO determine if source should be required everywhere
    ProjectIssueModel testProjectIssueModel = createPlaceholderProjectIssueModel(testJobModel.getBlackDuckGlobalConfigId());
    String postCreateComment = String.format("Created by [ Test Configuration ] in the Alert Distribution Job: %s", testJobModel.getName());
    IssueCreationModel creationRequest = IssueCreationModel.simple(topicString, messageString, List.of(postCreateComment), testProjectIssueModel.getProvider());
    IssueTrackerModelHolder<T> creationRequestModelHolder = new IssueTrackerModelHolder<>(List.of(creationRequest), List.of(), List.of());
    IssueTrackerTestActionFieldStatusCreator fieldStatusCreator = new IssueTrackerTestActionFieldStatusCreator();
    List<IssueTrackerIssueResponseModel<T>> createdIssues;
    try {
        createdIssues = messageSender.sendMessages(creationRequestModelHolder);
    } catch (AlertFieldException e) {
        logger.error("Failed to create test issue", e);
        return new MessageResult("Failed to create issue: " + e.getMessage(), e.getFieldErrors());
    } catch (AlertException e) {
        logger.error("Failed to create test issue", e);
        return new MessageResult("Failed to create issue: " + e.getMessage(), fieldStatusCreator.createWithoutField(e.getMessage()));
    }
    int createdIssuesSize = createdIssues.size();
    if (createdIssuesSize != 1) {
        String errorMessage = String.format("Expected [1] issue to be created, but there were actually [%d]", createdIssuesSize);
        return new MessageResult(errorMessage, fieldStatusCreator.createWithoutField(errorMessage));
    }
    IssueTrackerIssueResponseModel<T> createdIssue = createdIssues.get(0);
    ExistingIssueDetails<T> existingIssueDetails = new ExistingIssueDetails<>(createdIssue.getIssueId(), createdIssue.getIssueKey(), createdIssue.getIssueTitle(), createdIssue.getIssueLink(), IssueStatus.RESOLVABLE, IssueCategory.BOM);
    if (!hasResolveTransition(distributionDetails)) {
        return createSuccessMessageResult(existingIssueDetails);
    }
    IssueTrackerTransitionTestAction<T> transitionTestAction = new IssueTrackerTransitionTestAction<>(messageSender, fieldStatusCreator);
    Optional<MessageResult> optionalResolveFailure = transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel);
    if (optionalResolveFailure.isPresent()) {
        return optionalResolveFailure.get();
    }
    if (!hasReopenTransition(distributionDetails)) {
        return createSuccessMessageResult(existingIssueDetails);
    }
    return transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.OPEN, existingIssueDetails, testProjectIssueModel).orElseGet(() -> transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel).orElse(createSuccessMessageResult(existingIssueDetails)));
}
Also used : IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 65 with AlertException

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

the class RestChannelUtilityTest method sendMessageSuccessTest.

@Test
public void sendMessageSuccessTest() throws IntegrationException {
    Response response = createMockResponse(HttpStatus.OK);
    IntHttpClient intHttpClient = createMockHttpClientWithResponse(response);
    RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
    try {
        restChannelUtility.sendMessage(List.of(TEST_REQUEST, TEST_REQUEST), CLASS_NAME);
    } catch (AlertException e) {
        fail("Expected no exception to be thrown", e);
    }
}
Also used : Response(com.synopsys.integration.rest.response.Response) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

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