Search in sources :

Example 1 with AutomaticRoleAttributeEvent

use of eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeEvent in project CzechIdMng by bcvsolutions.

the class DuplicateRoleAutomaticByAttributeProcessor method process.

@Override
public EventResult<IdmRoleDto> process(EntityEvent<IdmRoleDto> event) {
    IdmRoleDto cloned = event.getContent();
    IdmRoleDto originalSource = event.getOriginalSource();
    // 
    IdmAutomaticRoleFilter filter = new IdmAutomaticRoleFilter();
    filter.setRoleId(cloned.getId());
    Set<UUID> usedAutomaticRoles = new HashSet<>();
    List<IdmAutomaticRoleAttributeDto> currentAutomaticRoles = automaticRoleAttributeService.find(filter, null).getContent();
    // 
    filter.setRoleId(originalSource.getId());
    automaticRoleAttributeService.find(filter, null).forEach(automaticRole -> {
        UUID exists = exists(currentAutomaticRoles, automaticRole);
        if (exists != null) {
            usedAutomaticRoles.add(exists);
        } else {
            // create new with all rules
            IdmAutomaticRoleAttributeDto clonedAutomaticRole = new IdmAutomaticRoleAttributeDto();
            clonedAutomaticRole.setName(automaticRole.getName());
            clonedAutomaticRole.setRole(cloned.getId());
            clonedAutomaticRole.setConcept(true);
            // 
            clonedAutomaticRole = automaticRoleAttributeService.save(clonedAutomaticRole);
            // 
            for (IdmAutomaticRoleAttributeRuleDto rule : automaticRoleAttributeRuleService.findAllRulesForAutomaticRole(automaticRole.getId())) {
                IdmAutomaticRoleAttributeRuleDto clonedRule = new IdmAutomaticRoleAttributeRuleDto();
                clonedRule.setAutomaticRoleAttribute(clonedAutomaticRole.getId());
                clonedRule.setAttributeName(rule.getAttributeName());
                clonedRule.setFormAttribute(rule.getFormAttribute());
                clonedRule.setType(rule.getType());
                clonedRule.setValue(rule.getValue());
                clonedRule.setComparison(rule.getComparison());
                // 
                automaticRoleAttributeRuleService.save(clonedRule);
            }
            AutomaticRoleAttributeEvent automaticRoleEvent = new AutomaticRoleAttributeEvent(AutomaticRoleAttributeEventType.UPDATE, clonedAutomaticRole);
            // execute sync
            automaticRoleEvent.setPriority(PriorityType.IMMEDIATE);
            // FIXME: event parent ...
            automaticRoleAttributeService.recalculate(automaticRoleEvent);
        }
    });
    // 
    // remove not used originals
    currentAutomaticRoles.stream().filter(automaticRole -> {
        return !usedAutomaticRoles.contains(automaticRole.getId());
    }).forEach(automaticRole -> {
        // dirty flag automatic role only - will be processed after parent action ends
        IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
        stateDeleted.setEvent(event.getId());
        stateDeleted.setSuperOwnerId(cloned.getId());
        stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
        entityStateManager.saveState(automaticRole, stateDeleted);
    });
    return new DefaultEventResult<>(event, this);
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) CoreEventProcessor(eu.bcvsolutions.idm.core.api.event.CoreEventProcessor) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) HashSet(java.util.HashSet) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) Lists(com.google.common.collect.Lists) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) AutomaticRoleAttributeEvent(eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeEvent) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) RoleEventType(eu.bcvsolutions.idm.core.model.event.RoleEvent.RoleEventType) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder) Description(org.springframework.context.annotation.Description) RoleProcessor(eu.bcvsolutions.idm.core.api.event.processor.RoleProcessor) AutomaticRoleAttributeEventType(eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeEvent.AutomaticRoleAttributeEventType) Set(java.util.Set) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) UUID(java.util.UUID) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmAutomaticRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleFilter) List(java.util.List) Component(org.springframework.stereotype.Component) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) IdmAutomaticRoleAttributeRuleService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleService) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmAutomaticRoleAttributeService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmAutomaticRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleFilter) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) UUID(java.util.UUID) AutomaticRoleAttributeEvent(eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeEvent) HashSet(java.util.HashSet)

Example 2 with AutomaticRoleAttributeEvent

use of eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeEvent in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleAttributeService method recalculate.

@Override
@Transactional
public IdmAutomaticRoleAttributeDto recalculate(UUID automaticRoleId) {
    Assert.notNull(automaticRoleId, "Automatic role identifier is required.");
    IdmAutomaticRoleAttributeDto automaticRole = get(automaticRoleId);
    Assert.notNull(automaticRole, "Automatic role is required.");
    // 
    EntityEvent<IdmAutomaticRoleAttributeDto> event = new AutomaticRoleAttributeEvent(AutomaticRoleAttributeEventType.UPDATE, automaticRole);
    event.setPriority(PriorityType.NORMAL);
    // 
    return recalculate(event);
}
Also used : AutomaticRoleAttributeEvent(eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeEvent) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with AutomaticRoleAttributeEvent

use of eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeEvent in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleAttributeService method delete.

/**
 * Publish {@link AutomaticRoleAttributeEvent} only.
 *
 * @see {@link AutomaticRoleAttributeDeleteProcessor}
 */
@Override
@Transactional(noRollbackFor = AcceptedException.class)
public void delete(IdmAutomaticRoleAttributeDto dto, BasePermission... permission) {
    Assert.notNull(dto, "DTO is required.");
    checkAccess(this.getEntity(dto.getId()), permission);
    // 
    LOG.debug("Deleting automatic role by attribute [{}]", dto.getRole());
    // 
    EventContext<IdmAutomaticRoleAttributeDto> context = entityEventManager.process(new AutomaticRoleAttributeEvent(AutomaticRoleAttributeEventType.DELETE, dto));
    // 
    if (context.isSuspended()) {
        throw new AcceptedException();
    }
}
Also used : AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) AutomaticRoleAttributeEvent(eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeEvent) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)3 AutomaticRoleAttributeEvent (eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeEvent)3 Transactional (org.springframework.transaction.annotation.Transactional)2 Lists (com.google.common.collect.Lists)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)1 PriorityType (eu.bcvsolutions.idm.core.api.domain.PriorityType)1 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)1 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)1 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)1 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)1 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)1 IdmAutomaticRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleFilter)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 RoleProcessor (eu.bcvsolutions.idm.core.api.event.processor.RoleProcessor)1 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)1 EntityStateManager (eu.bcvsolutions.idm.core.api.service.EntityStateManager)1