mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 15:27:01 +00:00
refactor/(api): centralize API info properties in APIUtil
- Introduced centralized properties for hosted organization details, including email, phone, and website. - Updated JSONFactory classes to utilize the new centralized properties instead of direct property retrieval. - Simplified API info JSON generation by reducing redundancy in property access. - Enhanced clarity and maintainability of API information retrieval across different API versions.
This commit is contained in:
parent
ddee799b74
commit
c5e6b11e11
@ -331,6 +331,17 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
|
||||
commit
|
||||
}
|
||||
|
||||
// API info props helpers (keep values centralized)
|
||||
lazy val hostedByOrganisation: String = getPropsValue("hosted_by.organisation", "TESOBE")
|
||||
lazy val hostedByEmail: String = getPropsValue("hosted_by.email", "contact@tesobe.com")
|
||||
lazy val hostedByPhone: String = getPropsValue("hosted_by.phone", "+49 (0)30 8145 3994")
|
||||
lazy val organisationWebsite: String = getPropsValue("organisation_website", "https://www.tesobe.com")
|
||||
lazy val hostedAtOrganisation: String = getPropsValue("hosted_at.organisation", "")
|
||||
lazy val hostedAtOrganisationWebsite: String = getPropsValue("hosted_at.organisation_website", "")
|
||||
lazy val energySourceOrganisation: String = getPropsValue("energy_source.organisation", "")
|
||||
lazy val energySourceOrganisationWebsite: String = getPropsValue("energy_source.organisation_website", "")
|
||||
lazy val resourceDocsRequiresRole: Boolean = getPropsAsBoolValue("resource_docs_requires_role", false)
|
||||
|
||||
|
||||
/**
|
||||
* Caching of unchanged resources
|
||||
|
||||
@ -1095,22 +1095,22 @@ case class JsonCodeTemplateJson(
|
||||
object JSONFactory400 {
|
||||
|
||||
def getApiInfoJSON(apiVersion : ApiVersion, apiVersionStatus : String) = {
|
||||
val organisation = APIUtil.getPropsValue("hosted_by.organisation", "TESOBE")
|
||||
val email = APIUtil.getPropsValue("hosted_by.email", "contact@tesobe.com")
|
||||
val phone = APIUtil.getPropsValue("hosted_by.phone", "+49 (0)30 8145 3994")
|
||||
val organisationWebsite = APIUtil.getPropsValue("organisation_website", "https://www.tesobe.com")
|
||||
val organisation = APIUtil.hostedByOrganisation
|
||||
val email = APIUtil.hostedByEmail
|
||||
val phone = APIUtil.hostedByPhone
|
||||
val organisationWebsite = APIUtil.organisationWebsite
|
||||
val hostedBy = new HostedBy400(organisation, email, phone, organisationWebsite)
|
||||
|
||||
val organisationHostedAt = APIUtil.getPropsValue("hosted_at.organisation", "")
|
||||
val organisationWebsiteHostedAt = APIUtil.getPropsValue("hosted_at.organisation_website", "")
|
||||
val organisationHostedAt = APIUtil.hostedAtOrganisation
|
||||
val organisationWebsiteHostedAt = APIUtil.hostedAtOrganisationWebsite
|
||||
val hostedAt = new HostedAt400(organisationHostedAt, organisationWebsiteHostedAt)
|
||||
|
||||
val organisationEnergySource = APIUtil.getPropsValue("energy_source.organisation", "")
|
||||
val organisationWebsiteEnergySource = APIUtil.getPropsValue("energy_source.organisation_website", "")
|
||||
val organisationEnergySource = APIUtil.energySourceOrganisation
|
||||
val organisationWebsiteEnergySource = APIUtil.energySourceOrganisationWebsite
|
||||
val energySource = new EnergySource400(organisationEnergySource, organisationWebsiteEnergySource)
|
||||
|
||||
val connector = code.api.Constant.CONNECTOR.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ")
|
||||
val resourceDocsRequiresRole = APIUtil.getPropsAsBoolValue("resource_docs_requires_role", false)
|
||||
val resourceDocsRequiresRole = APIUtil.resourceDocsRequiresRole
|
||||
|
||||
APIInfoJson400(
|
||||
apiVersion.vDottedApiVersion,
|
||||
|
||||
@ -1049,22 +1049,22 @@ object JSONFactory510 extends CustomJsonFormats with MdcLoggable {
|
||||
}
|
||||
|
||||
def getApiInfoJSON(apiVersion : ApiVersion, apiVersionStatus: String) = {
|
||||
val organisation = APIUtil.getPropsValue("hosted_by.organisation", "TESOBE")
|
||||
val email = APIUtil.getPropsValue("hosted_by.email", "contact@tesobe.com")
|
||||
val phone = APIUtil.getPropsValue("hosted_by.phone", "+49 (0)30 8145 3994")
|
||||
val organisationWebsite = APIUtil.getPropsValue("organisation_website", "https://www.tesobe.com")
|
||||
val organisation = APIUtil.hostedByOrganisation
|
||||
val email = APIUtil.hostedByEmail
|
||||
val phone = APIUtil.hostedByPhone
|
||||
val organisationWebsite = APIUtil.organisationWebsite
|
||||
val hostedBy = new HostedBy400(organisation, email, phone, organisationWebsite)
|
||||
|
||||
val organisationHostedAt = APIUtil.getPropsValue("hosted_at.organisation", "")
|
||||
val organisationWebsiteHostedAt = APIUtil.getPropsValue("hosted_at.organisation_website", "")
|
||||
val organisationHostedAt = APIUtil.hostedAtOrganisation
|
||||
val organisationWebsiteHostedAt = APIUtil.hostedAtOrganisationWebsite
|
||||
val hostedAt = HostedAt400(organisationHostedAt, organisationWebsiteHostedAt)
|
||||
|
||||
val organisationEnergySource = APIUtil.getPropsValue("energy_source.organisation", "")
|
||||
val organisationWebsiteEnergySource = APIUtil.getPropsValue("energy_source.organisation_website", "")
|
||||
val organisationEnergySource = APIUtil.energySourceOrganisation
|
||||
val organisationWebsiteEnergySource = APIUtil.energySourceOrganisationWebsite
|
||||
val energySource = EnergySource400(organisationEnergySource, organisationWebsiteEnergySource)
|
||||
|
||||
val connector = code.api.Constant.CONNECTOR.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ")
|
||||
val resourceDocsRequiresRole = APIUtil.getPropsAsBoolValue("resource_docs_requires_role", false)
|
||||
val resourceDocsRequiresRole = APIUtil.resourceDocsRequiresRole
|
||||
|
||||
APIInfoJsonV510(
|
||||
version = apiVersion.vDottedApiVersion,
|
||||
|
||||
@ -77,7 +77,7 @@ object Http4s700 {
|
||||
val root: HttpRoutes[IO] = HttpRoutes.of[IO] {
|
||||
case req @ GET -> `prefixPath` / "root" =>
|
||||
val responseJson = convertAnyToJsonString(
|
||||
JSONFactory700.getApiInfoJSON(implementedInApiVersion, s"Hello")
|
||||
JSONFactory700.getApiInfoJSON(implementedInApiVersion, versionStatus)
|
||||
)
|
||||
|
||||
Ok(responseJson).map(_.withContentType(jsonContentType))
|
||||
@ -111,7 +111,7 @@ object Http4s700 {
|
||||
case req @ GET -> `prefixPath` / "banks" =>
|
||||
|
||||
val responseJson = convertAnyToJsonString(
|
||||
JSONFactory700.getApiInfoJSON(implementedInApiVersion, s"Hello ")
|
||||
JSONFactory700.getApiInfoJSON(implementedInApiVersion, versionStatus)
|
||||
)
|
||||
Ok(responseJson).map(_.withContentType(jsonContentType))
|
||||
}
|
||||
|
||||
@ -6,20 +6,9 @@ import code.api.util.ErrorMessages.MandatoryPropertyIsNotSet
|
||||
import code.api.v4_0_0.{EnergySource400, HostedAt400, HostedBy400}
|
||||
import code.util.Helper.MdcLoggable
|
||||
import com.openbankproject.commons.util.ApiVersion
|
||||
import net.liftweb.util.Props
|
||||
|
||||
object JSONFactory700 extends MdcLoggable {
|
||||
|
||||
// Get git commit from build info
|
||||
lazy val gitCommit: String = {
|
||||
val commit = try {
|
||||
Props.get("git.commit.id", "unknown")
|
||||
} catch {
|
||||
case _: Throwable => "unknown"
|
||||
}
|
||||
commit
|
||||
}
|
||||
|
||||
case class APIInfoJsonV700(
|
||||
version: String,
|
||||
version_status: String,
|
||||
@ -31,32 +20,31 @@ object JSONFactory700 extends MdcLoggable {
|
||||
hosted_by: HostedBy400,
|
||||
hosted_at: HostedAt400,
|
||||
energy_source: EnergySource400,
|
||||
resource_docs_requires_role: Boolean,
|
||||
message: String
|
||||
resource_docs_requires_role: Boolean
|
||||
)
|
||||
|
||||
def getApiInfoJSON(apiVersion: ApiVersion, message: String): APIInfoJsonV700 = {
|
||||
val organisation = APIUtil.getPropsValue("hosted_by.organisation", "TESOBE")
|
||||
val email = APIUtil.getPropsValue("hosted_by.email", "contact@tesobe.com")
|
||||
val phone = APIUtil.getPropsValue("hosted_by.phone", "+49 (0)30 8145 3994")
|
||||
val organisationWebsite = APIUtil.getPropsValue("organisation_website", "https://www.tesobe.com")
|
||||
def getApiInfoJSON(apiVersion: ApiVersion, apiVersionStatus: String): APIInfoJsonV700 = {
|
||||
val organisation = APIUtil.hostedByOrganisation
|
||||
val email = APIUtil.hostedByEmail
|
||||
val phone = APIUtil.hostedByPhone
|
||||
val organisationWebsite = APIUtil.organisationWebsite
|
||||
val hostedBy = new HostedBy400(organisation, email, phone, organisationWebsite)
|
||||
|
||||
val organisationHostedAt = APIUtil.getPropsValue("hosted_at.organisation", "")
|
||||
val organisationWebsiteHostedAt = APIUtil.getPropsValue("hosted_at.organisation_website", "")
|
||||
val organisationHostedAt = APIUtil.hostedAtOrganisation
|
||||
val organisationWebsiteHostedAt = APIUtil.hostedAtOrganisationWebsite
|
||||
val hostedAt = HostedAt400(organisationHostedAt, organisationWebsiteHostedAt)
|
||||
|
||||
val organisationEnergySource = APIUtil.getPropsValue("energy_source.organisation", "")
|
||||
val organisationWebsiteEnergySource = APIUtil.getPropsValue("energy_source.organisation_website", "")
|
||||
val organisationEnergySource = APIUtil.energySourceOrganisation
|
||||
val organisationWebsiteEnergySource = APIUtil.energySourceOrganisationWebsite
|
||||
val energySource = EnergySource400(organisationEnergySource, organisationWebsiteEnergySource)
|
||||
|
||||
val connector = code.api.Constant.CONNECTOR.openOrThrowException(s"$MandatoryPropertyIsNotSet. The missing prop is `connector` ")
|
||||
val resourceDocsRequiresRole = APIUtil.getPropsAsBoolValue("resource_docs_requires_role", false)
|
||||
val resourceDocsRequiresRole = APIUtil.resourceDocsRequiresRole
|
||||
|
||||
APIInfoJsonV700(
|
||||
version = apiVersion.vDottedApiVersion,
|
||||
version_status = "BLEEDING_EDGE",
|
||||
git_commit = gitCommit,
|
||||
version_status = apiVersionStatus,
|
||||
git_commit = APIUtil.gitCommit,
|
||||
connector = connector,
|
||||
hostname = Constant.HostName,
|
||||
stage = System.getProperty("run.mode"),
|
||||
@ -64,8 +52,7 @@ object JSONFactory700 extends MdcLoggable {
|
||||
hosted_by = hostedBy,
|
||||
hosted_at = hostedAt,
|
||||
energy_source = energySource,
|
||||
resource_docs_requires_role = resourceDocsRequiresRole,
|
||||
message = message
|
||||
resource_docs_requires_role = resourceDocsRequiresRole
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user