Skip to content

Commit

Permalink
OY-4717 karsittu koodia lisää ja siivottu kommentteja
Browse files Browse the repository at this point in the history
  • Loading branch information
marjakari committed Jan 16, 2025
1 parent 68c7046 commit 73ad953
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 254 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ cas.virkailija.username={{omatsivut_haku_app_username}}
cas.virkailija.password={{omatsivut_haku_app_password}}

cas.oppija.url=https://{{host_oppija}}/cas-oppija
cas.oppija.username={{omatsivut_haku_app_username}} # TODO
cas.oppija.password={{omatsivut_haku_app_password}} # TODO
cas.oppija.username={{omatsivut_haku_app_username}}
cas.oppija.password={{omatsivut_haku_app_password}}

omatsivut.oppija-raamit.url={{oppija_raamit_url}}
omatsivut.piwik.url=https://{{host_oppija}}/wp/wp-content/themes/ophver3/js/piwik.js
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/ScalatraBootstrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class ScalatraBootstrap extends LifeCycle with Logging {
context.mount(componentRegistry.newNonSensitiveApplicationServlet, "/insecure")
context.mount(new TranslationServlet, "/translations")
context.mount(componentRegistry.newMuistilistaServlet, "/muistilista")
context.mount(componentRegistry.newKoodistoServlet, "/koodisto")
context.mount(componentRegistry.newKoulutusServlet, "/koulutusinformaatio")
context.mount(componentRegistry.newSecuredSessionServlet, "/initsession")
context.mount(componentRegistry.newSessionServlet, "/session")
context.mount(new RaamitServlet(config), "/raamit")
Expand Down
68 changes: 9 additions & 59 deletions src/main/scala/fi/vm/sade/hakemuseditori/HakemusEditori.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@ package fi.vm.sade.hakemuseditori
import fi.vm.sade.ataru.AtaruServiceComponent
import fi.vm.sade.hakemuseditori.domain.Language
import fi.vm.sade.hakemuseditori.hakemus._
import fi.vm.sade.hakemuseditori.hakemus.domain.{Hakemus, ValidationError}
import fi.vm.sade.hakemuseditori.json.JsonFormats
import fi.vm.sade.hakemuseditori.localization.{Translations, TranslationsComponent}
import fi.vm.sade.hakemuseditori.hakemus.domain.{ValidationError}
import fi.vm.sade.hakemuseditori.localization.{TranslationsComponent}
import fi.vm.sade.hakemuseditori.ohjausparametrit.OhjausparametritComponent
import fi.vm.sade.hakemuseditori.oppijanumerorekisteri.OppijanumerorekisteriComponent
import fi.vm.sade.hakemuseditori.tarjonta.TarjontaComponent
import fi.vm.sade.hakemuseditori.tarjonta.kouta.RemoteKoutaComponent
import fi.vm.sade.hakemuseditori.tarjonta.vanha.RemoteTarjontaComponent
import fi.vm.sade.hakemuseditori.user.User
import fi.vm.sade.hakemuseditori.valintatulokset.{NoOpValintatulosService, ValintatulosService, ValintatulosServiceComponent}
import fi.vm.sade.hakemuseditori.viestintapalvelu.{AccessibleHtml, Pdf, TuloskirjeComponent, TuloskirjeKind}
import fi.vm.sade.omatsivut.config.AppConfig.AppConfig
import fi.vm.sade.hakemuseditori.valintatulokset.{ValintatulosServiceComponent}
import fi.vm.sade.hakemuseditori.viestintapalvelu.{TuloskirjeComponent, TuloskirjeKind}
import fi.vm.sade.omatsivut.util.Logging

import javax.servlet.http.HttpServletRequest
import org.json4s.jackson.Serialization
import org.springframework.context.ApplicationContext

import scala.util.{Failure, Success, Try}

Expand Down Expand Up @@ -85,23 +81,23 @@ trait HakemusEditoriComponent extends AtaruServiceComponent
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.")
logger.info(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 " +
logger.info(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 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)
logger.info(s"fetchByHakemusOid(): Haku-app returned no applications for 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)
logger.warn(s"fetchByHakemusOid(): Haku-app returned an application for hakemusOid $hakemusOid but its personOid $personOidFromHakemus" +
s"did not match the given personOid parameter $personOid")
}
oidsMatch
}
Expand All @@ -114,11 +110,6 @@ trait HakemusEditoriComponent extends AtaruServiceComponent
result
}


private def parseLang(lang: Option[String]): Language.Value = {
lang.flatMap(Language.parse).getOrElse(Language.fi)
}

}
}

Expand All @@ -132,47 +123,6 @@ class ValidationException(errors: List[ValidationError]) extends RuntimeExceptio
val validationErrors = errors
}

abstract class StandaloneHakemusEditoriComponent(
val translations: Translations
) extends HakemusEditoriComponent {
override lazy val hakemusConverter: HakemusConverter = new HakemusConverter
override val valintatulosService: ValintatulosService = new NoOpValintatulosService

}

class StubbedHakemusEditoriContext(appContext: ApplicationContext,
translations: Translations,
config: AppConfig)
extends StandaloneHakemusEditoriComponent(translations) {
override lazy val springContext = new HakemusSpringContext(appContext)
override lazy val ataruService = new StubbedAtaruService
override lazy val hakemusRepository: HakemusFinder = new StubbedHakemusFinder
override lazy val oppijanumerorekisteriService = new StubbedOppijanumerorekisteriService
override lazy val tarjontaService = new StubbedTarjontaService(config)
override lazy val tuloskirjeService = new StubbedTuloskirjeService
override lazy val ohjausparametritService = new StubbedOhjausparametritService
}

case class HakemusEditoriRemoteUrls(
tarjontaUrl: String,
koodistoUrl: String,
ohjausparametritUrl: String,
koulutusinformaatioAoUrl: String,
koulutusinformaationBIUrl: String,
koulutusinformaatioLopUrl: String
)

object Json extends JsonFormats {
def toJson(o: AnyRef): String = {
Serialization.write(o)
}

def fromJson[A](s: String): A = {
Serialization.read(s)
}

def fromJson[A](s: String, klass: Class[A]): A = {
val manifest = Manifest.classType(klass)
Serialization.read(s)(jsonFormats, manifest)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ trait HakemusConverterComponent {
}

private def amendWithKoulutusInformaatio(lang: Language, data: HakutoiveData): HakutoiveData = {
// TODO onko tämä tarpeen?
val koulutusOption = data.get("Koulutus")
val koulutus = koulutusOption match {
case Some(k) if StringUtils.isBlank(k) => tarjontaService.hakukohde(data("Koulutus-id"), lang).map(_.nimi)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ class ComponentRegistry(val config: AppConfig)
VastaanottoComponent with
ApplicationsServletContainer with
MuistilistaServletContainer with
KoulutusServletContainer with
SecuredSessionServletContainer with
FakeSecuredSessionServletContainer with
LogoutServletContainer with
FixtureServletContainer with
KoodistoServletContainer with
RemoteTarjontaComponent with
TarjontaComponent with
TuloskirjeComponent with
Expand Down Expand Up @@ -160,7 +158,6 @@ class ComponentRegistry(val config: AppConfig)

def vastaanottoService(implicit language: Language): VastaanottoService = new VastaanottoService(config)
def newApplicationsServlet = new ApplicationsServlet(config, sessionService)
def newKoulutusServlet = new KoulutusServlet
def newValintatulosServlet = new ValintatulosServlet(config, sessionService)
def newSecuredSessionServlet = config match {
case _: StubbedExternalDeps => new FakeSecuredSessionServlet(config,
Expand All @@ -177,7 +174,6 @@ class ComponentRegistry(val config: AppConfig)
def newSessionServlet = new SessionServlet()
def newLogoutServlet = new LogoutServlet()
def newFixtureServlet = new FixtureServlet(config)
def newKoodistoServlet = new KoodistoServlet
def newMuistilistaServlet = new MuistilistaServlet(config)
def newNonSensitiveApplicationServlet = new NonSensitiveApplicationServlet(config)
def newTuloskirjeetServlet = new TuloskirjeetServlet(config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trait OmatsivutRepository extends Logging {

val db: Database
val dataSource: DataSource
def runBlocking[R](operations: DBIO[R], timeout: Duration = Duration(10, TimeUnit.MINUTES)): R = { // TODO put these 3–4 different default timeouts behind common, configurable value
def runBlocking[R](operations: DBIO[R], timeout: Duration = Duration(10, TimeUnit.MINUTES)): R = {
if (logSqlOfSomeQueries) {
logger.error("This should not happen in production.")
operations.getClass.getDeclaredFields.foreach { f =>
Expand All @@ -40,7 +40,7 @@ trait OmatsivutRepository extends Logging {
timeout + Duration(1, TimeUnit.SECONDS)
)
}
def runBlockingTransactionally[R](operations: DBIO[R], timeout: Duration = Duration(20, TimeUnit.SECONDS)): Either[Throwable, R] = { // // TODO put these 3–4 different default timeouts behind common, configurable value
def runBlockingTransactionally[R](operations: DBIO[R], timeout: Duration = Duration(20, TimeUnit.SECONDS)): Either[Throwable, R] = {
val SERIALIZATION_VIOLATION = "40001"
try {
Right(runBlocking(operations.transactionally.withTransactionIsolation(Serializable), timeout))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import org.springframework.data.mongodb.core.MongoTemplate
case _ =>
}

// TODO lisää converter?
@Bean def mongoClient(@Value("${mongodb.url}") mongoUri: String): MongoClient = {
logger.info("Creating MongoClient for server(s): " + sanitizeMongoUrl(mongoUri))
val connectionString: ConnectionString = new ConnectionString(mongoUri)
Expand Down
21 changes: 0 additions & 21 deletions src/main/scala/fi/vm/sade/omatsivut/servlet/KoodistoServlet.scala

This file was deleted.

29 changes: 0 additions & 29 deletions src/main/scala/fi/vm/sade/omatsivut/servlet/KoulutusServlet.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ trait NonSensitiveApplicationServletContainer {
}

private def jwtAuthorize: Try[HakemusJWT] = {
logger.info(s"tunnistaudutaan jwt:llä")
val bearerMatch = """Bearer (.+)""".r
val authHeader = request.getHeader("Authorization")
authHeader match {
Expand All @@ -95,7 +94,6 @@ trait NonSensitiveApplicationServletContainer {
}

private def fetchHakemus(hakemusOid: String, personOid: Option[String]): Try[HakemusInfo] = {
logger.info(s"haetaan legacy-hakemus hakemus-oidilla $hakemusOid")
personOid.map(hakemusEditori.fetchByHakemusOid(request, _, hakemusOid, FetchIfNoHetuOrToinenAste))
.getOrElse(hakemusRepository.getHakemus(request, hakemusOid, FetchIfNoHetuOrToinenAste))
.fold[Try[HakemusInfo]](Failure(new NoSuchElementException(s"Hakemus $hakemusOid not found")))(h => Success(h.withoutKelaUrl))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import fi.vm.sade.omatsivut.cas.CasClient.OppijaAttributes
import fi.vm.sade.omatsivut.config.AppConfig.AppConfig
import fi.vm.sade.omatsivut.security._
import fi.vm.sade.omatsivut.servlet.OmatSivutServletBase
import fi.vm.sade.omatsivut.util.{BlazeHttpClient, Logging, OptionConverter}
import org.scalatra.{BadRequest, Cookie, CookieOptions, Ok}
import cats.effect.{IO, Resource}
import fi.vm.sade.omatsivut.util.{Logging, OptionConverter}
import org.scalatra.{BadRequest, Cookie, CookieOptions}
import cats.effect.{IO}
import cats.effect.unsafe.implicits.global
import org.http4s.client.Client

import java.util.concurrent.TimeUnit
import scala.concurrent.duration.Duration
Expand Down
68 changes: 0 additions & 68 deletions src/main/scala/fi/vm/sade/omatsivut/util/Cache.scala

This file was deleted.

Loading

0 comments on commit 73ad953

Please sign in to comment.