@Test public void shouldDeleteAProject() throws NotFoundException { User user = new User(); user.setId(USER_ID); Project project = new Project(); project.addOwner(user); given(projectRepository.findById(PROJECT_ID)).willReturn(Optional.of(project)); projectDAO.delete(user, PROJECT_ID); verify(projectRepository).delete(project); }
public void delete(User user, Long projectId) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); checkAccess(user, project); if (!project.getOwners().contains(user) && user.getRole() != UserRole.ADMIN) { throw new UnauthorizedException("You are not allowed to delete this project."); } symbolActionRepository.deleteAllBySymbol_Project_Id(projectId); symbolStepRepository.deleteAllBySymbol_Project_Id(projectId); testReportRepository.deleteAllByProject_Id(projectId); testRepository.deleteAllByProject_Id(projectId); learnerResultRepository.deleteAllByProject_Id(projectId); learnerSetupRepository.deleteAllByProject_Id(projectId); parameterizedSymbolRepository.deleteAllBySymbol_Project_Id(projectId); testExecutionConfigRepository.deleteAllByProject_Id(projectId); symbolParameterRepository.deleteAllBySymbol_Project_Id(projectId); uploadableFileRepository.deleteAllByProject_Id(projectId); project.getOwners().clear(); project.getMembers().clear(); projectRepository.save(project); try { fileDAO.deleteProjectDirectory(user, projectId); projectRepository.delete(project); } catch (IOException e) { LOGGER.info("The project has been deleted, the directory, however, not."); } }
ProjectDAO { public void delete(User user, Long projectId) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); checkAccess(user, project); if (!project.getOwners().contains(user) && user.getRole() != UserRole.ADMIN) { throw new UnauthorizedException("You are not allowed to delete this project."); } symbolActionRepository.deleteAllBySymbol_Project_Id(projectId); symbolStepRepository.deleteAllBySymbol_Project_Id(projectId); testReportRepository.deleteAllByProject_Id(projectId); testRepository.deleteAllByProject_Id(projectId); learnerResultRepository.deleteAllByProject_Id(projectId); learnerSetupRepository.deleteAllByProject_Id(projectId); parameterizedSymbolRepository.deleteAllBySymbol_Project_Id(projectId); testExecutionConfigRepository.deleteAllByProject_Id(projectId); symbolParameterRepository.deleteAllBySymbol_Project_Id(projectId); uploadableFileRepository.deleteAllByProject_Id(projectId); project.getOwners().clear(); project.getMembers().clear(); projectRepository.save(project); try { fileDAO.deleteProjectDirectory(user, projectId); projectRepository.delete(project); } catch (IOException e) { LOGGER.info("The project has been deleted, the directory, however, not."); } } }
ProjectDAO { public void delete(User user, Long projectId) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); checkAccess(user, project); if (!project.getOwners().contains(user) && user.getRole() != UserRole.ADMIN) { throw new UnauthorizedException("You are not allowed to delete this project."); } symbolActionRepository.deleteAllBySymbol_Project_Id(projectId); symbolStepRepository.deleteAllBySymbol_Project_Id(projectId); testReportRepository.deleteAllByProject_Id(projectId); testRepository.deleteAllByProject_Id(projectId); learnerResultRepository.deleteAllByProject_Id(projectId); learnerSetupRepository.deleteAllByProject_Id(projectId); parameterizedSymbolRepository.deleteAllBySymbol_Project_Id(projectId); testExecutionConfigRepository.deleteAllByProject_Id(projectId); symbolParameterRepository.deleteAllBySymbol_Project_Id(projectId); uploadableFileRepository.deleteAllByProject_Id(projectId); project.getOwners().clear(); project.getMembers().clear(); projectRepository.save(project); try { fileDAO.deleteProjectDirectory(user, projectId); projectRepository.delete(project); } catch (IOException e) { LOGGER.info("The project has been deleted, the directory, however, not."); } } @Autowired  ProjectDAO(ProjectRepository projectRepository,
                      LearnerResultRepository learnerResultRepository,
                      TestReportRepository testReportRepository,
                      @Lazy FileDAO fileDAO,
                      ParameterizedSymbolRepository parameterizedSymbolRepository,
                      SymbolStepRepository symbolStepRepository,
                      SymbolActionRepository symbolActionRepository,
                      @Lazy ProjectEnvironmentDAO projectEnvironmentDAO,
                      ProjectUrlRepository projectUrlRepository,
                      TestExecutionConfigRepository testExecutionConfigRepository,
                      @Lazy TestDAO testDAO,
                      @Lazy UserDAO userDAO,
                      ProjectEnvironmentRepository environmentRepository,
                      @Lazy SymbolGroupDAO symbolGroupDAO,
                      TestRepository testRepository,
                      SymbolParameterRepository symbolParameterRepository,
                      UploadableFileRepository uploadableFileRepository,
                      LearnerSetupRepository learnerSetupRepository); }
ProjectDAO { public void delete(User user, Long projectId) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); checkAccess(user, project); if (!project.getOwners().contains(user) && user.getRole() != UserRole.ADMIN) { throw new UnauthorizedException("You are not allowed to delete this project."); } symbolActionRepository.deleteAllBySymbol_Project_Id(projectId); symbolStepRepository.deleteAllBySymbol_Project_Id(projectId); testReportRepository.deleteAllByProject_Id(projectId); testRepository.deleteAllByProject_Id(projectId); learnerResultRepository.deleteAllByProject_Id(projectId); learnerSetupRepository.deleteAllByProject_Id(projectId); parameterizedSymbolRepository.deleteAllBySymbol_Project_Id(projectId); testExecutionConfigRepository.deleteAllByProject_Id(projectId); symbolParameterRepository.deleteAllBySymbol_Project_Id(projectId); uploadableFileRepository.deleteAllByProject_Id(projectId); project.getOwners().clear(); project.getMembers().clear(); projectRepository.save(project); try { fileDAO.deleteProjectDirectory(user, projectId); projectRepository.delete(project); } catch (IOException e) { LOGGER.info("The project has been deleted, the directory, however, not."); } } @Autowired  ProjectDAO(ProjectRepository projectRepository,
                      LearnerResultRepository learnerResultRepository,
                      TestReportRepository testReportRepository,
                      @Lazy FileDAO fileDAO,
                      ParameterizedSymbolRepository parameterizedSymbolRepository,
                      SymbolStepRepository symbolStepRepository,
                      SymbolActionRepository symbolActionRepository,
                      @Lazy ProjectEnvironmentDAO projectEnvironmentDAO,
                      ProjectUrlRepository projectUrlRepository,
                      TestExecutionConfigRepository testExecutionConfigRepository,
                      @Lazy TestDAO testDAO,
                      @Lazy UserDAO userDAO,
                      ProjectEnvironmentRepository environmentRepository,
                      @Lazy SymbolGroupDAO symbolGroupDAO,
                      TestRepository testRepository,
                      SymbolParameterRepository symbolParameterRepository,
                      UploadableFileRepository uploadableFileRepository,
                      LearnerSetupRepository learnerSetupRepository); Project create(final User user, final CreateProjectForm projectForm); List<Project> getAll(User user); Project getByID(User user, Long projectId); Project update(User user, Long projectId, Project project); void delete(User user, Long projectId); void delete(User user, List<Long> projectIds); Project importProject(User user, ProjectExportableEntity projectExportableEntity); void checkAccess(User user, Project project); Project addOwners(User user, Long projectId, List<Long> ownerIds); Project addMembers(User user, Long projectId, List<Long> memberIds); Project removeOwners(User user, Long projectId, List<Long> ownerIds); Project removeMembers(User user, Long projectId, List<Long> memberIds); }
ProjectDAO { public void delete(User user, Long projectId) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); checkAccess(user, project); if (!project.getOwners().contains(user) && user.getRole() != UserRole.ADMIN) { throw new UnauthorizedException("You are not allowed to delete this project."); } symbolActionRepository.deleteAllBySymbol_Project_Id(projectId); symbolStepRepository.deleteAllBySymbol_Project_Id(projectId); testReportRepository.deleteAllByProject_Id(projectId); testRepository.deleteAllByProject_Id(projectId); learnerResultRepository.deleteAllByProject_Id(projectId); learnerSetupRepository.deleteAllByProject_Id(projectId); parameterizedSymbolRepository.deleteAllBySymbol_Project_Id(projectId); testExecutionConfigRepository.deleteAllByProject_Id(projectId); symbolParameterRepository.deleteAllBySymbol_Project_Id(projectId); uploadableFileRepository.deleteAllByProject_Id(projectId); project.getOwners().clear(); project.getMembers().clear(); projectRepository.save(project); try { fileDAO.deleteProjectDirectory(user, projectId); projectRepository.delete(project); } catch (IOException e) { LOGGER.info("The project has been deleted, the directory, however, not."); } } @Autowired  ProjectDAO(ProjectRepository projectRepository,
                      LearnerResultRepository learnerResultRepository,
                      TestReportRepository testReportRepository,
                      @Lazy FileDAO fileDAO,
                      ParameterizedSymbolRepository parameterizedSymbolRepository,
                      SymbolStepRepository symbolStepRepository,
                      SymbolActionRepository symbolActionRepository,
                      @Lazy ProjectEnvironmentDAO projectEnvironmentDAO,
                      ProjectUrlRepository projectUrlRepository,
                      TestExecutionConfigRepository testExecutionConfigRepository,
                      @Lazy TestDAO testDAO,
                      @Lazy UserDAO userDAO,
                      ProjectEnvironmentRepository environmentRepository,
                      @Lazy SymbolGroupDAO symbolGroupDAO,
                      TestRepository testRepository,
                      SymbolParameterRepository symbolParameterRepository,
                      UploadableFileRepository uploadableFileRepository,
                      LearnerSetupRepository learnerSetupRepository); Project create(final User user, final CreateProjectForm projectForm); List<Project> getAll(User user); Project getByID(User user, Long projectId); Project update(User user, Long projectId, Project project); void delete(User user, Long projectId); void delete(User user, List<Long> projectIds); Project importProject(User user, ProjectExportableEntity projectExportableEntity); void checkAccess(User user, Project project); Project addOwners(User user, Long projectId, List<Long> ownerIds); Project addMembers(User user, Long projectId, List<Long> memberIds); Project removeOwners(User user, Long projectId, List<Long> ownerIds); Project removeMembers(User user, Long projectId, List<Long> memberIds);  }