use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter in project CzechIdMng by bcvsolutions.
the class IdmRequestFilterTest method ownerTest.
@Test
public void ownerTest() {
String ownerType = IdmIdentityDto.class.toString();
IdmRequestDto request1 = createRequest(ownerType, UUID.randomUUID());
IdmRequestDto request2 = createRequest(ownerType, UUID.randomUUID());
IdmRequestDto request3 = createRequest(ownerType, UUID.randomUUID());
IdmRequestFilter filter = new IdmRequestFilter();
filter.setOwnerType(ownerType);
filter.setOwnerId(request1.getOwnerId());
List<IdmRequestDto> content = requestService.find(filter, null).getContent();
Assert.assertEquals(1, content.size());
Assert.assertEquals(request1.getName(), content.get(0).getName());
filter.setOwnerId(request2.getOwnerId());
content = requestService.find(filter, null).getContent();
Assert.assertEquals(1, content.size());
Assert.assertEquals(request2.getName(), content.get(0).getName());
filter.setOwnerId(request3.getOwnerId());
content = requestService.find(filter, null).getContent();
Assert.assertEquals(1, content.size());
Assert.assertEquals(request3.getName(), content.get(0).getName());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter in project CzechIdMng by bcvsolutions.
the class IdmRequestFilterTest method stateTest.
@Test
public void stateTest() {
UUID ownerId = UUID.randomUUID();
String ownerType = IdmIdentityDto.class.toString();
List<RequestState> states = new ArrayList<>();
RequestState state = RequestState.APPROVED;
states.add(state);
changeState(state, createRequest(ownerType, ownerId));
changeState(state, createRequest(ownerType, ownerId));
changeState(state, createRequest(ownerType, ownerId));
IdmRequestFilter filter = new IdmRequestFilter();
filter.setOwnerType(ownerType);
filter.setOwnerId(ownerId);
filter.setStates(states);
List<IdmRequestDto> content = requestService.find(filter, null).getContent();
Assert.assertEquals(3, content.size());
state = RequestState.CANCELED;
states.add(state);
changeState(state, createRequest(ownerType, ownerId));
changeState(state, createRequest(ownerType, ownerId));
changeState(state, createRequest(ownerType, ownerId));
filter.setStates(states);
content = requestService.find(filter, null).getContent();
Assert.assertEquals(6, content.size());
state = RequestState.EXCEPTION;
states.add(state);
changeState(state, createRequest(ownerType, ownerId));
changeState(state, createRequest(ownerType, ownerId));
changeState(state, createRequest(ownerType, ownerId));
filter.setStates(states);
content = requestService.find(filter, null).getContent();
Assert.assertEquals(9, content.size());
state = RequestState.IN_PROGRESS;
states.add(state);
changeState(state, createRequest(ownerType, ownerId));
changeState(state, createRequest(ownerType, ownerId));
changeState(state, createRequest(ownerType, ownerId));
filter.setStates(states);
content = requestService.find(filter, null).getContent();
Assert.assertEquals(12, content.size());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter in project CzechIdMng by bcvsolutions.
the class IdmRequestController method toFilter.
@Override
protected IdmRequestFilter toFilter(MultiValueMap<String, Object> parameters) {
IdmRequestFilter filter = new IdmRequestFilter(parameters);
filter.setOwnerType(getParameterConverter().toString(parameters, "ownerType"));
filter.setOwnerId(getParameterConverter().toUuid(parameters, "ownerId"));
filter.setStates(getParameterConverter().toEnums(parameters, "states", RequestState.class));
filter.setCreatedAfter(getParameterConverter().toDateTime(parameters, "from"));
filter.setCreatedBefore(getParameterConverter().toDateTime(parameters, "till"));
return filter;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter in project CzechIdMng by bcvsolutions.
the class RequestByOwnerEvaluatorTest method testRightOnRequest.
@Test
public void testRightOnRequest() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmRoleDto roleForRequest = getHelper().createRole();
IdmRequestDto requestWithOwneredRole = requestManager.createRequest(roleForRequest);
IdmRoleDto roleForRequestWithoutRight = getHelper().createRole();
IdmRequestDto requestWithoutOwneredRole = requestManager.createRequest(roleForRequestWithoutRight);
IdmRoleDto role = getHelper().createRole();
getHelper().createRoleGuaranteeRole(role, role);
getHelper().createIdentityRole(identity, role);
getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.REQUEST, IdmRequest.class, RequestByOwnerEvaluator.class, IdmBasePermission.READ);
// User will have rights on the roleForRequest
ConfigurationMap properties = new ConfigurationMap();
properties.put(UuidEvaluator.PARAMETER_UUID, roleForRequest.getId());
getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.ROLE, IdmRole.class, UuidEvaluator.class, properties, IdmBasePermission.READ);
try {
getHelper().login(identity.getUsername(), identity.getPassword());
try {
requestService.get(requestWithoutOwneredRole.getId(), IdmBasePermission.READ);
fail();
} catch (ForbiddenEntityException ex) {
// It is OK
}
assertNotNull(requestService.get(requestWithOwneredRole.getId(), IdmBasePermission.READ));
IdmRequestFilter requestFilter = new IdmRequestFilter();
// We do not have right to that request
requestFilter.setId(requestWithoutOwneredRole.getId());
assertEquals(0, requestService.find(requestFilter, null, IdmBasePermission.READ).getContent().size());
// We have right to that request
requestFilter.setId(requestWithOwneredRole.getId());
assertEquals(1, requestService.find(requestFilter, null, IdmBasePermission.READ).getContent().size());
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method onDeleteRequestable.
@Override
@Transactional
public <R extends Requestable> void onDeleteRequestable(R requestable) {
Assert.notNull(requestable, "Requestable DTO cannot be null!");
// Search requests with that deleting owner
IdmRequestFilter requestFilter = new IdmRequestFilter();
requestFilter.setOwnerType(requestable.getClass().getName());
requestFilter.setOwnerId((UUID) requestable.getId());
List<IdmRequestDto> requests = requestService.find(requestFilter, null).getContent();
//
requests.stream().filter(// We need filtered request which
request -> RequestState.APPROVED != request.getState()).forEach(request -> {
//
request = changeRequestState(//
requestable, //
request, new //
ResultCodeException(//
CoreResultCode.REQUEST_OWNER_WAS_DELETED, //
ImmutableMap.of("owner", requestable.toString())));
requestService.save(request);
});
// Search request items with that deleting owner
IdmRequestItemFilter requestItemFilter = new IdmRequestItemFilter();
requestItemFilter.setOwnerType(requestable.getClass().getName());
requestItemFilter.setOwnerId((UUID) requestable.getId());
List<IdmRequestItemDto> requestItems = requestItemService.find(requestItemFilter, null).getContent();
//
requestItems.stream().filter(// We need filtered request which invoked that
item -> RequestState.APPROVED != item.getState()).forEach(item -> {
//
item = changeItemState(//
requestable, //
item, new //
ResultCodeException(//
CoreResultCode.REQUEST_OWNER_WAS_DELETED, //
ImmutableMap.of("owner", requestable.toString())));
requestItemService.save(item);
IdmRequestItemFilter subItemFilter = new IdmRequestItemFilter();
subItemFilter.setRequestId(item.getRequest());
// Search all items for that request
List<IdmRequestItemDto> subItems = requestItemService.find(subItemFilter, null).getContent();
// TODO: This can be (maybe) removed ... because that 'cancel' is implemented
// during realization of item
// Check if items in same request does not contains same ID of deleting owner in
// the DATA Json.
// If yes, then state will be changed to cancel.
//
subItems.stream().filter(// We need filtered request
subItem -> RequestState.APPROVED != subItem.getState()).filter(//
subItem -> !requestable.getId().equals(subItem.getOwnerId())).filter(//
subItem -> subItem.getData() != null).filter(subItem -> //
subItem.getData().indexOf(requestable.getId().toString()) != //
-1).forEach(subItem -> {
//
subItem = changeItemState(//
requestable, //
subItem, new //
ResultCodeException(//
CoreResultCode.REQUEST_OWNER_FROM_OTHER_REQUEST_WAS_DELETED, ImmutableMap.of("owner", requestable.toString(), "otherRequest", //
subItem.toString())));
requestItemService.save(subItem);
});
});
//
}
Aggregations