Search in sources :

Example 1 with IdmRequestFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter in project CzechIdMng by bcvsolutions.

the class IdmRequestFilterTest method ownerTest.

@Test
public void ownerTest() {
    String ownerType = IdmIdentityDto.class.toString();
    IdmRequestDto request1 = createRequest(ownerType, UUID.randomUUID());
    IdmRequestDto request2 = createRequest(ownerType, UUID.randomUUID());
    IdmRequestDto request3 = createRequest(ownerType, UUID.randomUUID());
    IdmRequestFilter filter = new IdmRequestFilter();
    filter.setOwnerType(ownerType);
    filter.setOwnerId(request1.getOwnerId());
    List<IdmRequestDto> content = requestService.find(filter, null).getContent();
    Assert.assertEquals(1, content.size());
    Assert.assertEquals(request1.getName(), content.get(0).getName());
    filter.setOwnerId(request2.getOwnerId());
    content = requestService.find(filter, null).getContent();
    Assert.assertEquals(1, content.size());
    Assert.assertEquals(request2.getName(), content.get(0).getName());
    filter.setOwnerId(request3.getOwnerId());
    content = requestService.find(filter, null).getContent();
    Assert.assertEquals(1, content.size());
    Assert.assertEquals(request3.getName(), content.get(0).getName());
}
Also used : IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 2 with IdmRequestFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter in project CzechIdMng by bcvsolutions.

the class IdmRequestFilterTest method stateTest.

@Test
public void stateTest() {
    UUID ownerId = UUID.randomUUID();
    String ownerType = IdmIdentityDto.class.toString();
    List<RequestState> states = new ArrayList<>();
    RequestState state = RequestState.APPROVED;
    states.add(state);
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    IdmRequestFilter filter = new IdmRequestFilter();
    filter.setOwnerType(ownerType);
    filter.setOwnerId(ownerId);
    filter.setStates(states);
    List<IdmRequestDto> content = requestService.find(filter, null).getContent();
    Assert.assertEquals(3, content.size());
    state = RequestState.CANCELED;
    states.add(state);
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    filter.setStates(states);
    content = requestService.find(filter, null).getContent();
    Assert.assertEquals(6, content.size());
    state = RequestState.EXCEPTION;
    states.add(state);
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    filter.setStates(states);
    content = requestService.find(filter, null).getContent();
    Assert.assertEquals(9, content.size());
    state = RequestState.IN_PROGRESS;
    states.add(state);
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    filter.setStates(states);
    content = requestService.find(filter, null).getContent();
    Assert.assertEquals(12, content.size());
}
Also used : RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) ArrayList(java.util.ArrayList) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) UUID(java.util.UUID) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 3 with IdmRequestFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter in project CzechIdMng by bcvsolutions.

the class IdmRequestController method toFilter.

@Override
protected IdmRequestFilter toFilter(MultiValueMap<String, Object> parameters) {
    IdmRequestFilter filter = new IdmRequestFilter(parameters);
    filter.setOwnerType(getParameterConverter().toString(parameters, "ownerType"));
    filter.setOwnerId(getParameterConverter().toUuid(parameters, "ownerId"));
    filter.setStates(getParameterConverter().toEnums(parameters, "states", RequestState.class));
    filter.setCreatedAfter(getParameterConverter().toDateTime(parameters, "from"));
    filter.setCreatedBefore(getParameterConverter().toDateTime(parameters, "till"));
    return filter;
}
Also used : RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter)

Example 4 with IdmRequestFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter in project CzechIdMng by bcvsolutions.

the class RequestByOwnerEvaluatorTest method testRightOnRequest.

@Test
public void testRightOnRequest() {
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmRoleDto roleForRequest = getHelper().createRole();
    IdmRequestDto requestWithOwneredRole = requestManager.createRequest(roleForRequest);
    IdmRoleDto roleForRequestWithoutRight = getHelper().createRole();
    IdmRequestDto requestWithoutOwneredRole = requestManager.createRequest(roleForRequestWithoutRight);
    IdmRoleDto role = getHelper().createRole();
    getHelper().createRoleGuaranteeRole(role, role);
    getHelper().createIdentityRole(identity, role);
    getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.REQUEST, IdmRequest.class, RequestByOwnerEvaluator.class, IdmBasePermission.READ);
    // User will have rights on the roleForRequest
    ConfigurationMap properties = new ConfigurationMap();
    properties.put(UuidEvaluator.PARAMETER_UUID, roleForRequest.getId());
    getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.ROLE, IdmRole.class, UuidEvaluator.class, properties, IdmBasePermission.READ);
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        try {
            requestService.get(requestWithoutOwneredRole.getId(), IdmBasePermission.READ);
            fail();
        } catch (ForbiddenEntityException ex) {
        // It is OK
        }
        assertNotNull(requestService.get(requestWithOwneredRole.getId(), IdmBasePermission.READ));
        IdmRequestFilter requestFilter = new IdmRequestFilter();
        // We do not have right to that request
        requestFilter.setId(requestWithoutOwneredRole.getId());
        assertEquals(0, requestService.find(requestFilter, null, IdmBasePermission.READ).getContent().size());
        // We have right to that request
        requestFilter.setId(requestWithOwneredRole.getId());
        assertEquals(1, requestService.find(requestFilter, null, IdmBasePermission.READ).getContent().size());
    } finally {
        logout();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Example 5 with IdmRequestFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter in project CzechIdMng by bcvsolutions.

the class DefaultRequestManager method onDeleteRequestable.

@Override
@Transactional
public <R extends Requestable> void onDeleteRequestable(R requestable) {
    Assert.notNull(requestable, "Requestable DTO cannot be null!");
    // Search requests with that deleting owner
    IdmRequestFilter requestFilter = new IdmRequestFilter();
    requestFilter.setOwnerType(requestable.getClass().getName());
    requestFilter.setOwnerId((UUID) requestable.getId());
    List<IdmRequestDto> requests = requestService.find(requestFilter, null).getContent();
    // 
    requests.stream().filter(// We need filtered request which
    request -> RequestState.APPROVED != request.getState()).forEach(request -> {
        // 
        request = changeRequestState(// 
        requestable, // 
        request, new // 
        ResultCodeException(// 
        CoreResultCode.REQUEST_OWNER_WAS_DELETED, // 
        ImmutableMap.of("owner", requestable.toString())));
        requestService.save(request);
    });
    // Search request items with that deleting owner
    IdmRequestItemFilter requestItemFilter = new IdmRequestItemFilter();
    requestItemFilter.setOwnerType(requestable.getClass().getName());
    requestItemFilter.setOwnerId((UUID) requestable.getId());
    List<IdmRequestItemDto> requestItems = requestItemService.find(requestItemFilter, null).getContent();
    // 
    requestItems.stream().filter(// We need filtered request which invoked that
    item -> RequestState.APPROVED != item.getState()).forEach(item -> {
        // 
        item = changeItemState(// 
        requestable, // 
        item, new // 
        ResultCodeException(// 
        CoreResultCode.REQUEST_OWNER_WAS_DELETED, // 
        ImmutableMap.of("owner", requestable.toString())));
        requestItemService.save(item);
        IdmRequestItemFilter subItemFilter = new IdmRequestItemFilter();
        subItemFilter.setRequestId(item.getRequest());
        // Search all items for that request
        List<IdmRequestItemDto> subItems = requestItemService.find(subItemFilter, null).getContent();
        // TODO: This can be (maybe) removed ... because that 'cancel' is implemented
        // during realization of item
        // Check if items in same request does not contains same ID of deleting owner in
        // the DATA Json.
        // If yes, then state will be changed to cancel.
        // 
        subItems.stream().filter(// We need filtered request
        subItem -> RequestState.APPROVED != subItem.getState()).filter(// 
        subItem -> !requestable.getId().equals(subItem.getOwnerId())).filter(// 
        subItem -> subItem.getData() != null).filter(subItem -> // 
        subItem.getData().indexOf(requestable.getId().toString()) != // 
        -1).forEach(subItem -> {
            // 
            subItem = changeItemState(// 
            requestable, // 
            subItem, new // 
            ResultCodeException(// 
            CoreResultCode.REQUEST_OWNER_FROM_OTHER_REQUEST_WAS_DELETED, ImmutableMap.of("owner", requestable.toString(), "otherRequest", // 
            subItem.toString())));
            requestItemService.save(subItem);
        });
    });
// 
}
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) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter)7 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)6 Test (org.junit.Test)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4 UUID (java.util.UUID)4 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)3 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 Codeable (eu.bcvsolutions.idm.core.api.domain.Codeable)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)1 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)1