Search in sources :

Example 6 with IdmRequestItemDto

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

the class RequestManagerTest method testDeleteRequestIntegrity.

@Test
public void testDeleteRequestIntegrity() {
    // Log as admin, but not user 'admin' (we don't want to skip WF)
    IdmIdentityDto adminUser = getHelper().createIdentity();
    loginAsAdmin(adminUser.getUsername());
    // Create role
    IdmRoleDto role = getHelper().createRole();
    // Create request
    IdmRequestDto request = requestManager.createRequest(role);
    Assert.assertNotNull(request);
    // Create guarantee
    IdmIdentityDto guarantee = getHelper().createIdentity();
    IdmRoleGuaranteeDto roleGuarantee = new IdmRoleGuaranteeDto();
    roleGuarantee.setRole(role.getId());
    roleGuarantee.setGuarantee(guarantee.getId());
    Requestable requestablePost = requestManager.post(request.getId(), roleGuarantee);
    IdmRequestItemDto changeRequestItem = DtoUtils.getEmbedded((AbstractDto) requestablePost, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.ADD, changeRequestItem.getOperation());
    Assert.assertTrue(requestablePost instanceof IdmRoleGuaranteeDto);
    // Change role (without save)
    role.setDescription(getHelper().createName());
    role.setPriority(1000);
    // Create request item
    Requestable requestable = requestManager.post(request.getId(), role);
    Assert.assertNotNull(requestable);
    Assert.assertNotNull(requestable.getRequestItem());
    changeRequestItem = DtoUtils.getEmbedded((AbstractDto) requestable, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.UPDATE, changeRequestItem.getOperation());
    Assert.assertTrue(requestable instanceof IdmRoleDto);
    // Request should be in concept state
    request = requestService.get(request.getId());
    Assert.assertEquals(RequestState.CONCEPT, request.getState());
    // Two items should be created
    Assert.assertEquals(2, requestManager.findRequestItems(request.getId(), null).size());
    // Delete the request
    requestService.delete(request);
    IdmRequestDto requestDeleted = requestService.get(request.getId());
    Assert.assertNull(requestDeleted);
    // All items should be deleted
    Assert.assertEquals(0, requestManager.findRequestItems(request.getId(), null).size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 7 with IdmRequestItemDto

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

the class RequestManagerTest method testDeleteRoleByRequest.

@Test
public void testDeleteRoleByRequest() {
    // Create role
    IdmRoleDto role = getHelper().createRole();
    // Create request
    IdmRequestDto request = requestManager.createRequest(role);
    Assert.assertNotNull(request);
    Assert.assertEquals(request.getOwnerType(), role.getClass().getName());
    Assert.assertEquals(request.getOwnerId(), role.getId());
    // Create 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);
    IdmRoleDto roleFromRequest = (IdmRoleDto) requestable;
    // Is not deleted yet
    IdmRoleDto currentRole = roleService.get(role.getId());
    Assert.assertNotNull(currentRole);
    // Start request
    IdmRequestDto executedRequest = requestManager.executeRequest(request.getId());
    Assert.assertNotNull(executedRequest);
    Assert.assertEquals(RequestState.EXECUTED, executedRequest.getState());
    // Role have to be deleted
    IdmRoleDto executedRole = roleService.get(roleFromRequest.getId());
    Assert.assertNull(executedRole);
}
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 8 with IdmRequestItemDto

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

the class RequestManagerTest method testThrowExceptionFromRequest.

@Test
public void testThrowExceptionFromRequest() {
    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);
    Assert.assertTrue(requestable instanceof IdmRoleDto);
    IdmRoleDto roleFromRequest = (IdmRoleDto) requestable;
    // Is not same instance
    Assert.assertTrue(newRole != roleFromRequest);
    // Has same values as new role
    Assert.assertEquals(newRole.getCode(), roleFromRequest.getCode());
    Assert.assertEquals(newRole.getName(), roleFromRequest.getName());
    Assert.assertEquals(newRole.getPriority(), roleFromRequest.getPriority());
    Assert.assertEquals(newRole.getDescription(), roleFromRequest.getDescription());
    // Role not exists yet
    Assert.assertNull(roleService.get(roleFromRequest.getId()));
    // We break the item (we want throw exception)
    IdmRequestItemDto requestItem = requestItemService.get(requestable.getRequestItem());
    requestItem.setOwnerType("TO BREAK IT");
    requestItemService.save(requestItem);
    IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
    Assert.assertNotNull(executedRequest);
    Assert.assertEquals(RequestState.EXCEPTION, executedRequest.getState());
}
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 9 with IdmRequestItemDto

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

the class IdmRequestController method startRequest.

@ResponseBody
@RequestMapping(value = "/{backendId}/start", method = RequestMethod.PUT)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.REQUEST_UPDATE + "')")
@ApiOperation(value = "Start request", nickname = "startRequest", response = IdmRequestDto.class, tags = { IdmRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_UPDATE, description = "") }) })
public ResponseEntity<?> startRequest(@ApiParam(value = "Request's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    UUID requestId = UUID.fromString(backendId);
    IdmRequestDto request = this.getService().get(requestId, IdmBasePermission.EXECUTE);
    // Validate request
    List<IdmRequestItemDto> items = requestManager.findRequestItems(request.getId(), null);
    if (items.isEmpty()) {
        throw new ResultCodeException(CoreResultCode.REQUEST_CANNOT_BE_EXECUTED_NONE_ITEMS, ImmutableMap.of("request", request.toString()));
    }
    requestManager.startRequest(requestId, true);
    return this.get(backendId);
}
Also used : IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) UUID(java.util.UUID) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with IdmRequestItemDto

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

the class DefaultIdmRequestItemService method deleteInternal.

@Override
@Transactional
public void deleteInternal(IdmRequestItemDto dto) {
    if (dto.getId() != null) {
        // We try to find value in the confidential storage and delete it
        String storageKey = RequestManager.getConfidentialStorageKey(dto.getId());
        confidentialStorage.delete(dto, storageKey);
    }
    super.deleteInternal(dto);
    // We have to ensure the referential integrity, because some item (his DTOs) could be child of that item (DTO)
    if (dto.getId() != null && dto.getOwnerId() != null && RequestOperationType.ADD == dto.getOperation()) {
        if (dto.getRequest() != null) {
            IdmRequestItemFilter requestItemFilter = new IdmRequestItemFilter();
            requestItemFilter.setRequestId(dto.getRequest());
            // Find all items
            List<IdmRequestItemDto> items = this.find(requestItemFilter, null).getContent();
            // Create predicate - find all DTOs with that UUID value in any fields
            ImmutableList<RequestPredicate> predicates = ImmutableList.of(new RequestPredicate(dto.getOwnerId(), null));
            List<IdmRequestItemDto> itemsToDelete = // Search items to delete
            items.stream().filter(item -> {
                try {
                    @SuppressWarnings("unchecked") Class<? extends Requestable> ownerType = (Class<? extends Requestable>) Class.forName(item.getOwnerType());
                    Requestable requestable = requestManager.convertItemToDto(item, ownerType);
                    if (requestable == null) {
                        return false;
                    }
                    List<Requestable> filteredDtos = requestManager.filterDtosByPredicates(ImmutableList.of(requestable), ownerType, predicates);
                    return filteredDtos.contains(requestable);
                } catch (ClassNotFoundException | IOException e) {
                    throw new CoreException(e);
                }
            }).collect(Collectors.toList());
            itemsToDelete.forEach(item -> {
                this.delete(item);
            });
        }
    }
}
Also used : RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) IdmRequestItem(eu.bcvsolutions.idm.core.model.entity.IdmRequestItem) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestPredicate(eu.bcvsolutions.idm.core.api.service.RequestManager.RequestPredicate) MessageFormat(java.text.MessageFormat) Strings(com.google.common.base.Strings) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Predicate(javax.persistence.criteria.Predicate) ImmutableList(com.google.common.collect.ImmutableList) IdmRequestItemRepository(eu.bcvsolutions.idm.core.model.repository.IdmRequestItemRepository) Service(org.springframework.stereotype.Service) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmRequestItem_(eu.bcvsolutions.idm.core.model.entity.IdmRequestItem_) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Root(javax.persistence.criteria.Root) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) WorkflowHistoricProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowHistoricProcessInstanceService) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Collection(java.util.Collection) RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto) List(java.util.List) IdmRequestItemService(eu.bcvsolutions.idm.core.api.service.IdmRequestItemService) Lazy(org.springframework.context.annotation.Lazy) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) AbstractRequestDto(eu.bcvsolutions.idm.core.api.dto.AbstractRequestDto) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) Transactional(org.springframework.transaction.annotation.Transactional) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) RequestPredicate(eu.bcvsolutions.idm.core.api.service.RequestManager.RequestPredicate) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmRequestItemDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto)27 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)21 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)14 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)12 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)10 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)9 Test (org.junit.Test)9 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)8 IdmRequestItemFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter)7 IOException (java.io.IOException)7 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)6 IdmRequestItemService (eu.bcvsolutions.idm.core.api.service.IdmRequestItemService)6 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)6 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)5 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)5 IdmRequestItemChangesDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto)5 RequestManager (eu.bcvsolutions.idm.core.api.service.RequestManager)5 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)5 WorkflowProcessInstanceService (eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService)5 ArrayList (java.util.ArrayList)5