Skip to content

Commit

Permalink
Salli duplikaattiopiskeluoikeudet perusopetuksen raportin testille
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkkahanninen committed Dec 29, 2023
1 parent 98d589b commit fc5ece0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ class CompositeOpiskeluoikeusRepository(main: KoskiOpiskeluoikeusRepository, vir
def findByOid(oid: String)(implicit user: KoskiSpecificSession): Either[HttpStatus, KoskiOpiskeluoikeusRow] =
main.findByOid(oid)

/**
* @param disableDuplicateChecks Kytkee duplikaattitarkastukset pois päältä. Älä käytä tuotannossa!
* Tämä on tarkoitettu testien alustamiseen, joissa tutkitaan jo kantaan päätyneitä viallisia datoja.
*/
def createOrUpdate(
oppijaOid: PossiblyUnverifiedHenkilöOid,
opiskeluoikeus: KoskeenTallennettavaOpiskeluoikeus,
allowUpdate: Boolean,
allowDeleteCompleted: Boolean = false
allowDeleteCompleted: Boolean = false,
disableDuplicateChecks: Boolean = false,
)(
implicit user: KoskiSpecificSession
): Either[HttpStatus, CreateOrUpdateResult] =
withErrorLogging(() => main.createOrUpdate(oppijaOid, opiskeluoikeus, allowUpdate, allowDeleteCompleted))
withErrorLogging(() => main.createOrUpdate(oppijaOid, opiskeluoikeus, allowUpdate, allowDeleteCompleted, disableDuplicateChecks))

def mapFailureToVirtaUnavailable(result: Try[Seq[Opiskeluoikeus]], oid: String): Try[WithWarnings[Seq[Opiskeluoikeus]]] = {
result match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ trait KoskiOpiskeluoikeusRepository {
oppijaOid: PossiblyUnverifiedHenkilöOid,
opiskeluoikeus: KoskeenTallennettavaOpiskeluoikeus,
allowUpdate: Boolean,
allowDeleteComplete: Boolean = false
allowDeleteComplete: Boolean = false,
disableDuplicateChecks: Boolean = false,
)(implicit user: KoskiSpecificSession): Either[HttpStatus, CreateOrUpdateResult]
def filterOppijat[A <: HenkilönTunnisteet](oppijat: List[A])(implicit user: KoskiSpecificSession): List[A]
def findByOppijaOids(oids: List[String])(implicit user: KoskiSpecificSession): Seq[Opiskeluoikeus]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ class PostgresKoskiOpiskeluoikeusRepository(
oppijaOid: PossiblyUnverifiedHenkilöOid,
opiskeluoikeus: KoskeenTallennettavaOpiskeluoikeus,
allowUpdate: Boolean,
allowDeleteCompleted: Boolean = false
allowDeleteCompleted: Boolean = false,
disableDuplicateChecks: Boolean = false,
)(implicit user: KoskiSpecificSession): Either[HttpStatus, CreateOrUpdateResult] = {
actions.createOrUpdate(oppijaOid, opiskeluoikeus, allowUpdate, allowDeleteCompleted)
actions.createOrUpdate(oppijaOid, opiskeluoikeus, allowUpdate, allowDeleteCompleted, disableDuplicateChecks)
}

def merkitseSuoritusjakoTehdyksiIlmanKäyttöoikeudenTarkastusta(oid: String): HttpStatus = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ class PostgresKoskiOpiskeluoikeusRepositoryActions(
oppijaOid: PossiblyUnverifiedHenkilöOid,
opiskeluoikeus: KoskeenTallennettavaOpiskeluoikeus,
allowUpdate: Boolean,
allowDeleteCompleted: Boolean
allowDeleteCompleted: Boolean,
disableDuplicateChecks: Boolean = false,
)(implicit user: KoskiSpecificSession): DBIOAction[Either[HttpStatus, CreateOrUpdateResult], NoStream, Read with Write with Transactional] = {
val identifier = OpiskeluoikeusIdentifier(oppijaOid.oppijaOid, opiskeluoikeus)

findByIdentifierAction(identifier).flatMap {
case Right(Nil) =>
createAction(oppijaOid, opiskeluoikeus)
case Right(_) if disableDuplicateChecks =>
createAction(oppijaOid, opiskeluoikeus)
case Right(aiemmatOpiskeluoikeudet) if allowUpdate =>
updateIfUnambiguousAiempiOpiskeluoikeusAction(oppijaOid, opiskeluoikeus, identifier, aiemmatOpiskeluoikeudet, allowDeleteCompleted)
case Right(aiemmatOpiskeluoikeudet) if vastaavanRinnakkaisenOpiskeluoikeudenLisääminenSallittu(opiskeluoikeus, aiemmatOpiskeluoikeudet) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ trait PostgresOpiskeluoikeusRepositoryActions[OOROW <: OpiskeluoikeusRow, OOTABL
oppijaOid: PossiblyUnverifiedHenkilöOid,
opiskeluoikeus: KoskeenTallennettavaOpiskeluoikeus,
allowUpdate: Boolean,
allowDeleteCompleted: Boolean
allowDeleteCompleted: Boolean,
disableDuplicateChecks: Boolean = false,
)(implicit user: KoskiSpecificSession): Either[HttpStatus, CreateOrUpdateResult] = {
def createOrUpdateWithRetry: Either[HttpStatus, CreateOrUpdateResult] = {
val result = try {
runDbSync {
(for {
result <- createOrUpdateAction(oppijaOid, opiskeluoikeus, allowUpdate, allowDeleteCompleted)
result <- createOrUpdateAction(oppijaOid, opiskeluoikeus, allowUpdate, allowDeleteCompleted, disableDuplicateChecks)
syncAction <- syncAction(oppijaOid, opiskeluoikeus, result)
} yield result).transactionally
}
Expand Down Expand Up @@ -114,7 +115,8 @@ trait PostgresOpiskeluoikeusRepositoryActions[OOROW <: OpiskeluoikeusRow, OOTABL
oppijaOid: PossiblyUnverifiedHenkilöOid,
opiskeluoikeus: KoskeenTallennettavaOpiskeluoikeus,
allowUpdate: Boolean,
allowDeleteCompleted: Boolean = false
allowDeleteCompleted: Boolean = false,
disableDuplicateChecks: Boolean = false,
)(implicit user: KoskiSpecificSession): dbio.DBIOAction[Either[HttpStatus, CreateOrUpdateResult], NoStream, Read with Write with Transactional]

protected def findByIdentifierAction(identifier: OpiskeluoikeusIdentifier)(implicit user: KoskiSpecificSession): dbio.DBIOAction[Either[HttpStatus, List[OOROW]], NoStream, Read] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class PostgresYtrOpiskeluoikeusRepositoryActions(
oppijaOid: PossiblyUnverifiedHenkilöOid,
opiskeluoikeus: KoskeenTallennettavaOpiskeluoikeus,
allowUpdate: Boolean,
allowDeleteCompleted: Boolean
allowDeleteCompleted: Boolean,
disableDuplicateChecks: Boolean = false,
)(implicit user: KoskiSpecificSession): DBIOAction[Either[HttpStatus, CreateOrUpdateResult], NoStream, Read with Write with Transactional] = {
val identifier = OpiskeluoikeusIdentifier(oppijaOid.oppijaOid, opiskeluoikeus)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class PerusopetuksenOppijamäärätRaporttiSpec extends AnyFreeSpec with Matcher
val createResult = application.opiskeluoikeusRepository.createOrUpdate(
oppijaOid = VerifiedHenkilöOid(vuonna2005SyntynytEiOpiskeluoikeuksiaFikstuurissa),
opiskeluoikeus = oo,
allowUpdate = false
allowUpdate = false,
disableDuplicateChecks = true,
)(session(defaultUser))
createResult.map(_.created) should be(Right(true))
createResult.map(_.oid)
Expand Down

0 comments on commit fc5ece0

Please sign in to comment.