use of io.gravitee.repository.management.model.NotificationTemplate in project gravitee-management-rest-api by gravitee-io.
the class NotificationTemplateServiceTest method shouldFindAllNotificationTemplate.
@Test
public void shouldFindAllNotificationTemplate() throws TechnicalException {
NotificationTemplate temp1 = new NotificationTemplate();
temp1.setId("TEMP1");
temp1.setType(NotificationTemplateType.PORTAL);
NotificationTemplate temp2 = new NotificationTemplate();
temp2.setId("TEMP2");
temp2.setType(NotificationTemplateType.EMAIL);
when(notificationTemplateRepository.findAllByReferenceIdAndReferenceType(NOTIFICATION_TEMPLATE_REFERENCE_ID, NOTIFICATION_TEMPLATE_REFERENCE_TYPE)).thenReturn(Sets.newSet(temp1, temp2));
final Set<NotificationTemplateEntity> all = notificationTemplateService.findAll();
assertNotNull(all);
assertEquals(2, all.size());
}
use of io.gravitee.repository.management.model.NotificationTemplate in project gravitee-management-rest-api by gravitee-io.
the class NotificationTemplateServiceTest method shouldFindNotificationTemplateByType.
@Test
public void shouldFindNotificationTemplateByType() throws TechnicalException {
NotificationTemplate temp1 = new NotificationTemplate();
temp1.setId("TEMP1");
temp1.setType(NotificationTemplateType.PORTAL);
when(notificationTemplateRepository.findByTypeAndReferenceIdAndReferenceType(NotificationTemplateType.PORTAL, NOTIFICATION_TEMPLATE_REFERENCE_ID, NOTIFICATION_TEMPLATE_REFERENCE_TYPE)).thenReturn(Sets.newSet(temp1));
final Set<NotificationTemplateEntity> byType = notificationTemplateService.findByType(io.gravitee.rest.api.model.notification.NotificationTemplateType.PORTAL);
assertNotNull(byType);
assertEquals(1, byType.size());
}
use of io.gravitee.repository.management.model.NotificationTemplate in project gravitee-management-rest-api by gravitee-io.
the class NotificationTemplateServiceImpl method convert.
private NotificationTemplate convert(NotificationTemplateEntity notificationTemplateEntity) {
NotificationTemplate notificationTemplate = new NotificationTemplate();
notificationTemplate.setId(notificationTemplateEntity.getId());
notificationTemplate.setHook(notificationTemplateEntity.getHook());
notificationTemplate.setScope(notificationTemplateEntity.getScope());
notificationTemplate.setReferenceId(GraviteeContext.getCurrentOrganization());
notificationTemplate.setReferenceType(NotificationTemplateReferenceType.ORGANIZATION);
notificationTemplate.setName(notificationTemplateEntity.getName());
notificationTemplate.setDescription((notificationTemplateEntity.getDescription()));
notificationTemplate.setTitle(notificationTemplateEntity.getTitle());
notificationTemplate.setContent(notificationTemplateEntity.getContent());
notificationTemplate.setType(NotificationTemplateType.valueOf(notificationTemplateEntity.getType().name()));
notificationTemplate.setCreatedAt(notificationTemplateEntity.getCreatedAt());
notificationTemplate.setUpdatedAt(notificationTemplateEntity.getUpdatedAt());
notificationTemplate.setEnabled(notificationTemplateEntity.isEnabled());
return notificationTemplate;
}
use of io.gravitee.repository.management.model.NotificationTemplate in project gravitee-management-rest-api by gravitee-io.
the class NotificationTemplateServiceImpl method create.
@Override
public NotificationTemplateEntity create(NotificationTemplateEntity newNotificationTemplate) {
try {
LOGGER.debug("Create notificationTemplate {}", newNotificationTemplate);
newNotificationTemplate.setId(UuidString.generateRandom());
if (newNotificationTemplate.getCreatedAt() == null) {
newNotificationTemplate.setCreatedAt(new Date());
}
NotificationTemplate createdNotificationTemplate = notificationTemplateRepository.create(convert(newNotificationTemplate));
this.createAuditLog(NotificationTemplate.AuditEvent.NOTIFICATION_TEMPLATE_CREATED, newNotificationTemplate.getCreatedAt(), null, createdNotificationTemplate);
final NotificationTemplateEntity createdNotificationTemplateEntity = convert(createdNotificationTemplate);
// Update template in loader cache
updateFreemarkerCache(createdNotificationTemplateEntity);
return createdNotificationTemplateEntity;
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create or update notificationTemplate {}", newNotificationTemplate, ex);
throw new TechnicalManagementException("An error occurs while trying to create or update " + newNotificationTemplate, ex);
}
}
use of io.gravitee.repository.management.model.NotificationTemplate in project gravitee-management-rest-api by gravitee-io.
the class NotificationTemplateServiceImpl method update.
@Override
public NotificationTemplateEntity update(NotificationTemplateEntity updatingNotificationTemplate) {
try {
LOGGER.debug("Update notificationTemplate {}", updatingNotificationTemplate);
if (updatingNotificationTemplate.getUpdatedAt() == null) {
updatingNotificationTemplate.setUpdatedAt(new Date());
}
Optional<NotificationTemplate> optNotificationTemplate = notificationTemplateRepository.findById(updatingNotificationTemplate.getId());
NotificationTemplate notificationTemplateToUpdate = optNotificationTemplate.orElseThrow(() -> new NotificationTemplateNotFoundException(updatingNotificationTemplate.getId()));
notificationTemplateToUpdate.setTitle(updatingNotificationTemplate.getTitle());
notificationTemplateToUpdate.setContent(updatingNotificationTemplate.getContent());
notificationTemplateToUpdate.setEnabled(updatingNotificationTemplate.isEnabled());
NotificationTemplate updatedNotificationTemplate = notificationTemplateRepository.update(notificationTemplateToUpdate);
createAuditLog(NotificationTemplate.AuditEvent.NOTIFICATION_TEMPLATE_UPDATED, updatingNotificationTemplate.getUpdatedAt(), optNotificationTemplate.get(), updatedNotificationTemplate);
final NotificationTemplateEntity updatedNotificationTemplateEntity = convert(updatedNotificationTemplate);
// Update template in loader cache
updateFreemarkerCache(updatedNotificationTemplateEntity);
return updatedNotificationTemplateEntity;
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create or update notificationTemplate {}", updatingNotificationTemplate, ex);
throw new TechnicalManagementException("An error occurs while trying to create or update " + updatingNotificationTemplate, ex);
}
}
Aggregations