use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter in project CzechIdMng by bcvsolutions.
the class NotificationTemplateBackupBulkActionIntegrationTest method processBulkActionByFilter.
@Test
public void processBulkActionByFilter() {
IdmNotificationTemplateDto template1 = templateService.getByCode(TEST_TEMPLATE);
Set<UUID> templates = new HashSet<UUID>();
templates.add(template1.getId());
template1.setSubject(CHANGED_TEST_DESC);
template1 = templateService.save(template1);
assertEquals(template1.getSubject(), CHANGED_TEST_DESC);
IdmNotificationTemplateFilter filter = new IdmNotificationTemplateFilter();
filter.setText(CHANGED_TEST_DESC);
List<IdmNotificationTemplateDto> checkScripts = templateService.find(filter, null).getContent();
assertEquals(1, checkScripts.size());
IdmBulkActionDto bulkAction = this.findBulkAction(IdmNotificationTemplate.class, NotificationTemplateBackupBulkAction.NAME);
bulkAction.setTransformedFilter(filter);
bulkAction.setFilter(toMap(filter));
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, 1l, null, null);
testBackupFileContent(template1, loggedUser.getUsername());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter in project CzechIdMng by bcvsolutions.
the class NotificationTemplateRedeployBulkActionIntegrationTest method processBulkActionByFilter.
@Test
public void processBulkActionByFilter() {
IdmNotificationTemplateDto template1 = templateService.getByCode(TEST_TEMPLATE);
Set<UUID> templates = new HashSet<UUID>();
templates.add(template1.getId());
String origSubj = template1.getSubject();
template1.setSubject(CHANGED_TEST_DESC);
template1 = templateService.save(template1);
assertNotEquals(template1.getSubject(), origSubj);
IdmNotificationTemplateFilter filter = new IdmNotificationTemplateFilter();
filter.setText(CHANGED_TEST_DESC);
List<IdmNotificationTemplateDto> checkScripts = templateService.find(filter, null).getContent();
assertEquals(1, checkScripts.size());
IdmBulkActionDto bulkAction = this.findBulkAction(IdmNotificationTemplate.class, NotificationTemplateRedeployBulkAction.NAME);
bulkAction.setTransformedFilter(filter);
bulkAction.setFilter(toMap(filter));
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, 1l, null, null);
template1 = templateService.get(template1.getId());
assertEquals(template1.getSubject(), origSubj);
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter in project CzechIdMng by bcvsolutions.
the class NotificationTemplateDeleteBulkAction method prevalidate.
@Override
public ResultModels prevalidate() {
IdmBulkActionDto action = getAction();
List<UUID> entities = getEntities(action, new StringBuilder());
ResultModels results = new ResultModels();
IdmNotificationTemplateFilter templateFilter = new IdmNotificationTemplateFilter();
templateFilter.setUnmodifiable(Boolean.TRUE);
List<IdmNotificationTemplateDto> unmodifiable = notificationService.find(templateFilter, null).getContent();
List<IdmNotificationTemplateDto> templatesToWarn = unmodifiable.stream().filter(dto -> {
return entities.contains(dto.getId());
}).collect(Collectors.toList());
for (IdmNotificationTemplateDto item : templatesToWarn) {
results.addInfo(new DefaultResultModel(CoreResultCode.NOTIFICATION_SYSTEM_TEMPLATE_DELETE_FAILED, ImmutableMap.of("template", item.getCode())));
}
return results;
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmNotificationTemplateServiceIntegrationTest method templateReferentialIntegrityTest.
@Test
public void templateReferentialIntegrityTest() {
IdmNotificationTemplateDto template = new IdmNotificationTemplateDto();
template.setCode(getHelper().createName());
template.setName(getHelper().createName());
template.setSubject(getHelper().createName());
template = notificationTemplateService.save(template);
// Template Dto successfully saved
IdmNotificationTemplateFilter templateFilter = new IdmNotificationTemplateFilter();
templateFilter.setText(template.getCode());
assertEquals(1, notificationTemplateService.find(templateFilter, null).getContent().size());
// Prevent from template deleting if used in notification configuration
NotificationConfigurationDto notificationCfgDto = new NotificationConfigurationDto(getHelper().createName(), NotificationLevel.INFO, getHelper().createName(), getHelper().createName(), template.getId());
notificationCfgDto = notificationConfigService.save(notificationCfgDto);
try {
notificationTemplateService.delete(template);
fail("Template deleted although used in a notification configuration.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
notificationConfigService.delete(notificationCfgDto);
// Found proper notification according to the used template
IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).build();
List<IdmEmailLogDto> emailLogDtos = emailSenderService.send(getHelper().createName(), message);
assertEquals(1, emailLogDtos.size());
IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
notificationFilter.setTemplateId(template.getId());
List<IdmEmailLogDto> foundNotificationDtos = emailLogService.find(notificationFilter, null).getContent();
assertEquals(1, foundNotificationDtos.size());
assertEquals(emailLogDtos.get(0).getId(), foundNotificationDtos.get(0).getId());
// Prevent from template deleting if used in notification
try {
notificationTemplateService.delete(template);
fail("Template deleted although used in a notification.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
emailLogService.delete(emailLogDtos.get(0));
// Template Dto successfully deleted
notificationTemplateService.delete(template);
assertEquals(0, notificationTemplateService.find(templateFilter, null).getContent().size());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter in project CzechIdMng by bcvsolutions.
the class NotificationTemplateDeleteBulkActionIntegrationTest method processBulkActionByFilter.
@Test
public void processBulkActionByFilter() {
templateService.init();
String desc = "script description" + getHelper().createName();
IdmNotificationTemplateDto template1 = templateService.getByCode(TEST_TEMPLATE);
IdmNotificationTemplateDto template2 = templateService.getByCode(TEST_TEMPLATE_TWO);
template1.setUnmodifiable(false);
template1.setSubject(desc);
template2.setUnmodifiable(false);
template2.setSubject(desc);
template1 = templateService.save(template1);
template2 = templateService.save(template2);
Set<UUID> templates = new HashSet<UUID>();
templates.add(template1.getId());
templates.add(template2.getId());
IdmNotificationTemplateFilter filter = new IdmNotificationTemplateFilter();
filter.setText(desc);
List<IdmNotificationTemplateDto> checkTemplates = templateService.find(filter, null).getContent();
assertEquals(2, checkTemplates.size());
IdmBulkActionDto bulkAction = this.findBulkAction(IdmNotificationTemplate.class, NotificationTemplateDeleteBulkAction.NAME);
bulkAction.setTransformedFilter(filter);
bulkAction.setFilter(toMap(filter));
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, 2l, null, null);
for (UUID id : templates) {
IdmNotificationTemplateDto templateDto = templateService.get(id);
assertNull(templateDto);
}
}
Aggregations