generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PI-2673 - move test data creation back to data loader
- Loading branch information
1 parent
c71147d
commit 40d58af
Showing
4 changed files
with
60 additions
and
58 deletions.
There are no files selected for viewing
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
30 changes: 30 additions & 0 deletions
30
...es-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/EntityManagerDataLoader.kt
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,30 @@ | ||
package uk.gov.justice.digital.hmpps.data | ||
|
||
import jakarta.persistence.EntityManager | ||
import jakarta.persistence.PersistenceContext | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonManagerGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.ProviderGenerator | ||
import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.Staff | ||
|
||
@Component | ||
class EntityManagerDataLoader{ | ||
|
||
@PersistenceContext | ||
private lateinit var entityManager: EntityManager | ||
|
||
@Transactional | ||
fun loadData():Map<String, Staff> { | ||
|
||
val staffMap = (PersonManagerGenerator.ALL.map { it.staff } + ProviderGenerator.UNALLOCATED_STAFF).associateBy { it.code } | ||
|
||
val savedStaffMap = staffMap.map { | ||
entityManager.merge(it.value) | ||
}.associateBy { it.code } | ||
|
||
return savedStaffMap | ||
|
||
} | ||
|
||
} |
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