Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iris: Answer questions about lecture slides #8636

Merged
merged 131 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
afa41c5
Ingestion Pipeline with status callback
yassinsws May 15, 2024
662a429
erase pyris status update dto because not used and will not be used
yassinsws May 15, 2024
cbcc0b3
Merge changes and make a button for admins to enable ingestion
yassinsws May 19, 2024
269cbb8
Merge remote-tracking branch 'origin/develop' into feature/iris/Final…
yassinsws May 19, 2024
b70e198
Add a longer timerout for the Job webhook Job
yassinsws May 20, 2024
819a355
Erase console logs
yassinsws May 20, 2024
11c9c02
Implement PR review remarks by timor. And change Lecture ingestion en…
yassinsws May 27, 2024
5539de0
Add a new Iris Subsettings
yassinsws May 27, 2024
3ccd29f
Change pyris webhook service to optional
yassinsws May 27, 2024
2d83e14
Fix tests
yassinsws May 27, 2024
cab46bf
Fix tests
yassinsws May 27, 2024
a454bad
Update src/main/webapp/app/entities/iris/settings/iris-sub-settings.m…
yassinsws May 27, 2024
ba90c2f
Update src/main/webapp/i18n/de/iris.json
yassinsws May 27, 2024
58c2814
rollback file
yassinsws May 27, 2024
73cb821
Update src/main/java/de/tum/in/www1/artemis/domain/iris/settings/Iris…
yassinsws May 27, 2024
2357431
Typo
yassinsws May 27, 2024
24b416e
fix typo
yassinsws May 27, 2024
f67cfc1
Fix failing tests
yassinsws May 28, 2024
33805d0
Make server tests
yassinsws May 28, 2024
3499242
Make Ingestion server tests on PyrisLectureIngestionTest
yassinsws May 28, 2024
b39d193
Erase test from LectureUnitIntegrationTest because mover to PyrisLect…
yassinsws May 28, 2024
81908d8
Test should not be public
yassinsws May 28, 2024
4a9fa5d
Split process attachments to two units
yassinsws May 29, 2024
ab19f57
Fix tests
yassinsws May 29, 2024
727ec1d
Merge branch 'develop' into feature/iris/FinalIngestionBranch
bassner May 30, 2024
9e7f4bc
erase where discriminator equals null to make tests pass ?
yassinsws May 30, 2024
37ce242
Merge remote-tracking branch 'origin/feature/iris/FinalIngestionBranc…
yassinsws May 30, 2024
0120624
revert migration file
yassinsws May 30, 2024
446c756
Erase PyrisLectureIngestionTest.java to locate the error
yassinsws May 30, 2024
8c9966e
Fix Pyris tests
yassinsws May 30, 2024
c247ac7
Fix Migration
yassinsws May 30, 2024
df06b54
Max review: Refractoring
yassinsws Jun 1, 2024
f70fdab
Max review: Refractoring
yassinsws Jun 1, 2024
6c7279a
liquibase file update
yassinsws Jun 1, 2024
ff25fac
Refractoring the class to test
yassinsws Jun 1, 2024
8417aec
Merge remote-tracking branch 'origin/develop' into feature/iris/Final…
yassinsws Jun 1, 2024
5305f8f
update PyrisStageState
yassinsws Jun 1, 2024
4cbbc7a
Fix style error
yassinsws Jun 1, 2024
7a62922
Merge branch 'develop' into feature/iris/FinalIngestionBranch
MaximilianAnzinger Jun 3, 2024
3711009
Kaan Review, refractor
yassinsws Jun 3, 2024
f869219
Merge remote-tracking branch 'origin/feature/iris/FinalIngestionBranc…
yassinsws Jun 3, 2024
c1081cc
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 3, 2024
23e353c
change NON_EMPTY TO NON_NULL
yassinsws Jun 3, 2024
ebcf922
Revert "change NON_EMPTY TO NON_NULL"
yassinsws Jun 3, 2024
8aee2ed
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 3, 2024
e1381e1
change var to Explicit declaration
yassinsws Jun 3, 2024
eac031c
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 3, 2024
9c2d08e
Merge remote-tracking branch 'origin/feature/iris/FinalIngestionBranc…
yassinsws Jun 3, 2024
adaf00e
Merge remote-tracking branch 'origin/feature/iris/FinalIngestionBranc…
yassinsws Jun 3, 2024
1d646d1
log error instead of throwing it.
yassinsws Jun 3, 2024
e8d37dd
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 3, 2024
a2058af
log error instead of throwing it.
yassinsws Jun 4, 2024
41a6028
Refractor code + add new tests
yassinsws Jun 5, 2024
20ea20d
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 5, 2024
4d6b5db
remove public from tests
yassinsws Jun 5, 2024
8926633
Merge remote-tracking branch 'origin/feature/iris/FinalIngestionBranc…
yassinsws Jun 5, 2024
87ef5ca
nullpointer exception edge case
yassinsws Jun 5, 2024
5593633
Merge remote-tracking branch 'origin/develop' into feature/iris/Final…
yassinsws Jun 5, 2024
9129e52
Solve merge conflicts
yassinsws Jun 5, 2024
8acb377
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 5, 2024
abd7164
Fix server tsts
yassinsws Jun 6, 2024
cfa76b1
Merge branch 'develop' into feature/iris/FinalIngestionBranch
bassner Jun 7, 2024
48b86a1
merge and make files only get sent to pyris when the are in pdf format
yassinsws Jun 7, 2024
c356f73
Merge remote-tracking branch 'origin/feature/iris/FinalIngestionBranc…
yassinsws Jun 8, 2024
4890abb
do not need a discriminator migration
yassinsws Jun 8, 2024
3561567
Add try catch Block to Ingestion
yassinsws Jun 8, 2024
f954a46
Add lecture ingestion settings, only ingest if auto ingestion is enab…
yassinsws Jun 9, 2024
af73012
merge
yassinsws Jun 9, 2024
1b8d239
lint
yassinsws Jun 9, 2024
6850710
Add send lectures automatically to iris button
yassinsws Jun 10, 2024
2fe1e17
always try to erase the course from pyris
yassinsws Jun 10, 2024
a47a269
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 10, 2024
ccbb64b
erase PyrisIngestionState for now
yassinsws Jun 10, 2024
1e513b0
Add 2 client test for send lecture button
yassinsws Jun 10, 2024
2013c97
Add client tests for iris-settings-update-component
yassinsws Jun 10, 2024
91388d9
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 10, 2024
681c459
refractoring
yassinsws Jun 10, 2024
66d89f3
Merge remote-tracking branch 'origin/feature/iris/FinalIngestionBranc…
yassinsws Jun 10, 2024
484742a
fix failing test
yassinsws Jun 10, 2024
8b21932
better error message
yassinsws Jun 10, 2024
4287dcd
Add checks for pdf files in the test
yassinsws Jun 11, 2024
750761c
Add test for ingest all button
yassinsws Jun 11, 2024
12a6b07
Add test for executeLectureWebhook
yassinsws Jun 11, 2024
7e7be0c
Add test for lecture autoingestion
yassinsws Jun 11, 2024
4802603
Add test for lecture autoingestion
yassinsws Jun 11, 2024
1efd1d5
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 11, 2024
2f7c70a
Refractor for tests
yassinsws Jun 11, 2024
1708f9a
Merge remote-tracking branch 'origin/feature/iris/FinalIngestionBranc…
yassinsws Jun 11, 2024
5997f37
Refractor for tests
yassinsws Jun 11, 2024
c3772f2
Add tests exceptions in ingestion job
yassinsws Jun 11, 2024
7d848d6
Erase Pyris state ingestion for now
yassinsws Jun 11, 2024
bc02ef9
Actualise change-set id
yassinsws Jun 12, 2024
1cc43fa
Reset database migration for now
yassinsws Jun 12, 2024
965aacc
refractor
yassinsws Jun 12, 2024
d4d6f82
refractor
yassinsws Jun 12, 2024
a8df13c
reset the liquibase file
yassinsws Jun 12, 2024
c122cb3
fix database migration for ts5?
yassinsws Jun 13, 2024
5c0eb06
fix database migration for ts5
yassinsws Jun 13, 2024
439e06c
reset database migration to the latest state
yassinsws Jun 13, 2024
fb353e0
add enable and diable send lectures to Iris when user is admin
yassinsws Jun 14, 2024
5cace0f
Add proper logging for the ingestion phases
yassinsws Jun 14, 2024
68a411f
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 14, 2024
8a08433
Added Logging when lecture sent to Pyris.
yassinsws Jun 14, 2024
0f9d9dc
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 14, 2024
05b636e
Handle Kaans' error, null pointer exception with getLecture ingestion
yassinsws Jun 14, 2024
2a9db64
Merge remote-tracking branch 'origin/feature/iris/FinalIngestionBranc…
yassinsws Jun 14, 2024
438b3c5
Implement kaans feedback, for the create lecture button to only appea…
yassinsws Jun 14, 2024
fcaea9c
refractor
yassinsws Jun 14, 2024
ee439da
add client tests
yassinsws Jun 14, 2024
8f4e7e8
Feature/iris/add button to ingest one lecture (#8796)
yassinsws Jun 15, 2024
cac1c77
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 15, 2024
7bdabac
refractor
yassinsws Jun 15, 2024
a515280
Add client tests
yassinsws Jun 15, 2024
14b0c00
erase one client test
yassinsws Jun 15, 2024
411dff5
ADD CLIENT TEST FOR INGEST LECTURES IN PYRIS
yassinsws Jun 15, 2024
5e0a034
ADD CLIENT TEST FOR INGEST LECTURES IN PYRIS
yassinsws Jun 15, 2024
9d80cbb
Fix inconsitency in method send lectures to iris
yassinsws Jun 15, 2024
9197076
Fix test
yassinsws Jun 15, 2024
4bcc6f3
Add tests for client side
yassinsws Jun 15, 2024
ca3f0c9
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 16, 2024
787a7a3
Apply suggestions from code review
yassinsws Jun 16, 2024
a34e46e
inject irisSettingsRepository as dependency and refractor code
yassinsws Jun 16, 2024
043fdb9
Update src/test/java/de/tum/in/www1/artemis/iris/PyrisLectureIngestio…
yassinsws Jun 16, 2024
1b4752a
inject irisSettingsRepository as dependency and refractor code
yassinsws Jun 16, 2024
f7ee13a
Merge remote-tracking branch 'origin/feature/iris/FinalIngestionBranc…
yassinsws Jun 16, 2024
6cc7b2f
merge
yassinsws Jun 16, 2024
31d5698
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 17, 2024
80471ed
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 18, 2024
98b275d
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 19, 2024
e942dcd
Merge branch 'develop' into feature/iris/FinalIngestionBranch
bassner Jun 21, 2024
735e529
Merge branch 'develop' into feature/iris/FinalIngestionBranch
yassinsws Jun 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public class IrisCourseSettings extends IrisSettings {
@JoinColumn(name = "iris_chat_settings_id")
private IrisChatSubSettings irisChatSettings;

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@JoinColumn(name = "iris_lecture_ingestion_settings_id")
private IrisLectureIngestionSubSettings irisLectureIngestionSettings;

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@JoinColumn(name = "iris_hestia_settings_id")
private IrisHestiaSubSettings irisHestiaSettings;
Expand All @@ -49,6 +53,16 @@ public void setCourse(Course course) {
this.course = course;
}

@Override
public IrisLectureIngestionSubSettings getIrisLectureIngestionSettings() {
return irisLectureIngestionSettings;
}

@Override
public void setIrisLectureIngestionSettings(IrisLectureIngestionSubSettings irisLectureIngestionSettings) {
this.irisLectureIngestionSettings = irisLectureIngestionSettings;
}

@Override
public IrisChatSubSettings getIrisChatSettings() {
return irisChatSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public void setExercise(Exercise exercise) {
this.exercise = exercise;
}

@Override
public IrisLectureIngestionSubSettings getIrisLectureIngestionSettings() {
return null;
}

@Override
public void setIrisLectureIngestionSettings(IrisLectureIngestionSubSettings irisLectureIngestionSettings) {
}
yassinsws marked this conversation as resolved.
Show resolved Hide resolved

@Override
public IrisChatSubSettings getIrisChatSettings() {
return irisChatSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ public class IrisGlobalSettings extends IrisSettings {
@Column(name = "enable_auto_update_hestia")
private boolean enableAutoUpdateHestia;

@Column(name = "enable_auto_update_lecture_ingestion")
private boolean enableAutoUpdateLectureIngestion;

@Column(name = "enable_auto_update_competency_generation")
private boolean enableAutoUpdateCompetencyGeneration;

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "iris_chat_settings_id")
private IrisChatSubSettings irisChatSettings;

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "iris_lecture_ingestion_settings_id")
private IrisLectureIngestionSubSettings irisLectureIngestionSettings;
yassinsws marked this conversation as resolved.
Show resolved Hide resolved

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "iris_hestia_settings_id")
private IrisHestiaSubSettings irisHestiaSettings;
Expand Down Expand Up @@ -74,6 +81,14 @@ public void setEnableAutoUpdateChat(boolean enableAutoUpdateChat) {
this.enableAutoUpdateChat = enableAutoUpdateChat;
}

public boolean isEnableAutoUpdateLectureIngestion() {
return enableAutoUpdateLectureIngestion;
}

public void setEnableAutoUpdateLectureIngestion(boolean enableAutoUpdateLectureIngestion) {
this.enableAutoUpdateLectureIngestion = enableAutoUpdateLectureIngestion;
}

public boolean isEnableAutoUpdateHestia() {
return enableAutoUpdateHestia;
}
Expand All @@ -90,6 +105,16 @@ public void setEnableAutoUpdateCompetencyGeneration(boolean enableAutoUpdateComp
this.enableAutoUpdateCompetencyGeneration = enableAutoUpdateCompetencyGeneration;
}

@Override
public IrisLectureIngestionSubSettings getIrisLectureIngestionSettings() {
return irisLectureIngestionSettings;
}

@Override
public void setIrisLectureIngestionSettings(IrisLectureIngestionSubSettings irisLectureIngestionSettings) {
this.irisLectureIngestionSettings = irisLectureIngestionSettings;
}

@Override
public IrisChatSubSettings getIrisChatSettings() {
return irisChatSettings;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.tum.in.www1.artemis.domain.iris.settings;

import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
* Represents the specific ingestion sub-settings of lectures for Iris.
* This class extends {@link IrisSubSettings} to provide settings required for lecture data ingestion.
*/
@Entity
@DiscriminatorValue("LECTURE_INGESTION")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class IrisLectureIngestionSubSettings extends IrisSubSettings {
yassinsws marked this conversation as resolved.
Show resolved Hide resolved

@Column(name = "auto_ingest_on_lecture_attachment_upload")
private boolean autoIngestOnLectureAttachmentUpload;

public boolean getAutoIngestOnLectureAttachmentUpload() {
return autoIngestOnLectureAttachmentUpload;
}

public void setAutoIngestOnLectureAttachmentUpload(boolean autoIngestOnLectureAttachmentUpload) {
this.autoIngestOnLectureAttachmentUpload = autoIngestOnLectureAttachmentUpload;
}
yassinsws marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public abstract class IrisSettings extends DomainObject {

public abstract void setIrisChatSettings(IrisChatSubSettings irisChatSettings);

public abstract IrisLectureIngestionSubSettings getIrisLectureIngestionSettings();

public abstract void setIrisLectureIngestionSettings(IrisLectureIngestionSubSettings irisLectureIngestionSettings);

public abstract IrisHestiaSubSettings getIrisHestiaSettings();

public abstract void setIrisHestiaSettings(IrisHestiaSubSettings irisHestiaSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
// @formatter:off
@JsonSubTypes({
@JsonSubTypes.Type(value = IrisChatSubSettings.class, name = "chat"),
@JsonSubTypes.Type(value = IrisLectureIngestionSubSettings.class, name = "lecture-ingestion"),
@JsonSubTypes.Type(value = IrisHestiaSubSettings.class, name = "hestia"),
@JsonSubTypes.Type(value = IrisCompetencyGenerationSubSettings.class, name = "competency-generation")
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package de.tum.in.www1.artemis.domain.iris.settings;

public enum IrisSubSettingsType {
CHAT, HESTIA, COMPETENCY_GENERATION
CHAT, HESTIA, COMPETENCY_GENERATION, LECTURE_INGESTION
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public interface IrisSettingsRepository extends ArtemisJpaRepository<IrisSetting
SELECT irisSettings
FROM IrisGlobalSettings irisSettings
LEFT JOIN FETCH irisSettings.irisChatSettings
LEFT JOIN FETCH irisSettings.irisLectureIngestionSettings
LEFT JOIN FETCH irisSettings.irisHestiaSettings
LEFT JOIN FETCH irisSettings.irisCompetencyGenerationSettings
""")
Expand All @@ -36,6 +37,7 @@ default IrisGlobalSettings findGlobalSettingsElseThrow() {
SELECT irisSettings
FROM IrisCourseSettings irisSettings
LEFT JOIN FETCH irisSettings.irisChatSettings
LEFT JOIN FETCH irisSettings.irisLectureIngestionSettings
LEFT JOIN FETCH irisSettings.irisHestiaSettings
LEFT JOIN FETCH irisSettings.irisCompetencyGenerationSettings
WHERE irisSettings.course.id = :courseId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.apache.commons.io.FilenameUtils;
import org.springframework.context.annotation.Profile;
Expand All @@ -20,6 +21,8 @@
import de.tum.in.www1.artemis.repository.AttachmentRepository;
import de.tum.in.www1.artemis.repository.AttachmentUnitRepository;
import de.tum.in.www1.artemis.repository.SlideRepository;
import de.tum.in.www1.artemis.repository.iris.IrisSettingsRepository;
import de.tum.in.www1.artemis.service.connectors.pyris.PyrisWebhookService;
import de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException;

@Profile(PROFILE_CORE)
Expand All @@ -36,13 +39,20 @@ public class AttachmentUnitService {

private final SlideRepository slideRepository;

private final Optional<PyrisWebhookService> pyrisWebhookService;

private final Optional<IrisSettingsRepository> irisSettingsRepository;

public AttachmentUnitService(SlideRepository slideRepository, SlideSplitterService slideSplitterService, AttachmentUnitRepository attachmentUnitRepository,
AttachmentRepository attachmentRepository, FileService fileService) {
AttachmentRepository attachmentRepository, FileService fileService, Optional<PyrisWebhookService> pyrisWebhookService,
Optional<IrisSettingsRepository> irisSettingsRepository) {
this.attachmentUnitRepository = attachmentUnitRepository;
this.attachmentRepository = attachmentRepository;
this.fileService = fileService;
this.slideSplitterService = slideSplitterService;
this.slideRepository = slideRepository;
this.pyrisWebhookService = pyrisWebhookService;
this.irisSettingsRepository = irisSettingsRepository;
yassinsws marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -70,7 +80,9 @@ public AttachmentUnit createAttachmentUnit(AttachmentUnit attachmentUnit, Attach
Attachment savedAttachment = attachmentRepository.saveAndFlush(attachment);
savedAttachmentUnit.setAttachment(savedAttachment);
evictCache(file, savedAttachmentUnit);

if (pyrisWebhookService.isPresent() && irisSettingsRepository.isPresent()) {
pyrisWebhookService.get().autoUpdateAttachmentUnitsInPyris(lecture.getCourse().getId(), List.of(savedAttachmentUnit));
}
return savedAttachmentUnit;
}

Expand Down Expand Up @@ -118,8 +130,10 @@ public AttachmentUnit updateAttachmentUnit(AttachmentUnit existingAttachmentUnit
if (Objects.equals(FilenameUtils.getExtension(updateFile.getOriginalFilename()), "pdf")) {
slideSplitterService.splitAttachmentUnitIntoSingleSlides(savedAttachmentUnit);
}
if (pyrisWebhookService.isPresent() && irisSettingsRepository.isPresent()) {
pyrisWebhookService.get().autoUpdateAttachmentUnitsInPyris(savedAttachmentUnit.getLecture().getCourse().getId(), List.of(savedAttachmentUnit));
}
}

return savedAttachmentUnit;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.apache.commons.io.FileUtils;
Expand All @@ -30,6 +31,8 @@
import de.tum.in.www1.artemis.repository.AttachmentRepository;
import de.tum.in.www1.artemis.repository.LectureRepository;
import de.tum.in.www1.artemis.repository.LectureUnitRepository;
import de.tum.in.www1.artemis.repository.iris.IrisSettingsRepository;
import de.tum.in.www1.artemis.service.connectors.pyris.PyrisWebhookService;

@Profile(PROFILE_CORE)
@Service
Expand All @@ -43,10 +46,17 @@ public class LectureImportService {

private final AttachmentRepository attachmentRepository;

public LectureImportService(LectureRepository lectureRepository, LectureUnitRepository lectureUnitRepository, AttachmentRepository attachmentRepository) {
private final Optional<PyrisWebhookService> pyrisWebhookService;

private final Optional<IrisSettingsRepository> irisSettingsRepository;

public LectureImportService(LectureRepository lectureRepository, LectureUnitRepository lectureUnitRepository, AttachmentRepository attachmentRepository,
Optional<PyrisWebhookService> pyrisWebhookService, Optional<IrisSettingsRepository> irisSettingsRepository) {
this.lectureRepository = lectureRepository;
this.lectureUnitRepository = lectureUnitRepository;
this.attachmentRepository = attachmentRepository;
this.pyrisWebhookService = pyrisWebhookService;
this.irisSettingsRepository = irisSettingsRepository;
yassinsws marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -92,7 +102,11 @@ public Lecture importLecture(final Lecture importedLecture, final Course course)
}
lecture.setAttachments(attachments);
attachmentRepository.saveAll(attachments);

// Send lectures to pyris
if (pyrisWebhookService.isPresent() && irisSettingsRepository.isPresent()) {
pyrisWebhookService.get().autoUpdateAttachmentUnitsInPyris(lecture.getCourse().getId(),
lectureUnits.stream().filter(lectureUnit -> lectureUnit instanceof AttachmentUnit).map(lectureUnit -> (AttachmentUnit) lectureUnit).toList());
}
// Save again to establish the ordered list relationship
return lectureRepository.save(lecture);
}
Expand Down Expand Up @@ -133,7 +147,6 @@ else if (importedLectureUnit instanceof AttachmentUnit importedAttachmentUnit) {
attachment.setAttachmentUnit(attachmentUnit);
attachmentRepository.save(attachment);
attachmentUnit.setAttachment(attachment);

return attachmentUnit;
}
else if (importedLectureUnit instanceof OnlineUnit importedOnlineUnit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.springframework.context.annotation.Profile;
Expand All @@ -21,6 +22,7 @@
import de.tum.in.www1.artemis.domain.metis.conversation.Channel;
import de.tum.in.www1.artemis.repository.LectureRepository;
import de.tum.in.www1.artemis.repository.metis.conversation.ChannelRepository;
import de.tum.in.www1.artemis.service.connectors.pyris.PyrisWebhookService;
import de.tum.in.www1.artemis.service.metis.conversation.ChannelService;
import de.tum.in.www1.artemis.web.rest.dto.SearchResultPageDTO;
import de.tum.in.www1.artemis.web.rest.dto.pageablesearch.SearchTermPageableSearchDTO;
Expand All @@ -38,11 +40,15 @@ public class LectureService {

private final ChannelService channelService;

public LectureService(LectureRepository lectureRepository, AuthorizationCheckService authCheckService, ChannelRepository channelRepository, ChannelService channelService) {
private final Optional<PyrisWebhookService> pyrisWebhookService;

public LectureService(LectureRepository lectureRepository, AuthorizationCheckService authCheckService, ChannelRepository channelRepository, ChannelService channelService,
Optional<PyrisWebhookService> pyrisWebhookService) {
this.lectureRepository = lectureRepository;
this.authCheckService = authCheckService;
this.channelRepository = channelRepository;
this.channelService = channelService;
this.pyrisWebhookService = pyrisWebhookService;
yassinsws marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -133,9 +139,33 @@ public SearchResultPageDTO<Lecture> getAllOnPageWithSize(final SearchTermPageabl
* @param lecture the lecture to be deleted
*/
public void delete(Lecture lecture) {
if (pyrisWebhookService.isPresent()) {
Lecture lectureWithAttachmentUnits = lectureRepository.findByIdWithLectureUnitsAndAttachmentsElseThrow(lecture.getId());
List<AttachmentUnit> attachmentUnitList = lectureWithAttachmentUnits.getLectureUnits().stream().filter(lectureUnit -> lectureUnit instanceof AttachmentUnit)
.map(lectureUnit -> (AttachmentUnit) lectureUnit).toList();
if (!attachmentUnitList.isEmpty()) {
Jan-Thurner marked this conversation as resolved.
Show resolved Hide resolved
pyrisWebhookService.get().deleteLectureFromPyrisDB(attachmentUnitList);
}
}
yassinsws marked this conversation as resolved.
Show resolved Hide resolved
Channel lectureChannel = channelRepository.findChannelByLectureId(lecture.getId());
channelService.deleteChannel(lectureChannel);
lectureRepository.deleteById(lecture.getId());
}

/**
* Ingest the lectures when triggered by the ingest lectures button
*
* @param lectures set of lectures to be ingested
* @return returns the job token if the operation is successful else it returns null
*/
public boolean ingestLecturesInPyris(Set<Lecture> lectures) {
Comment on lines +159 to +161
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a boolean is not a job token

if (pyrisWebhookService.isPresent()) {
List<AttachmentUnit> attachmentUnitList = lectures.stream().flatMap(lec -> lec.getLectureUnits().stream()).filter(unit -> unit instanceof AttachmentUnit)
yassinsws marked this conversation as resolved.
Show resolved Hide resolved
.map(unit -> (AttachmentUnit) unit).toList();
if (!attachmentUnitList.isEmpty()) {
return pyrisWebhookService.get().addLectureUnitsToPyrisDB(attachmentUnitList) != null;
}
}
return false;
}
yassinsws marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import de.tum.in.www1.artemis.repository.LectureUnitCompletionRepository;
import de.tum.in.www1.artemis.repository.LectureUnitRepository;
import de.tum.in.www1.artemis.repository.SlideRepository;
import de.tum.in.www1.artemis.service.connectors.pyris.PyrisWebhookService;

@Profile(PROFILE_CORE)
@Service
Expand All @@ -55,15 +56,19 @@ public class LectureUnitService {

private final ExerciseRepository exerciseRepository;

private final Optional<PyrisWebhookService> pyrisWebhookService;

public LectureUnitService(LectureUnitRepository lectureUnitRepository, LectureRepository lectureRepository, CompetencyRepository competencyRepository,
LectureUnitCompletionRepository lectureUnitCompletionRepository, FileService fileService, SlideRepository slideRepository, ExerciseRepository exerciseRepository) {
LectureUnitCompletionRepository lectureUnitCompletionRepository, FileService fileService, SlideRepository slideRepository, ExerciseRepository exerciseRepository,
Optional<PyrisWebhookService> pyrisWebhookService) {
this.lectureUnitRepository = lectureUnitRepository;
this.lectureRepository = lectureRepository;
this.competencyRepository = competencyRepository;
this.lectureUnitCompletionRepository = lectureUnitCompletionRepository;
this.fileService = fileService;
this.slideRepository = slideRepository;
this.exerciseRepository = exerciseRepository;
this.pyrisWebhookService = pyrisWebhookService;
yassinsws marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -162,6 +167,7 @@ public void removeLectureUnit(@NotNull LectureUnit lectureUnit) {
for (Slide slide : slides) {
fileService.schedulePathForDeletion(FilePathService.actualPathForPublicPathOrThrow(URI.create(slide.getSlideImagePath())), 5);
}
pyrisWebhookService.ifPresent(service -> service.deleteLectureFromPyrisDB(List.of(attachmentUnit)));
slideRepository.deleteAll(slides);
}
}
Expand Down
Loading
Loading