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);
}
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);
}
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());
}
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));
}
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);
}
Aggregations