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;
}
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;
}
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())));
}
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));
}
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));
}
Aggregations