forked from OpenBankProject/OBP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiVersionUtils.scala
More file actions
63 lines (55 loc) · 2.87 KB
/
ApiVersionUtils.scala
File metadata and controls
63 lines (55 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package code.api.util
import com.openbankproject.commons.util.ApiVersion._
import com.openbankproject.commons.util.ScannedApiVersion
object ApiVersionUtils {
val scannedApis = ScannedApis.versionMapScannedApis.keysIterator.toList
val versions =
v1_2_1 ::
v1_3_0 ::
v1_4_0 ::
v2_0_0 ::
v2_1_0 ::
v2_2_0 ::
v3_0_0 ::
v3_1_0 ::
v4_0_0 ::
v5_0_0 ::
v5_1_0 ::
v6_0_0 ::
v7_0_0 ::
`dynamic-endpoint` ::
`dynamic-entity` ::
scannedApis
def valueOf(value: String): ScannedApiVersion = {
//This `match` is used for compatibility. Previously we did not take care about BerlinGroup and UKOpenBanking versions carefully (since they didn't exist back in the day).
// eg: v1 ==BGv1, v1.3 ==BGv1.3, v2.0 == UKv2.0
// Now, we use the BerlinGroup standard version in OBP. But we need still make sure old version system is working.
val compatibilityVersion = value match {
case v1_2_1.fullyQualifiedVersion | v1_2_1.apiShortVersion => v1_2_1
case v1_3_0.fullyQualifiedVersion | v1_3_0.apiShortVersion => v1_3_0
case v1_4_0.fullyQualifiedVersion | v1_4_0.apiShortVersion => v1_4_0
case v2_0_0.fullyQualifiedVersion | v2_0_0.apiShortVersion => v2_0_0
case v2_1_0.fullyQualifiedVersion | v2_1_0.apiShortVersion => v2_1_0
case v2_2_0.fullyQualifiedVersion | v2_2_0.apiShortVersion => v2_2_0
case v3_0_0.fullyQualifiedVersion | v3_0_0.apiShortVersion => v3_0_0
case v3_1_0.fullyQualifiedVersion | v3_1_0.apiShortVersion => v3_1_0
case v4_0_0.fullyQualifiedVersion | v4_0_0.apiShortVersion => v4_0_0
case v5_0_0.fullyQualifiedVersion | v5_0_0.apiShortVersion => v5_0_0
case v5_1_0.fullyQualifiedVersion | v5_1_0.apiShortVersion => v5_1_0
case v6_0_0.fullyQualifiedVersion | v6_0_0.apiShortVersion => v6_0_0
case v7_0_0.fullyQualifiedVersion | v7_0_0.apiShortVersion => v7_0_0
case `dynamic-endpoint`.fullyQualifiedVersion | `dynamic-endpoint`.apiShortVersion => `dynamic-endpoint`
case `dynamic-entity`.fullyQualifiedVersion | `dynamic-entity`.apiShortVersion => `dynamic-entity`
case version if(scannedApis.map(_.fullyQualifiedVersion).contains(version))
=>scannedApis.filter(_.fullyQualifiedVersion==version).head
case version if(scannedApis.map(_.apiShortVersion).contains(version))
=>scannedApis.filter(_.apiShortVersion==version).head
case _=> throw new IllegalArgumentException("Incorrect ApiVersion value: " + value) // There is no Role
}
versions.filter(_ == compatibilityVersion) match {
case x :: Nil => x // We find exactly one Role
case x :: _ => throw new Exception("Duplicated version: " + x) // We find more than one Role
case _ => throw new IllegalArgumentException("Incorrect ApiVersion value: " + value) // There is no Role
}
}
}