Search in sources :

Example 1 with IdmRoleRequest_

use of eu.bcvsolutions.idm.core.model.entity.IdmRoleRequest_ in project CzechIdMng by bcvsolutions.

the class RoleRequestNotificationProcessor method sendNotification.

/**
 * Send notification to applicant and implementer
 *
 * @param request
 */
private void sendNotification(IdmRoleRequestDto request) {
    UUID requestId = request.getId();
    Assert.notNull(requestId, "Role request has to persisted before notification is sent.");
    boolean sendNotificationToApplicant = configurationService.getBooleanValue(WorkflowConfig.SEND_NOTIFICATION_TO_APPLICANT_CONFIGURATION_PROPERTY, true);
    boolean sendNotificationToImplementer = configurationService.getBooleanValue(WorkflowConfig.SEND_NOTIFICATION_TO_IMPLEMENTER_CONFIGURATION_PROPERTY, false);
    // Transform created date
    DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(ConfigurationService.DEFAULT_APP_DATETIME_FORMAT);
    String from = request.getCreated().format(dateFormat);
    List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(request.getId());
    Set<IdmConceptRoleRequestDto> addedRoles = // 
    concepts.stream().filter(// 
    concept -> ConceptRoleRequestOperation.ADD == concept.getOperation()).collect(// 
    Collectors.toSet());
    Set<IdmConceptRoleRequestDto> changedRoles = // 
    concepts.stream().filter(// 
    concept -> ConceptRoleRequestOperation.UPDATE == concept.getOperation()).collect(// 
    Collectors.toSet());
    Set<IdmConceptRoleRequestDto> removedRoles = // 
    concepts.stream().filter(// 
    concept -> ConceptRoleRequestOperation.REMOVE == concept.getOperation()).collect(// 
    Collectors.toSet());
    IdmIdentityDto applicantIdentity = DtoUtils.getEmbedded(request, IdmRoleRequest_.applicant.getName(), IdmIdentityDto.class);
    IdmIdentityDto implementerIdentity = identityService.get(request.getCreatorId());
    if (implementerIdentity.equals(applicantIdentity)) {
        // implementer and applicant is same identity
        if (sendNotificationToImplementer || sendNotificationToApplicant) {
            send(CoreModuleDescriptor.TOPIC_REQUEST_REALIZED_IMPLEMENTER, request, from, addedRoles, changedRoles, removedRoles, applicantIdentity, implementerIdentity);
        }
    } else {
        // Send notification to applicant
        if (sendNotificationToApplicant) {
            send(CoreModuleDescriptor.TOPIC_REQUEST_REALIZED_APPLICANT, request, from, addedRoles, changedRoles, removedRoles, applicantIdentity, applicantIdentity);
        }
        // Send notification to implementer
        if (sendNotificationToImplementer) {
            send(CoreModuleDescriptor.TOPIC_REQUEST_REALIZED_IMPLEMENTER, request, from, addedRoles, changedRoles, removedRoles, applicantIdentity, implementerIdentity);
        }
    }
}
Also used : RoleRequestProcessor(eu.bcvsolutions.idm.core.api.event.processor.RoleRequestProcessor) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmRoleRequest_) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmConfigurationService(eu.bcvsolutions.idm.core.api.service.IdmConfigurationService) CoreEventProcessor(eu.bcvsolutions.idm.core.api.event.CoreEventProcessor) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) MessageFormat(java.text.MessageFormat) CoreModuleDescriptor(eu.bcvsolutions.idm.core.CoreModuleDescriptor) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Description(org.springframework.context.annotation.Description) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) WorkflowConfig(eu.bcvsolutions.idm.core.workflow.config.WorkflowConfig) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Set(java.util.Set) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) DateTimeFormatter(java.time.format.DateTimeFormatter) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert(org.springframework.util.Assert) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) DateTimeFormatter(java.time.format.DateTimeFormatter)

Aggregations

CoreModuleDescriptor (eu.bcvsolutions.idm.core.CoreModuleDescriptor)1 ConceptRoleRequestOperation (eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation)1 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)1 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)1 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)1 CoreEventProcessor (eu.bcvsolutions.idm.core.api.event.CoreEventProcessor)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 EntityEvent (eu.bcvsolutions.idm.core.api.event.EntityEvent)1 EventResult (eu.bcvsolutions.idm.core.api.event.EventResult)1 RoleRequestProcessor (eu.bcvsolutions.idm.core.api.event.processor.RoleRequestProcessor)1 ConfigurationService (eu.bcvsolutions.idm.core.api.service.ConfigurationService)1 IdmConceptRoleRequestService (eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService)1 IdmConfigurationService (eu.bcvsolutions.idm.core.api.service.IdmConfigurationService)1 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)1 DtoUtils (eu.bcvsolutions.idm.core.api.utils.DtoUtils)1 IdmRoleRequest_ (eu.bcvsolutions.idm.core.model.entity.IdmRoleRequest_)1 RoleRequestEventType (eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType)1 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)1