From 7812d47c4f4f6881199fa1c52bd32e3733057636 Mon Sep 17 00:00:00 2001 From: entholzer Date: Tue, 19 Nov 2024 15:23:19 +0100 Subject: [PATCH] cleanup 4 --- .../localvc/LocalVCServletService.java | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/LocalVCServletService.java b/src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/LocalVCServletService.java index 90d6a05706b2..d9ffeff3e0e9 100644 --- a/src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/LocalVCServletService.java +++ b/src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/LocalVCServletService.java @@ -621,15 +621,21 @@ public void processNewPush(String commitHash, Repository repository, Optional getProgrammingExercise(projectKey)); - RepositoryType repositoryType = getRepositoryType(repositoryTypeOrUserName, exercise); - - ProgrammingExerciseParticipation participation = cachedParticipation.orElseGet(() -> fetchParticipationFromLocalVCRepositoryUri(localVCRepositoryUri, exercise)); - ProgrammingExerciseParticipation participation; - if (repositoryType.equals(RepositoryType.AUXILIARY) || repositoryType.equals(RepositoryType.TESTS)) { - participation = retrieveSolutionParticipation(exercise); + RepositoryType repositoryType = getRepositoryTypeWithoutAuxiliary(repositoryTypeOrUserName, exercise); + ; + + try { + participation = cachedParticipation.orElseGet(() -> fetchParticipationFromLocalVCRepositoryUri(localVCRepositoryUri, exercise)); } - else { + catch (EntityNotFoundException e) { + repositoryType = getRepositoryType(repositoryTypeOrUserName, exercise); + if (repositoryType.equals(RepositoryType.AUXILIARY) || repositoryType.equals(RepositoryType.TESTS)) { + participation = retrieveSolutionParticipation(exercise); + } + else { + throw e; + } } try { @@ -766,19 +772,21 @@ else if (auxiliaryRepositoryService.isAuxiliaryRepositoryOfExercise(repositoryTy return RepositoryType.USER; } } - // - // private ProgrammingExerciseParticipation getProgrammingExerciseParticipation(LocalVCRepositoryUri localVCRepositoryUri, String repositoryTypeOrUserName, - // ProgrammingExercise exercise) { - // ProgrammingExerciseParticipation participation; - // try { - // participation = programmingExerciseParticipationService.retrieveParticipationWithSubmissionsByRepository(exercise, repositoryTypeOrUserName, - // localVCRepositoryUri.isPracticeRepository()); - // } - // catch (EntityNotFoundException e) { - // throw new VersionControlException("Could not find participation for repository " + repositoryTypeOrUserName + " of exercise " + exercise, e); - // } - // return participation; - // } + + private RepositoryType getRepositoryTypeWithoutAuxiliary(String repositoryTypeOrUserName, ProgrammingExercise exercise) { + if (repositoryTypeOrUserName.equals("exercise")) { + return RepositoryType.TEMPLATE; + } + else if (repositoryTypeOrUserName.equals("solution")) { + return RepositoryType.SOLUTION; + } + else if (repositoryTypeOrUserName.equals("tests")) { + return RepositoryType.TESTS; + } + else { + return RepositoryType.USER; + } + } /** * TODO: this could be done asynchronously to shorten the duration of the push operation