Search in sources :

Example 6 with Visibility

use of de.tum.in.www1.artemis.domain.enumeration.Visibility in project Artemis by ls1intum.

the class UserTestService method updateUserNotificationVisibilityShowAllAsStudentIsSuccessful.

// Test
public void updateUserNotificationVisibilityShowAllAsStudentIsSuccessful() throws Exception {
    request.put("/api/users/notification-visibility", true, HttpStatus.OK);
    User userInDB = userRepository.findOneByLogin("student1").get();
    assertThat(userInDB.getHideNotificationsUntil()).isNull();
}
Also used : User(de.tum.in.www1.artemis.domain.User)

Example 7 with Visibility

use of de.tum.in.www1.artemis.domain.enumeration.Visibility in project ArTEMiS by ls1intum.

the class ProgrammingExerciseTestCaseResource method updateTestCases.

/**
 * Update the changeable fields of the provided test case dtos.
 * We don't transfer the whole test case object here, because we need to make sure that only weights and visibility can be updated!
 * Will only return test case objects in the response that could be updated.
 *
 * @param exerciseId            of exercise the test cases belong to.
 * @param testCaseProgrammingExerciseTestCaseDTOS of the test cases to update the weights and visibility of.
 * @return the set of test cases for the given programming exercise.
 */
@PatchMapping(Endpoints.UPDATE_TEST_CASES)
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Set<ProgrammingExerciseTestCase>> updateTestCases(@PathVariable Long exerciseId, @RequestBody Set<ProgrammingExerciseTestCaseDTO> testCaseProgrammingExerciseTestCaseDTOS) {
    log.debug("REST request to update the weights {} of the exercise {}", testCaseProgrammingExerciseTestCaseDTOS, exerciseId);
    var programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationElseThrow(exerciseId);
    authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, programmingExercise, null);
    Set<ProgrammingExerciseTestCase> updatedTests = programmingExerciseTestCaseService.update(exerciseId, testCaseProgrammingExerciseTestCaseDTOS);
    // A test case is now marked as AFTER_DUE_DATE: a scheduled score update might be needed.
    if (updatedTests.stream().anyMatch(ProgrammingExerciseTestCase::isAfterDueDate)) {
        programmingExerciseService.scheduleOperations(programmingExercise.getId());
    }
    // We don't need the linked exercise here.
    for (ProgrammingExerciseTestCase testCase : updatedTests) {
        testCase.setExercise(null);
    }
    return ResponseEntity.ok(updatedTests);
}
Also used : ProgrammingExerciseTestCase(de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 8 with Visibility

use of de.tum.in.www1.artemis.domain.enumeration.Visibility in project ArTEMiS by ls1intum.

the class UserResource method updateUserNotificationVisibility.

/**
 * Updates the HideNotificationsUntil property that indicates which notifications to show (based on their creation date)
 *
 * @param showAllNotifications is true if all notifications should be displayed in the sidebar else depending on the HideNotificationsUntil property
 * @return void
 */
@PutMapping("users/notification-visibility")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Void> updateUserNotificationVisibility(@RequestBody boolean showAllNotifications) {
    log.debug("REST request to update notification visibility for logged-in user");
    User user = userRepository.getUser();
    // if all notifications (regardless of their creation date) should be shown hideUntil should be null
    ZonedDateTime hideUntil = showAllNotifications ? null : ZonedDateTime.now();
    userService.updateUserNotificationVisibility(user.getId(), hideUntil);
    return ResponseEntity.ok().build();
}
Also used : User(de.tum.in.www1.artemis.domain.User) ZonedDateTime(java.time.ZonedDateTime) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 9 with Visibility

use of de.tum.in.www1.artemis.domain.enumeration.Visibility in project ArTEMiS by ls1intum.

the class ProgrammingExerciseGradingServiceTest method shouldRecalculateScoreWithTestCaseBonusAndExerciseBonus.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void shouldRecalculateScoreWithTestCaseBonusAndExerciseBonus() {
    // Set up test cases with bonus
    var testCases = testCaseService.findByExerciseId(programmingExercise.getId()).stream().collect(Collectors.toMap(ProgrammingExerciseTestCase::getTestName, Function.identity()));
    testCases.get("test1").active(true).visibility(Visibility.ALWAYS).weight(4.).bonusMultiplier(1D).setBonusPoints(0D);
    testCases.get("test2").active(true).visibility(Visibility.ALWAYS).weight(3.).bonusMultiplier(3D).setBonusPoints(21D);
    testCases.get("test3").active(true).visibility(Visibility.ALWAYS).weight(3.).bonusMultiplier(2D).setBonusPoints(14D);
    testCaseRepository.saveAll(testCases.values());
    // Score should be capped at 200%
    programmingExercise.setBonusPoints(programmingExercise.getMaxPoints());
    programmingExerciseRepository.save(programmingExercise);
    Participation participation = database.addStudentParticipationForProgrammingExercise(programmingExercise, "student1");
    var result1 = new Result();
    result1.setParticipation(participation);
    result1 = updateAndSaveAutomaticResult(result1, false, false, true);
    var result2 = new Result();
    result2.setParticipation(participation);
    result2 = updateAndSaveAutomaticResult(result2, true, false, true);
    var result3 = new Result();
    result3.setParticipation(participation);
    result3 = updateAndSaveAutomaticResult(result3, true, true, false);
    var result4 = new Result();
    result4.setParticipation(participation);
    result4 = updateAndSaveAutomaticResult(result4, false, true, true);
    // Assertions result1 - calculated
    assertThat(result1.getScore()).isEqualTo(93.3333);
    assertThat(result1.getResultString()).isEqualTo("1 of 3 passed");
    assertThat(result1.getHasFeedback()).isTrue();
    assertThat(result1.isSuccessful()).isFalse();
    assertThat(result1.getFeedbacks()).hasSize(3);
    // Assertions result2 - calculated
    assertThat(result2.getScore()).isEqualTo(133.3333);
    assertThat(result2.getResultString()).isEqualTo("2 of 3 passed");
    assertThat(result2.getHasFeedback()).isTrue();
    assertThat(result2.isSuccessful()).isTrue();
    assertThat(result2.getFeedbacks()).hasSize(3);
    // Assertions result3 - calculated
    assertThat(result3.getScore()).isEqualTo(180D, Offset.offset(offsetByTenThousandth));
    assertThat(result3.getResultString()).isEqualTo("2 of 3 passed");
    assertThat(result3.getHasFeedback()).isTrue();
    assertThat(result3.isSuccessful()).isTrue();
    assertThat(result3.getFeedbacks()).hasSize(3);
    // Assertions result4 - capped at 200%
    assertThat(result4.getScore()).isEqualTo(200D);
    assertThat(result4.getResultString()).isEqualTo("2 of 3 passed");
    assertThat(result4.getHasFeedback()).isTrue();
    assertThat(result4.isSuccessful()).isTrue();
    assertThat(result4.getFeedbacks()).hasSize(3);
}
Also used : Participation(de.tum.in.www1.artemis.domain.participation.Participation) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) SolutionProgrammingExerciseParticipation(de.tum.in.www1.artemis.domain.participation.SolutionProgrammingExerciseParticipation) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with Visibility

use of de.tum.in.www1.artemis.domain.enumeration.Visibility in project ArTEMiS by ls1intum.

the class ProgrammingExerciseTestCaseService method update.

/**
 * Update the updatable attributes of the provided test case dtos. Returns an entry in the set for each test case that could be updated.
 *
 * @param exerciseId            of exercise the test cases belong to.
 * @param testCaseProgrammingExerciseTestCaseDTOS of the test cases to update the weights and visibility of.
 * @return the updated test cases.
 * @throws EntityNotFoundException if the programming exercise could not be found.
 */
public Set<ProgrammingExerciseTestCase> update(Long exerciseId, Set<ProgrammingExerciseTestCaseDTO> testCaseProgrammingExerciseTestCaseDTOS) throws EntityNotFoundException {
    ProgrammingExercise programmingExercise = programmingExerciseRepository.findWithTestCasesById(exerciseId).orElseThrow(() -> new EntityNotFoundException("Programming Exercise", exerciseId));
    Set<ProgrammingExerciseTestCase> existingTestCases = programmingExercise.getTestCases();
    Set<ProgrammingExerciseTestCase> updatedTests = new HashSet<>();
    for (ProgrammingExerciseTestCaseDTO programmingExerciseTestCaseDTO : testCaseProgrammingExerciseTestCaseDTOS) {
        Optional<ProgrammingExerciseTestCase> matchingTestCaseOpt = existingTestCases.stream().filter(testCase -> testCase.getId().equals(programmingExerciseTestCaseDTO.getId())).findFirst();
        if (matchingTestCaseOpt.isEmpty()) {
            continue;
        }
        ProgrammingExerciseTestCase matchingTestCase = matchingTestCaseOpt.get();
        matchingTestCase.setWeight(programmingExerciseTestCaseDTO.getWeight());
        matchingTestCase.setVisibility(programmingExerciseTestCaseDTO.getVisibility());
        matchingTestCase.setBonusMultiplier(programmingExerciseTestCaseDTO.getBonusMultiplier());
        matchingTestCase.setBonusPoints(programmingExerciseTestCaseDTO.getBonusPoints());
        validateTestCase(matchingTestCase);
        updatedTests.add(matchingTestCase);
    }
    if (!isTestCaseWeightSumValid(programmingExercise, existingTestCases)) {
        throw new BadRequestAlertException("The sum of all test case weights is 0 or below.", "TestCaseGrading", "weightSumError", true);
    }
    testCaseRepository.saveAll(updatedTests);
    programmingExerciseTaskService.updateTasksFromProblemStatement(programmingExercise);
    // At least one test was updated with a new weight or runAfterDueDate flag. We use this flag to inform the instructor about outdated student results.
    programmingSubmissionService.setTestCasesChangedAndTriggerTestCaseUpdate(exerciseId);
    return updatedTests;
}
Also used : java.util(java.util) Logger(org.slf4j.Logger) AuditEventRepository(org.springframework.boot.actuate.audit.AuditEventRepository) ProgrammingExerciseTestCaseType(de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseTestCaseType) ProgrammingLanguage(de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) LoggerFactory(org.slf4j.LoggerFactory) ProgrammingExerciseTestCaseRepository(de.tum.in.www1.artemis.repository.ProgrammingExerciseTestCaseRepository) Visibility(de.tum.in.www1.artemis.domain.enumeration.Visibility) AssessmentType(de.tum.in.www1.artemis.domain.enumeration.AssessmentType) Collectors(java.util.stream.Collectors) ProgrammingExerciseTestCaseDTO(de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO) Constants(de.tum.in.www1.artemis.config.Constants) ProgrammingExerciseRepository(de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository) ProgrammingExerciseTaskService(de.tum.in.www1.artemis.service.hestia.ProgrammingExerciseTaskService) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) ErrorConstants(de.tum.in.www1.artemis.web.rest.errors.ErrorConstants) AuditEvent(org.springframework.boot.actuate.audit.AuditEvent) Service(org.springframework.stereotype.Service) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) ProgrammingExerciseTestCaseDTO(de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO)

Aggregations

User (de.tum.in.www1.artemis.domain.User)6 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)4 Participation (de.tum.in.www1.artemis.domain.participation.Participation)4 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)4 SolutionProgrammingExerciseParticipation (de.tum.in.www1.artemis.domain.participation.SolutionProgrammingExerciseParticipation)4 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 Constants (de.tum.in.www1.artemis.config.Constants)2 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)2 ProgrammingExerciseTestCase (de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase)2 AssessmentType (de.tum.in.www1.artemis.domain.enumeration.AssessmentType)2 ProgrammingLanguage (de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage)2 Visibility (de.tum.in.www1.artemis.domain.enumeration.Visibility)2 ProgrammingExerciseTestCaseType (de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseTestCaseType)2 ProgrammingExerciseRepository (de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository)2 ProgrammingExerciseTestCaseRepository (de.tum.in.www1.artemis.repository.ProgrammingExerciseTestCaseRepository)2 ProgrammingExerciseTaskService (de.tum.in.www1.artemis.service.hestia.ProgrammingExerciseTaskService)2