Search in sources :

Example 11 with AlertConfigurationException

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

the class EmailGlobalConfigAccessor method updateConfiguration.

@Override
@Transactional(propagation = Propagation.REQUIRED)
public EmailGlobalConfigModel updateConfiguration(EmailGlobalConfigModel configuration) throws AlertConfigurationException {
    EmailConfigurationEntity configurationEntity = emailConfigurationRepository.findByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME).orElseThrow(() -> new AlertConfigurationException(String.format("Config with name '%s' did not exist", AlertRestConstants.DEFAULT_CONFIGURATION_NAME)));
    if (BooleanUtils.toBoolean(configuration.getIsSmtpPasswordSet()) && configuration.getSmtpPassword().isEmpty()) {
        String decryptedPassword = encryptionUtility.decrypt(configurationEntity.getAuthPassword());
        configuration.setSmtpPassword(decryptedPassword);
    }
    return populateConfiguration(configurationEntity.getConfigurationId(), configuration, configurationEntity.getCreatedAt());
}
Also used : EmailConfigurationEntity(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with AlertConfigurationException

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

the class EmailEnvironmentVariableHandlerFactory method updateConfiguration.

private EnvironmentProcessingResult updateConfiguration() {
    EnvironmentProcessingResult.Builder builder = new EnvironmentProcessingResult.Builder(EMAIL_CONFIGURATION_KEYSET).addVariableNames(OLD_ADDITIONAL_PROPERTY_KEYSET);
    EmailGlobalConfigModel configModel = new EmailGlobalConfigModel();
    configModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    configureEmailSettings(configModel);
    configureAdditionalProperties(builder, configModel);
    ValidationResponseModel validationResponseModel = validator.validate(configModel);
    if (validationResponseModel.hasErrors()) {
        logger.error("Error inserting startup values: {}", validationResponseModel.getMessage());
        Map<String, AlertFieldStatus> errors = validationResponseModel.getErrors();
        for (Map.Entry<String, AlertFieldStatus> error : errors.entrySet()) {
            AlertFieldStatus status = error.getValue();
            logger.error("Field: '{}' failed with the error: {}", status.getFieldName(), status.getFieldMessage());
        }
        return EnvironmentProcessingResult.empty();
    }
    EmailGlobalConfigModel obfuscatedModel = configModel.obfuscate();
    obfuscatedModel.getSmtpHost().ifPresent(value -> builder.addVariableValue(EMAIL_HOST_KEY, value));
    obfuscatedModel.getSmtpPort().map(String::valueOf).ifPresent(value -> builder.addVariableValue(EMAIL_PORT_KEY, value));
    obfuscatedModel.getSmtpFrom().ifPresent(value -> builder.addVariableValue(EMAIL_FROM_KEY, value));
    obfuscatedModel.getSmtpAuth().map(String::valueOf).ifPresent(value -> builder.addVariableValue(AUTH_REQUIRED_KEY, value));
    obfuscatedModel.getSmtpUsername().ifPresent(value -> builder.addVariableValue(AUTH_USER_KEY, value));
    if (Boolean.TRUE.equals(obfuscatedModel.getIsSmtpPasswordSet())) {
        builder.addVariableValue(AUTH_PASSWORD_KEY, AlertConstants.MASKED_VALUE);
    }
    EnvironmentProcessingResult result = builder.build();
    if (result.hasValues()) {
        try {
            configAccessor.createConfiguration(configModel);
        } catch (AlertConfigurationException ex) {
            logger.error("Failed to create config: ", ex);
        }
    }
    return result;
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) HashMap(java.util.HashMap) Map(java.util.Map) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 13 with AlertConfigurationException

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

the class JobConfigActionsTest method updateServerErrorTest.

@Test
public void updateServerErrorTest() throws Exception {
    Mockito.when(mockedJobAccessor.getJobById(jobId)).thenReturn(Optional.of(distributionJobModel));
    Mockito.doThrow(new AlertConfigurationException("Exception for Alert test")).when(mockedFieldModelProcessor).performBeforeUpdateAction(Mockito.any());
    ActionResponse<JobFieldModel> jobFieldModelActionResponse = defaultJobConfigActions.update(jobId, 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) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 14 with AlertConfigurationException

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

the class ProjectVersionNotificationMessageExtractor method extract.

@Override
protected ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, ProjectVersionNotificationContent notificationContent) {
    AlertNotificationModel alertNotificationModel = notificationContentWrapper.getAlertNotificationModel();
    Long providerConfigId = alertNotificationModel.getProviderConfigId();
    String providerUrl;
    try {
        BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
        providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
    } catch (AlertConfigurationException e) {
        logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, alertNotificationModel.getProviderConfigName(), e);
        return ProviderMessageHolder.empty();
    }
    LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), alertNotificationModel.getProviderConfigName(), providerUrl);
    ProviderDetails providerDetails = new ProviderDetails(alertNotificationModel.getProviderConfigId(), providerItem);
    LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), notificationContent.getProject());
    LinkableItem projectVersion = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT_VERSION, notificationContent.getProjectVersionName(), notificationContent.getProjectVersion());
    ProjectOperation operation = ProjectOperation.fromOperationType(notificationContent.getOperationType());
    ProjectMessage projectVersionMessage = ProjectMessage.projectVersionStatusInfo(providerDetails, project, projectVersion, operation);
    return new ProviderMessageHolder(List.of(projectVersionMessage), List.of());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) ProjectOperation(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)

Example 15 with AlertConfigurationException

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

the class ProjectNotificationMessageExtractor method extract.

@Override
protected ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, ProjectNotificationContent notificationContent) {
    AlertNotificationModel alertNotificationModel = notificationContentWrapper.getAlertNotificationModel();
    Long providerConfigId = alertNotificationModel.getProviderConfigId();
    String providerUrl;
    try {
        BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
        providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
    } catch (AlertConfigurationException e) {
        logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, alertNotificationModel.getProviderConfigName(), e);
        return ProviderMessageHolder.empty();
    }
    LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), alertNotificationModel.getProviderConfigName(), providerUrl);
    ProviderDetails providerDetails = new ProviderDetails(alertNotificationModel.getProviderConfigId(), providerItem);
    LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), notificationContent.getProject());
    ProjectOperation operation = ProjectOperation.fromOperationType(notificationContent.getOperationType());
    ProjectMessage projectMessage = ProjectMessage.projectStatusInfo(providerDetails, project, operation);
    return new ProviderMessageHolder(List.of(projectMessage), List.of());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) ProjectOperation(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)

Aggregations

AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)54 Test (org.junit.jupiter.api.Test)20 Transactional (org.springframework.transaction.annotation.Transactional)10 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)8 UUID (java.util.UUID)8 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)5 Map (java.util.Map)5 JiraServerConfigurationEntity (com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity)4 JiraServerGlobalConfigModel (com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel)4 AlertForbiddenOperationException (com.synopsys.integration.alert.common.exception.AlertForbiddenOperationException)4 UserModel (com.synopsys.integration.alert.common.persistence.model.UserModel)4 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)4 HashMap (java.util.HashMap)4 EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)3 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)3 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)3 UserRoleModel (com.synopsys.integration.alert.common.persistence.model.UserRoleModel)3 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)3 UserEntity (com.synopsys.integration.alert.database.user.UserEntity)3 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)3