DefaultIdmProcessedTaskItemService extends AbstractReadWriteDtoService<IdmProcessedTaskItemDto, IdmProcessedTaskItem, IdmProcessedTaskItemFilter> implements IdmProcessedTaskItemService { @Override @Transactional public IdmProcessedTaskItemDto saveInternal(IdmProcessedTaskItemDto dto) { Assert.notNull(dto, "DTO is required."); if (dto.getLongRunningTask() != null && dto.getScheduledTaskQueueOwner() != null) { throw new CoreException("Item cannot be in both scheduled task queue and long running task log."); } if (dto.getLongRunningTask() == null && dto.getScheduledTaskQueueOwner() == null) { throw new CoreException("Item must have either queue (IdmScheduledTask) or log (IdmLongRunningTask) association."); } return super.saveInternal(dto); } @Autowired  DefaultIdmProcessedTaskItemService(IdmProcessedTaskItemRepository repository); @Override @Transactional IdmProcessedTaskItemDto saveInternal(IdmProcessedTaskItemDto dto); @Override AuthorizableType getAuthorizableType(); @Override @Transactional void deleteAllByLongRunningTask(IdmLongRunningTaskDto dto); @Override @Transactional void deleteAllByScheduledTask(IdmScheduledTaskDto dto); @Override @Transactional void deleteItem(UUID scheduledTaskId, UUID referencedEntityId); @Override @Transactional(readOnly = true) List<UUID> findAllRefEntityIdsInQueueByScheduledTaskId(UUID scheduledTaskId); @Override @Transactional(readOnly = true) Page<IdmProcessedTaskItemDto> findQueueItems(IdmScheduledTaskDto scheduledTask, Pageable pageable); @Override @Transactional(readOnly = true) Page<IdmProcessedTaskItemDto> findLogItems(IdmLongRunningTaskDto longRunningTask, Pageable pageable); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) IdmProcessedTaskItemDto createLogItem(
			E processedItem, 
			OperationResult result, 
			UUID longRunningTaskId); @Override @Transactional IdmProcessedTaskItemDto createQueueItem(E processedItem, OperationResult result, UUID scheduledTaskId);  }
@Test public void testCreateItem() { IdmScheduledTaskDto d = getHelper().createSchedulableTask(); IdmLongRunningTaskDto lrt = this.createLongRunningTask(d); IdmProcessedTaskItemDto item = getHelper().prepareProcessedItem(lrt); IdmProcessedTaskItemDto retrieved = service.get(service.saveInternal(item).getId()); assertNotNull(retrieved); assertEquals(item.getReferencedDtoType(), retrieved.getReferencedDtoType()); assertEquals(item.getReferencedEntityId(), retrieved.getReferencedEntityId()); assertEquals(item.getLongRunningTask(), retrieved.getLongRunningTask()); }
@Test public void testImmutable() { IdmScheduledTaskDto d = getHelper().createSchedulableTask(); IdmLongRunningTaskDto lrt = this.createLongRunningTask(d); IdmProcessedTaskItemDto item = getHelper().prepareProcessedItem(lrt); IdmProcessedTaskItemDto saved = service.get(service.saveInternal(item).getId()); saved.setReferencedDtoType(IdmIdentityContractDto.class.getCanonicalName()); saved.setReferencedEntityId(UUID.randomUUID()); saved.setLongRunningTask(this.createLongRunningTask(d).getId()); IdmProcessedTaskItemDto retrieved = service.get(service.saveInternal(saved).getId()); assertEquals(item.getLongRunningTask(), retrieved.getLongRunningTask()); assertEquals(item.getReferencedDtoType(), retrieved.getReferencedDtoType()); assertEquals(item.getReferencedEntityId(), retrieved.getReferencedEntityId()); assertNotEquals(item.getLongRunningTask(), saved.getLongRunningTask()); assertNotEquals(item.getReferencedDtoType(), saved.getReferencedDtoType()); assertNotEquals(item.getReferencedEntityId(), saved.getReferencedEntityId()); }
@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()); } }
@Test public void testDeleteLogItemIntegrity() { IdmScheduledTaskDto d = getHelper().createSchedulableTask(); IdmLongRunningTaskDto lrt = this.createLongRunningTask(d); IdmProcessedTaskItemDto item = service.saveInternal(getHelper().prepareProcessedItem(lrt)); longrunningService.deleteInternal(lrt); assertNull(longrunningService.get(lrt.getId())); assertNull(service.get(item.getId())); assertNotNull(scheduledTaskService.get(d.getId())); }
@Test public void testDeleteQueueItemIntegrity() { IdmScheduledTaskDto d = getHelper().createSchedulableTask(); IdmProcessedTaskItemDto item = service.saveInternal(getHelper().prepareProcessedItem(d)); scheduledTaskService.deleteInternal(d); assertNull(scheduledTaskService.get(d.getId())); assertNull(service.get(item.getId())); }
@Test public void textFilter(){ IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter(); IdmScheduledTaskDto d = getHelper().createSchedulableTask(); IdmProcessedTaskItemDto item = service.saveInternal(getHelper().prepareProcessedItem(d)); IdmProcessedTaskItemDto item2 = service.saveInternal(getHelper().prepareProcessedItem(d)); filter.setText(item.getReferencedDtoType()); Page<IdmProcessedTaskItemDto> result = service.find(filter,null); Assert.assertTrue(result.getContent().contains(item)); Assert.assertTrue(result.getContent().contains(item2)); }
@Test public void scheduledTaskIdFilter(){ IdmScheduledTaskDto d = getHelper().createSchedulableTask(); IdmProcessedTaskItemDto item = service.saveInternal(getHelper().prepareProcessedItem(d)); IdmProcessedTaskItemDto item2 = service.saveInternal(getHelper().prepareProcessedItem(d)); IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter(); filter.setScheduledTaskId(d.getId()); Page<IdmProcessedTaskItemDto> result = service.find(filter,null); assertEquals("Wrong number of items!", 2, result.getTotalElements()); assertTrue(result.getContent().contains(item)); assertTrue(result.getContent().contains(item2)); }
@Test public void datesFilter(){ IdmScheduledTaskDto d = getHelper().createSchedulableTask(); IdmProcessedTaskItemDto item = service.saveInternal(getHelper().prepareProcessedItem(d)); IdmProcessedTaskItemDto item2 = getHelper().prepareProcessedItem(d); item2.setCreated(item.getCreated()); item2 = service.saveInternal(item2); IdmProcessedTaskItemDto item3 = service.saveInternal(getHelper().prepareProcessedItem(d)); IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter(); filter.setFrom(item.getCreated().truncatedTo(ChronoUnit.MILLIS)); Page<IdmProcessedTaskItemDto> result = service.find(filter,null); assertTrue("#1", result.getContent().contains(item)); assertTrue("#2", result.getContent().contains(item2)); filter.setFrom(null); filter.setTill(item3.getCreated().truncatedTo(ChronoUnit.MILLIS).plus(1, ChronoUnit.MILLIS)); result = service.find(filter,null); assertTrue("#4",result.getContent().contains(item3)); }
@Test public void referencedEntityIdFilter(){ IdmScheduledTaskDto d = getHelper().createSchedulableTask(); IdmProcessedTaskItemDto item = service.saveInternal(getHelper().prepareProcessedItem(d)); IdmProcessedTaskItemDto item2 = service.saveInternal(getHelper().prepareProcessedItem(d)); IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter(); filter.setReferencedEntityId(item.getReferencedEntityId()); Page<IdmProcessedTaskItemDto> result = service.find(filter,null); assertEquals("Wrong number of items!",1,result.getTotalElements()); assertTrue(result.getContent().contains(item)); assertFalse(result.getContent().contains(item2)); filter.setReferencedEntityId(item2.getReferencedEntityId()); result = service.find(filter,null); assertEquals("Wrong number of items!",1,result.getTotalElements()); assertTrue(result.getContent().contains(item2)); assertFalse(result.getContent().contains(item)); }
@Test public void referencedEntityTypeFilter(){ IdmScheduledTaskDto d = getHelper().createSchedulableTask(); IdmProcessedTaskItemDto item = service.saveInternal(getHelper().prepareProcessedItem(d)); IdmProcessedTaskItemDto item2 = service.saveInternal(getHelper().prepareProcessedItem(d)); IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter(); filter.setReferencedEntityId(item.getReferencedEntityId()); filter.setReferencedEntityType(item.getReferencedDtoType()); Page<IdmProcessedTaskItemDto> result = service.find(filter,null); Assert.assertEquals(1, result.getTotalElements()); Assert.assertTrue(result.getContent().contains(item)); filter.setReferencedEntityId(item2.getReferencedEntityId()); result = service.find(filter,null); Assert.assertEquals(1, result.getTotalElements()); Assert.assertTrue(result.getContent().contains(item2)); }
@Test public void getLongRunningTaskIdFilter(){ IdmScheduledTaskDto d = getHelper().createSchedulableTask(); IdmLongRunningTaskDto lrt = this.createLongRunningTask(d); IdmLongRunningTaskDto lrt2 = this.createLongRunningTask(d); IdmProcessedTaskItemDto item = service.saveInternal(getHelper().prepareProcessedItem(lrt)); IdmProcessedTaskItemDto item2 = service.saveInternal(getHelper().prepareProcessedItem(lrt)); IdmProcessedTaskItemDto item3 = service.saveInternal(getHelper().prepareProcessedItem(lrt2)); IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter(); filter.setLongRunningTaskId(lrt.getId()); Page<IdmProcessedTaskItemDto> result = service.find(filter,null); assertEquals("Wrong number of items!",2,result.getTotalElements()); assertTrue(result.getContent().contains(item)); assertTrue(result.getContent().contains(item2)); assertFalse(result.getContent().contains(item3)); }
@Test public void getOperationState(){ IdmScheduledTaskDto d = getHelper().createSchedulableTask(); IdmProcessedTaskItemDto item = service.saveInternal(getHelper().prepareProcessedItem(d)); IdmProcessedTaskItemDto item2 = service.saveInternal(getHelper().prepareProcessedItem(d)); IdmProcessedTaskItemDto item3 = service.saveInternal(getHelper().prepareProcessedItem(d,OperationState.CANCELED)); IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter(); filter.setOperationState(item.getOperationResult().getState()); Page<IdmProcessedTaskItemDto> result = service.find(filter,null); assertTrue(result.getContent().contains(item)); assertTrue(result.getContent().contains(item2)); assertFalse(result.getContent().contains(item3)); }