use of eu.bcvsolutions.idm.core.api.domain.Requestable in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testChangeRoleWithGuaranteesDisapprov.
@Test
public void testChangeRoleWithGuaranteesDisapprov() {
// 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());
// Start request
IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
Assert.assertNotNull(executedRequest);
// Role has guarantee, approval process must be started
Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
loginAsNoAdmin(guarantee.getUsername());
try {
completeTasksFromUsers(guarantee.getId().toString(), "disapprove");
} catch (ResultCodeException e) {
fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
} catch (Exception e) {
fail("Some problem: " + e.getLocalizedMessage());
}
// Reload the request (after disapproving)
executedRequest = requestService.get(executedRequest.getId());
Assert.assertEquals(RequestState.DISAPPROVED, executedRequest.getState());
IdmRoleDto executedRole = roleService.get(roleFromRequest.getId());
Assert.assertNotNull(executedRole);
// Has different values as new role
Assert.assertNotEquals(changedRole.getPriority(), executedRole.getPriority());
Assert.assertNotEquals(changedRole.getDescription(), executedRole.getDescription());
}
use of eu.bcvsolutions.idm.core.api.domain.Requestable 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.domain.Requestable in project CzechIdMng by bcvsolutions.
the class AbstractRequestDtoController method put.
/**
* Update DTO by given backendId and convert to response
*
* @param requestId
* @param backendId
* @param dto
* @return
*/
@ApiOperation(value = "Update record", authorizations = { @Authorization(SwaggerConfig.AUTHENTICATION_BASIC), @Authorization(SwaggerConfig.AUTHENTICATION_CIDMST) })
public //
ResponseEntity<?> put(//
@ApiParam(value = "Request ID", required = true) String requestId, //
@ApiParam(value = "Record's uuid identifier or unique code", required = true) String backendId, @ApiParam(value = "Record (dto).", required = true) DTO dto) {
//
DTO updatedDto = getDto(requestId, backendId);
if (updatedDto == null) {
throw new EntityNotFoundException(getService().getEntityClass(), backendId);
}
Requestable resultDto = requestManager.post(requestId, dto, IdmBasePermission.UPDATE);
@SuppressWarnings("unchecked") ResourceSupport resource = toResource(requestId, (DTO) resultDto);
if (resource == null) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(resource, HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.api.domain.Requestable in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method findRelatedAddedItems.
/**
* Find related added DTOs by given parents. !!Searching of added DTOs are very
* naive!! We use all UUID value in the filter and try to find it in the DTOs.
* It means only equals is implemented.
*
* @param request
* @param predicates
* @param items
* @param dtoClass
* @return
*/
private <R extends Requestable> List<R> findRelatedAddedItems(IdmRequestDto request, List<RequestPredicate> predicates, List<IdmRequestItemDto> items, Class<? extends R> dtoClass) {
List<R> requestables = new ArrayList<>();
//
items.stream().filter(//
i -> RequestOperationType.ADD == i.getOperation()).forEach(item -> {
//
try {
R requestedDto = this.convertItemToDto(item, dtoClass);
AbstractDto requested = (AbstractDto) requestedDto;
addEmbedded(requested, request.getId());
addRequestItemToDto((Requestable) requested, item);
requestables.add((R) requestedDto);
return;
} catch (IOException | ReflectiveOperationException | IllegalArgumentException | IntrospectionException e) {
throw new ResultCodeException(CoreResultCode.JSON_CANNOT_BE_CONVERT_TO_DTO, ImmutableMap.of("json", item.getData()), e);
}
});
return filterDtosByPredicates(requestables, dtoClass, predicates);
}
use of eu.bcvsolutions.idm.core.api.domain.Requestable in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method addEmbedded.
/**
* Loads and adds DTOs by embedded annotation
*
* @param dto
* @param requestId
*
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws InvocationTargetException
* @throws IntrospectionException
* @throws InstantiationException
*/
private void addEmbedded(AbstractDto dto, UUID requestId) throws ReflectiveOperationException, IllegalArgumentException, IntrospectionException {
Assert.notNull(dto, "DTO is required!");
Field[] fields = dto.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.isAnnotationPresent(Embedded.class)) {
Embedded embeddedAnnotation = field.getAnnotation(Embedded.class);
if (embeddedAnnotation.enabled()) {
// If DTO class is abstract then continue
if (Modifier.isAbstract(embeddedAnnotation.dtoClass().getModifiers())) {
continue;
}
Object value = EntityUtils.getEntityValue(dto, field.getName());
if (value instanceof UUID) {
// Create mock instance of embedded DTO only with ID
UUID id = (UUID) value;
AbstractDto embeddedDto = null;
if (Requestable.class.isAssignableFrom(embeddedAnnotation.dtoClass())) {
embeddedDto = embeddedAnnotation.dtoClass().getDeclaredConstructor().newInstance();
embeddedDto.setId(id);
Requestable originalEmbeddedDto = this.getDtoService((Requestable) embeddedDto).get(embeddedDto.getId());
if (originalEmbeddedDto != null) {
// Call standard method for load request's DTO with original DTO
embeddedDto = (AbstractDto) this.get(requestId, originalEmbeddedDto);
} else {
// Call standard method for load request's DTO with mock DTO (only with ID)
embeddedDto = (AbstractDto) this.get(requestId, (Requestable) embeddedDto);
}
} else {
// If embedded DTO is not Requestable, then standard service is using
embeddedDto = (AbstractDto) lookupService.getDtoService(embeddedAnnotation.dtoClass()).get(id);
}
if (embeddedDto == null) {
continue;
}
embeddedDto.setTrimmed(true);
dto.getEmbedded().put(field.getName(), embeddedDto);
}
}
}
}
}
Aggregations