Search in sources :

Example 21 with Requestable

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 22 with Requestable

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);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 23 with Requestable

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) ResourceSupport(org.springframework.hateoas.ResourceSupport) ApiOperation(io.swagger.annotations.ApiOperation)

Example 24 with Requestable

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);
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) Map(java.util.Map) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) PropertyDescriptor(java.beans.PropertyDescriptor) Builder(eu.bcvsolutions.idm.core.api.dto.OperationResultDto.Builder) Lazy(org.springframework.context.annotation.Lazy) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Introspector(java.beans.Introspector) Strings(com.google.common.base.Strings) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Service(org.springframework.stereotype.Service) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IOException(java.io.IOException) Field(java.lang.reflect.Field) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemService(eu.bcvsolutions.idm.core.api.service.IdmRequestItemService) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) FormValueService(eu.bcvsolutions.idm.core.eav.api.service.FormValueService) RequestEventType(eu.bcvsolutions.idm.core.model.event.RequestEvent.RequestEventType) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Embedded(eu.bcvsolutions.idm.core.api.domain.Embedded) RequestEvent(eu.bcvsolutions.idm.core.model.event.RequestEvent) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Pageable(org.springframework.data.domain.Pageable) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) Modifier(java.lang.reflect.Modifier) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) PageImpl(org.springframework.data.domain.PageImpl) IdmRequestService(eu.bcvsolutions.idm.core.api.service.IdmRequestService) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) IdmRequestItem(eu.bcvsolutions.idm.core.model.entity.IdmRequestItem) HashMap(java.util.HashMap) MessageFormat(java.text.MessageFormat) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) ReadDtoService(eu.bcvsolutions.idm.core.api.service.ReadDtoService) RequestFilterPredicate(eu.bcvsolutions.idm.core.api.domain.RequestFilterPredicate) ImmutableList(com.google.common.collect.ImmutableList) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) Niceable(eu.bcvsolutions.idm.core.api.domain.Niceable) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) IdmRequestAttributeValueDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestAttributeValueDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto) MethodDescriptor(java.beans.MethodDescriptor) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) Comparator(java.util.Comparator) IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ArrayList(java.util.ArrayList) IntrospectionException(java.beans.IntrospectionException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException)

Example 25 with Requestable

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);
                }
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Embedded(eu.bcvsolutions.idm.core.api.domain.Embedded) UUID(java.util.UUID)

Aggregations

Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)28 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)20 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)16 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)13 IdmRequestItemDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto)13 Test (org.junit.Test)13 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)8 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)8 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)7 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)6 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 IdmRequestItemAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto)5 IdmRequestItemChangesDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto)5 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)5 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)5 IOException (java.io.IOException)5 Strings (com.google.common.base.Strings)4 ImmutableList (com.google.common.collect.ImmutableList)4 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)4 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)4