use of eu.bcvsolutions.idm.core.api.domain.Requestable in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestService method toDto.
@Override
public IdmRequestDto toDto(IdmRequest entity, IdmRequestDto dto) {
IdmRequestDto requestDto = super.toDto(entity, dto);
// Load and add WF process DTO to embedded. Prevents of many requests from FE.
if (requestDto != null && requestDto.getWfProcessId() != null) {
if (RequestState.IN_PROGRESS == requestDto.getState()) {
// Instance of process should exists only in 'IN_PROGRESS' state
WorkflowProcessInstanceDto processInstanceDto = workflowProcessInstanceService.get(requestDto.getWfProcessId());
// size
if (processInstanceDto != null) {
processInstanceDto.setProcessVariables(null);
}
requestDto.getEmbedded().put(AbstractRequestDto.WF_PROCESS_FIELD, processInstanceDto);
} else {
// In others states we need load historic process
WorkflowHistoricProcessInstanceDto processHistDto = workflowHistoricProcessInstanceService.get(requestDto.getWfProcessId());
// size
if (processHistDto != null) {
processHistDto.setProcessVariables(null);
}
requestDto.getEmbedded().put(AbstractRequestDto.WF_PROCESS_FIELD, processHistDto);
}
}
// Load and add owner DTO to embedded. Prevents of many requests from FE.
if (requestDto != null && requestDto.getOwnerId() != null && requestDto.getOwnerType() != null) {
try {
@SuppressWarnings("unchecked") Requestable requestable = requestManager.get(requestDto.getId(), requestDto.getOwnerId(), (Class<Requestable>) Class.forName(requestDto.getOwnerType()));
if (requestable instanceof AbstractDto) {
// If is requestable realized REMOVE, then requestable DTO does not contains
// data (only ID). In this case we don't want send this DTO to FE.
AbstractDto requestableDto = (AbstractDto) requestable;
IdmRequestItemDto itemDto = DtoUtils.getEmbedded(requestableDto, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class, null);
if (itemDto != null && RequestOperationType.REMOVE == itemDto.getOperation() && itemDto.getState().isTerminatedState()) {
requestable = null;
}
// Minimise response size
requestableDto.setEmbedded(null);
}
if (requestable == null) {
// Entity was not found ... maybe was deleted or not exists yet
LOG.debug(MessageFormat.format("Owner [{0}, {1}] not found for request {2}.", requestDto.getOwnerType(), requestDto.getOwnerId(), requestDto.getId()));
}
requestDto.getEmbedded().put(IdmRequestDto.OWNER_FIELD, requestable);
} catch (ClassNotFoundException e) {
// Only print warning
LOG.warn(MessageFormat.format("Class not found for request {0}.", requestDto.getId()), e);
}
}
return requestDto;
}
use of eu.bcvsolutions.idm.core.api.domain.Requestable in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestItemService method toDto.
@Override
public IdmRequestItemDto toDto(IdmRequestItem entity, IdmRequestItemDto dto) {
IdmRequestItemDto requestItemDto = super.toDto(entity, dto);
// Load and add WF process DTO to embedded. Prevents of many requests from FE.
if (requestItemDto != null && requestItemDto.getWfProcessId() != null) {
if (RequestState.IN_PROGRESS == requestItemDto.getState()) {
// Instance of process should exists only in 'IN_PROGRESS' state
WorkflowProcessInstanceDto processInstanceDto = workflowProcessInstanceService.get(requestItemDto.getWfProcessId());
// size
if (processInstanceDto != null) {
processInstanceDto.setProcessVariables(null);
}
requestItemDto.getEmbedded().put(AbstractRequestDto.WF_PROCESS_FIELD, processInstanceDto);
} else {
// In others states we need load historic process
WorkflowHistoricProcessInstanceDto processHistDto = workflowHistoricProcessInstanceService.get(requestItemDto.getWfProcessId());
// size
if (processHistDto != null) {
processHistDto.setProcessVariables(null);
}
requestItemDto.getEmbedded().put(AbstractRequestDto.WF_PROCESS_FIELD, processHistDto);
}
}
// Load and add owner DTO to embedded. Prevents of many requests from FE.
if (requestItemDto != null && requestItemDto.getOwnerId() != null && requestItemDto.getOwnerType() != null) {
try {
@SuppressWarnings("unchecked") Requestable requestable = requestManager.convertItemToDto(requestItemDto, (Class<Requestable>) Class.forName(requestItemDto.getOwnerType()));
// Item for remove operation does not contains the JSON data, so we need load owner via lookupService
if (requestable == null && RequestOperationType.REMOVE == requestItemDto.getOperation()) {
requestable = (Requestable) lookupService.lookupDto(requestItemDto.getOwnerType(), requestItemDto.getOwnerId());
}
if (requestable == null) {
// Entity was not found ... maybe was deleted or not exists yet
LOG.debug(MessageFormat.format("Owner [{0}, {1}] not found for request {2}.", requestItemDto.getOwnerType(), requestItemDto.getOwnerId(), requestItemDto.getId()));
}
requestItemDto.getEmbedded().put(IdmRequestDto.OWNER_FIELD, requestable);
} catch (ClassNotFoundException e) {
// Only print warning
LOG.warn(MessageFormat.format("Class not found for request item {0}.", requestItemDto.getId()), e);
} catch (JsonParseException e) {
// Only print warning
LOG.warn(MessageFormat.format("JsonParseException for request item {0}.", requestItemDto.getId()), e);
} catch (JsonMappingException e) {
// Only print warning
LOG.warn(MessageFormat.format("JsonMappingException for request item {0}.", requestItemDto.getId()), e);
} catch (IOException e) {
// Only print warning
LOG.warn(MessageFormat.format("IOException for request item {0}.", requestItemDto.getId()), e);
}
}
return requestItemDto;
}
use of eu.bcvsolutions.idm.core.api.domain.Requestable in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testDeleteRequestIntegrityWithWf.
@Test
public void testDeleteRequestIntegrityWithWf() {
// 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);
// Start request
IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
executedRequest = requestService.get(executedRequest.getId());
Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
String processId = executedRequest.getWfProcessId();
Assert.assertNotNull(processId);
// Wf process is in progress
WorkflowProcessInstanceDto processInstace = workflowProcessInstanceService.get(processId);
Assert.assertNotNull(processInstace);
// Two items should be created
Assert.assertEquals(2, requestManager.findRequestItems(request.getId(), null).size());
// Delete the request
requestService.delete(executedRequest);
IdmRequestDto requestDeleted = requestService.get(executedRequest.getId());
Assert.assertNull(requestDeleted);
// Process should be deleted (canceled)
processInstace = workflowProcessInstanceService.get(processId);
Assert.assertNull(processInstace);
}
use of eu.bcvsolutions.idm.core.api.domain.Requestable in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testBasicItemIntegrity.
@Test
public void testBasicItemIntegrity() {
// Create role
IdmRoleDto role = getHelper().createRole();
// Create request
IdmRequestDto request = requestManager.createRequest(role);
Assert.assertNotNull(request);
// null -> DELETE
// Create delete 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);
// DELETE -> CHANGE
// Create change request item
role.setDescription(getHelper().createName());
Requestable requestablePost = requestManager.post(request.getId(), requestable);
IdmRequestItemDto changeRequestItem = DtoUtils.getEmbedded((AbstractDto) requestablePost, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
Assert.assertEquals(RequestOperationType.UPDATE, changeRequestItem.getOperation());
// In one request can exists only one item for same owner -> change item must be
// same (updated) as in delete cause.
Assert.assertEquals(requestItem.getId(), changeRequestItem.getId());
// CHANGE -> null
// Create delete request item (again)
requestable = requestManager.delete(request.getId(), requestablePost);
Assert.assertNotNull(requestable);
Assert.assertNull(requestable.getRequestItem());
// Previous item was deleted
List<IdmRequestItemDto> items = requestManager.findRequestItems(request.getId(), null);
Assert.assertEquals(0, items.size());
// null -> DELETE
// Create delete request item
requestable = requestManager.delete(request.getId(), requestable);
Assert.assertNotNull(requestable);
Assert.assertNotNull(requestable.getRequestItem());
requestItem = DtoUtils.getEmbedded((AbstractDto) requestable, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
Assert.assertEquals(RequestOperationType.REMOVE, requestItem.getOperation());
// DELETE -> null
// Again delete same DTO. In this situation should be previous item (delete)
// deleted.
requestable = requestManager.delete(request.getId(), requestable);
Assert.assertNotNull(requestable);
Assert.assertNull(requestable.getRequestItem());
Assert.assertEquals(0, requestManager.findRequestItems(request.getId(), null).size());
IdmRoleDto newRole = new IdmRoleDto();
newRole.setCode(getHelper().createName());
newRole.setName(newRole.getCode());
// null -> ADD
Requestable newRequestable = requestManager.post(request.getId(), newRole);
Assert.assertNotNull(newRequestable);
Assert.assertNotNull(newRequestable.getRequestItem());
IdmRequestItemDto newRequestItem = DtoUtils.getEmbedded((AbstractDto) newRequestable, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
Assert.assertEquals(RequestOperationType.ADD, newRequestItem.getOperation());
// One item must exists now
Assert.assertEquals(1, requestManager.findRequestItems(request.getId(), null).size());
// ADD -> null
// Delete of DTO, which is not created in DB causes his deleting.
requestable = requestManager.delete(request.getId(), newRequestable);
Assert.assertNotNull(requestable);
Assert.assertNull(requestable.getRequestItem());
Assert.assertEquals(0, requestManager.findRequestItems(request.getId(), null).size());
}
use of eu.bcvsolutions.idm.core.api.domain.Requestable in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testChangeRoleByRequest.
@Test
public void testChangeRoleByRequest() {
// Create role
IdmRoleDto changedRole = getHelper().createRole();
// 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());
// Start request
IdmRequestDto executedRequest = requestManager.executeRequest(request.getId());
Assert.assertNotNull(executedRequest);
Assert.assertEquals(RequestState.EXECUTED, executedRequest.getState());
IdmRoleDto executedRole = roleService.get(roleFromRequest.getId());
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());
}
Aggregations