-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Iris: Enable IRIS to answer with FAQs (#10093)
- Loading branch information
Showing
51 changed files
with
1,245 additions
and
59 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
src/main/java/de/tum/cit/aet/artemis/communication/service/FaqService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package de.tum.cit.aet.artemis.communication.service; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Service; | ||
|
||
import de.tum.cit.aet.artemis.communication.domain.Faq; | ||
import de.tum.cit.aet.artemis.communication.domain.FaqState; | ||
import de.tum.cit.aet.artemis.communication.repository.FaqRepository; | ||
import de.tum.cit.aet.artemis.core.service.ProfileService; | ||
import de.tum.cit.aet.artemis.iris.service.pyris.PyrisWebhookService; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Service | ||
public class FaqService { | ||
|
||
private final Optional<PyrisWebhookService> pyrisWebhookService; | ||
|
||
private final FaqRepository faqRepository; | ||
|
||
public FaqService(FaqRepository faqRepository, Optional<PyrisWebhookService> pyrisWebhookService, ProfileService profileService) { | ||
|
||
this.pyrisWebhookService = pyrisWebhookService; | ||
this.faqRepository = faqRepository; | ||
|
||
} | ||
|
||
/** | ||
* Ingests FAQs into the Pyris system. If a specific FAQ ID is provided, the method will attempt to add | ||
* that FAQ to Pyris. Otherwise, it will ingest all FAQs for the specified course that are in the "ACCEPTED" state. | ||
* If the PyrisWebhookService is unavailable, the method does nothing. | ||
* | ||
* @param courseId the ID of the course for which FAQs will be ingested | ||
* @param faqId an optional ID of a specific FAQ to ingest; if not provided, all accepted FAQs for the course are processed | ||
* @throws IllegalArgumentException if a specific FAQ is provided but its state is not "ACCEPTED" | ||
*/ | ||
public void ingestFaqsIntoPyris(Long courseId, Optional<Long> faqId) { | ||
if (pyrisWebhookService.isEmpty()) { | ||
return; | ||
} | ||
|
||
faqId.ifPresentOrElse(id -> { | ||
Faq faq = faqRepository.findById(id).orElseThrow(); | ||
if (faq.getFaqState() != FaqState.ACCEPTED) { | ||
throw new IllegalArgumentException("Faq is not in the state accepted, you cannot ingest this faq"); | ||
} | ||
pyrisWebhookService.get().addFaq(faq); | ||
}, () -> faqRepository.findAllByCourseIdAndFaqState(courseId, FaqState.ACCEPTED).forEach(faq -> pyrisWebhookService.get().addFaq(faq))); | ||
} | ||
|
||
/** | ||
* Deletes an existing FAQ from the Pyris system. If the PyrisWebhookService is unavailable, the method does nothing. | ||
* | ||
* @param existingFaq the FAQ to be removed from Pyris | ||
*/ | ||
public void deleteFaqInPyris(Faq existingFaq) { | ||
if (pyrisWebhookService.isEmpty()) { | ||
return; | ||
} | ||
|
||
pyrisWebhookService.get().deleteFaq(existingFaq); | ||
} | ||
|
||
/** | ||
* Automatically updates or ingests a specific FAQ into the Pyris system for a given course. | ||
* If the PyrisWebhookService is unavailable, the method does nothing. | ||
* | ||
* @param courseId the ID of the course to which the FAQ belongs | ||
* @param faq the FAQ to be ingested or updated in Pyris | ||
*/ | ||
public void autoIngestFaqsIntoPyris(Long courseId, Faq faq) { | ||
if (pyrisWebhookService.isEmpty()) { | ||
return; | ||
} | ||
|
||
if (faq.getFaqState() != FaqState.ACCEPTED) { | ||
return; | ||
} | ||
|
||
pyrisWebhookService.get().autoUpdateFaqInPyris(courseId, faq); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/de/tum/cit/aet/artemis/iris/domain/settings/IrisFaqIngestionSubSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package de.tum.cit.aet.artemis.iris.domain.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 faqs for Iris. | ||
* This class extends {@link IrisSubSettings} to provide settings required for faq data ingestion. | ||
*/ | ||
@Entity | ||
@DiscriminatorValue("FAQ_INGESTION") | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public class IrisFaqIngestionSubSettings extends IrisSubSettings { | ||
|
||
@Column(name = "auto_ingest_on_faq_creation") | ||
private boolean autoIngestOnFaqCreation; | ||
|
||
public boolean getAutoIngestOnFaqCreation() { | ||
return autoIngestOnFaqCreation; | ||
} | ||
|
||
public void setAutoIngestOnFaqCreation(boolean autoIngestOnFaqCreation) { | ||
this.autoIngestOnFaqCreation = autoIngestOnFaqCreation; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/de/tum/cit/aet/artemis/iris/dto/IrisCombinedFaqIngestionSubSettingsDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.tum.cit.aet.artemis.iris.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public record IrisCombinedFaqIngestionSubSettingsDTO(boolean enabled) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.