forked from ls1intum/Artemis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Programming exercises: Allow instructors to check the consistency of …
…repositories (version control) and build plans (continuous integration) (ls1intum#3840)
- Loading branch information
1 parent
b1de2af
commit b50de55
Showing
19 changed files
with
883 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/main/java/de/tum/in/www1/artemis/service/ConsistencyCheckService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package de.tum.in.www1.artemis.service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import de.tum.in.www1.artemis.domain.ProgrammingExercise; | ||
import de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository; | ||
import de.tum.in.www1.artemis.service.connectors.ContinuousIntegrationService; | ||
import de.tum.in.www1.artemis.service.connectors.VersionControlService; | ||
import de.tum.in.www1.artemis.service.dto.ConsistencyErrorDTO; | ||
|
||
/** | ||
* Service Implementation for consistency checks | ||
* of programming exercises | ||
*/ | ||
@Service | ||
public class ConsistencyCheckService { | ||
|
||
private final Optional<VersionControlService> versionControlService; | ||
|
||
private final Optional<ContinuousIntegrationService> continuousIntegrationService; | ||
|
||
private final ProgrammingExerciseRepository programmingExerciseRepository; | ||
|
||
public ConsistencyCheckService(Optional<VersionControlService> versionControlService, Optional<ContinuousIntegrationService> continuousIntegrationService, | ||
ProgrammingExerciseRepository programmingExerciseRepository) { | ||
this.versionControlService = versionControlService; | ||
this.continuousIntegrationService = continuousIntegrationService; | ||
this.programmingExerciseRepository = programmingExerciseRepository; | ||
} | ||
|
||
/** | ||
* Overloaded method for consistency checks, which retrieves the programming exercise before calling | ||
* the consistency checks method | ||
* | ||
* @param exerciseId of the programming exercise to check | ||
* @return List containing the resulting errors, if any. | ||
*/ | ||
public List<ConsistencyErrorDTO> checkConsistencyOfProgrammingExercise(long exerciseId) { | ||
ProgrammingExercise programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationElseThrow(exerciseId); | ||
|
||
return checkConsistencyOfProgrammingExercise(programmingExercise); | ||
} | ||
|
||
/** | ||
* Performs multiple checks for a given programming exercise and returns a list | ||
* of the resulting errors, if any. | ||
* | ||
* Make sure to load Template and Solution participations along with the programming exercise. | ||
* | ||
* Checks: | ||
* - Existence of VCS repositories and project | ||
* - Existence of CI build plans | ||
* | ||
* @param programmingExercise of the programming exercise to check | ||
* @return List containing the resulting errors, if any. | ||
*/ | ||
public List<ConsistencyErrorDTO> checkConsistencyOfProgrammingExercise(ProgrammingExercise programmingExercise) { | ||
List<ConsistencyErrorDTO> result = new ArrayList<>(); | ||
|
||
programmingExercise.checksAndSetsIfProgrammingExerciseIsLocalSimulation(); | ||
if (programmingExercise.getIsLocalSimulation()) { | ||
result.add(new ConsistencyErrorDTO(programmingExercise, ConsistencyErrorDTO.ErrorType.IS_LOCAL_SIMULATION)); | ||
return result; | ||
} | ||
|
||
result.addAll(checkVCSConsistency(programmingExercise)); | ||
result.addAll(checkCIConsistency(programmingExercise)); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Checks if a project and its repositories (TEMPLATE, TEST, SOLUTION) exists in the VCS | ||
* for a given programming exercise. | ||
* @param programmingExercise to check | ||
* @return List containing the resulting errors, if any. | ||
*/ | ||
private List<ConsistencyErrorDTO> checkVCSConsistency(ProgrammingExercise programmingExercise) { | ||
List<ConsistencyErrorDTO> result = new ArrayList<>(); | ||
|
||
if (!versionControlService.get().checkIfProjectExists(programmingExercise.getProjectKey(), programmingExercise.getProjectName())) { | ||
result.add(new ConsistencyErrorDTO(programmingExercise, ConsistencyErrorDTO.ErrorType.VCS_PROJECT_MISSING)); | ||
} | ||
else { | ||
if (!versionControlService.get().repositoryUrlIsValid(programmingExercise.getVcsTemplateRepositoryUrl())) { | ||
result.add(new ConsistencyErrorDTO(programmingExercise, ConsistencyErrorDTO.ErrorType.TEMPLATE_REPO_MISSING)); | ||
} | ||
if (!versionControlService.get().repositoryUrlIsValid(programmingExercise.getVcsTestRepositoryUrl())) { | ||
result.add(new ConsistencyErrorDTO(programmingExercise, ConsistencyErrorDTO.ErrorType.TEST_REPO_MISSING)); | ||
} | ||
if (!versionControlService.get().repositoryUrlIsValid(programmingExercise.getVcsSolutionRepositoryUrl())) { | ||
result.add(new ConsistencyErrorDTO(programmingExercise, ConsistencyErrorDTO.ErrorType.SOLUTION_REPO_MISSING)); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* Checks if build plans (TEMPLATE, SOLUTION) exist in the CI for a given | ||
* programming exercise. | ||
* @param programmingExercise to check | ||
* @return List containing the resulting errors, if any. | ||
*/ | ||
private List<ConsistencyErrorDTO> checkCIConsistency(ProgrammingExercise programmingExercise) { | ||
List<ConsistencyErrorDTO> result = new ArrayList<>(); | ||
|
||
if (!continuousIntegrationService.get().checkIfBuildPlanExists(programmingExercise.getProjectKey(), programmingExercise.getTemplateBuildPlanId())) { | ||
result.add(new ConsistencyErrorDTO(programmingExercise, ConsistencyErrorDTO.ErrorType.TEMPLATE_BUILD_PLAN_MISSING)); | ||
} | ||
if (!continuousIntegrationService.get().checkIfBuildPlanExists(programmingExercise.getProjectKey(), programmingExercise.getSolutionBuildPlanId())) { | ||
result.add(new ConsistencyErrorDTO(programmingExercise, ConsistencyErrorDTO.ErrorType.SOLUTION_BUILD_PLAN_MISSING)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/de/tum/in/www1/artemis/service/dto/ConsistencyErrorDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package de.tum.in.www1.artemis.service.dto; | ||
|
||
import java.util.Objects; | ||
|
||
import de.tum.in.www1.artemis.domain.ProgrammingExercise; | ||
|
||
/** | ||
* A DTO representing a consistency error | ||
*/ | ||
public class ConsistencyErrorDTO { | ||
|
||
private ProgrammingExercise programmingExercise; | ||
|
||
private ErrorType type; | ||
|
||
public ConsistencyErrorDTO(ProgrammingExercise programmingExercise, ErrorType type) { | ||
this.programmingExercise = programmingExercise; | ||
this.type = type; | ||
} | ||
|
||
public ProgrammingExercise getProgrammingExercise() { | ||
return programmingExercise; | ||
} | ||
|
||
public void setProgrammingExercise(ProgrammingExercise programmingExercise) { | ||
this.programmingExercise = programmingExercise; | ||
} | ||
|
||
public ErrorType getType() { | ||
return type; | ||
} | ||
|
||
public void setType(ErrorType type) { | ||
this.type = type; | ||
} | ||
|
||
public enum ErrorType { | ||
|
||
IS_LOCAL_SIMULATION("IS_LOCAL_SIMULATION"), VCS_PROJECT_MISSING("VCS_PROJECT_MISSING"), TEMPLATE_REPO_MISSING("TEMPLATE_REPO_MISSING"), | ||
SOLUTION_REPO_MISSING("SOLUTION_REPO_MISSING"), TEST_REPO_MISSING("TEST_REPO_MISSING"), TEMPLATE_BUILD_PLAN_MISSING("TEMPLATE_BUILD_PLAN_MISSING"), | ||
SOLUTION_BUILD_PLAN_MISSING("SOLUTION_BUILD_PLAN_MISSING"); | ||
|
||
ErrorType(final String value) { | ||
// This empty constructor is added to avoid Codacy issues | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (this == object) { | ||
return true; | ||
} | ||
if (object == null || getClass() != object.getClass()) { | ||
return false; | ||
} | ||
ConsistencyErrorDTO that = (ConsistencyErrorDTO) object; | ||
return Objects.equals(getProgrammingExercise(), that.getProgrammingExercise()) && getType() == that.getType(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getProgrammingExercise(), getType()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ConsistencyErrorDTO{" + "programmingExercise='" + programmingExercise.getTitle() + "', type='" + type.name() + "'}"; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/de/tum/in/www1/artemis/web/rest/ConsistencyCheckResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package de.tum.in.www1.artemis.web.rest; | ||
|
||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import de.tum.in.www1.artemis.domain.Exercise; | ||
import de.tum.in.www1.artemis.repository.ExerciseRepository; | ||
import de.tum.in.www1.artemis.security.Role; | ||
import de.tum.in.www1.artemis.service.AuthorizationCheckService; | ||
import de.tum.in.www1.artemis.service.ConsistencyCheckService; | ||
import de.tum.in.www1.artemis.service.dto.ConsistencyErrorDTO; | ||
|
||
/** | ||
* REST controller for consistency checks | ||
*/ | ||
@RestController | ||
@RequestMapping("api/") | ||
@PreAuthorize("hasRole('INSTRUCTOR')") | ||
public class ConsistencyCheckResource { | ||
|
||
private final Logger log = LoggerFactory.getLogger(ConsistencyCheckResource.class); | ||
|
||
private final AuthorizationCheckService authCheckService; | ||
|
||
private final ConsistencyCheckService consistencyCheckService; | ||
|
||
private final ExerciseRepository exerciseRepository; | ||
|
||
public ConsistencyCheckResource(AuthorizationCheckService authCheckService, ConsistencyCheckService consistencyCheckService, ExerciseRepository exerciseRepository) { | ||
this.authCheckService = authCheckService; | ||
this.consistencyCheckService = consistencyCheckService; | ||
this.exerciseRepository = exerciseRepository; | ||
} | ||
|
||
/** | ||
* GET programming-exercises/{programmingExerciseId}/consistency-check : request consistency check for a programming exercise | ||
* @param programmingExerciseId id of the exercise to check | ||
* @return List containing the resulting errors, if any. | ||
*/ | ||
@GetMapping("programming-exercises/{programmingExerciseId}/consistency-check") | ||
public ResponseEntity<List<ConsistencyErrorDTO>> checkConsistencyOfProgrammingExercise(@PathVariable long programmingExerciseId) { | ||
log.debug("REST request to check consistencies of programming exercise [{}]", programmingExerciseId); | ||
final Exercise exercise = exerciseRepository.findByIdElseThrow(programmingExerciseId); | ||
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.INSTRUCTOR, exercise, null); | ||
List<ConsistencyErrorDTO> result = consistencyCheckService.checkConsistencyOfProgrammingExercise(programmingExerciseId); | ||
return ResponseEntity.ok(result); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/webapp/app/entities/consistency-check-result.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { BaseEntity } from 'app/shared/model/base-entity'; | ||
import { ProgrammingExercise } from 'app/entities/programming-exercise.model'; | ||
|
||
export const enum ErrorType { | ||
TEMPLATE_REPO_MISSING = 'TEMPLATE_REPO_MISSING', | ||
SOLUTION_REPO_MISSING = 'SOLUTION_REPO_MISSING', | ||
TEST_REPO_MISSING = 'TEST_REPO_MISSING', | ||
TEMPLATE_BUILD_PLAN_MISSING = 'TEMPLATE_BUILD_PLAN_MISSING', | ||
SOLUTION_BUILD_PLAN_MISSING = 'SOLUTION_BUILD_PLAN_MISSING', | ||
} | ||
|
||
export class ConsistencyCheckError implements BaseEntity { | ||
public id?: number; | ||
public type?: ErrorType; | ||
public programmingExercise?: ProgrammingExercise; | ||
public programmingExerciseCourseId?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.