Search in sources :

Example 96 with AlertException

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

the class UpdateEmailService method handleSend.

private void handleSend(Properties javamailProperties, String smtpFrom, String smtpHost, int smtpPort, boolean smtpAuth, String smtpUsername, String smtpPassword, Map<String, Object> templateFields, String emailAddress) throws AlertException {
    try {
        String alertLogo = alertProperties.createSynopsysLogoPath();
        Map<String, String> contentIdsToFilePaths = new HashMap<>();
        emailMessagingService.addTemplateImage(templateFields, contentIdsToFilePaths, EmailPropertyKeys.EMAIL_LOGO_IMAGE.getPropertyKey(), alertLogo);
        EmailTarget passwordResetEmail = new EmailTarget(emailAddress, TEMPLATE_NAME, templateFields, contentIdsToFilePaths);
        emailMessagingService.sendEmailMessage(javamailProperties, smtpFrom, smtpHost, smtpPort, smtpAuth, smtpUsername, smtpPassword, passwordResetEmail);
    } catch (Exception genericException) {
        throw new AlertException("Problem sending version update email. " + StringUtils.defaultIfBlank(genericException.getMessage(), StringUtils.EMPTY), genericException);
    }
}
Also used : HashMap(java.util.HashMap) EmailTarget(com.synopsys.integration.alert.service.email.EmailTarget) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 97 with AlertException

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

the class JobConfigActionsTest method deleteServerErrorTest.

@Test
public void deleteServerErrorTest() throws Exception {
    Mockito.when(mockedJobAccessor.getJobById(Mockito.any())).thenReturn(Optional.of(distributionJobModel));
    Mockito.doThrow(new AlertException("Exception for Alert test")).when(mockedFieldModelProcessor).performBeforeDeleteAction(Mockito.any());
    ActionResponse<JobFieldModel> jobFieldModelActionResponse = defaultJobConfigActions.delete(jobId);
    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 98 with AlertException

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

the class ProviderSchedulingManager method initializeConfiguredProviders.

private List<ProviderTask> initializeConfiguredProviders(Provider provider, List<ConfigurationModel> providerConfigurations) {
    List<ProviderTask> initializedTasks = new ArrayList<>();
    for (ConfigurationModel providerConfig : providerConfigurations) {
        try {
            StatefulProvider statefulProvider = provider.createStatefulProvider(providerConfig);
            if (statefulProvider.isConfigEnabled()) {
                List<ProviderTask> initializedTasksForConfig = scheduleTasksForProviderConfig(provider, providerConfig);
                initializedTasks.addAll(initializedTasksForConfig);
            } else {
                logger.debug("The provider configuration '{}' was disabled. No tasks will be scheduled for this config.", statefulProvider.getConfigName());
            }
        } catch (AlertException e) {
            logger.error("Something went wrong while attempting to schedule provider tasks", e);
        }
    }
    return initializedTasks;
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ArrayList(java.util.ArrayList) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider)

Example 99 with AlertException

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

the class CertificateActions method updateWithoutChecks.

@Override
protected ActionResponse<CertificateModel> updateWithoutChecks(Long id, CertificateModel resource) {
    try {
        Optional<CustomCertificateModel> existingCertificate = certificateAccessor.getCertificate(id);
        String logableId = escapeUtil.replaceWithUnderscore(resource.getId());
        String loggableAlias = escapeUtil.replaceWithUnderscore(resource.getAlias());
        logger.info("Updating certificate with id: {} and alias: {}", logableId, loggableAlias);
        if (existingCertificate.isPresent()) {
            CertificateModel certificateModel = importCertificate(resource);
            return new ActionResponse<>(HttpStatus.NO_CONTENT, certificateModel);
        }
        logger.error("Certificate with id: {} missing.", logableId);
        return new ActionResponse<>(HttpStatus.NOT_FOUND, "Certificate not found.");
    } catch (AlertException ex) {
        logger.error("Error occurred updating certificate", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}
Also used : CustomCertificateModel(com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel) CustomCertificateModel(com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel) 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 100 with AlertException

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

the class CertificateActions method deleteWithoutChecks.

@Override
protected ActionResponse<CertificateModel> deleteWithoutChecks(Long id) {
    try {
        Optional<CustomCertificateModel> certificate = certificateAccessor.getCertificate(id);
        if (certificate.isPresent()) {
            CustomCertificateModel certificateModel = certificate.get();
            logger.info("Delete certificate with id: {} and alias: {}", certificateModel.getNullableId(), certificateModel.getAlias());
            trustStoreService.removeCertificate(certificateModel);
            certificateAccessor.deleteCertificate(id);
        }
    } catch (AlertException ex) {
        logger.error("Error deleting certificate", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error deleting certificate: %s", ex.getMessage()));
    }
    return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
Also used : CustomCertificateModel(com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel) 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)

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