use of de.tum.in.www1.artemis.domain.Team in project ArTEMiS by ls1intum.
the class ScoreService method createNewTeamScore.
private void createNewTeamScore(Result newResult, StudentParticipation studentParticipation, Exercise exercise) {
TeamScore newTeamScore = new TeamScore();
newTeamScore.setExercise(exercise);
newTeamScore.setTeam(studentParticipation.getTeam().get());
setLastAttributes(newTeamScore, newResult, exercise);
if (newResult.isRated() != null && newResult.isRated()) {
setLastRatedAttributes(newTeamScore, newResult, exercise);
}
TeamScore teamScore = teamScoreRepository.saveAndFlush(newTeamScore);
logger.info("Saved a new team score: " + teamScore);
}
use of de.tum.in.www1.artemis.domain.Team in project ArTEMiS by ls1intum.
the class ProgrammingExerciseExportService method createZipForRepositoryWithParticipation.
/**
* Checks out the repository for the given participation, zips it and adds the path to the given list of already
* zipped repos.
*
* @param programmingExercise The programming exercise for the participation
* @param participation The participation, for which the repository should get zipped
* @param repositoryExportOptions The options, that should get applied to the zipped repo
* @param outputDir The directory used for downloading and zipping the repository
* @return The checked out and zipped repository
* @throws IOException if zip file creation failed
*/
private Path createZipForRepositoryWithParticipation(final ProgrammingExercise programmingExercise, final ProgrammingExerciseStudentParticipation participation, final RepositoryExportOptionsDTO repositoryExportOptions, Path outputDir) throws IOException, UncheckedIOException {
if (participation.getVcsRepositoryUrl() == null) {
log.warn("Ignore participation {} for export, because its repository URL is null", participation.getId());
return null;
}
try {
// Checkout the repository
Repository repository = gitService.getOrCheckoutRepository(participation, outputDir.toString());
if (repository == null) {
log.warn("Cannot checkout repository for participation id: {}", participation.getId());
return null;
}
gitService.resetToOriginHead(repository);
if (repositoryExportOptions.isFilterLateSubmissions()) {
filterLateSubmissions(repositoryExportOptions, participation, repository);
}
if (repositoryExportOptions.isAddParticipantName()) {
log.debug("Adding student or team name to participation {}", participation);
addParticipantIdentifierToProjectName(repository, programmingExercise, participation);
}
if (repositoryExportOptions.isCombineStudentCommits()) {
log.debug("Combining commits for participation {}", participation);
gitService.combineAllStudentCommits(repository, programmingExercise, repositoryExportOptions.isAnonymizeStudentCommits());
}
if (repositoryExportOptions.isAnonymizeStudentCommits()) {
log.debug("Anonymizing commits for participation {}", participation);
gitService.anonymizeStudentCommits(repository, programmingExercise);
}
if (repositoryExportOptions.isNormalizeCodeStyle()) {
try {
log.debug("Normalizing code style for participation {}", participation);
fileService.normalizeLineEndingsDirectory(repository.getLocalPath().toString());
fileService.convertToUTF8Directory(repository.getLocalPath().toString());
} catch (IOException ex) {
log.warn("Cannot normalize code style in the repository {} due to the following exception: {}", repository.getLocalPath(), ex.getMessage());
}
}
log.debug("Create temporary zip file for repository {}", repository.getLocalPath().toString());
return gitService.zipRepositoryWithParticipation(repository, outputDir.toString(), repositoryExportOptions.isHideStudentNameInZippedFolder());
} catch (GitAPIException | GitException ex) {
log.error("Failed to create zip for participation id {} with exercise id {} because of the following exception ", participation.getId(), participation.getProgrammingExercise().getId(), ex);
return null;
}
}
use of de.tum.in.www1.artemis.domain.Team in project ArTEMiS by ls1intum.
the class ParticipationTeamWebsocketService method updateSubmission.
/**
* Updates a modeling or text submission
*
* @param participationId id of participation
* @param submission updated modeling text submission
* @param principal principal of user who wants to update the submission
* @param topicPath path of websocket destination topic where to send the new submission
*/
private void updateSubmission(@DestinationVariable Long participationId, @Payload Submission submission, Principal principal, String topicPath) {
// Without this, custom jpa repository methods don't work in websocket channel.
SecurityUtils.setAuthorizationObject();
final StudentParticipation participation = studentParticipationRepository.findByIdElseThrow(participationId);
// user must belong to the team who owns the participation in order to update a submission
if (!participation.isOwnedBy(principal.getName())) {
return;
}
final User user = userRepository.getUserWithGroupsAndAuthorities(principal.getName());
final Exercise exercise = exerciseRepository.findByIdElseThrow(participation.getExercise().getId());
if (submission instanceof ModelingSubmission && exercise instanceof ModelingExercise) {
submission = modelingSubmissionService.save((ModelingSubmission) submission, (ModelingExercise) exercise, principal.getName());
modelingSubmissionService.hideDetails(submission, user);
} else if (submission instanceof TextSubmission && exercise instanceof TextExercise) {
submission = textSubmissionService.handleTextSubmission((TextSubmission) submission, (TextExercise) exercise, principal);
textSubmissionService.hideDetails(submission, user);
} else {
throw new IllegalArgumentException("Submission type '" + submission.getType() + "' not allowed.");
}
// update the last action date for the user and send out list of team members
updateValue(lastActionTracker, participationId, principal.getName());
sendOnlineTeamStudents(participationId);
SubmissionSyncPayload payload = new SubmissionSyncPayload(submission, user);
messagingTemplate.convertAndSend(getDestination(participationId, topicPath), payload);
}
use of de.tum.in.www1.artemis.domain.Team in project ArTEMiS by ls1intum.
the class ComplaintResource method getNumberOfAllowedComplaintsInCourse.
/**
* Get courses/{courseId}/allowed-complaints get the number of complaints that a student or team is still allowed to submit in the given course.
* It is determined by the max. complaint limit and the current number of open or rejected complaints of the student or team in the course.
* Students use their personal complaints for individual exercises and team complaints for team-based exercises, i.e. each student has
* maxComplaints for personal complaints and additionally maxTeamComplaints for complaints by their team in the course.
*
* @param courseId the id of the course for which we want to get the number of allowed complaints
* @param teamMode whether to return the number of allowed complaints per team (instead of per student)
* @return the ResponseEntity with status 200 (OK) and the number of still allowed complaints
*/
@GetMapping("courses/{courseId}/allowed-complaints")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Long> getNumberOfAllowedComplaintsInCourse(@PathVariable Long courseId, @RequestParam(defaultValue = "false") Boolean teamMode) {
log.debug("REST request to get the number of unaccepted Complaints associated to the current user in course : {}", courseId);
User user = userRepository.getUser();
Participant participant = user;
Course course = courseRepository.findByIdElseThrow(courseId);
if (!course.getComplaintsEnabled()) {
throw new BadRequestAlertException("Complaints are disabled for this course", COMPLAINT_ENTITY_NAME, "complaintsDisabled");
}
if (teamMode) {
Optional<Team> team = teamRepository.findAllByCourseIdAndUserIdOrderByIdDesc(course.getId(), user.getId()).stream().findFirst();
participant = team.orElseThrow(() -> new BadRequestAlertException("You do not belong to a team in this course.", COMPLAINT_ENTITY_NAME, "noAssignedTeamInCourse"));
}
long unacceptedComplaints = complaintService.countUnacceptedComplaintsByParticipantAndCourseId(participant, courseId);
return ResponseEntity.ok(Math.max(complaintService.getMaxComplaintsPerParticipant(course, participant) - unacceptedComplaints, 0));
}
use of de.tum.in.www1.artemis.domain.Team in project ArTEMiS by ls1intum.
the class LearningGoalIntegrationTest method getLearningGoalCourseProgressTeamsTest_asInstructorOne.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void getLearningGoalCourseProgressTeamsTest_asInstructorOne() throws Exception {
cleanUpInitialParticipations();
// will be ignored in favor of last submission from team
createParticipationSubmissionAndResult(idOfTeamTextExercise, teams.get(0), 10.0, 0.0, 100, true);
createParticipationSubmissionAndResult(idOfTeamTextExercise, teams.get(0), 10.0, 0.0, 50, false);
// will be ignored in favor of last submission from team
// will be ignored in favor of last submission from team
createParticipationSubmissionAndResult(idOfTeamTextExercise, teams.get(1), 10.0, 0.0, 100, true);
createParticipationSubmissionAndResult(idOfTeamTextExercise, teams.get(1), 10.0, 0.0, 10, false);
createParticipationSubmissionAndResult(idOfTeamTextExercise, teams.get(2), 10.0, 0.0, 10, true);
createParticipationSubmissionAndResult(idOfTeamTextExercise, teams.get(3), 10.0, 0.0, 50, true);
CourseLearningGoalProgress courseLearningGoalProgress = request.get("/api/courses/" + idOfCourse + "/goals/" + idOfLearningGoal + "/course-progress", HttpStatus.OK, CourseLearningGoalProgress.class);
assertThat(courseLearningGoalProgress.totalPointsAchievableByStudentsInLearningGoal).isEqualTo(30.0);
assertThat(courseLearningGoalProgress.averagePointsAchievedByStudentInLearningGoal).isEqualTo(3.0);
assertThatSpecificCourseLectureUnitProgressExists(courseLearningGoalProgress, 80.0, 4, 30);
}
Aggregations