use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto 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.dto.IdmRequestItemDto in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testFind.
@Test
public void testFind() {
// Create role
IdmRoleDto role = getHelper().createRole();
// Create guarantee One
IdmIdentityDto guaranteeOne = getHelper().createIdentity();
IdmRoleGuaranteeDto roleGuaranteeOne = getHelper().createRoleGuarantee(role, guaranteeOne);
IdmRoleGuaranteeFilter guaranteeFilter = new IdmRoleGuaranteeFilter();
guaranteeFilter.setRole(role.getId());
Assert.assertEquals(1, roleGuaranteeService.find(guaranteeFilter, null).getTotalElements());
// Create request
IdmRequestDto request = requestManager.createRequest(role);
Assert.assertNotNull(request);
List<IdmRoleGuaranteeDto> guarantees = requestManager.find(IdmRoleGuaranteeDto.class, request.getId(), guaranteeFilter, null).getContent();
Assert.assertEquals(1, guarantees.size());
// Create guarantee
IdmIdentityDto guarantee = getHelper().createIdentity();
IdmRoleGuaranteeDto roleGuaranteeTwo = new IdmRoleGuaranteeDto();
roleGuaranteeTwo.setRole(role.getId());
roleGuaranteeTwo.setGuarantee(guarantee.getId());
IdmRoleGuaranteeDto requestablePost = requestManager.post(request.getId(), roleGuaranteeTwo);
IdmRequestItemDto changeRequestItem = DtoUtils.getEmbedded(requestablePost, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
Assert.assertEquals(RequestOperationType.ADD, changeRequestItem.getOperation());
// Find via standard service returns still only one result
Assert.assertEquals(1, roleGuaranteeService.find(guaranteeFilter, null).getTotalElements());
// Find via request manager returns two results
guarantees = requestManager.find(IdmRoleGuaranteeDto.class, request.getId(), guaranteeFilter, null).getContent();
Assert.assertEquals(2, guarantees.size());
// Create new request
IdmRequestDto requestTwo = requestManager.createRequest(role);
Assert.assertNotNull(requestTwo);
guarantees = requestManager.find(IdmRoleGuaranteeDto.class, requestTwo.getId(), guaranteeFilter, null).getContent();
Assert.assertEquals(1, guarantees.size());
// Change the role-guarantee (use new guarantee)
IdmIdentityDto guaranteeTwo = getHelper().createIdentity();
roleGuaranteeOne.setGuarantee(guaranteeTwo.getId());
IdmRoleGuaranteeDto roleGuaranteeOneRequest = requestManager.post(requestTwo.getId(), roleGuaranteeOne);
changeRequestItem = DtoUtils.getEmbedded(roleGuaranteeOneRequest, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
Assert.assertEquals(RequestOperationType.UPDATE, changeRequestItem.getOperation());
// Role guarantee One are equals (same ID), but must have different guarantee
IdmRoleGuaranteeDto currentRoleGuaranteeOne = roleGuaranteeService.get(roleGuaranteeOne);
Assert.assertEquals(currentRoleGuaranteeOne, roleGuaranteeOneRequest);
Assert.assertNotEquals(currentRoleGuaranteeOne.getGuarantee(), roleGuaranteeOneRequest.getGuarantee());
guarantees = roleGuaranteeService.find(guaranteeFilter, null).getContent();
// Find via standard service returns still only one result
Assert.assertEquals(1, guarantees.size());
// Find via request manager returns one result too (item was only updated in the
// request)
List<IdmRoleGuaranteeDto> guaranteesRequest = requestManager.find(IdmRoleGuaranteeDto.class, requestTwo.getId(), guaranteeFilter, null).getContent();
Assert.assertEquals(1, guaranteesRequest.size());
// Role guarantee One are equals (same ID), but must have different guarantee
Assert.assertEquals(guarantees.get(0), guaranteesRequest.get(0));
Assert.assertNotEquals(guarantees.get(0).getGuarantee(), guaranteesRequest.get(0).getGuarantee());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testGetChangesEAV.
@Test
public void testGetChangesEAV() {
// Create role
IdmRoleDto role = getHelper().createRole();
// Get definition
IdmFormInstanceDto formInstance = formService.getFormInstance(role);
// None values yet
Assert.assertEquals(0, formInstance.getValues().size());
IdmFormDefinitionDto formDefinition = formInstance.getFormDefinition();
// Create form attributes
IdmFormAttributeDto attributeShortText = new IdmFormAttributeDto();
attributeShortText.setCode(getHelper().createName());
attributeShortText.setName(attributeShortText.getCode());
attributeShortText.setPersistentType(PersistentType.SHORTTEXT);
attributeShortText.setFormDefinition(formDefinition.getId());
attributeShortText = formService.saveAttribute(attributeShortText);
IdmFormAttributeDto attributeBoolean = new IdmFormAttributeDto();
attributeBoolean.setCode(getHelper().createName());
attributeBoolean.setName(attributeBoolean.getCode());
attributeBoolean.setPersistentType(PersistentType.BOOLEAN);
attributeBoolean.setFormDefinition(formDefinition.getId());
attributeBoolean = formService.saveAttribute(attributeBoolean);
IdmFormAttributeDto attributeConfidential = new IdmFormAttributeDto();
attributeConfidential.setCode(getHelper().createName());
attributeConfidential.setName(attributeConfidential.getCode());
attributeConfidential.setPersistentType(PersistentType.SHORTTEXT);
attributeConfidential.setConfidential(true);
attributeConfidential.setFormDefinition(formDefinition.getId());
attributeConfidential = formService.saveAttribute(attributeConfidential);
IdmFormAttributeDto attributeInt = new IdmFormAttributeDto();
attributeInt.setCode(getHelper().createName());
attributeInt.setName(attributeInt.getCode());
attributeInt.setPersistentType(PersistentType.INT);
attributeInt.setFormDefinition(formDefinition.getId());
attributeInt = formService.saveAttribute(attributeInt);
// Create request
IdmRequestDto request = requestManager.createRequest(role);
Assert.assertNotNull(request);
IdmFormInstanceDto formInstanceRequest = requestManager.getFormInstance(request.getId(), role, formDefinition);
// None values yet
Assert.assertEquals(0, formInstanceRequest.getValues().size());
IdmFormValueDto valueShortText = new IdmFormValueDto(attributeShortText);
valueShortText.setValue(getHelper().createName());
formInstanceRequest.getValues().add(valueShortText);
IdmFormValueDto valueBoolean = new IdmFormValueDto(attributeBoolean);
valueBoolean.setValue(true);
formInstanceRequest.getValues().add(valueBoolean);
IdmFormValueDto valueConfidential = new IdmFormValueDto(attributeConfidential);
String confidentialValueString = getHelper().createName();
valueConfidential.setValue(confidentialValueString);
formInstanceRequest.getValues().add(valueConfidential);
IdmFormValueDto valueInt = new IdmFormValueDto(attributeInt);
valueInt.setValue(111);
formInstanceRequest.getValues().add(valueInt);
formDefinition = formService.getDefinition(IdmRoleDto.class);
requestManager.saveFormInstance(request.getId(), role, formDefinition, formInstanceRequest.getValues());
formInstanceRequest = requestManager.getFormInstance(request.getId(), role, formDefinition);
// Four values in request
Assert.assertEquals(4, formInstanceRequest.getValues().size());
formInstance = formService.getFormInstance(role);
// None values via standard service
Assert.assertEquals(0, formInstance.getValues().size());
formInstanceRequest.getValues().forEach(value -> {
IdmRequestItemDto item = DtoUtils.getEmbedded(value, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
IdmRequestItemChangesDto changes = requestManager.getChanges(item);
Assert.assertNotNull(changes);
List<IdmRequestItemAttributeDto> attributes = changes.getAttributes();
attributes.forEach(attribute -> {
Assert.assertEquals(RequestOperationType.ADD, attribute.getValue().getChange());
});
IdmRequestItemAttributeDto attributeDto = attributes.stream().filter(attribute -> "stringValue".equals(attribute.getName())).findFirst().get();
Assert.assertEquals(value.getStringValue(), attributeDto.getValue().getValue());
attributeDto = attributes.stream().filter(attribute -> "booleanValue".equals(attribute.getName())).findFirst().get();
Assert.assertEquals(value.getBooleanValue(), attributeDto.getValue().getValue());
attributeDto = attributes.stream().filter(attribute -> "doubleValue".equals(attribute.getName())).findFirst().get();
Assert.assertEquals(value.getDoubleValue(), attributeDto.getValue().getValue());
attributeDto = attributes.stream().filter(attribute -> "longValue".equals(attribute.getName())).findFirst().get();
Assert.assertEquals(value.getLongValue(), attributeDto.getValue().getValue());
attributeDto = attributes.stream().filter(attribute -> "shortTextValue".equals(attribute.getName())).findFirst().get();
Assert.assertEquals(value.getShortTextValue(), attributeDto.getValue().getValue());
});
request = requestManager.startRequest(request.getId(), true);
Assert.assertEquals(RequestState.EXECUTED, request.getState());
formInstance = formService.getFormInstance(role);
// Four values via standard service
Assert.assertEquals(4, formInstance.getValues().size());
// All changes was applied, check on none changes
formInstanceRequest = requestManager.getFormInstance(request.getId(), role, formDefinition);
formInstanceRequest.getValues().forEach(value -> {
IdmRequestItemDto item = DtoUtils.getEmbedded(value, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
IdmRequestItemChangesDto changes = requestManager.getChanges(item);
Assert.assertNotNull(changes);
List<IdmRequestItemAttributeDto> attributes = changes.getAttributes();
attributes.forEach(attribute -> {
Assert.assertEquals(attribute.getValue().getOldValue(), attribute.getValue().getValue());
});
});
// Make changes
final UUID attributeShortTextId = attributeShortText.getId();
IdmFormValueDto changedValueShortText = new IdmFormValueDto(attributeShortText);
changedValueShortText.setValue(getHelper().createName());
// Create new request
IdmRequestDto requestChange = requestManager.createRequest(role);
Assert.assertNotNull(requestChange);
// Create request items
requestManager.saveFormInstance(requestChange.getId(), role, formDefinition, Lists.newArrayList(changedValueShortText));
formInstanceRequest = requestManager.getFormInstance(requestChange.getId(), role, formDefinition);
// One change in the request
Assert.assertEquals(4, formInstanceRequest.getValues().size());
IdmFormValueDto changedValueShortTextRequest = formInstanceRequest.getValues().stream().filter(value -> value.getFormAttribute().equals(attributeShortTextId)).findFirst().get();
IdmRequestItemDto item = DtoUtils.getEmbedded(changedValueShortTextRequest, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
IdmRequestItemChangesDto changes = requestManager.getChanges(item);
Assert.assertNotNull(changes);
List<IdmRequestItemAttributeDto> attributes = changes.getAttributes();
IdmRequestItemAttributeDto attributeDto = attributes.stream().filter(attribute -> "shortTextValue".equals(attribute.getName())).findFirst().get();
Assert.assertNotEquals(attributeDto.getValue().getOldValue(), attributeDto.getValue().getValue());
Assert.assertEquals(changedValueShortText.getShortTextValue(), attributeDto.getValue().getValue());
// Delete attributes
formService.deleteValues(role, attributeShortText);
formService.deleteAttribute(attributeShortText);
formService.deleteValues(role, attributeBoolean);
formService.deleteAttribute(attributeBoolean);
formService.deleteValues(role, attributeConfidential);
formService.deleteAttribute(attributeConfidential);
formService.deleteValues(role, attributeInt);
formService.deleteAttribute(attributeInt);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testDeleteRequest.
@Test
public void testDeleteRequest() {
// 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());
Assert.assertNotNull(requestItemService.get(requestable.getRequestItem()));
// Delete the request
requestService.delete(request);
// Request item must be canceled
IdmRequestItemDto requestItem = requestItemService.get(requestable.getRequestItem());
Assert.assertNull(requestItem);
// Request must be canceled
request = requestService.get(request.getId());
Assert.assertNull(request);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto in project CzechIdMng by bcvsolutions.
the class IdmRequestItemController method getChanges.
@ResponseBody
@RequestMapping(value = "/{backendId}/changes", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.REQUEST_ITEM_READ + "')")
@ApiOperation(value = "Request detail item", nickname = "getRequestItem", response = IdmRequestItemDto.class, tags = { IdmRequestItemController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_ITEM_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_ITEM_READ, description = "") }) })
public ResponseEntity<?> getChanges(@ApiParam(value = "Item's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
IdmRequestItemDto dto = this.getDto(backendId);
IdmRequestItemChangesDto result = requestManager.getChanges(dto);
if (result == null) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
//
return new ResponseEntity<>(result, HttpStatus.OK);
}
Aggregations