use of de.tum.in.www1.artemis.domain.modeling.ModelingSubmission in project ArTEMiS by ls1intum.
the class ModelingSubmissionResourceIntTest method updateModelingSubmission.
@Test
@Transactional
public void updateModelingSubmission() throws Exception {
// Initialize the database
modelingSubmissionRepository.saveAndFlush(modelingSubmission);
int databaseSizeBeforeUpdate = modelingSubmissionRepository.findAll().size();
// Update the modelingSubmission
ModelingSubmission updatedModelingSubmission = modelingSubmissionRepository.findOne(modelingSubmission.getId());
updatedModelingSubmission.submissionPath(UPDATED_SUBMISSION_PATH);
restModelingSubmissionMockMvc.perform(put("/api/modeling-submissions").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedModelingSubmission))).andExpect(status().isOk());
// Validate the ModelingSubmission in the database
List<ModelingSubmission> modelingSubmissionList = modelingSubmissionRepository.findAll();
assertThat(modelingSubmissionList).hasSize(databaseSizeBeforeUpdate);
ModelingSubmission testModelingSubmission = modelingSubmissionList.get(modelingSubmissionList.size() - 1);
assertThat(testModelingSubmission.getSubmissionPath()).isEqualTo(UPDATED_SUBMISSION_PATH);
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingSubmission in project ArTEMiS by ls1intum.
the class ModelingSubmissionResource method getModelingSubmission.
/**
* GET /modeling-submissions/:id : get the "id" modelingSubmission.
*
* @param id the id of the modelingSubmission to retrieve
* @return the ResponseEntity with status 200 (OK) and with body the modelingSubmission, or with status 404 (Not Found)
*/
@GetMapping("/modeling-submissions/{id}")
@Timed
public ResponseEntity<ModelingSubmission> getModelingSubmission(@PathVariable Long id) {
log.debug("REST request to get ModelingSubmission : {}", id);
ModelingSubmission modelingSubmission = modelingSubmissionRepository.findOne(id);
return ResponseUtil.wrapOrNotFound(Optional.ofNullable(modelingSubmission));
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingSubmission in project Artemis by ls1intum.
the class AssessmentKnowledgeIntegrationTest method testSetModelAssessmentKnowledgeToModelElements.
/**
* Tests that a ModelAssessmentKnowledge is correctly set to model elements
* based on the ModelAssessmentKnowledge of the respective exercise
*
* @throws Exception might be thrown from Network Call to Artemis API
*/
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testSetModelAssessmentKnowledgeToModelElements() throws Exception {
ModelingSubmission submission1 = ModelFactory.generateModelingSubmission(FileUtils.loadFileFromResources("test-data/model-submission/model.54727.json"), true);
submission1.setId(1L);
ModelingSubmission submission2 = ModelFactory.generateModelingSubmission(FileUtils.loadFileFromResources("test-data/model-submission/model.54727.cpy.json"), true);
submission2.setId(2L);
ModelingSubmission submission3 = ModelFactory.generateModelingSubmission(FileUtils.loadFileFromResources("test-data/model-submission/model.54727.cpy.json"), true);
submission3.setId(3L);
ModelingSubmission submission4 = ModelFactory.generateModelingSubmission(FileUtils.loadFileFromResources("test-data/model-submission/model.54727.cpy.json"), true);
submission4.setId(4L);
Course course = database.addEmptyCourse();
ModelingExercise exercise1 = modelingExerciseUtilService.createModelingExercise(course.getId());
ModelingExercise exercise2 = modelingExerciseUtilService.createModelingExercise(course.getId());
modelAssessmentKnowledgeService = new ModelAssessmentKnowledgeService(modelAssesmentKnowledgeRepository, modelingExerciseRepository);
exercise1.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
exercise2.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
ModelClusterFactory modelClusterFactory = new ModelClusterFactory();
List<ModelCluster> modelClusters1 = modelClusterFactory.buildClusters(List.of(submission1, submission2), exercise1);
List<ModelCluster> modelClusters2 = modelClusterFactory.buildClusters(List.of(submission3, submission4), exercise2);
ModelCluster modelCluster = modelClusters1.get(0);
for (ModelElement element : modelCluster.getModelElements()) {
assertThat(element.getKnowledge().getId()).isEqualTo(exercise1.getKnowledge().getId());
}
modelCluster = modelClusters2.get(0);
for (ModelElement element : modelCluster.getModelElements()) {
assertThat(element.getKnowledge().getId()).isEqualTo(exercise2.getKnowledge().getId());
}
assertThat(exercise1.getKnowledge().getId()).isNotEqualTo(exercise2.getKnowledge().getId());
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingSubmission 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.modeling.ModelingSubmission in project Artemis by ls1intum.
the class ProgrammingSubmissionIntegrationTest method triggerFailedBuildSubmissionNotFound.
@Test
@WithMockUser(username = "student1", roles = "USER")
void triggerFailedBuildSubmissionNotFound() throws Exception {
String login = "student1";
Course course = database.addCourseWithDifferentModelingExercises();
ModelingExercise classExercise = database.findModelingExerciseWithTitle(course.getExercises(), "ClassDiagram");
ModelingSubmission modelingSubmission = ModelFactory.generateModelingSubmission(FileUtils.loadFileFromResources("test-data/model-submission/empty-class-diagram.json"), true);
modelingSubmission = database.addModelingSubmission(classExercise, modelingSubmission, login);
String url = "/api/programming-submissions/" + modelingSubmission.getParticipation().getId() + "/trigger-failed-build";
request.postWithoutLocation(url, null, HttpStatus.NOT_FOUND, new HttpHeaders());
}
Aggregations