use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto 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.IdmRequestDto in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testCreateRoleByRequest.
@Test
public void testCreateRoleByRequest() {
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()));
IdmRequestDto executedRequest = requestManager.executeRequest(request.getId());
Assert.assertNotNull(executedRequest);
Assert.assertEquals(RequestState.EXECUTED, executedRequest.getState());
IdmRoleDto executedRole = roleService.get(roleFromRequest.getId());
// Role must exists now
Assert.assertNotNull(executedRole);
// Has same values as new role
Assert.assertEquals(newRole.getCode(), executedRole.getCode());
Assert.assertEquals(newRole.getName(), executedRole.getName());
Assert.assertEquals(newRole.getPriority(), executedRole.getPriority());
Assert.assertEquals(newRole.getDescription(), executedRole.getDescription());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto 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.IdmRequestDto 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.IdmRequestDto in project CzechIdMng by bcvsolutions.
the class AbstractRemoveBulkAction method processDto.
@Override
protected OperationResult processDto(DTO dto) {
try {
if (dto instanceof Requestable && requestConfiguration.isRequestModeEnabled(dto.getClass())) {
// Request mode is enabled for that DTO
Requestable requestable = (Requestable) dto;
IdmRequestDto request = requestManager.deleteRequestable(requestable, false);
if (RequestState.IN_PROGRESS == request.getState()) {
throw new AcceptedException(request.getId().toString());
}
if (RequestState.EXCEPTION == request.getState()) {
throw new CoreException(ExceptionUtils.resolveException(request.getResult().getException()));
}
return new OperationResult.Builder(request.getResult().getState()).setCause(request.getResult().getException()).build();
}
this.getService().delete(dto);
return new OperationResult.Builder(OperationState.EXECUTED).build();
} catch (AcceptedException ex) {
return new OperationResult.Builder(OperationState.RUNNING).setException(ex).build();
} catch (ResultCodeException ex) {
return new OperationResult.Builder(OperationState.EXCEPTION).setException(ex).build();
} catch (Exception ex) {
Throwable resolvedException = ExceptionUtils.resolveException(ex);
if (resolvedException instanceof ResultCodeException) {
return //
new OperationResult.Builder(OperationState.EXCEPTION).setException(//
(ResultCodeException) resolvedException).build();
}
return new OperationResult.Builder(OperationState.EXCEPTION).setCause(ex).build();
}
}
Aggregations