use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class DefaultUniformPasswordManager method endUniformPasswordProcess.
@Override
@Transactional
public void endUniformPasswordProcess(UUID transactionId) {
Assert.notNull(transactionId, "Transaction cannot be null!");
IdmEntityStateFilter entityStateFilter = new IdmEntityStateFilter();
entityStateFilter.setTransactionId(transactionId);
entityStateFilter.setResultCode(CoreResultCode.IDENTITY_UNIFORM_PASSWORD.getCode());
entityStateFilter.setStates(Lists.newArrayList(OperationState.BLOCKED));
List<IdmEntityStateDto> entityStateDtos = entityStateManager.findStates(entityStateFilter, null).getContent();
// Send notification with password to identities where was uniform password used.
entityStateDtos.stream().filter(entityState -> IdmIdentity.class.getCanonicalName().equals(entityState.getOwnerType())).filter(this::uniformPasswordUsed).forEach(entityState -> {
UUID identityId = entityState.getOwnerId();
if (identityId != null) {
IdmIdentityDto identityDto = identityService.get(identityId);
if (identityDto != null) {
// Send notification with uniform password.
this.sendUniformPasswordNotification(identityDto, entityState);
}
}
});
// Remove all uniform password entity states for this transaction.
entityStateDtos.forEach(entityState -> entityStateManager.deleteState(entityState));
}
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 List<IdmEntityStateDto> saveStates(EntityEvent<?> event, List<IdmEntityStateDto> previousStates, EventResult<?> 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 -> {
entityStateManager.deleteState(state);
});
}
//
if (result == null) {
IdmEntityStateDto state = new IdmEntityStateDto(entityEvent);
// default result without model
state.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).build());
results.add(entityStateManager.saveState(null, state));
return results;
}
if (result.getResults().isEmpty()) {
results.add(entityStateManager.saveState(null, createState(entityEvent, result, new OperationResultDto.Builder(OperationState.EXECUTED).build())));
return results;
}
result.getResults().forEach(opeartionResult -> {
results.add(entityStateManager.saveState(null, createState(entityEvent, result, opeartionResult.toDto())));
});
//
return results;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManager method createState.
private <E extends Serializable> IdmEntityStateDto createState(IdmEntityEventDto entityEvent, EventResult<E> eventResult, OperationResultDto operationResult) {
IdmEntityStateDto state = new IdmEntityStateDto(entityEvent);
//
state.setClosed(eventResult.isClosed());
state.setSuspended(eventResult.isSuspended());
state.setProcessedOrder(eventResult.getProcessedOrder());
state.setProcessorId(eventResult.getProcessor().getId());
state.setProcessorModule(eventResult.getProcessor().getModule());
state.setProcessorName(eventResult.getProcessor().getName());
state.setResult(operationResult);
//
return state;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class IdmEntityStateControllerRestTest method testFindByOperationStates.
@Test
public void testFindByOperationStates() {
UUID ownerId = UUID.randomUUID();
//
IdmEntityStateDto state = prepareDto();
state.setOwnerId(ownerId);
state.getResult().setState(OperationState.RUNNING);
IdmEntityStateDto stateOne = entityStateService.save(state);
//
state = prepareDto();
state.setOwnerId(ownerId);
state.getResult().setState(OperationState.BLOCKED);
IdmEntityStateDto stateTwo = entityStateService.save(state);
//
state = prepareDto();
state.setOwnerId(ownerId);
state.getResult().setState(OperationState.EXCEPTION);
// other
entityStateService.save(state);
//
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.set("ownerId", ownerId.toString());
parameters.put("states", Lists.newArrayList(stateOne.getResult().getState().name(), stateTwo.getResult().getState().name()));
//
List<IdmEntityStateDto> results = find(parameters);
Assert.assertEquals(2, results.size());
Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateOne.getId())));
Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateTwo.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class IdmEntityStateControllerRestTest method testFindByText.
@Test
public void testFindByText() {
UUID ownerOne = UUID.randomUUID();
UUID ownerTwo = UUID.randomUUID();
String ownerTypeOne = getHelper().createName();
String ownerTypeTwo = ownerTypeOne + getHelper().createName();
//
IdmEntityStateDto state = prepareDto();
state.setOwnerId(ownerOne);
state.setOwnerType(ownerTypeOne);
IdmEntityStateDto stateOne = entityStateService.save(state);
//
state = prepareDto();
state.setOwnerId(ownerTwo);
state.setOwnerType(ownerTypeTwo);
state.getResult().setCode("mOck-code");
IdmEntityStateDto stateTwo = entityStateService.save(state);
//
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.set("text", ownerTypeOne);
List<IdmEntityStateDto> results = find(parameters);
Assert.assertEquals(2, results.size());
Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateOne.getId())));
Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateTwo.getId())));
//
parameters.set("text", ownerOne.toString().substring(0, 6));
parameters.set("ownerType", ownerTypeOne);
results = find(parameters);
//
if (!getHelper().isDatabaseMssql()) {
// search by uuid as string is not supported for mssql
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateOne.getId())));
//
parameters.set("text", "moCk-");
parameters.set("ownerType", ownerTypeTwo);
results = find(parameters);
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateTwo.getId())));
} else {
// not found on mssql
Assert.assertEquals(0, results.size());
}
//
parameters.set("text", ownerOne.toString());
parameters.set("ownerType", ownerTypeOne);
results = find(parameters);
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateOne.getId())));
}
Aggregations