Search in sources :

Example 1 with IdmProcessedTaskItemDto

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

the class DefaultIdmProcessedTaskItemService method createProcessedItemDto.

private <E extends AbstractDto> IdmProcessedTaskItemDto createProcessedItemDto(E dto, OperationResult opResult) {
    IdmProcessedTaskItemDto item = new IdmProcessedTaskItemDto();
    item.setReferencedEntityId(dto.getId());
    item.setReferencedDtoType(dto.getClass().getCanonicalName());
    item.setOperationResult(opResult);
    return item;
}
Also used : IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)

Example 2 with IdmProcessedTaskItemDto

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

the class AbstractSchedulableStatefulExecutor method getItemFromQueue.

private Page<IdmProcessedTaskItemDto> getItemFromQueue(UUID entityRef) {
    // TODO: this is probably not good idea, but for now it is only choice
    if (this.getScheduledTaskId() == null) {
        return new PageImpl<>(Collections.emptyList());
    }
    IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter();
    filter.setReferencedEntityId(entityRef);
    filter.setScheduledTaskId(this.getScheduledTaskId());
    Page<IdmProcessedTaskItemDto> p = itemService.find(filter, new PageRequest(0, 1));
    if (p.getTotalElements() > 1) {
        LOG.warn("Multiple same item references found in [{}] process queue.", this.getClass());
    }
    return p;
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest) IdmProcessedTaskItemFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)

Example 3 with IdmProcessedTaskItemDto

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

the class IdmLongRunningTaskItemControllerRestTest method itemFoundById.

@Test
public void itemFoundById() throws Exception {
    IdmScheduledTaskDto scheduledTaskDto = helper.createSchedulableTask();
    IdmProcessedTaskItemDto taskItem = service.saveInternal(helper.prepareProcessedItem(scheduledTaskDto));
    getMockMvc().perform(get(BaseController.BASE_PATH + PATH + "/" + taskItem.getId()).with(authentication(getAuthentication())).contentType(InitTestData.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(MockMvcResultMatchers.content().contentType(InitTestData.HAL_CONTENT_TYPE)).andExpect(jsonPath("$.id", equalTo(taskItem.getId().toString())));
}
Also used : IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 4 with IdmProcessedTaskItemDto

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

the class AbstractSchedulableStatefulExecutorUnitTest method testLogItemProcessed.

@Test
public void testLogItemProcessed() {
    IdmLongRunningTaskDto lrt = new IdmLongRunningTaskDto();
    lrt.setId(UUID.randomUUID());
    when(itemService.saveInternal(any(IdmProcessedTaskItemDto.class))).then(AdditionalAnswers.returnsFirstArg());
    when(longRunningTaskService.get(any(UUID.class))).thenReturn(lrt);
    when(itemService.createLogItem(any(AbstractDto.class), any(OperationResult.class), any(IdmLongRunningTaskDto.class))).thenCallRealMethod();
    // 
    IdmIdentityDto dto = getTestIdentityDto();
    OperationResult opResult = new OperationResult.Builder(OperationState.EXCEPTION).build();
    IdmProcessedTaskItemDto qItem = executor.logItemProcessed(dto, opResult);
    // 
    assertEquals(lrt.getId(), qItem.getLongRunningTask());
    assertEquals(opResult, qItem.getOperationResult());
    assertEquals(dto.getClass().getCanonicalName(), qItem.getReferencedDtoType());
    assertEquals(dto.getId(), qItem.getReferencedEntityId());
    assertNull(qItem.getScheduledTaskQueueOwner());
    // 
    verify(itemService, times(1)).saveInternal(any(IdmProcessedTaskItemDto.class));
    verify(executor, times(1)).logItemProcessed(any(IdmIdentityDto.class), any(OperationResult.class));
    verify(executor, times(1)).getLongRunningTaskId();
    verify(longRunningTaskService, times(1)).get(any(UUID.class));
    verify(itemService, times(1)).createLogItem(any(AbstractDto.class), any(OperationResult.class), any(IdmLongRunningTaskDto.class));
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Example 5 with IdmProcessedTaskItemDto

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

the class AbstractSchedulableStatefulExecutorUnitTest method testIsInProcessedQueue.

@Test
public void testIsInProcessedQueue() {
    IdmScheduledTaskDto scheduledTask = new IdmScheduledTaskDto();
    UUID randomId = UUID.randomUUID();
    scheduledTask.setId(randomId);
    when(scheduledTaskService.findByLongRunningTaskId(randomId)).thenReturn(scheduledTask);
    // 
    List<IdmProcessedTaskItemDto> items = Lists.newArrayList(new IdmProcessedTaskItemDto());
    // 
    when(itemService.find(any(IdmProcessedTaskItemFilter.class), any(Pageable.class))).thenReturn(new PageImpl<>(items));
    // 
    when(executor.getLongRunningTaskId()).thenReturn(randomId);
    // 
    boolean inProcessedQueue = executor.isInProcessedQueue(getTestIdentityDto());
    assertTrue(inProcessedQueue);
    // 
    when(itemService.find(any(IdmProcessedTaskItemFilter.class), any(Pageable.class))).thenReturn(new PageImpl<>(Lists.newArrayList()));
    // 
    inProcessedQueue = executor.isInProcessedQueue(getTestIdentityDto());
    assertFalse(inProcessedQueue);
    // 
    verify(executor, times(2)).isInProcessedQueue(any(IdmIdentityDto.class));
    verify(scheduledTaskService, times(1)).findByLongRunningTaskId(randomId);
    verify(itemService, times(2)).find(any(IdmProcessedTaskItemFilter.class), any(Pageable.class));
}
Also used : Pageable(org.springframework.data.domain.Pageable) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmProcessedTaskItemFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Aggregations

IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)42 Test (org.junit.Test)32 IdmScheduledTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)22 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)16 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)13 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)12 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)11 IdmProcessedTaskItemFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter)9 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)4 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)4 AbstractVerifiableUnitTest (eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest)4 UUID (java.util.UUID)4 LocalDate (org.joda.time.LocalDate)4 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)3 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)2 PageImpl (org.springframework.data.domain.PageImpl)2 PageRequest (org.springframework.data.domain.PageRequest)2 Pageable (org.springframework.data.domain.Pageable)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1