Search in sources :

Example 1 with IdmEntityStateDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManager method saveStates.

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public <E extends Serializable> List<IdmEntityStateDto> saveStates(EntityEvent<E> event, List<IdmEntityStateDto> previousStates, EventResult<E> result) {
    IdmEntityEventDto entityEvent = getEvent(event);
    List<IdmEntityStateDto> results = new ArrayList<>();
    if (entityEvent == null) {
        return results;
    }
    // simple drop - we don't need to find and update results, we'll create new ones
    if (previousStates != null && !previousStates.isEmpty()) {
        previousStates.forEach(state -> {
            entityStateService.delete(state);
        });
    }
    // 
    if (result == null) {
        IdmEntityStateDto state = new IdmEntityStateDto(entityEvent);
        // default result without model
        state.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).build());
        results.add(entityStateService.save(state));
        return results;
    }
    if (result.getResults().isEmpty()) {
        results.add(entityStateService.save(createState(entityEvent, result, new OperationResultDto.Builder(OperationState.EXECUTED).build())));
        return results;
    }
    result.getResults().forEach(opeartionResult -> {
        results.add(entityStateService.save(createState(entityEvent, result, opeartionResult.toDto())));
    });
    // 
    return results;
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) ArrayList(java.util.ArrayList) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with IdmEntityStateDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.

the class EntityStateDeleteProcessor method process.

@Override
public EventResult<IdmEntityStateDto> process(EntityEvent<IdmEntityStateDto> event) {
    IdmEntityStateDto entityState = event.getContent();
    // 
    service.deleteInternal(entityState);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 3 with IdmEntityStateDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.

the class ContractSliceDeleteProcessor method createDeleteDirtyState.

/**
 * Create new dirty state for delete of contract slice
 *
 * @param slice
 * @param parameters
 * @return
 */
private IdmEntityStateDto createDeleteDirtyState(IdmContractSliceDto slice, Map<String, Serializable> parameters) {
    Map<String, Object> transformedMarameters = new HashMap<String, Object>();
    transformedMarameters.put("entityId", slice.getId());
    // Mark state for delete the slice
    transformedMarameters.put(ClearDirtyStateForContractSliceTaskExecutor.TO_DELETE, Boolean.TRUE);
    transformedMarameters.putAll(parameters);
    DefaultResultModel resultModel = new DefaultResultModel(CoreResultCode.DIRTY_STATE, transformedMarameters);
    IdmEntityStateDto dirtyState = new IdmEntityStateDto();
    dirtyState.setResult(new OperationResultDto.Builder(OperationState.BLOCKED).setModel(resultModel).build());
    return entityStateManager.saveState(slice, dirtyState);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto)

Example 4 with IdmEntityStateDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.

the class ComplexHrProcessIntegrationTest method roleCleanup.

/**
 **************** Cleanup methods *********************
 */
private void roleCleanup() {
    Set<String> roleNames = Set.of(adGroupAllRole, adGroupPkiRole, adGroupDep1Role, adGroupDep2Role, adGroupCons1Role, adGroupCons2Role, adGroupDirectorRole, consultantBusinessRole, allBusinessRole, adUsersRole, system2ManualRole);
    List<IdmRoleDto> roles = new ArrayList<IdmRoleDto>(roleNames.size());
    for (String name : roleNames) {
        IdmRoleDto dto = roleService.getByCode(name);
        if (dto != null) {
            roles.add(dto);
        }
    }
    // sync role force deletion
    Map<String, Serializable> properties = ImmutableMap.of(EntityEventProcessor.PROPERTY_FORCE_DELETE, Boolean.TRUE);
    for (IdmRoleDto role : roles) {
        EntityEvent<IdmRoleDto> event = new RoleEvent(RoleEventType.DELETE, role, properties);
        roleService.publish(event);
    }
    // performing delete operation on all items marked in entity state as to delete
    for (IdmRoleDto role : roles) {
        List<IdmEntityStateDto> entityStates = entityStateManager.findStates(role, null).getContent();
        OperationResultDto result = entityStates.get(0).getResult();
        if (OperationState.RUNNING.equals(result.getState()) && CoreResultCode.DELETED.getCode().equals(result.getModel().getStatusEnum())) {
            roleService.delete(role);
        }
    }
    // check proper deletion
    for (String name : roleNames) {
        Assert.assertNull(roleService.getByCode(name));
    }
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) RoleEvent(eu.bcvsolutions.idm.core.model.event.RoleEvent)

Example 5 with IdmEntityStateDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto 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)

Aggregations

IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)77 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)43 Test (org.junit.Test)41 UUID (java.util.UUID)40 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)33 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)30 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)30 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)24 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)23 List (java.util.List)21 Autowired (org.springframework.beans.factory.annotation.Autowired)21 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)20 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)19 Transactional (org.springframework.transaction.annotation.Transactional)19 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)18 Lists (com.google.common.collect.Lists)15 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)15 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)15 Assert (org.junit.Assert)14 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)13