Skip to content

Commit

Permalink
OY-4717 mongo-kantahaut
Browse files Browse the repository at this point in the history
  • Loading branch information
marjakari committed Jan 7, 2025
1 parent c97ab7c commit 95b4acb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
48 changes: 22 additions & 26 deletions src/main/scala/fi/vm/sade/hakemuseditori/HakemusEditori.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ trait HakemusEditoriComponent extends AtaruServiceComponent
def fetchByPersonOid(request: HttpServletRequest,
personOid: String,
valintatulosFetchStrategy: ValintatulosFetchStrategy): HakemusResult = {
logger.info(s"Fetching hakemus list by person oid $personOid")
val ataruHakemukset = Try(ataruService.findApplications(request, personOid, valintatulosFetchStrategy, language))
val hakuAppHakemukset = oppijanumerorekisteriService.fetchAllDuplicateOids(personOid).toList
.map(oid => Try(hakemusRepository.fetchHakemukset(request, oid, valintatulosFetchStrategy)))
Expand All @@ -83,36 +82,33 @@ trait HakemusEditoriComponent extends AtaruServiceComponent
personOid: String,
hakemusOid: String,
valintatulosFetchStrategy: ValintatulosFetchStrategy): Option[HakemusInfo] = {
logger.info(s"fetchByHakemusOid hakemus-oidilla $hakemusOid")
// TODO käännä toisinpäin, haetaan ensin atarusta ja sitten vasta haku-appista
val optFromHakemusRepository = hakemusRepository.getHakemus(request, hakemusOid, valintatulosFetchStrategy)
if (optFromHakemusRepository.isEmpty) {
logger.info("fetchByHakemusOid(): Hakemus repository returned no application for given hakemusOid {}. Searching from ataru.", hakemusOid)
val ataruApplications = ataruService.findApplications(request, personOid, valintatulosFetchStrategy, language)
val matchingAtaruApplication = ataruApplications.find(_.hakemus.oid == hakemusOid)
if (ataruApplications.isEmpty) {
logger.warn(s"fetchByHakemusOid(): Ataru returned no applications for given personOid $personOid, searching from haku-app.")
} else if (matchingAtaruApplication.isEmpty) {
logger.warn(s"fetchByHakemusOid(): Ataru returned applications for personOid $personOid but " +
s"their hakemusOids ${ataruApplications.map(_.hakemus.oid).mkString(",")} did not match the given hakemusOid $hakemusOid")
}

val matchingFromHakemusRepository = optFromHakemusRepository.filter { hakemus =>
val personOidFromHakemus = hakemus.hakemus.personOid
val oidsMatch = personOidFromHakemus == personOid
if (!oidsMatch) {
logger.warn("fetchByHakemusOid(): Hakemus repository returned an application for hakemusOid {} but its personOid {}" +
"did not match the given personOid parameter {}. Searching from ataru.", hakemusOid, personOidFromHakemus, personOid)
val result = matchingAtaruApplication.orElse {
// jos ei löydy atarusta, haetaan haku-appista
val optFromHakemusRepository = hakemusRepository.getHakemus(request, hakemusOid, valintatulosFetchStrategy)
if (optFromHakemusRepository.isEmpty) {
logger.info("fetchByHakemusOid(): Hakemus repository returned no application for given hakemusOid {}. Searching from ataru.", hakemusOid)
}
oidsMatch
}

val result: Option[HakemusInfo] = matchingFromHakemusRepository.orElse {
val ataruApplications = ataruService.findApplications(request, personOid, valintatulosFetchStrategy, language)
val matchingAtaruApplication = ataruApplications.find(_.hakemus.oid == hakemusOid)
if (ataruApplications.isEmpty) {
logger.warn("fetchByHakemusOid(): Ataru returned no applications for given personOid {}", personOid)
} else if (matchingAtaruApplication.isEmpty) {
logger.warn(s"fetchByHakemusOid(): Ataru returned applications for personOid $personOid but " +
s"their hakemusOids ${ataruApplications.map(_.hakemus.oid).mkString(",")} did not match the given hakemusOid $hakemusOid")
val matchingFromHakemusRepository = optFromHakemusRepository.filter { hakemus =>
val personOidFromHakemus = hakemus.hakemus.personOid
val oidsMatch = personOidFromHakemus == personOid
if (!oidsMatch) {
logger.warn("fetchByHakemusOid(): Hakemus repository returned an application for hakemusOid {} but its personOid {}" +
"did not match the given personOid parameter {}. Searching from ataru.", hakemusOid, personOidFromHakemus, personOid)
}
oidsMatch
}
matchingAtaruApplication
matchingFromHakemusRepository
}
if (result.isEmpty){
logger.warn(s"fetchByHakemusOid(): neither hakemus repository nor ataru returned a " +
logger.warn(s"fetchByHakemusOid(): neither ataru nor hakemus repository returned a " +
s"matching application for personOid $personOid, hakemusOid $hakemusOid")
}
result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ trait HakemusRepositoryComponent {
val tarjontaService: TarjontaService
val hakemusRepository: HakemusFinder

val dao = new ApplicationDao()

val dao = new ApplicationDao(springContext.mongoTemplate)

trait HakemusFinder {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package fi.vm.sade.hakemuseditori.hakemus.hakuapp


import fi.vm.sade.hakemuseditori.hakemus.hakuapp.domain.Application
import org.springframework.data.mongodb.core.MongoTemplate
import org.springframework.data.mongodb.core.query.{Criteria, Query}
import scala.jdk.CollectionConverters._

class ApplicationDao {
class ApplicationDao(mongoTemplate: MongoTemplate) {

def findByPersonOid(personOid: String): List[Application] = {
// TODO implement
List.empty
// List(new Application().setState(Application.State.INCOMPLETE))
val query: Query = new Query();
query.addCriteria(Criteria.where("personOid").is(personOid));
val applications = mongoTemplate.find(query, classOf[Application]);
applications.asScala.toList
}

def findByOid(oid: String): Option[Application] = {
// TODO implement
None
// Some(new Application())
val query = new Query()
query.addCriteria(Criteria.where("oid").is(oid))
Option(mongoTemplate.findOne(query, classOf[Application]))
}

}

0 comments on commit 95b4acb

Please sign in to comment.