use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testGetChangesOnCreateRoleByRequest.
@Test
public void testGetChangesOnCreateRoleByRequest() {
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);
IdmRequestItemChangesDto changes = requestManager.getChanges(requestItemService.get(requestable.getRequestItem()));
Assert.assertNotNull(changes);
List<IdmRequestItemAttributeDto> attributes = changes.getAttributes();
attributes.forEach(attribute -> {
Assert.assertEquals(RequestOperationType.ADD, attribute.getValue().getChange());
});
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method getChanges.
@SuppressWarnings("unchecked")
@Override
public IdmRequestItemChangesDto getChanges(IdmRequestItemDto item, BasePermission... permission) {
LOG.debug(MessageFormat.format("Start read request item with changes [{0}].", item));
Assert.notNull(item, "Idm request item cannot be null!");
if (Strings.isNullOrEmpty(item.getOwnerType()) || item.getOwnerId() == null) {
return null;
}
Class<? extends Requestable> dtoClass;
try {
dtoClass = (Class<? extends Requestable>) Class.forName(item.getOwnerType());
} catch (ClassNotFoundException e) {
throw new CoreException(e);
}
ReadDtoService<?, ?> readService = getServiceByItem(item, dtoClass);
Requestable currentDto = (Requestable) readService.get(item.getOwnerId(), permission);
if (currentDto == null) {
try {
currentDto = (Requestable) dtoClass.getDeclaredConstructor().newInstance();
currentDto.setId(item.getOwnerId());
} catch (ReflectiveOperationException e) {
throw new CoreException(e);
}
}
Requestable changedDto = this.get(item.getRequest(), currentDto);
RequestOperationType itemOperation = item.getOperation();
List<IdmRequestItemAttributeDto> resultAttributes = getChanges((AbstractDto) currentDto, (AbstractDto) changedDto, itemOperation);
IdmRequestItemChangesDto result = new IdmRequestItemChangesDto();
result.setRequestItem(item);
result.getAttributes().addAll(resultAttributes);
LOG.debug(MessageFormat.format("End of reading the request item with changes [{0}].", item));
return result;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto 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.IdmRequestItemChangesDto 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);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto in project CzechIdMng by bcvsolutions.
the class IdmRequestController method getChanges.
@ResponseBody
@RequestMapping(value = "/{backendId}/entity/{entityId}/changes", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.REQUEST_READ + "')")
@ApiOperation(value = "Request changes of entity", nickname = "getRequestEntityChange", response = IdmRequestItemDto.class, tags = { IdmRequestItemController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_READ, description = "") }) })
public ResponseEntity<?> getChanges(@ApiParam(value = "Item's uuid identifier.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Entity's uuid identifier.", required = true) @PathVariable @NotNull String entityId) {
IdmRequestDto dto = this.getDto(backendId);
// Find item by entity ID and request ID
IdmRequestItemFilter itemFilter = new IdmRequestItemFilter();
itemFilter.setRequestId(dto.getId());
itemFilter.setOwnerId(UUID.fromString(entityId));
List<IdmRequestItemDto> items = requestItemService.find(itemFilter, null, IdmBasePermission.READ).getContent();
if (items.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
IdmRequestItemChangesDto result = requestManager.getChanges(items.get(0));
if (result == null) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
//
return new ResponseEntity<>(result, HttpStatus.OK);
}
Aggregations