-
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.
organisaatiohierarkia käyttöoikeuksiin ja cachetus
- Loading branch information
Showing
14 changed files
with
252 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,7 +163,7 @@ object LocalUtil { | |
new LambdaHandler().handleRequest(null, new TestAwsContext("migraatio")) | ||
|
||
// alustetaan data | ||
val kayttooikeus = Kayttooikeus(Option.apply("1.2.3"), "OIKEUS") | ||
val kayttooikeus = Kayttooikeus("OIKEUS", Option.apply("1.2.246.562.10.240484683010")) | ||
val kantaOperaatiot = new KantaOperaatiot(DbUtil.database) | ||
val lahetyksia = kantaOperaatiot.getLahetykset(Option.empty, Option.apply(20), Set(kayttooikeus)) | ||
if(lahetyksia.isEmpty || lahetyksia.length < 3) { | ||
|
@@ -270,6 +270,40 @@ object LocalUtil { | |
Set(kayttooikeus), | ||
Map("avain" -> Seq("arvo")), | ||
"omistaja") | ||
kantaOperaatiot.tallennaViesti("Kuopio yhteiskunta- ja kauppatieteet viesti", | ||
"Tämä on viesti käyttöoikeushierarkian todentamiseen", | ||
SisallonTyyppi.TEXT, | ||
Set(Kieli.FI), | ||
Map.empty, | ||
Option.apply("0.1.2.3"), | ||
Option.apply(Kontakti(Option.apply("Testi Virkailija"), "[email protected]")), | ||
Option.apply("[email protected]"), | ||
Range(0, 3).map(suffix => Kontakti(Option.apply("Testi Vastaanottaja" + suffix), "testi.vastaanottaja" + suffix + "@example.com")), | ||
Seq.empty, | ||
Option.apply("hakemuspalvelu"), | ||
Option.empty, | ||
Option.apply(Prioriteetti.NORMAALI), | ||
Option.apply(365), | ||
Set(Kayttooikeus("APP_HAKEMUS_CRUD", Some("1.2.246.562.10.2014041814455745619200"))), | ||
Map("avain" -> Seq("arvo")), | ||
"omistaja") | ||
kantaOperaatiot.tallennaViesti("Viesti ilman organisaatiota", | ||
"Tämä on viesti käyttöoikeustarkistuksen todentamiseen ilman organisaatiorajausta", | ||
SisallonTyyppi.TEXT, | ||
Set(Kieli.FI), | ||
Map.empty, | ||
Option.apply("0.1.2.3"), | ||
Option.apply(Kontakti(Option.apply("Testi Virkailija"), "[email protected]")), | ||
Option.apply("[email protected]"), | ||
Range(0, 3).map(suffix => Kontakti(Option.apply("Testi Vastaanottaja" + suffix), "testi.vastaanottaja" + suffix + "@example.com")), | ||
Seq.empty, | ||
Option.apply("hakemuspalvelu"), | ||
Option.empty, | ||
Option.apply(Prioriteetti.NORMAALI), | ||
Option.apply(365), | ||
Set(Kayttooikeus("OIKEUS", None)), | ||
Map("avain" -> Seq("arvo")), | ||
"omistaja") | ||
} | ||
|
||
} | ||
|
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
37 changes: 37 additions & 0 deletions
37
lambdat/raportointi/src/main/scala/fi/oph/viestinvalitys/raportointi/integration/Cache.scala
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,37 @@ | ||
package fi.oph.viestinvalitys.raportointi.integration | ||
|
||
import com.google.common.cache.{CacheBuilder, CacheLoader, LoadingCache} | ||
import org.slf4j.LoggerFactory | ||
import sttp.client4.quick.* | ||
import sttp.client4.Response | ||
import sttp.model.Uri | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
object OrganisaatioCache extends OrganisaatioCache | ||
class OrganisaatioCache { | ||
val callerId: String = "1.2.246.562.10.00000000001.viestinvalitys-raportointi" | ||
val headers: Map[String, String] = Map("Caller-Id" -> callerId, "CSRF" -> callerId) | ||
val queryParams = | ||
Map("rekursiivisesti" -> "true", "aktiiviset" -> "true", "suunnitellut" -> "false", "lakkautetut" -> "false") | ||
|
||
val LOG = LoggerFactory.getLogger(classOf[OrganisaatioCache]) | ||
|
||
val childOidsLoader = new CacheLoader[String, Response[String]] { | ||
def load(oid: String): Response[String] = | ||
// TODO url konfiguraatioihin | ||
val uri: Uri = uri"https://virkailija.testiopintopolku.fi/organisaatio-service/api/$oid/childoids?$queryParams" | ||
quickRequest | ||
.headers(headers) | ||
.cookie("CSRF", callerId) | ||
.get(uri) | ||
.send() | ||
} | ||
|
||
// TODO asetukset konffeihin? | ||
val childOidsCache: LoadingCache[String, Response[String]] = CacheBuilder.newBuilder() | ||
.maximumSize(1500) | ||
.expireAfterAccess(60, TimeUnit.MINUTES) | ||
.build(childOidsLoader) | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
...nti/src/main/scala/fi/oph/viestinvalitys/raportointi/integration/OrganisaatioClient.scala
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,26 @@ | ||
package fi.oph.viestinvalitys.raportointi.integration | ||
|
||
import com.google.common.cache.* | ||
import org.slf4j.LoggerFactory | ||
import sttp.client4.Response | ||
import upickle.default.* | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
object OrganisaatioClient extends OrganisaatioClient | ||
class OrganisaatioClient { | ||
|
||
val LOG = LoggerFactory.getLogger(classOf[OrganisaatioClient]) | ||
|
||
def getAllChildOidsFlat(oid: String): Set[String] = | ||
if (!OrganisaatioOid.isValid(oid)) | ||
LOG.error(s"Organisaation oid $oid on virheellinen") | ||
throw new RuntimeException(s"Organisaation oid $oid on virheellinen") | ||
val response: Response[String] = OrganisaatioCache.childOidsCache.get(oid) | ||
response.code.code match | ||
case 200 => read[List[String]](response.body).toSet | ||
case _ => | ||
LOG.error(s"organisaatioiden haku epäonnistui, status ${response.code.code} error ${response.statusText}") | ||
throw new RuntimeException(s"Organisaatioiden haku epäonnistui: ${response.statusText}") | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...portointi/src/main/scala/fi/oph/viestinvalitys/raportointi/integration/organisaatio.scala
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,23 @@ | ||
package fi.oph.viestinvalitys.raportointi.integration | ||
|
||
import scala.util.matching.Regex | ||
|
||
object OrganisaatioOid { | ||
|
||
val organisaatioOidPattern: Regex = "^1\\.2\\.246\\.562\\.(10|99)\\.\\d+$".r | ||
def isValid(oid: String): Boolean = organisaatioOidPattern.matches(oid) | ||
} | ||
|
||
case class Organisaatio(oid: String, | ||
parentOidPath: String, | ||
oppilaitostyyppi: Option[String] = None, | ||
nimi: Map[String, String], | ||
status: String, | ||
kotipaikkaUri: Option[String] = None, | ||
children: List[Organisaatio] = List(), | ||
organisaatiotyypit: List[String] = List(), | ||
tyypit: List[String] = List()) { | ||
|
||
} | ||
|
||
case class OrganisaatioHierarkia(organisaatiot: List[Organisaatio]) |
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
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
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
Oops, something went wrong.