Search in sources :

Example 6 with NotificationTemplate

use of io.gravitee.repository.management.model.NotificationTemplate in project gravitee-management-rest-api by gravitee-io.

the class NotificationTemplateServiceImpl method findById.

@Override
public NotificationTemplateEntity findById(String id) {
    try {
        LOGGER.debug("Find notificationTemplate by ID: {}", id);
        Optional<NotificationTemplate> notificationTemplate = notificationTemplateRepository.findById(id);
        if (notificationTemplate.isPresent()) {
            return convert(notificationTemplate.get());
        }
        throw new NotificationTemplateNotFoundException(id);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to delete a notificationTemplate using its ID {}", id, ex);
        throw new TechnicalManagementException("An error occurs while trying to delete a notificationTemplate using its ID " + id, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) NotificationTemplateNotFoundException(io.gravitee.rest.api.service.exceptions.NotificationTemplateNotFoundException) NotificationTemplate(io.gravitee.repository.management.model.NotificationTemplate) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 7 with NotificationTemplate

use of io.gravitee.repository.management.model.NotificationTemplate in project gravitee-management-rest-api by gravitee-io.

the class NotificationTemplateServiceTest method shouldUpdateNotificationTemplate.

@Test
public void shouldUpdateNotificationTemplate() throws TechnicalException {
    NotificationTemplateEntity updatingNotificationTemplateEntity = new NotificationTemplateEntity();
    updatingNotificationTemplateEntity.setId(NOTIFICATION_TEMPLATE_ID);
    updatingNotificationTemplateEntity.setName("New Name");
    updatingNotificationTemplateEntity.setType(io.gravitee.rest.api.model.notification.NotificationTemplateType.valueOf(NOTIFICATION_TEMPLATE_TYPE.name()));
    updatingNotificationTemplateEntity.setEnabled(NOTIFICATION_TEMPLATE_ENABLED);
    final NotificationTemplate toUpdate = mock(NotificationTemplate.class);
    when(notificationTemplateRepository.findById(NOTIFICATION_TEMPLATE_ID)).thenReturn(Optional.of(toUpdate));
    when(notificationTemplateRepository.update(any())).thenReturn(notificationTemplate);
    notificationTemplateService.update(updatingNotificationTemplateEntity);
    verify(notificationTemplateRepository, times(1)).update(any());
    verify(auditService, times(1)).createOrganizationAuditLog(any(), eq(NotificationTemplate.AuditEvent.NOTIFICATION_TEMPLATE_UPDATED), any(), eq(toUpdate), eq(notificationTemplate));
}
Also used : NotificationTemplateEntity(io.gravitee.rest.api.model.notification.NotificationTemplateEntity) NotificationTemplate(io.gravitee.repository.management.model.NotificationTemplate) Test(org.junit.Test)

Example 8 with NotificationTemplate

use of io.gravitee.repository.management.model.NotificationTemplate in project gravitee-management-rest-api by gravitee-io.

the class NotificationTemplateServiceTest method init.

@Before
public void init() {
    notificationTemplate = new NotificationTemplate();
    notificationTemplate.setId(NOTIFICATION_TEMPLATE_ID);
    notificationTemplate.setHook(NOTIFICATION_TEMPLATE_HOOK);
    notificationTemplate.setScope(NOTIFICATION_TEMPLATE_SCOPE);
    notificationTemplate.setReferenceId(NOTIFICATION_TEMPLATE_REFERENCE_ID);
    notificationTemplate.setReferenceType(NOTIFICATION_TEMPLATE_REFERENCE_TYPE);
    notificationTemplate.setName(NOTIFICATION_TEMPLATE_NAME);
    notificationTemplate.setDescription(NOTIFICATION_TEMPLATE_DESCRIPTION);
    notificationTemplate.setTitle(NOTIFICATION_TEMPLATE_TITLE);
    notificationTemplate.setContent(NOTIFICATION_TEMPLATE_CONTENT);
    notificationTemplate.setType(NOTIFICATION_TEMPLATE_TYPE);
    notificationTemplate.setCreatedAt(NOTIFICATION_TEMPLATE_CREATED_AT);
    notificationTemplate.setUpdatedAt(NOTIFICATION_TEMPLATE_UPDATED_AT);
    notificationTemplate.setEnabled(NOTIFICATION_TEMPLATE_ENABLED);
}
Also used : NotificationTemplate(io.gravitee.repository.management.model.NotificationTemplate) Before(org.junit.Before)

Aggregations

NotificationTemplate (io.gravitee.repository.management.model.NotificationTemplate)8 NotificationTemplateEntity (io.gravitee.rest.api.model.notification.NotificationTemplateEntity)5 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)3 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)3 Test (org.junit.Test)3 NotificationTemplateNotFoundException (io.gravitee.rest.api.service.exceptions.NotificationTemplateNotFoundException)2 Before (org.junit.Before)1