Search in sources :

Example 1 with IdmNotificationTemplateFilter

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());
}
Also used : IdmNotificationTemplateFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) UUID(java.util.UUID) HashSet(java.util.HashSet) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 2 with IdmNotificationTemplateFilter

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);
}
Also used : IdmNotificationTemplateFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) UUID(java.util.UUID) HashSet(java.util.HashSet) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 3 with IdmNotificationTemplateFilter

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;
}
Also used : Description(org.springframework.context.annotation.Description) AbstractRemoveBulkAction(eu.bcvsolutions.idm.core.api.bulk.action.AbstractRemoveBulkAction) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) NotificationGroupPermission(eu.bcvsolutions.idm.core.notification.domain.NotificationGroupPermission) ImmutableMap(com.google.common.collect.ImmutableMap) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) Autowired(org.springframework.beans.factory.annotation.Autowired) UUID(java.util.UUID) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) Collectors(java.util.stream.Collectors) IdmNotificationTemplateFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) IdmNotificationTemplateService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationTemplateService) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmNotificationTemplateFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) UUID(java.util.UUID) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels)

Example 4 with IdmNotificationTemplateFilter

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());
}
Also used : IdmNotificationTemplateFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException) ConstraintViolationException(javax.validation.ConstraintViolationException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 5 with IdmNotificationTemplateFilter

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);
    }
}
Also used : IdmNotificationTemplateFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) UUID(java.util.UUID) HashSet(java.util.HashSet) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Aggregations

IdmNotificationTemplateFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter)6 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)5 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)4 UUID (java.util.UUID)4 Test (org.junit.Test)4 AbstractBulkActionTest (eu.bcvsolutions.idm.test.api.AbstractBulkActionTest)3 HashSet (java.util.HashSet)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 AbstractRemoveBulkAction (eu.bcvsolutions.idm.core.api.bulk.action.AbstractRemoveBulkAction)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)1 ResultModels (eu.bcvsolutions.idm.core.api.dto.ResultModels)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 ReadWriteDtoService (eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService)1 IdmEmailLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto)1 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)1 NotificationConfigurationDto (eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto)1 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)1 IdmNotificationTemplateService (eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationTemplateService)1