|
1 | 1 | package de.tum.cit.aet.job.repository; |
2 | 2 |
|
| 3 | +import de.tum.cit.aet.ai.domain.BiasedIssue; |
| 4 | +import de.tum.cit.aet.ai.domain.ComplianceIssue; |
3 | 5 | import de.tum.cit.aet.core.repository.DocApplyJpaRepository; |
4 | 6 | import de.tum.cit.aet.job.constants.Campus; |
5 | 7 | import de.tum.cit.aet.job.constants.JobState; |
@@ -358,16 +360,47 @@ ORDER BY CONCAT(p.firstName, ' ', p.lastName) ASC |
358 | 360 | @Query("SELECT DISTINCT j.image.imageId FROM Job j WHERE j.image.imageId IN :imageIds") |
359 | 361 | Set<UUID> findInUseImageIds(@Param("imageIds") List<UUID> imageIds); |
360 | 362 |
|
| 363 | + /** |
| 364 | + * Loads a job with its supervising professor, research group and image. |
| 365 | + * The issue collections are intentionally not part of the entity graph and |
| 366 | + * are fetched by their own queries instead, |
| 367 | + * since joining both would produce a Cartesian product. |
| 368 | + * |
| 369 | + * @param jobId the job identifier |
| 370 | + * @return the job, if it exists |
| 371 | + */ |
361 | 372 | @EntityGraph(attributePaths = { "supervisingProfessor", "researchGroup", "image" }) |
362 | 373 | @Query("SELECT j FROM Job j WHERE j.jobId = :jobId") |
363 | 374 | Optional<Job> findByIdWithDetails(@Param("jobId") UUID jobId); |
364 | 375 |
|
| 376 | + /** |
| 377 | + * Loads the compliance issues of a job in a dedicated query. Fetching them together |
| 378 | + * with the biased issues would produce a Cartesian product and duplicate list entries. |
| 379 | + * |
| 380 | + * @param jobId the job identifier |
| 381 | + * @return the persisted compliance issues |
| 382 | + */ |
365 | 383 | @Query("SELECT issue FROM Job j JOIN j.complianceIssues issue WHERE j.jobId = :jobId") |
366 | | - List<de.tum.cit.aet.ai.domain.ComplianceIssue> findComplianceIssuesByJobId(@Param("jobId") UUID jobId); |
| 384 | + List<ComplianceIssue> findComplianceIssuesByJobId(@Param("jobId") UUID jobId); |
367 | 385 |
|
| 386 | + /** |
| 387 | + * Loads biased issues separately from compliance issues to avoid a Cartesian |
| 388 | + * product and retain the set semantics of the persisted collection. |
| 389 | + * |
| 390 | + * @param jobId the job identifier |
| 391 | + * @return the persisted biased issues |
| 392 | + */ |
368 | 393 | @Query("SELECT issue FROM Job j JOIN j.biasedIssues issue WHERE j.jobId = :jobId") |
369 | | - Set<de.tum.cit.aet.ai.domain.BiasedIssue> findBiasedIssuesByJobId(@Param("jobId") UUID jobId); |
| 394 | + Set<BiasedIssue> findBiasedIssuesByJobId(@Param("jobId") UUID jobId); |
370 | 395 |
|
| 396 | + /** |
| 397 | + * Loads the job used for an analysis update deliberately without an entity graph: |
| 398 | + * the update only touches the score and the issue collections, so eagerly loading |
| 399 | + * the professor, research group and image would be wasted work. |
| 400 | + * |
| 401 | + * @param jobId the job identifier |
| 402 | + * @return the job to update, if it exists |
| 403 | + */ |
371 | 404 | @Query("SELECT j FROM Job j WHERE j.jobId = :jobId") |
372 | 405 | Optional<Job> findByIdForAiUpdate(@Param("jobId") UUID jobId); |
373 | 406 | } |
0 commit comments