use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testDeleteRequestIntegrity.
@Test
public void testDeleteRequestIntegrity() {
// Log as admin, but not user 'admin' (we don't want to skip WF)
IdmIdentityDto adminUser = getHelper().createIdentity();
loginAsAdmin(adminUser.getUsername());
// Create role
IdmRoleDto role = getHelper().createRole();
// Create request
IdmRequestDto request = requestManager.createRequest(role);
Assert.assertNotNull(request);
// Create guarantee
IdmIdentityDto guarantee = getHelper().createIdentity();
IdmRoleGuaranteeDto roleGuarantee = new IdmRoleGuaranteeDto();
roleGuarantee.setRole(role.getId());
roleGuarantee.setGuarantee(guarantee.getId());
Requestable requestablePost = requestManager.post(request.getId(), roleGuarantee);
IdmRequestItemDto changeRequestItem = DtoUtils.getEmbedded((AbstractDto) requestablePost, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
Assert.assertEquals(RequestOperationType.ADD, changeRequestItem.getOperation());
Assert.assertTrue(requestablePost instanceof IdmRoleGuaranteeDto);
// Change role (without save)
role.setDescription(getHelper().createName());
role.setPriority(1000);
// Create request item
Requestable requestable = requestManager.post(request.getId(), role);
Assert.assertNotNull(requestable);
Assert.assertNotNull(requestable.getRequestItem());
changeRequestItem = DtoUtils.getEmbedded((AbstractDto) requestable, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
Assert.assertEquals(RequestOperationType.UPDATE, changeRequestItem.getOperation());
Assert.assertTrue(requestable instanceof IdmRoleDto);
// Request should be in concept state
request = requestService.get(request.getId());
Assert.assertEquals(RequestState.CONCEPT, request.getState());
// Two items should be created
Assert.assertEquals(2, requestManager.findRequestItems(request.getId(), null).size());
// Delete the request
requestService.delete(request);
IdmRequestDto requestDeleted = requestService.get(request.getId());
Assert.assertNull(requestDeleted);
// All items should be deleted
Assert.assertEquals(0, requestManager.findRequestItems(request.getId(), null).size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testDeleteRoleByRequest.
@Test
public void testDeleteRoleByRequest() {
// Create role
IdmRoleDto role = getHelper().createRole();
// Create request
IdmRequestDto request = requestManager.createRequest(role);
Assert.assertNotNull(request);
Assert.assertEquals(request.getOwnerType(), role.getClass().getName());
Assert.assertEquals(request.getOwnerId(), role.getId());
// Create request item
Requestable requestable = requestManager.delete(request.getId(), role);
Assert.assertNotNull(requestable);
Assert.assertNotNull(requestable.getRequestItem());
IdmRequestItemDto requestItem = DtoUtils.getEmbedded((AbstractDto) requestable, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
Assert.assertEquals(RequestOperationType.REMOVE, requestItem.getOperation());
Assert.assertTrue(requestable instanceof IdmRoleDto);
IdmRoleDto roleFromRequest = (IdmRoleDto) requestable;
// Is not deleted yet
IdmRoleDto currentRole = roleService.get(role.getId());
Assert.assertNotNull(currentRole);
// Start request
IdmRequestDto executedRequest = requestManager.executeRequest(request.getId());
Assert.assertNotNull(executedRequest);
Assert.assertEquals(RequestState.EXECUTED, executedRequest.getState());
// Role have to be deleted
IdmRoleDto executedRole = roleService.get(roleFromRequest.getId());
Assert.assertNull(executedRole);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testThrowExceptionFromRequest.
@Test
public void testThrowExceptionFromRequest() {
IdmRoleDto newRole = new IdmRoleDto();
newRole.setCode(getHelper().createName());
newRole.setName(newRole.getCode());
newRole.setPriority(10);
newRole.setDescription(getHelper().createName());
IdmRequestDto request = requestManager.createRequest(newRole);
Assert.assertNotNull(request);
Requestable requestable = requestManager.post(request.getId(), newRole);
Assert.assertNotNull(requestable);
Assert.assertTrue(requestable instanceof IdmRoleDto);
IdmRoleDto roleFromRequest = (IdmRoleDto) requestable;
// Is not same instance
Assert.assertTrue(newRole != roleFromRequest);
// Has same values as new role
Assert.assertEquals(newRole.getCode(), roleFromRequest.getCode());
Assert.assertEquals(newRole.getName(), roleFromRequest.getName());
Assert.assertEquals(newRole.getPriority(), roleFromRequest.getPriority());
Assert.assertEquals(newRole.getDescription(), roleFromRequest.getDescription());
// Role not exists yet
Assert.assertNull(roleService.get(roleFromRequest.getId()));
// We break the item (we want throw exception)
IdmRequestItemDto requestItem = requestItemService.get(requestable.getRequestItem());
requestItem.setOwnerType("TO BREAK IT");
requestItemService.save(requestItem);
IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
Assert.assertNotNull(executedRequest);
Assert.assertEquals(RequestState.EXCEPTION, executedRequest.getState());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto in project CzechIdMng by bcvsolutions.
the class IdmRequestController method startRequest.
@ResponseBody
@RequestMapping(value = "/{backendId}/start", method = RequestMethod.PUT)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.REQUEST_UPDATE + "')")
@ApiOperation(value = "Start request", nickname = "startRequest", response = IdmRequestDto.class, tags = { IdmRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_UPDATE, description = "") }) })
public ResponseEntity<?> startRequest(@ApiParam(value = "Request's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
UUID requestId = UUID.fromString(backendId);
IdmRequestDto request = this.getService().get(requestId, IdmBasePermission.EXECUTE);
// Validate request
List<IdmRequestItemDto> items = requestManager.findRequestItems(request.getId(), null);
if (items.isEmpty()) {
throw new ResultCodeException(CoreResultCode.REQUEST_CANNOT_BE_EXECUTED_NONE_ITEMS, ImmutableMap.of("request", request.toString()));
}
requestManager.startRequest(requestId, true);
return this.get(backendId);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestItemService method deleteInternal.
@Override
@Transactional
public void deleteInternal(IdmRequestItemDto dto) {
if (dto.getId() != null) {
// We try to find value in the confidential storage and delete it
String storageKey = RequestManager.getConfidentialStorageKey(dto.getId());
confidentialStorage.delete(dto, storageKey);
}
super.deleteInternal(dto);
// We have to ensure the referential integrity, because some item (his DTOs) could be child of that item (DTO)
if (dto.getId() != null && dto.getOwnerId() != null && RequestOperationType.ADD == dto.getOperation()) {
if (dto.getRequest() != null) {
IdmRequestItemFilter requestItemFilter = new IdmRequestItemFilter();
requestItemFilter.setRequestId(dto.getRequest());
// Find all items
List<IdmRequestItemDto> items = this.find(requestItemFilter, null).getContent();
// Create predicate - find all DTOs with that UUID value in any fields
ImmutableList<RequestPredicate> predicates = ImmutableList.of(new RequestPredicate(dto.getOwnerId(), null));
List<IdmRequestItemDto> itemsToDelete = // Search items to delete
items.stream().filter(item -> {
try {
@SuppressWarnings("unchecked") Class<? extends Requestable> ownerType = (Class<? extends Requestable>) Class.forName(item.getOwnerType());
Requestable requestable = requestManager.convertItemToDto(item, ownerType);
if (requestable == null) {
return false;
}
List<Requestable> filteredDtos = requestManager.filterDtosByPredicates(ImmutableList.of(requestable), ownerType, predicates);
return filteredDtos.contains(requestable);
} catch (ClassNotFoundException | IOException e) {
throw new CoreException(e);
}
}).collect(Collectors.toList());
itemsToDelete.forEach(item -> {
this.delete(item);
});
}
}
}
Aggregations