Search in sources :

Example 26 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class TestTaskExecutor method processItem.

@Override
public Optional<OperationResult> processItem(IdmIdentityDto dto) {
    try {
        LOG.warn("identity: [{}], loggedUser: [{}], transactionId: [{}]", dto.getUsername(), AutowireHelper.getBean(SecurityService.class).getCurrentUsername(), TransactionContextHolder.getContext().getTransactionId());
        Thread.sleep(300L);
        return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
    } catch (Exception ex) {
        throw new CoreException(ex);
    }
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException)

Example 27 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException 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)

Example 28 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class AbstractSchedulableStatefulExecutorIntegrationTest method testContinueWithRequiresNew.

@Test
public void testContinueWithRequiresNew() throws Exception {
    List<IdmIdentityDto> identities = createTestIdentities(3);
    // 
    TestIdentityIntegrationExecutor executor = new TestIdentityIntegrationExecutor();
    executor.dtos = identities;
    executor.continueOnException = true;
    executor.requireNewTransaction = true;
    String changeLastName = "last-name-update";
    executor.changeLastName = changeLastName;
    executor.exceptionOnItem = 2;
    // 
    try {
        getTransactionTemplate().execute(new TransactionCallback<Object>() {

            public Object doInTransaction(TransactionStatus transactionStatus) {
                longRunningTaskManager.execute(executor);
                // lookout: long running task never fails on exception => processed with exception. Rollback has to be controlled manually.
                throw new CoreException("fail");
            }
        });
    } catch (Exception ex) {
    // nothing
    }
    // 
    IdmLongRunningTaskDto taskDto = longRunningTaskService.get(executor.getLongRunningTaskId(), getContext());
    Assert.assertEquals(3, taskDto.getCount().intValue());
    Assert.assertEquals(2, taskDto.getSuccessItemCount().intValue());
    Assert.assertEquals(1, taskDto.getFailedItemCount().intValue());
    // first, third commited
    Assert.assertEquals(changeLastName, identityService.get(identities.get(0)).getLastName());
    Assert.assertNotEquals(changeLastName, identityService.get(identities.get(1)).getLastName());
    Assert.assertEquals(changeLastName, identityService.get(identities.get(2)).getLastName());
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) TransactionStatus(org.springframework.transaction.TransactionStatus) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 29 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class AbstractSchedulableStatefulExecutorIntegrationTest method testNotContinueWithRequiresNew.

@Test
public void testNotContinueWithRequiresNew() throws Exception {
    List<IdmIdentityDto> identities = createTestIdentities(3);
    // 
    TestIdentityIntegrationExecutor executor = new TestIdentityIntegrationExecutor();
    executor.dtos = identities;
    executor.continueOnException = false;
    executor.requireNewTransaction = true;
    String changeLastName = "last-name-update";
    executor.changeLastName = changeLastName;
    executor.exceptionOnItem = 2;
    // 
    try {
        getTransactionTemplate().execute(new TransactionCallback<Object>() {

            public Object doInTransaction(TransactionStatus transactionStatus) {
                longRunningTaskManager.execute(executor);
                // lookout: long running task never fails on exception => processed with exception. Rollback has to be controlled manually.
                throw new CoreException("fail");
            }
        });
    } catch (Exception ex) {
    // nothing
    }
    // 
    IdmLongRunningTaskDto taskDto = longRunningTaskService.get(executor.getLongRunningTaskId(), getContext());
    Assert.assertNotNull(taskDto);
    Assert.assertNotNull(taskDto.getCount());
    Assert.assertEquals(3, taskDto.getCount().intValue());
    Assert.assertEquals(1, taskDto.getSuccessItemCount().intValue());
    Assert.assertEquals(1, taskDto.getFailedItemCount().intValue());
    // first commited only
    Assert.assertEquals(changeLastName, identityService.get(identities.get(0)).getLastName());
    Assert.assertNotEquals(changeLastName, identityService.get(identities.get(1)).getLastName());
    Assert.assertNotEquals(changeLastName, identityService.get(identities.get(2)).getLastName());
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) TransactionStatus(org.springframework.transaction.TransactionStatus) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 30 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class DefaultIdmProcessedTaskItemServiceTest method testItemTypeReference.

@Test
public void testItemTypeReference() {
    IdmScheduledTaskDto d = getHelper().createSchedulableTask();
    IdmLongRunningTaskDto lrt = this.createLongRunningTask(d);
    IdmProcessedTaskItemDto item = getHelper().prepareProcessedItem(lrt);
    // 
    try {
        item.setScheduledTaskQueueOwner(d.getId());
        service.get(service.saveInternal(item).getId());
        fail("Both log and queue association is forbidden.");
    } catch (CoreException e) {
        assertNotNull(e.getMessage());
    }
    // 
    try {
        item.setScheduledTaskQueueOwner(null);
        item.setLongRunningTask(null);
        service.get(service.saveInternal(item).getId());
        fail("Empty log and queue association is forbidden.");
    } catch (CoreException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)64 UUID (java.util.UUID)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 Test (org.junit.Test)14 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)11 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)10 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Field (java.lang.reflect.Field)9 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)8 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)8 BaseEntity (eu.bcvsolutions.idm.core.api.entity.BaseEntity)8 List (java.util.List)8 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)7 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)7 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)7 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)7 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)6 IntrospectionException (java.beans.IntrospectionException)6