Skip to content

Commit

Permalink
Development: Add JavaDocs to UtilServices and Factories [10] (#7420)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikRemo authored Oct 20, 2023
1 parent c9d2120 commit 5a47e3c
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 14 deletions.
28 changes: 18 additions & 10 deletions src/test/java/de/tum/in/www1/artemis/lecture/LectureFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
*/
public class LectureFactory {

/**
* Generates a Lecture for the given Course.
*
* @param startDate The start date of the Lecture
* @param endDate The end date of the Lecture
* @param course The Course the Lecture belongs to
* @return The generated Lecture
*/
public static Lecture generateLecture(ZonedDateTime startDate, ZonedDateTime endDate, Course course) {
Lecture lecture = new Lecture();
lecture.setVisibleDate(startDate);
Expand All @@ -35,14 +43,14 @@ public static Lecture generateLecture(ZonedDateTime startDate, ZonedDateTime end
}

/**
* Create a dummy attachment unit for testing. Includes a dummy attachment with optional placeholder image file on disk
* Generates an AttachmentUnit with an Attachment. The Attachment can be created with or without a link to an image file.
*
* @param withFile Whether to include a placeholder image file on disk
* @return AttachmentUnit that was created
* @param withFile True, if the Attachment should link to a file
* @return The generated AttachmentUnit
*/
public static AttachmentUnit generateAttachmentUnit(boolean withFile) {
ZonedDateTime started = ZonedDateTime.now().minusDays(5);
Attachment attachmentOfAttachmentUnit = withFile ? LectureFactory.generateAttachmentWithFile(started) : LectureFactory.generateAttachment(started);
Attachment attachmentOfAttachmentUnit = withFile ? generateAttachmentWithFile(started) : generateAttachment(started);
AttachmentUnit attachmentUnit = new AttachmentUnit();
attachmentUnit.setDescription("Lorem Ipsum");
attachmentOfAttachmentUnit.setAttachmentUnit(attachmentUnit);
Expand All @@ -51,10 +59,10 @@ public static AttachmentUnit generateAttachmentUnit(boolean withFile) {
}

/**
* Create a dummy attachment for testing
* Generates an Attachment with AttachmentType FILE.
*
* @param date The optional upload and release date to set on the attachment
* @return Attachment that was created
* @param date The optional upload and release date of the Attachment
* @return The generated Attachment
*/
public static Attachment generateAttachment(ZonedDateTime date) {
Attachment attachment = new Attachment();
Expand All @@ -69,10 +77,10 @@ public static Attachment generateAttachment(ZonedDateTime date) {
}

/**
* Create a dummy attachment for testing with a placeholder image file on disk
* Generates an Attachment with AttachmentType FILE and a link to an image file.
*
* @param startDate The release date to set on the attachment
* @return Attachment that was created with its link set to a testing file on disk
* @param startDate The optional upload and release date of the Attachment
* @return The generated Attachment
*/
public static Attachment generateAttachmentWithFile(ZonedDateTime startDate) {
Attachment attachment = generateAttachment(startDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public class LectureUtilService {
@Autowired
private LectureUnitCompletionRepository lectureUnitCompletionRepository;

/**
* Creates and saves a Course with a Lecture. The Lecture is only saved optionally. The Lecture is empty as it does not contain any LectureUnits.
*
* @param saveLecture True, if the Lecture should be saved
* @return The created Lecture
*/
public Lecture createCourseWithLecture(boolean saveLecture) {
Course course = CourseFactory.generateCourse(null, pastTimestamp, futureFutureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");

Expand All @@ -87,6 +93,13 @@ public Lecture createCourseWithLecture(boolean saveLecture) {
return lecture;
}

/**
* Creates and saves a Lecture for the given Course. The Lecture is empty as it does not contain any LectureUnits.
*
* @param course The Course the Lecture belongs to
* @param visibleDate The visible date of the Lecture
* @return The created Lecture
*/
public Lecture createLecture(Course course, ZonedDateTime visibleDate) {
Lecture lecture = new Lecture();
lecture.setDescription("Test Lecture");
Expand All @@ -96,6 +109,16 @@ public Lecture createLecture(Course course, ZonedDateTime visibleDate) {
return lecture;
}

/**
* Creates and saves two Courses with Exercises of each type and two Lectures. For each Lecture, a LectureUnit of each type is added.
*
* @param userPrefix The prefix of the Course's user groups
* @param withParticipations True, if 5 participations by student1 should be added for the Course's Exercises
* @param withFiles True, if the LectureUnit of type AttachmentUnit should contain an Attachment with a link to an image file
* @param numberOfTutorParticipations The number of tutor participations to add to the ModelingExercise ("withParticipations" must be true for this to have an effect)
* @return A List of the created Courses
* @throws IOException If a file cannot be loaded from resources
*/
public List<Course> createCoursesWithExercisesAndLecturesAndLectureUnits(String userPrefix, boolean withParticipations, boolean withFiles, int numberOfTutorParticipations)
throws IOException {
List<Course> courses = courseUtilService.createCoursesWithExercisesAndLectures(userPrefix, withParticipations, withFiles, numberOfTutorParticipations);
Expand All @@ -113,6 +136,13 @@ public List<Course> createCoursesWithExercisesAndLecturesAndLectureUnits(String
}).toList();
}

/**
* Adds the given Competencies to all LectureUnits of the given Lecture and saves the updated LectureUnits.
*
* @param lecture The Lecture whose LectureUnits should be updated
* @param competencies The Competencies to add to the LectureUnits
* @return The Lecture with updated LectureUnits
*/
public Lecture addCompetencyToLectureUnits(Lecture lecture, Set<Competency> competencies) {
Lecture l = lectureRepo.findByIdWithLectureUnitsAndCompetenciesElseThrow(lecture.getId());
l.getLectureUnits().forEach(lectureUnit -> {
Expand All @@ -122,6 +152,13 @@ public Lecture addCompetencyToLectureUnits(Lecture lecture, Set<Competency> comp
return l;
}

/**
* Adds the given LectureUnits to the given Lecture and saves the updated Lecture.
*
* @param lecture The Lecture to add the LectureUnits to
* @param lectureUnits The LectureUnits to add to the Lecture
* @return The updated Lecture
*/
public Lecture addLectureUnitsToLecture(Lecture lecture, List<LectureUnit> lectureUnits) {
Lecture l = lectureRepo.findByIdWithLectureUnits(lecture.getId()).orElseThrow();
for (LectureUnit lectureUnit : lectureUnits) {
Expand All @@ -130,18 +167,36 @@ public Lecture addLectureUnitsToLecture(Lecture lecture, List<LectureUnit> lectu
return lectureRepo.save(l);
}

/**
* Creates and saves a Channel for the given Lecture.
*
* @param lecture The Lecture the Channel belongs to
* @return The created Channel
*/
public Channel addLectureChannel(Lecture lecture) {
Channel channel = ConversationFactory.generateCourseWideChannel(lecture.getCourse());
channel.setLecture(lecture);
return conversationRepository.save(channel);
}

/**
* Creates and saves an ExerciseUnit for the given Exercise.
*
* @param exercise The Exercise the ExerciseUnit belongs to
* @return The created ExerciseUnit
*/
public ExerciseUnit createExerciseUnit(Exercise exercise) {
ExerciseUnit exerciseUnit = new ExerciseUnit();
exerciseUnit.setExercise(exercise);
return exerciseUnitRepository.save(exerciseUnit);
}

/**
* Creates and saves an AttachmentUnit with an Attachment. The Attachment can be created with or without a link to an image file.
*
* @param withFile True, if the Attachment should link to a file
* @return The created AttachmentUnit
*/
public AttachmentUnit createAttachmentUnit(Boolean withFile) {
ZonedDateTime started = ZonedDateTime.now().minusDays(5);
Attachment attachmentOfAttachmentUnit = withFile ? LectureFactory.generateAttachmentWithFile(started) : LectureFactory.generateAttachment(started);
Expand All @@ -154,6 +209,12 @@ public AttachmentUnit createAttachmentUnit(Boolean withFile) {
return attachmentUnitRepository.save(attachmentUnit);
}

/**
* Creates and saves an AttachmentUnit with an Attachment. Also creates and saves the given number of Slides for the AttachmentUnit. The Slides link to image files.
*
* @param numberOfSlides The number of Slides to create
* @return The created AttachmentUnit
*/
public AttachmentUnit createAttachmentUnitWithSlides(int numberOfSlides) {
ZonedDateTime started = ZonedDateTime.now().minusDays(5);
Attachment attachmentOfAttachmentUnit = LectureFactory.generateAttachment(started);
Expand All @@ -180,20 +241,35 @@ public AttachmentUnit createAttachmentUnitWithSlides(int numberOfSlides) {
return attachmentUnitRepository.save(attachmentUnit);
}

/**
* Creates and saves a TextUnit.
*
* @return The created TextUnit
*/
public TextUnit createTextUnit() {
TextUnit textUnit = new TextUnit();
textUnit.setName("Name Lorem Ipsum");
textUnit.setContent("Lorem Ipsum");
return textUnitRepository.save(textUnit);
}

/**
* Creates and saves a VideoUnit.
*
* @return The created VideoUnit
*/
public VideoUnit createVideoUnit() {
VideoUnit videoUnit = new VideoUnit();
videoUnit.setDescription("Lorem Ipsum");
videoUnit.setSource("http://video.fake");
return videoUnitRepository.save(videoUnit);
}

/**
* Creates and saves an OnlineUnit.
*
* @return The created OnlineUnit
*/
public OnlineUnit createOnlineUnit() {
OnlineUnit onlineUnit = new OnlineUnit();
onlineUnit.setDescription("Lorem Ipsum");
Expand All @@ -202,11 +278,11 @@ public OnlineUnit createOnlineUnit() {
}

/**
* Creates lecture unit completion entry for the user and the specified lecture unit
* Creates and saves a LectureUnitCompletion entry for the given LectureUnit and User.
*
* @param lectureUnit the lecture unit that should be completed by the user
* @param user the user that has completed the lecture unit
* @return the updated lecture unit
* @param lectureUnit The LectureUnit that has been completed
* @param user The User that completed the LectureUnit
* @return The completed LectureUnit
*/
public LectureUnit completeLectureUnitForUser(LectureUnit lectureUnit, User user) {
var lectureUnitCompletion = new LectureUnitCompletion();
Expand Down

0 comments on commit 5a47e3c

Please sign in to comment.