use of de.tum.in.www1.artemis.domain.lecture.TextUnit in project Artemis by ls1intum.
the class LectureUnitIntegrationTest method updateLectureUnitOrder_asInstructorNewTextUnitInOrderedList_shouldReturnConflict.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateLectureUnitOrder_asInstructorNewTextUnitInOrderedList_shouldReturnConflict() throws Exception {
TextUnitList newlyOrderedList = new TextUnitList();
newlyOrderedList.add(textUnit);
newlyOrderedList.add(textUnit2);
newlyOrderedList.add(textUnit3);
for (TextUnit textUnit : newlyOrderedList) {
textUnit.setLecture(null);
}
request.put("/api/lectures/" + lecture1.getId() + "/lecture-units-order", List.of(), HttpStatus.CONFLICT);
}
use of de.tum.in.www1.artemis.domain.lecture.TextUnit in project Artemis by ls1intum.
the class LectureUnitIntegrationTest method updateLectureUnitOrder_asInstructor_shouldUpdateLectureUnitOrder.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateLectureUnitOrder_asInstructor_shouldUpdateLectureUnitOrder() throws Exception {
long idOfOriginalFirstPosition = lecture1.getLectureUnits().get(0).getId();
long idOfOriginalSecondPosition = lecture1.getLectureUnits().get(1).getId();
TextUnitList newlyOrderedList = new TextUnitList();
newlyOrderedList.add(textUnit);
newlyOrderedList.add(textUnit2);
for (TextUnit textUnit : newlyOrderedList) {
textUnit.setLecture(null);
}
Collections.swap(newlyOrderedList, 0, 1);
List<TextUnit> returnedList = request.putWithResponseBodyList("/api/lectures/" + lecture1.getId() + "/lecture-units-order", newlyOrderedList, TextUnit.class, HttpStatus.OK);
assertThat(returnedList.get(0).getId()).isEqualTo(idOfOriginalSecondPosition);
assertThat(returnedList.get(1).getId()).isEqualTo(idOfOriginalFirstPosition);
}
use of de.tum.in.www1.artemis.domain.lecture.TextUnit in project ArTEMiS by ls1intum.
the class LectureUnitIntegrationTest method updateLectureUnitOrder_asInstructor_shouldUpdateLectureUnitOrder.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateLectureUnitOrder_asInstructor_shouldUpdateLectureUnitOrder() throws Exception {
long idOfOriginalFirstPosition = lecture1.getLectureUnits().get(0).getId();
long idOfOriginalSecondPosition = lecture1.getLectureUnits().get(1).getId();
TextUnitList newlyOrderedList = new TextUnitList();
newlyOrderedList.add(textUnit);
newlyOrderedList.add(textUnit2);
for (TextUnit textUnit : newlyOrderedList) {
textUnit.setLecture(null);
}
Collections.swap(newlyOrderedList, 0, 1);
List<TextUnit> returnedList = request.putWithResponseBodyList("/api/lectures/" + lecture1.getId() + "/lecture-units-order", newlyOrderedList, TextUnit.class, HttpStatus.OK);
assertThat(returnedList.get(0).getId()).isEqualTo(idOfOriginalSecondPosition);
assertThat(returnedList.get(1).getId()).isEqualTo(idOfOriginalFirstPosition);
}
use of de.tum.in.www1.artemis.domain.lecture.TextUnit in project ArTEMiS by ls1intum.
the class LectureUnitIntegrationTest method updateLectureUnitOrder_asInstructorNewTextUnitInOrderedList_shouldReturnConflict.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateLectureUnitOrder_asInstructorNewTextUnitInOrderedList_shouldReturnConflict() throws Exception {
TextUnitList newlyOrderedList = new TextUnitList();
newlyOrderedList.add(textUnit);
newlyOrderedList.add(textUnit2);
newlyOrderedList.add(textUnit3);
for (TextUnit textUnit : newlyOrderedList) {
textUnit.setLecture(null);
}
request.put("/api/lectures/" + lecture1.getId() + "/lecture-units-order", List.of(), HttpStatus.CONFLICT);
}
use of de.tum.in.www1.artemis.domain.lecture.TextUnit in project ArTEMiS by ls1intum.
the class LectureImportService method cloneLectureUnit.
/**
* This helper function clones the {@code importedLectureUnit} and returns it
*
* @param importedLectureUnit The original lecture unit to be copied
* @param newLecture The new lecture to which the lecture units are appended
* @return The cloned lecture unit
*/
private LectureUnit cloneLectureUnit(final LectureUnit importedLectureUnit, final Lecture newLecture) {
log.debug("Creating a new LectureUnit from lecture unit {}", importedLectureUnit);
if (importedLectureUnit instanceof TextUnit) {
TextUnit textUnit = new TextUnit();
textUnit.setName(importedLectureUnit.getName());
textUnit.setReleaseDate(importedLectureUnit.getReleaseDate());
textUnit.setContent(((TextUnit) importedLectureUnit).getContent());
return textUnit;
} else if (importedLectureUnit instanceof VideoUnit) {
VideoUnit videoUnit = new VideoUnit();
videoUnit.setName(importedLectureUnit.getName());
videoUnit.setReleaseDate(importedLectureUnit.getReleaseDate());
videoUnit.setDescription(((VideoUnit) importedLectureUnit).getDescription());
videoUnit.setSource(((VideoUnit) importedLectureUnit).getSource());
return videoUnit;
} else if (importedLectureUnit instanceof AttachmentUnit) {
// Create and save the attachment unit, then the attachment itself, as the id is needed for file handling
AttachmentUnit attachmentUnit = new AttachmentUnit();
attachmentUnit.setDescription(((AttachmentUnit) importedLectureUnit).getDescription());
attachmentUnit.setLecture(newLecture);
lectureUnitRepository.save(attachmentUnit);
Attachment attachment = cloneAttachment(((AttachmentUnit) importedLectureUnit).getAttachment());
attachment.setAttachmentUnit(attachmentUnit);
attachmentRepository.save(attachment);
attachmentUnit.setAttachment(attachment);
return attachmentUnit;
} else if (importedLectureUnit instanceof ExerciseUnit) {
// We have a dedicated exercise import system, so this is left out for now
return null;
}
return null;
}
Aggregations