Search in sources :

Example 16 with IdmEntityStateDto

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

the class ClearDirtyStateForContractSliceTaskExecutor method process.

@Override
public OperationResult process() {
    boolean canContinue = true;
    List<IdmEntityStateDto> dirtyStates = findAllDirtyStatesForSlices(null).getContent();
    if (count == null) {
        count = Long.valueOf(dirtyStates.size());
    }
    counter = 0l;
    List<IdmEntityStateDto> updateDirtyStates = Lists.newArrayList();
    List<IdmEntityStateDto> validDirtyStates = Lists.newArrayList();
    List<IdmEntityStateDto> futureDirtyStates = Lists.newArrayList();
    List<IdmEntityStateDto> unvalidDirtyStates = Lists.newArrayList();
    List<IdmEntityStateDto> deleteDirtyStates = Lists.newArrayList();
    dirtyStates.forEach(dirtyState -> {
        ResultModel resultModel = dirtyState.getResult().getModel();
        Map<String, Object> parameters = new HashMap<>();
        if (resultModel != null) {
            parameters = resultModel.getParameters();
        }
        boolean sliceIsToDelete = this.getBooleanProperty(ClearDirtyStateForContractSliceTaskExecutor.TO_DELETE, parameters);
        if (sliceIsToDelete) {
            deleteDirtyStates.add(dirtyState);
        } else {
            updateDirtyStates.add(dirtyState);
        }
    });
    updateDirtyStates.forEach(dirtyState -> {
        IdmContractSliceDto contractSliceDto = contractSliceService.get(dirtyState.getOwnerId());
        if (contractSliceDto == null) {
            DefaultResultModel model = new DefaultResultModel(CoreResultCode.NOT_FOUND, ImmutableMap.of("ownerId", dirtyState.getOwnerId()));
            this.logItemProcessed(dirtyState, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(model).build());
            return;
        }
        // Temporary put current slice to the dirtyState
        dirtyState.getEmbedded().put(CURRENT_SLICE, contractSliceDto);
        // Divide slices by validity
        IdmIdentityContractDto mockContract = new IdmIdentityContractDto();
        contractSliceManager.convertSliceToContract(contractSliceDto, mockContract);
        if (!mockContract.isValidNowOrInFuture()) {
            unvalidDirtyStates.add(dirtyState);
        } else if (mockContract.isValid()) {
            validDirtyStates.add(dirtyState);
        } else {
            futureDirtyStates.add(dirtyState);
        }
    });
    // Process for new and updated slices - valid
    for (IdmEntityStateDto dirtyState : validDirtyStates) {
        canContinue = processState(canContinue, dirtyState);
        if (!canContinue) {
            break;
        }
    }
    // Process for new and updated slices - future valid
    for (IdmEntityStateDto dirtyState : futureDirtyStates) {
        canContinue = processState(canContinue, dirtyState);
        if (!canContinue) {
            break;
        }
    }
    // Process for new and updated slices - invalid
    for (IdmEntityStateDto dirtyState : unvalidDirtyStates) {
        canContinue = processState(canContinue, dirtyState);
        if (!canContinue) {
            break;
        }
    }
    // Process for slices to delete
    for (IdmEntityStateDto dirtyState : deleteDirtyStates) {
        Assert.notNull(dirtyState, "State (dirty) is required.");
        Assert.notNull(dirtyState.getId(), "State identifier (dirty) is required.");
        processItemToDelete(dirtyState);
        counter++;
        // clear it (same behavior as in stateful tasks)
        if (getHibernateSession().isOpen()) {
            getHibernateSession().flush();
            getHibernateSession().clear();
        }
        canContinue &= this.updateState();
        if (!canContinue) {
            break;
        }
    }
    return new OperationResult(OperationState.EXECUTED);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 17 with IdmEntityStateDto

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

the class ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor method getItemsToProcess.

@Override
public Page<IdmEntityStateDto> getItemsToProcess(Pageable pageable) {
    List<IdmEntityStateDto> states = new ArrayList<>();
    // find all states for flag
    IdmEntityStateFilter filter = new IdmEntityStateFilter();
    pageable = PageRequest.of(0, Integer.MAX_VALUE, Sort.by(Direction.ASC, IdmEntityState_.created.getName()));
    filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
    filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
    // for position
    filter.setOwnerType(entityStateManager.getOwnerType(IdmContractPositionDto.class));
    states.addAll(entityStateManager.findStates(filter, pageable).getContent());
    // for contract
    filter.setOwnerType(entityStateManager.getOwnerType(IdmIdentityContractDto.class));
    states.addAll(entityStateManager.findStates(filter, pageable).getContent());
    // for invalid contracts - has to be last => new roles are assigned already
    filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED_INVALID_CONTRACT.getCode());
    states.addAll(entityStateManager.findStates(filter, pageable).getContent());
    // 
    return new PageImpl<>(states);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) PageImpl(org.springframework.data.domain.PageImpl) ArrayList(java.util.ArrayList) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 18 with IdmEntityStateDto

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

the class DefaultEntityEventManagerIntergationTest method testInit.

@Test
@Transactional
public void testInit() {
    MockOwner mockOwner = new MockOwner();
    // 
    IdmEntityEventDto entityEventDto = manager.prepareEvent(mockOwner, null);
    entityEventDto.setResult(new OperationResultDto.Builder(OperationState.RUNNING).build());
    entityEventDto.setEventType(CoreEventType.CREATE.name());
    entityEventDto.setPriority(PriorityType.HIGH);
    entityEventDto = manager.saveEvent(entityEventDto);
    // 
    EventResult<?> result = new DefaultEventResult.Builder<>(manager.toEvent(entityEventDto), new EmptyEntityEventProcessor<>()).setResults(Lists.newArrayList(new OperationResult.Builder(OperationState.RUNNING).build())).build();
    List<IdmEntityStateDto> states = manager.saveStates(manager.toEvent(entityEventDto), null, result);
    // 
    manager.init();
    // 
    entityEventDto = entityEventService.get(entityEventDto);
    states = entityStateManager.findStates(mockOwner, null).getContent();
    // 
    Assert.assertEquals(1, states.size());
    Assert.assertEquals(OperationState.CANCELED, entityEventDto.getResult().getState());
    Assert.assertEquals(OperationState.CANCELED, states.get(0).getResult().getState());
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with IdmEntityStateDto

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

the class DefaultEntityEventManagerIntergationTest method testSaveStates.

@Test
@Transactional
public void testSaveStates() {
    MockOwner mockOwner = new MockOwner();
    // 
    IdmEntityEventDto entityEventDto = manager.prepareEvent(mockOwner, null);
    entityEventDto.setResult(new OperationResultDto.Builder(OperationState.RUNNING).build());
    entityEventDto.setEventType(CoreEventType.CREATE.name());
    entityEventDto.setPriority(PriorityType.HIGH);
    entityEventDto = manager.saveEvent(entityEventDto);
    // 
    List<IdmEntityStateDto> states = manager.saveStates(manager.toEvent(entityEventDto), null, null);
    Assert.assertEquals(1, states.size());
    Assert.assertTrue(states.stream().anyMatch(s -> s.getResult().getState() == OperationState.EXECUTED));
    // 
    states = manager.saveStates(manager.toEvent(entityEventDto), states, new DefaultEventResult.Builder<>(manager.toEvent(entityEventDto), new EmptyEntityEventProcessor<>()).build());
    // 
    Assert.assertEquals(1, states.size());
    Assert.assertTrue(states.stream().anyMatch(s -> s.getResult().getState() == OperationState.EXECUTED));
    // 
    EventResult<?> result = new DefaultEventResult.Builder<>(manager.toEvent(entityEventDto), new EmptyEntityEventProcessor<>()).setResults(Lists.newArrayList(new OperationResult.Builder(OperationState.EXCEPTION).build(), new OperationResult.Builder(OperationState.CANCELED).build())).build();
    // 
    states = manager.saveStates(manager.toEvent(entityEventDto), null, result);
    // 
    Assert.assertEquals(2, states.size());
    Assert.assertTrue(states.stream().anyMatch(s -> s.getResult().getState() == OperationState.EXCEPTION));
    Assert.assertTrue(states.stream().anyMatch(s -> s.getResult().getState() == OperationState.CANCELED));
    // 
    result = new DefaultEventResult.Builder<>(manager.toEvent(entityEventDto), new EmptyEntityEventProcessor<>()).setResults(Lists.newArrayList(new OperationResult.Builder(OperationState.BLOCKED).build())).build();
    states = manager.saveStates(manager.toEvent(entityEventDto), states, result);
    // 
    Assert.assertEquals(1, states.size());
    Assert.assertTrue(states.stream().anyMatch(s -> s.getResult().getState() == OperationState.BLOCKED));
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultEventContext(eu.bcvsolutions.idm.core.api.event.DefaultEventContext) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) AcceptedContent(eu.bcvsolutions.idm.core.event.AcceptedContent) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) EntityGenerateValuesProcessor(eu.bcvsolutions.idm.core.model.event.processor.EntityGenerateValuesProcessor) Autowired(org.springframework.beans.factory.annotation.Autowired) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) MockDto(eu.bcvsolutions.idm.core.event.domain.MockDto) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdentityEventType(eu.bcvsolutions.idm.core.model.event.IdentityEvent.IdentityEventType) ObserveDtoProcessor(eu.bcvsolutions.idm.core.model.event.processor.ObserveDtoProcessor) TestEntityEventProcessorConfiguration(eu.bcvsolutions.idm.core.event.TestEntityEventProcessorConfiguration) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) PageRequest(org.springframework.data.domain.PageRequest) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) NeverEndingProcessor(eu.bcvsolutions.idm.core.model.event.processor.NeverEndingProcessor) EventType(eu.bcvsolutions.idm.core.api.event.EventType) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) TestContentTwo(eu.bcvsolutions.idm.core.event.TestContentTwo) EntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EntityEventProcessor) MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) ArrayList(java.util.ArrayList) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) Lists(com.google.common.collect.Lists) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) Qualifier(org.springframework.beans.factory.annotation.Qualifier) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdentityRoleEventType(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent.IdentityRoleEventType) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) ConditionalContent(eu.bcvsolutions.idm.core.event.ConditionalContent) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) TestIdentityNotifyProcessor(eu.bcvsolutions.idm.core.model.event.processor.TestIdentityNotifyProcessor) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) ApplicationContext(org.springframework.context.ApplicationContext) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) EmptyEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EmptyEntityEventProcessor) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) TestContent(eu.bcvsolutions.idm.core.event.TestContent) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) EmptyEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EmptyEntityEventProcessor) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with IdmEntityStateDto

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

the class DefaultEntityStateManagerIntergationTest method testSaveState.

@Test
public void testSaveState() {
    IdmIdentityDto owner = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto ownerTwo = getHelper().createIdentity((GuardedString) null);
    // 
    IdmEntityStateDto state = new IdmEntityStateDto();
    state.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
    state = manager.saveState(owner, state);
    IdmEntityStateDto stateOther = new IdmEntityStateDto();
    stateOther.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
    manager.saveState(ownerTwo, stateOther);
    List<IdmEntityStateDto> states = manager.findStates(owner, null).getContent();
    Assert.assertEquals(1, states.size());
    IdmEntityStateDto persistedState = states.get(0);
    // 
    Assert.assertEquals(owner.getId(), persistedState.getOwnerId());
    Assert.assertEquals(manager.getOwnerType(owner), persistedState.getOwnerType());
    Assert.assertEquals(OperationState.RUNNING, persistedState.getResult().getState());
    // 
    manager.deleteState(state);
    // 
    Assert.assertTrue(manager.findStates(owner, PageRequest.of(0, 1)).getTotalElements() == 0);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

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