From d0cbf6df4ffb255dbd0a4a666e55ee1b0052cb92 Mon Sep 17 00:00:00 2001 From: Tim Cremer Date: Fri, 17 Jan 2025 17:22:45 +0100 Subject: [PATCH] Updated comments and names --- .../communication/web/FaqResource.java | 4 +--- .../settings/IrisFaqIngestionSubSettings.java | 4 ++-- .../service/pyris/PyrisConnectorService.java | 2 +- .../iris/service/pyris/PyrisJobService.java | 4 +++- .../pyris/PyrisStatusUpdateService.java | 2 +- .../service/pyris/PyrisWebhookService.java | 17 +++++++++++++++-- .../PyrisFaqWebhookDTO.java | 4 ++-- .../service/settings/IrisSettingsService.java | 19 ++++++++++++++++--- .../settings/IrisSubSettingsService.java | 4 ++-- .../spec/component/faq/faq.component.spec.ts | 2 +- .../spec/service/faq.service.spec.ts | 2 +- 11 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/web/FaqResource.java b/src/main/java/de/tum/cit/aet/artemis/communication/web/FaqResource.java index 1338bf7987af..d267d13357da 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/web/FaqResource.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/web/FaqResource.java @@ -40,7 +40,6 @@ import de.tum.cit.aet.artemis.core.security.annotations.enforceRoleInCourse.EnforceAtLeastTutorInCourse; import de.tum.cit.aet.artemis.core.service.AuthorizationCheckService; import de.tum.cit.aet.artemis.core.util.HeaderUtil; -import de.tum.cit.aet.artemis.iris.service.settings.IrisSettingsService; /** * REST controller for managing Faqs. @@ -65,8 +64,7 @@ public class FaqResource { private final FaqService faqService; - public FaqResource(CourseRepository courseRepository, AuthorizationCheckService authCheckService, FaqRepository faqRepository, FaqService faqService, - Optional irisSettingsService) { + public FaqResource(CourseRepository courseRepository, AuthorizationCheckService authCheckService, FaqRepository faqRepository, FaqService faqService) { this.faqRepository = faqRepository; this.courseRepository = courseRepository; this.authCheckService = authCheckService; diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/domain/settings/IrisFaqIngestionSubSettings.java b/src/main/java/de/tum/cit/aet/artemis/iris/domain/settings/IrisFaqIngestionSubSettings.java index 49ad759ef33b..fe344e1b8d97 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/domain/settings/IrisFaqIngestionSubSettings.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/domain/settings/IrisFaqIngestionSubSettings.java @@ -22,8 +22,8 @@ public boolean getAutoIngestOnFaqCreation() { return autoIngestOnFaqCreation; } - public void setAutoIngestOnFaqCreation(boolean autoIngestOnLectureAttachmentUpload) { - this.autoIngestOnFaqCreation = autoIngestOnLectureAttachmentUpload; + public void setAutoIngestOnFaqCreation(boolean autoIngestOnFaqCreation) { + this.autoIngestOnFaqCreation = autoIngestOnFaqCreation; } } diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisConnectorService.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisConnectorService.java index 2d5ec6d0e3c6..a7ac1119511d 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisConnectorService.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisConnectorService.java @@ -240,7 +240,7 @@ public void executeFaqDeletionWebhook(PyrisWebhookFaqDeletionExecutionDTO execut } /** - * Retrieves the ingestion state of the lecture unit specified by retrieving the ingestion state from the vector database in Pyris. + * Retrieves the ingestion state of the faq specified by retrieving the ingestion state from the vector database in Pyris. * * @param courseId id of the course * @return The ingestion state of the faq diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisJobService.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisJobService.java index 0bfec287116f..3e9b660e5902 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisJobService.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisJobService.java @@ -119,7 +119,9 @@ public String addLectureIngestionWebhookJob(long courseId, long lectureId, long public String addFaqIngestionWebhookJob(long courseId, long faqId) { var token = generateJobIdToken(); var job = new FaqIngestionWebhookJob(token, courseId, faqId); - jobMap.put(token, job); + long timeoutWebhookJob = 60; + TimeUnit unitWebhookJob = TimeUnit.MINUTES; + jobMap.put(token, job, timeoutWebhookJob, unitWebhookJob); return token; } diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisStatusUpdateService.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisStatusUpdateService.java index 416154f73049..f763555f3957 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisStatusUpdateService.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisStatusUpdateService.java @@ -138,7 +138,7 @@ public void handleStatusUpdate(LectureIngestionWebhookJob job, PyrisLectureInges } /** - * Handles the status update of a lecture ingestion job. + * Handles the status update of a FAQ ingestion job. * * @param job the job that is updated * @param statusUpdate the status update diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisWebhookService.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisWebhookService.java index 65224c4d4301..b9eaff381656 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisWebhookService.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisWebhookService.java @@ -251,7 +251,7 @@ private boolean faqIngestionEnabled(Course course) { } /** - * send the updated / created attachment to Pyris for ingestion if autoLecturesUpdate is enabled + * send the updated / created faqs to Pyris for ingestion if autoLecturesUpdate is enabled * * @param courseId Id of the course where the attachment is added * @param newFaq the new faqs to be sent to pyris for ingestion @@ -265,7 +265,7 @@ public void autoUpdateFaqInPyris(Long courseId, Faq newFaq) { } /** - * adds the lectures to the vector database in Pyris + * adds the faq to the vector database in Pyris * * @param faq The faq that got Updated * @return jobToken if the job was created else null @@ -278,6 +278,13 @@ public String addFaqToPyris(Faq faq) { return null; } + /** + * executes the faq addition webhook to add faq to the vector database on pyris + * + * @param toUpdateFaq The faq that got Updated as webhook DTO + * @return jobToken if the job was created else null + */ + private String executeFaqAdditionWebhook(PyrisFaqWebhookDTO toUpdateFaq) { String jobToken = pyrisJobService.addFaqIngestionWebhookJob(toUpdateFaq.courseId(), toUpdateFaq.faqId()); PyrisPipelineExecutionSettingsDTO settingsDTO = new PyrisPipelineExecutionSettingsDTO(jobToken, List.of(), artemisBaseUrl); @@ -299,6 +306,12 @@ public String deleteFaqFromPyrisDB(Faq faq) { } + /** + * executes the faq deletion webhook to delete faq from the vector database on pyris + * + * @param toUpdateFaqs The faq that got Updated as webhook DTO + * @return jobToken if the job was created else null + */ private String executeFaqDeletionWebhook(PyrisFaqWebhookDTO toUpdateFaqs) { String jobToken = pyrisJobService.addFaqIngestionWebhookJob(0, 0); PyrisPipelineExecutionSettingsDTO settingsDTO = new PyrisPipelineExecutionSettingsDTO(jobToken, List.of(), artemisBaseUrl); diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/dto/faqingestionwebhook/PyrisFaqWebhookDTO.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/dto/faqingestionwebhook/PyrisFaqWebhookDTO.java index 25f11b6da8f5..4387daa03364 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/dto/faqingestionwebhook/PyrisFaqWebhookDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/dto/faqingestionwebhook/PyrisFaqWebhookDTO.java @@ -4,8 +4,8 @@ /** * Represents a webhook data transfer object for an FAQ in the Pyris system. - * This DTO is used to encapsulate the information related to updates of lecture units, - * providing necessary details such as lecture and course identifiers, names, and descriptions. + * This DTO is used to encapsulate the information related to the faqs + * providing necessary details such as faqId the content as questionTitle and questionAnswer as well as the course description. */ @JsonInclude(JsonInclude.Include.NON_EMPTY) diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/settings/IrisSettingsService.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/settings/IrisSettingsService.java index 438e2242d21a..6a1d4457c11f 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/settings/IrisSettingsService.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/settings/IrisSettingsService.java @@ -158,10 +158,23 @@ private void initializeIrisCompetencyGenerationSettings(IrisGlobalSettings setti settings.setIrisCompetencyGenerationSettings(irisCompetencyGenerationSettings); } + /** + * Get the combined Iris settings for a course. + * Combines the global settings with the course settings. + * + * @return The combined Iris settings for the course + */ public IrisGlobalSettings getGlobalSettings() { return irisSettingsRepository.findGlobalSettingsElseThrow(); } + /** + * Get the combined Iris settings for a course. + * Combines the global settings with the course settings. + * + * @param settings The course settings + * @return The combined Iris settings for the course + */ private void initializeIrisFaqIngestionSettings(IrisGlobalSettings settings) { var irisFaqIngestionSubSettings = settings.getIrisFaqIngestionSettings(); irisFaqIngestionSubSettings = initializeSettings(irisFaqIngestionSubSettings, IrisFaqIngestionSubSettings::new); @@ -606,7 +619,7 @@ public IrisCombinedSettingsDTO getCombinedIrisGlobalSettings() { irisSubSettingsService.combineCourseChatSettings(settingsList, false), irisSubSettingsService.combineLectureIngestionSubSettings(settingsList, false), irisSubSettingsService.combineCompetencyGenerationSettings(settingsList, false), - irisSubSettingsService.combinceFaqIngestionSubSettings(settingsList, false) + irisSubSettingsService.combineFaqIngestionSubSettings(settingsList, false) ); // @formatter:on } @@ -633,7 +646,7 @@ public IrisCombinedSettingsDTO getCombinedIrisSettingsFor(Course course, boolean irisSubSettingsService.combineCourseChatSettings(settingsList, minimal), irisSubSettingsService.combineLectureIngestionSubSettings(settingsList, minimal), irisSubSettingsService.combineCompetencyGenerationSettings(settingsList, minimal), - irisSubSettingsService.combinceFaqIngestionSubSettings(settingsList, minimal) + irisSubSettingsService.combineFaqIngestionSubSettings(settingsList, minimal) ); // @formatter:on } @@ -661,7 +674,7 @@ public IrisCombinedSettingsDTO getCombinedIrisSettingsFor(Exercise exercise, boo irisSubSettingsService.combineCourseChatSettings(settingsList, minimal), irisSubSettingsService.combineLectureIngestionSubSettings(settingsList, minimal), irisSubSettingsService.combineCompetencyGenerationSettings(settingsList, minimal), - irisSubSettingsService.combinceFaqIngestionSubSettings(settingsList, minimal) + irisSubSettingsService.combineFaqIngestionSubSettings(settingsList, minimal) ); // @formatter:on } diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/settings/IrisSubSettingsService.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/settings/IrisSubSettingsService.java index 6823ea0e3186..76c12b6ec62d 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/settings/IrisSubSettingsService.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/settings/IrisSubSettingsService.java @@ -368,7 +368,7 @@ public IrisCombinedLectureIngestionSubSettingsDTO combineLectureIngestionSubSett } /** - * Combines the Lecture Ingestion settings of multiple {@link IrisSettings} objects. + * Combines the FAQ Ingestion settings of multiple {@link IrisSettings} objects. * If minimal is true, the returned object will only contain the enabled and rateLimit fields. * The minimal version can safely be sent to students. * @@ -376,7 +376,7 @@ public IrisCombinedLectureIngestionSubSettingsDTO combineLectureIngestionSubSett * @param minimal Whether to return a minimal version of the combined settings. * @return Combined Lecture Ingestion settings. */ - public IrisCombinedFaqIngestionSubSettingsDTO combinceFaqIngestionSubSettings(ArrayList settingsList, boolean minimal) { + public IrisCombinedFaqIngestionSubSettingsDTO combineFaqIngestionSubSettings(ArrayList settingsList, boolean minimal) { var enabled = getCombinedEnabled(settingsList, IrisSettings::getIrisFaqIngestionSettings); return new IrisCombinedFaqIngestionSubSettingsDTO(enabled); } diff --git a/src/test/javascript/spec/component/faq/faq.component.spec.ts b/src/test/javascript/spec/component/faq/faq.component.spec.ts index e7c6288ccd67..f345c9ff6650 100644 --- a/src/test/javascript/spec/component/faq/faq.component.spec.ts +++ b/src/test/javascript/spec/component/faq/faq.component.spec.ts @@ -245,7 +245,7 @@ describe('FaqComponent', () => { expect(faq1.faqState).toEqual(FaqState.PROPOSED); }); - it('should call the service to ingest lectures when ingestLecturesInPyris is called', () => { + it('should call the service to ingest faqs when ingestFaqsInPyris is called', () => { faqComponent.faqs = [faq1]; const ingestSpy = jest.spyOn(faqService, 'ingestFaqsInPyris').mockImplementation(() => of(new HttpResponse({ status: 200 }))); faqComponent.ingestFaqsInPyris(); diff --git a/src/test/javascript/spec/service/faq.service.spec.ts b/src/test/javascript/spec/service/faq.service.spec.ts index ebbd3c1ebfd0..a0b70974320b 100644 --- a/src/test/javascript/spec/service/faq.service.spec.ts +++ b/src/test/javascript/spec/service/faq.service.spec.ts @@ -258,7 +258,7 @@ describe('Faq Service', () => { expect(service.hasSearchTokens(faq1, 'title answer missing')).toBeFalse(); }); - it('should send a POST request to ingest lectures and return an OK response', () => { + it('should send a POST request to ingest faqs and return an OK response', () => { const courseId = 123; const expectedUrl = `api/courses/${courseId}/faqs/ingest`; const expectedStatus = 200;