@Test public void shouldDeleteMultipleResults() throws NotFoundException { List<Long> testNos = Arrays.asList(0L, 1L); given(learnerResultRepository.deleteByProject_IdAndTestNoIn(PROJECT_ID, testNos)).willReturn(2L); learnerResultDAO.deleteAll(new User(USER_ID), PROJECT_ID, testNos); verify(learnerResultRepository).deleteByProject_IdAndTestNoIn(PROJECT_ID, testNos); }
public void deleteAll(User user, Long projectId, List<Long> testNos) throws NotFoundException, ValidationException { final Project project = projectDAO.getByID(user, projectId); final List<LearnerResult> results = learnerResultRepository.findByProject_IdAndTestNoIn(projectId, testNos); for (LearnerResult result: results) { checkAccess(user, project, result); } checkIfResultsCanBeDeleted(results); learnerResultRepository.deleteByProject_IdAndTestNoIn(projectId, testNos); }
LearnerResultDAO { public void deleteAll(User user, Long projectId, List<Long> testNos) throws NotFoundException, ValidationException { final Project project = projectDAO.getByID(user, projectId); final List<LearnerResult> results = learnerResultRepository.findByProject_IdAndTestNoIn(projectId, testNos); for (LearnerResult result: results) { checkAccess(user, project, result); } checkIfResultsCanBeDeleted(results); learnerResultRepository.deleteByProject_IdAndTestNoIn(projectId, testNos); } }
LearnerResultDAO { public void deleteAll(User user, Long projectId, List<Long> testNos) throws NotFoundException, ValidationException { final Project project = projectDAO.getByID(user, projectId); final List<LearnerResult> results = learnerResultRepository.findByProject_IdAndTestNoIn(projectId, testNos); for (LearnerResult result: results) { checkAccess(user, project, result); } checkIfResultsCanBeDeleted(results); learnerResultRepository.deleteByProject_IdAndTestNoIn(projectId, testNos); } @Autowired  LearnerResultDAO(ProjectDAO projectDAO, LearnerResultRepository learnerResultRepository,
                            LearnerResultStepRepository learnerResultStepRepository, EntityManager entityManager,
                            LearnerSetupDAO learnerSetupDAO); }
LearnerResultDAO { public void deleteAll(User user, Long projectId, List<Long> testNos) throws NotFoundException, ValidationException { final Project project = projectDAO.getByID(user, projectId); final List<LearnerResult> results = learnerResultRepository.findByProject_IdAndTestNoIn(projectId, testNos); for (LearnerResult result: results) { checkAccess(user, project, result); } checkIfResultsCanBeDeleted(results); learnerResultRepository.deleteByProject_IdAndTestNoIn(projectId, testNos); } @Autowired  LearnerResultDAO(ProjectDAO projectDAO, LearnerResultRepository learnerResultRepository,
                            LearnerResultStepRepository learnerResultStepRepository, EntityManager entityManager,
                            LearnerSetupDAO learnerSetupDAO); LearnerResult create(User user, Project project, LearnerResult learnerResult); List<LearnerResult> getAll(User user, Long projectId); List<LearnerResult> getAll(User user, Long projectId, List<Long> testNos); Page<LearnerResult> getAll(User user, Long projectId, PageRequest pr); LearnerResult getLatest(User user, Long projectId); LearnerResult get(User user, Long projectId, Long testNo); LearnerResultStep createStep(LearnerResult result); LearnerResult copy(User user, Long projectId, Long testNo); LearnerResultStep createStep(LearnerResult result, LearnerResultStep step); LearnerResultStep updateStep(LearnerResultStep step); void deleteAll(User user, Long projectId, List<Long> testNos); void initializeLazyRelations(LearnerResult result); void checkAccess(User user, Project project, LearnerResult learnerResult); }
LearnerResultDAO { public void deleteAll(User user, Long projectId, List<Long> testNos) throws NotFoundException, ValidationException { final Project project = projectDAO.getByID(user, projectId); final List<LearnerResult> results = learnerResultRepository.findByProject_IdAndTestNoIn(projectId, testNos); for (LearnerResult result: results) { checkAccess(user, project, result); } checkIfResultsCanBeDeleted(results); learnerResultRepository.deleteByProject_IdAndTestNoIn(projectId, testNos); } @Autowired  LearnerResultDAO(ProjectDAO projectDAO, LearnerResultRepository learnerResultRepository,
                            LearnerResultStepRepository learnerResultStepRepository, EntityManager entityManager,
                            LearnerSetupDAO learnerSetupDAO); LearnerResult create(User user, Project project, LearnerResult learnerResult); List<LearnerResult> getAll(User user, Long projectId); List<LearnerResult> getAll(User user, Long projectId, List<Long> testNos); Page<LearnerResult> getAll(User user, Long projectId, PageRequest pr); LearnerResult getLatest(User user, Long projectId); LearnerResult get(User user, Long projectId, Long testNo); LearnerResultStep createStep(LearnerResult result); LearnerResult copy(User user, Long projectId, Long testNo); LearnerResultStep createStep(LearnerResult result, LearnerResultStep step); LearnerResultStep updateStep(LearnerResultStep step); void deleteAll(User user, Long projectId, List<Long> testNos); void initializeLazyRelations(LearnerResult result); void checkAccess(User user, Project project, LearnerResult learnerResult);  }