use of eu.bcvsolutions.idm.core.api.domain.Requestable 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.domain.Requestable 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.domain.Requestable 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.domain.Requestable in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testChangeRoleWithGuaranteesSkipApproving.
@Test
public void testChangeRoleWithGuaranteesSkipApproving() {
// Create role with guarantee
IdmIdentityDto guarantee = getHelper().createIdentity();
IdmRoleDto changedRole = getHelper().createRole();
getHelper().createRoleGuarantee(changedRole, guarantee);
// Create request
IdmRequestDto request = requestManager.createRequest(changedRole);
Assert.assertNotNull(request);
Assert.assertEquals(request.getOwnerType(), changedRole.getClass().getName());
Assert.assertEquals(request.getOwnerId(), changedRole.getId());
// Change role (without save)
changedRole.setDescription(getHelper().createName());
changedRole.setPriority(1000);
// Create request item
Requestable requestable = requestManager.post(request.getId(), changedRole);
Assert.assertNotNull(requestable);
Assert.assertNotNull(requestable.getRequestItem());
Assert.assertTrue(requestable instanceof IdmRoleDto);
IdmRoleDto roleFromRequest = (IdmRoleDto) requestable;
// Is not same instance
Assert.assertTrue(changedRole != roleFromRequest);
// Has same values as new role
Assert.assertEquals(changedRole.getPriority(), roleFromRequest.getPriority());
Assert.assertEquals(changedRole.getDescription(), roleFromRequest.getDescription());
IdmRoleDto currentRole = roleService.get(changedRole.getId());
Assert.assertNotEquals(changedRole.getPriority(), currentRole.getPriority());
Assert.assertNotEquals(changedRole.getDescription(), currentRole.getDescription());
// Skip approving
request.setExecuteImmediately(true);
request = requestService.save(request);
// Start request
IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
Assert.assertNotNull(executedRequest);
// Role has guarantee, but approval process wasn't started because the request
// skipped approving.
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(changedRole.getCode(), executedRole.getCode());
Assert.assertEquals(changedRole.getName(), executedRole.getName());
Assert.assertEquals(changedRole.getPriority(), executedRole.getPriority());
Assert.assertEquals(changedRole.getDescription(), executedRole.getDescription());
}
use of eu.bcvsolutions.idm.core.api.domain.Requestable in project CzechIdMng by bcvsolutions.
the class RequestApprovalProcessor method process.
@SuppressWarnings("unchecked")
@Override
public EventResult<IdmRequestDto> process(EntityEvent<IdmRequestDto> event) {
IdmRequestDto dto = event.getContent();
boolean checkRight = (boolean) event.getProperties().get(CHECK_RIGHT_PROPERTY);
//
String ownerTyp = dto.getOwnerType();
Assert.notNull(ownerTyp, "Owner type is rquired for start approval process!");
Class<Requestable> ownerClass = null;
try {
ownerClass = (Class<Requestable>) Class.forName(ownerTyp);
} catch (ClassNotFoundException e) {
throw new CoreException(e);
}
String wfDefinition = requestConfiguration.getRequestApprovalProcessKey(ownerClass);
if (Strings.isNullOrEmpty(wfDefinition)) {
throw new ResultCodeException(CoreResultCode.REQUEST_NO_WF_DEF_FOUND, ImmutableMap.of("entityType", dto.getOwnerType()));
}
boolean approved = manager.startApprovalProcess(dto, checkRight, event, wfDefinition);
DefaultEventResult<IdmRequestDto> result = new DefaultEventResult<>(event, this);
result.setSuspended(!approved);
return result;
}
Aggregations