diff --git a/obp-api/src/main/scala/code/api/util/APIUtil.scala b/obp-api/src/main/scala/code/api/util/APIUtil.scala index f8469d92cd..13e54222e2 100644 --- a/obp-api/src/main/scala/code/api/util/APIUtil.scala +++ b/obp-api/src/main/scala/code/api/util/APIUtil.scala @@ -452,9 +452,14 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ val commit = try { val properties = new java.util.Properties() logger.debug("Before getResourceAsStream git.properties") - properties.load(getClass().getClassLoader().getResourceAsStream("git.properties")) - logger.debug("Before get Property git.commit.id") - properties.getProperty("git.commit.id", "") + val stream = getClass().getClassLoader().getResourceAsStream("git.properties") + try { + properties.load(stream) + logger.debug("Before get Property git.commit.id") + properties.getProperty("git.commit.id", "") + } finally { + stream.close() + } } catch { case e : Throwable => { logger.warn("gitCommit says: Could not return git commit. Does resources/git.properties exist?") diff --git a/obp-api/src/main/scala/code/api/v1_2_1/APIMethods121.scala b/obp-api/src/main/scala/code/api/v1_2_1/APIMethods121.scala index 756335808f..21aa689e8b 100644 --- a/obp-api/src/main/scala/code/api/v1_2_1/APIMethods121.scala +++ b/obp-api/src/main/scala/code/api/v1_2_1/APIMethods121.scala @@ -111,23 +111,6 @@ trait APIMethods121 { } yield metadata } - private def getApiInfoJSON(apiVersion : ApiVersion, apiVersionStatus : String) = { - val apiDetails: JValue = { - - 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 connector = APIUtil.getPropsValue("connector").openOrThrowException("no connector set") - - val hostedBy = new HostedBy(organisation, email, phone, organisationWebsite) - val apiInfoJSON = new APIInfoJSON(apiVersion.vDottedApiVersion, apiVersionStatus, gitCommit, connector, hostedBy) - Extraction.decompose(apiInfoJSON) - } - apiDetails - } - // helper methods end here val Implementations1_2_1 = new Object(){ @@ -161,7 +144,7 @@ trait APIMethods121 { for { _ <- Future() // Just start async call } yield { - (getApiInfoJSON(apiVersion,apiVersionStatus), HttpCode.`200`(cc.callContext)) + (JSONFactory.getApiInfoJSON(apiVersion,apiVersionStatus), HttpCode.`200`(cc.callContext)) } } } diff --git a/obp-api/src/main/scala/code/api/v1_2_1/JSONFactory1.2.1.scala b/obp-api/src/main/scala/code/api/v1_2_1/JSONFactory1.2.1.scala index d23c115a25..48205ca036 100644 --- a/obp-api/src/main/scala/code/api/v1_2_1/JSONFactory1.2.1.scala +++ b/obp-api/src/main/scala/code/api/v1_2_1/JSONFactory1.2.1.scala @@ -28,10 +28,14 @@ package code.api.v1_2_1 import java.util.Date +import code.api.util.APIUtil import net.liftweb.common.{Box, Full} import code.model._ import code.api.util.APIUtil._ import com.openbankproject.commons.model._ +import com.openbankproject.commons.util.ApiVersion +import net.liftweb.json.Extraction +import net.liftweb.json.JsonAST.JValue case class APIInfoJSON( version : String, @@ -358,6 +362,24 @@ case class MakePaymentJson( ) object JSONFactory{ + + def getApiInfoJSON(apiVersion : ApiVersion, apiVersionStatus : String) = { + val apiDetails: JValue = { + + 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 connector = APIUtil.getPropsValue("connector").openOrThrowException("no connector set") + + val hostedBy = new HostedBy(organisation, email, phone, organisationWebsite) + val apiInfoJSON = new APIInfoJSON(apiVersion.vDottedApiVersion, apiVersionStatus, gitCommit, connector, hostedBy) + Extraction.decompose(apiInfoJSON) + } + apiDetails + } + def createBankJSON(bank : Bank) : BankJSON = { new BankJSON( stringOrNull(bank.bankId.value), diff --git a/obp-api/src/main/scala/code/api/v1_2_1/OBPAPI1.2.1.scala b/obp-api/src/main/scala/code/api/v1_2_1/OBPAPI1.2.1.scala index 773cd31222..c4b84dc89b 100644 --- a/obp-api/src/main/scala/code/api/v1_2_1/OBPAPI1.2.1.scala +++ b/obp-api/src/main/scala/code/api/v1_2_1/OBPAPI1.2.1.scala @@ -41,7 +41,7 @@ object OBPAPI1_2_1 extends OBPRestHelper with APIMethods121 with MdcLoggable wit val versionStatus = ApiVersionStatus.STABLE.toString lazy val endpointsOf1_2_1 = List( - Implementations1_2_1.root(version, versionStatus), + Implementations1_2_1.root, Implementations1_2_1.getBanks, Implementations1_2_1.bankById, Implementations1_2_1.getPrivateAccountsAllBanks, @@ -117,8 +117,7 @@ object OBPAPI1_2_1 extends OBPRestHelper with APIMethods121 with MdcLoggable wit // Filter the possible endpoints by the disabled / enabled Props settings and add them together val routes : List[OBPEndpoint] = - List(Implementations1_2_1.root(version, versionStatus)) ::: // For now we make this mandatory - getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) + getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) registerRoutes(routes, allResourceDocs, apiPrefix) diff --git a/obp-api/src/main/scala/code/api/v1_3_0/APIMethods130.scala b/obp-api/src/main/scala/code/api/v1_3_0/APIMethods130.scala index 741d99f0d4..59d1c1456e 100644 --- a/obp-api/src/main/scala/code/api/v1_3_0/APIMethods130.scala +++ b/obp-api/src/main/scala/code/api/v1_3_0/APIMethods130.scala @@ -7,6 +7,7 @@ import code.api.util.ErrorMessages._ import code.api.util.FutureUtil.EndpointContext import code.api.util.NewStyle.HttpCode import code.api.util.{ErrorMessages, NewStyle} +import code.api.v1_2_1.JSONFactory import code.bankconnectors.Connector import code.model.BankX import com.openbankproject.commons.model.BankId @@ -18,6 +19,7 @@ import net.liftweb.json.Extraction import scala.collection.immutable.Nil import scala.collection.mutable.ArrayBuffer +import scala.concurrent.Future trait APIMethods130 { //needs to be a RestHelper to get access to JsonGet, JsonPost, etc. @@ -30,6 +32,35 @@ trait APIMethods130 { val apiVersion = ApiVersion.v1_3_0 // was String "1_3_0" + resourceDocs += ResourceDoc( + root, + apiVersion, + "root", + "GET", + "/root", + "Get API Info (root)", + """Returns information about: + | + |* API version + |* Hosted by information + |* Git Commit""", + emptyObjectJson, + apiInfoJSON, + List(UnknownError, "no connector set"), + apiTagApi :: Nil) + + lazy val root : OBPEndpoint = { + case (Nil | "root" :: Nil) JsonGet _ => { + cc => + implicit val ec = EndpointContext(Some(cc)) + for { + _ <- Future() // Just start async call + } yield { + (JSONFactory.getApiInfoJSON(OBPAPI1_3_0.version, OBPAPI1_3_0.versionStatus), HttpCode.`200`(cc.callContext)) + } + } + } + resourceDocs += ResourceDoc( getCards, apiVersion, diff --git a/obp-api/src/main/scala/code/api/v1_3_0/OBPAPI1_3_0.scala b/obp-api/src/main/scala/code/api/v1_3_0/OBPAPI1_3_0.scala index 281fe52a89..de3ed7d771 100644 --- a/obp-api/src/main/scala/code/api/v1_3_0/OBPAPI1_3_0.scala +++ b/obp-api/src/main/scala/code/api/v1_3_0/OBPAPI1_3_0.scala @@ -20,7 +20,6 @@ object OBPAPI1_3_0 extends OBPRestHelper with APIMethods130 with APIMethods121 w //TODO: check all these calls to see if they should really have the same behaviour as 1.2.1 lazy val endpointsOf1_2_1 = List( - Implementations1_2_1.root(version, versionStatus), Implementations1_2_1.getBanks, Implementations1_2_1.bankById, Implementations1_2_1.getPrivateAccountsAllBanks, @@ -93,6 +92,7 @@ object OBPAPI1_3_0 extends OBPRestHelper with APIMethods130 with APIMethods121 w ) val endpointsOf1_3_0 = List( + Implementations1_3_0.root, Implementations1_3_0.getCards, Implementations1_3_0.getCardsForBank ) @@ -103,7 +103,6 @@ object OBPAPI1_3_0 extends OBPRestHelper with APIMethods130 with APIMethods121 w // Filter the possible endpoints by the disabled / enabled Props settings and add them together val routes : List[OBPEndpoint] = - List(Implementations1_2_1.root(version, versionStatus)) ::: // For now we make this mandatory getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) ::: getAllowedEndpoints(endpointsOf1_3_0, Implementations1_3_0.resourceDocs) diff --git a/obp-api/src/main/scala/code/api/v1_4_0/APIMethods140.scala b/obp-api/src/main/scala/code/api/v1_4_0/APIMethods140.scala index 964cd3abd4..9c89b1c17e 100644 --- a/obp-api/src/main/scala/code/api/v1_4_0/APIMethods140.scala +++ b/obp-api/src/main/scala/code/api/v1_4_0/APIMethods140.scala @@ -5,6 +5,8 @@ import code.api.util.ApiTag._ import code.api.util.FutureUtil.EndpointContext import code.api.util.NewStyle.HttpCode import code.api.util._ +import code.api.v1_2_1.JSONFactory +import code.api.v1_3_0.OBPAPI1_3_0 import code.api.v1_4_0.JSONFactory1_4_0._ import code.api.v2_0_0.CreateCustomerJson import code.atms.Atms @@ -62,6 +64,36 @@ trait APIMethods140 extends MdcLoggable with APIMethods130 with APIMethods121{ val apiVersion = ApiVersion.v1_4_0 // was noV i.e. "1_4_0" val apiVersionStatus : String = "STABLE" + + resourceDocs += ResourceDoc( + root, + apiVersion, + "root", + "GET", + "/root", + "Get API Info (root)", + """Returns information about: + | + |* API version + |* Hosted by information + |* Git Commit""", + emptyObjectJson, + apiInfoJSON, + List(UnknownError, "no connector set"), + apiTagApi :: Nil) + + lazy val root : OBPEndpoint = { + case (Nil | "root" :: Nil) JsonGet _ => { + cc => + implicit val ec = EndpointContext(Some(cc)) + for { + _ <- Future() // Just start async call + } yield { + (JSONFactory.getApiInfoJSON(OBPAPI1_4_0.version, OBPAPI1_4_0.versionStatus), HttpCode.`200`(cc.callContext)) + } + } + } + resourceDocs += ResourceDoc( getCustomer, apiVersion, diff --git a/obp-api/src/main/scala/code/api/v1_4_0/OBPAPI1_4_0.scala b/obp-api/src/main/scala/code/api/v1_4_0/OBPAPI1_4_0.scala index b69fb403fa..0e4585cb27 100644 --- a/obp-api/src/main/scala/code/api/v1_4_0/OBPAPI1_4_0.scala +++ b/obp-api/src/main/scala/code/api/v1_4_0/OBPAPI1_4_0.scala @@ -13,7 +13,6 @@ object OBPAPI1_4_0 extends OBPRestHelper with APIMethods140 with MdcLoggable wit val versionStatus = ApiVersionStatus.STABLE.toString lazy val endpointsOf1_2_1 = List( - Implementations1_2_1.root(version, versionStatus), Implementations1_2_1.getBanks, Implementations1_2_1.bankById, Implementations1_2_1.getPrivateAccountsAllBanks, @@ -95,6 +94,7 @@ object OBPAPI1_4_0 extends OBPRestHelper with APIMethods140 with MdcLoggable wit // New in 1.4.0 val endpointsOf1_4_0 = List( + Implementations1_4_0.root, Implementations1_4_0.getCustomer, Implementations1_4_0.addCustomer, Implementations1_4_0.getCustomersMessages, @@ -117,8 +117,7 @@ object OBPAPI1_4_0 extends OBPRestHelper with APIMethods140 with MdcLoggable wit // Filter the possible endpoints by the disabled / enabled Props settings and add them together val routes : List[OBPEndpoint] = - List(Implementations1_2_1.root(version, versionStatus)) ::: // For now we make this mandatory - getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) ::: + getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) ::: getAllowedEndpoints(endpointsOf1_3_0, Implementations1_3_0.resourceDocs) ::: getAllowedEndpoints(endpointsOf1_4_0, Implementations1_4_0.resourceDocs) diff --git a/obp-api/src/main/scala/code/api/v2_0_0/APIMethods200.scala b/obp-api/src/main/scala/code/api/v2_0_0/APIMethods200.scala index f4d5a5e8f5..2009a08f8e 100644 --- a/obp-api/src/main/scala/code/api/v2_0_0/APIMethods200.scala +++ b/obp-api/src/main/scala/code/api/v2_0_0/APIMethods200.scala @@ -15,6 +15,7 @@ import code.api.util.NewStyle.HttpCode import code.api.util._ import code.api.v1_2_1.OBPAPI1_2_1._ import code.api.v1_2_1.{JSONFactory => JSONFactory121} +import code.api.v1_3_0.OBPAPI1_3_0 import code.api.v1_4_0.JSONFactory1_4_0 import code.api.v1_4_0.JSONFactory1_4_0.ChallengeAnswerJSON import code.api.v2_0_0.JSONFactory200.{privateBankAccountsListToJson, _} @@ -134,6 +135,35 @@ trait APIMethods200 { + resourceDocs += ResourceDoc( + root, + apiVersion, + "root", + "GET", + "/root", + "Get API Info (root)", + """Returns information about: + | + |* API version + |* Hosted by information + |* Git Commit""", + emptyObjectJson, + apiInfoJSON, + List(UnknownError, "no connector set"), + apiTagApi :: Nil) + + lazy val root : OBPEndpoint = { + case (Nil | "root" :: Nil) JsonGet _ => { + cc => + implicit val ec = EndpointContext(Some(cc)) + for { + _ <- Future() // Just start async call + } yield { + (JSONFactory121.getApiInfoJSON(OBPAPI2_0_0.version, OBPAPI2_0_0.versionStatus), HttpCode.`200`(cc.callContext)) + } + } + } + resourceDocs += ResourceDoc( diff --git a/obp-api/src/main/scala/code/api/v2_0_0/OBPAPI2_0_0.scala b/obp-api/src/main/scala/code/api/v2_0_0/OBPAPI2_0_0.scala index 74df67e89c..54618256b1 100644 --- a/obp-api/src/main/scala/code/api/v2_0_0/OBPAPI2_0_0.scala +++ b/obp-api/src/main/scala/code/api/v2_0_0/OBPAPI2_0_0.scala @@ -44,7 +44,6 @@ object OBPAPI2_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w // Note: Since we pattern match on these routes, if two implementations match a given url the first will match lazy val endpointsOf1_2_1 = List( - Implementations1_2_1.root(version, versionStatus), Implementations1_2_1.getBanks, Implementations1_2_1.bankById, // Now in 2_0_0 @@ -139,6 +138,7 @@ object OBPAPI2_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w // Updated in 2.0.0 (less info about the views) val endpointsOf2_0_0 = List( + Implementations2_0_0.root, Implementations2_0_0.getPrivateAccountsAllBanks, Implementations2_0_0.corePrivateAccountsAllBanks, Implementations2_0_0.publicAccountsAllBanks, @@ -194,8 +194,7 @@ object OBPAPI2_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w // Filter the possible endpoints by the disabled / enabled Props settings and add them together val routes : List[OBPEndpoint] = - List(Implementations1_2_1.root(version, versionStatus)) ::: // For now we make this mandatory - getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) ::: + getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) ::: getAllowedEndpoints(endpointsOf1_3_0, Implementations1_3_0.resourceDocs) ::: getAllowedEndpoints(endpointsOf1_4_0, Implementations1_4_0.resourceDocs) ::: getAllowedEndpoints(endpointsOf2_0_0, Implementations2_0_0.resourceDocs) diff --git a/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala b/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala index b0f95cba0f..0437a4f0a6 100644 --- a/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala +++ b/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala @@ -9,6 +9,7 @@ import code.api.util.ErrorMessages.TransactionDisabled import code.api.util.FutureUtil.EndpointContext import code.api.util.NewStyle.HttpCode import code.api.util.{APIUtil, ApiRole, ErrorMessages, NewStyle} +import code.api.v1_2_1.JSONFactory import code.api.v1_3_0.{JSONFactory1_3_0, _} import code.api.v1_4_0.JSONFactory1_4_0 import code.api.v1_4_0.JSONFactory1_4_0._ @@ -75,6 +76,36 @@ trait APIMethods210 { val codeContext = CodeContext(resourceDocs, apiRelations) + resourceDocs += ResourceDoc( + root, + apiVersion, + "root", + "GET", + "/root", + "Get API Info (root)", + """Returns information about: + | + |* API version + |* Hosted by information + |* Git Commit""", + emptyObjectJson, + apiInfoJSON, + List(UnknownError, "no connector set"), + apiTagApi :: Nil) + + lazy val root : OBPEndpoint = { + case (Nil | "root" :: Nil) JsonGet _ => { + cc => + implicit val ec = EndpointContext(Some(cc)) + for { + _ <- Future() // Just start async call + } yield { + (JSONFactory.getApiInfoJSON(OBPAPI2_1_0.version, OBPAPI2_1_0.versionStatus), HttpCode.`200`(cc.callContext)) + } + } + } + + // TODO Add example body below resourceDocs += ResourceDoc( diff --git a/obp-api/src/main/scala/code/api/v2_1_0/OBPAPI2_1_0.scala b/obp-api/src/main/scala/code/api/v2_1_0/OBPAPI2_1_0.scala index c57c2c2078..e796bbee58 100644 --- a/obp-api/src/main/scala/code/api/v2_1_0/OBPAPI2_1_0.scala +++ b/obp-api/src/main/scala/code/api/v2_1_0/OBPAPI2_1_0.scala @@ -173,6 +173,7 @@ object OBPAPI2_1_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w // Possible Endpoints 2.1.0 val endpointsOf2_1_0 = Implementations2_1_0.sandboxDataImport :: + Implementations2_1_0.root :: Implementations2_1_0.getTransactionRequestTypesSupportedByBank :: Implementations2_1_0.createTransactionRequest :: Implementations2_1_0.answerTransactionRequestChallenge :: @@ -206,8 +207,7 @@ object OBPAPI2_1_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w // Filter the possible endpoints by the disabled / enabled Props settings and add them together val routes : List[OBPEndpoint] = - List(Implementations1_2_1.root(version, versionStatus)) ::: // For now we make this mandatory - getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) ::: + getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) ::: getAllowedEndpoints(endpointsOf1_3_0, Implementations1_3_0.resourceDocs) ::: getAllowedEndpoints(endpointsOf1_4_0, Implementations1_4_0.resourceDocs) ::: getAllowedEndpoints(endpointsOf2_0_0, Implementations2_0_0.resourceDocs) ::: diff --git a/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala b/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala index 835027f6e2..614a5d14cf 100644 --- a/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala +++ b/obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala @@ -10,7 +10,8 @@ import code.api.util.ErrorMessages.{BankAccountNotFound, _} import code.api.util.FutureUtil.EndpointContext import code.api.util.NewStyle.HttpCode import code.api.util.{ErrorMessages, _} -import code.api.v1_2_1.{CreateViewJsonV121, UpdateViewJsonV121} +import code.api.v1_2_1.{CreateViewJsonV121, JSONFactory, UpdateViewJsonV121} +import code.api.v2_0_0.OBPAPI2_0_0 import code.api.v2_1_0._ import code.api.v2_2_0.JSONFactory220.transformV220ToBranch import code.bankconnectors._ @@ -56,6 +57,36 @@ trait APIMethods220 { val codeContext = CodeContext(resourceDocs, apiRelations) + resourceDocs += ResourceDoc( + root, + implementedInApiVersion, + "root", + "GET", + "/root", + "Get API Info (root)", + """Returns information about: + | + |* API version + |* Hosted by information + |* Git Commit""", + emptyObjectJson, + apiInfoJSON, + List(UnknownError, "no connector set"), + apiTagApi :: Nil) + + lazy val root : OBPEndpoint = { + case (Nil | "root" :: Nil) JsonGet _ => { + cc => + implicit val ec = EndpointContext(Some(cc)) + for { + _ <- Future() // Just start async call + } yield { + (JSONFactory.getApiInfoJSON(OBPAPI2_2_0.version, OBPAPI2_2_0.versionStatus), HttpCode.`200`(cc.callContext)) + } + } + } + + resourceDocs += ResourceDoc( getViewsForBankAccount, implementedInApiVersion, diff --git a/obp-api/src/main/scala/code/api/v2_2_0/OBPAPI2_2_0.scala b/obp-api/src/main/scala/code/api/v2_2_0/OBPAPI2_2_0.scala index ab10ff3ed1..3e3d015c63 100644 --- a/obp-api/src/main/scala/code/api/v2_2_0/OBPAPI2_2_0.scala +++ b/obp-api/src/main/scala/code/api/v2_2_0/OBPAPI2_2_0.scala @@ -174,6 +174,7 @@ object OBPAPI2_2_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w // Possible Endpoints 2.2.0 val endpointsOf2_2_0 = Implementations2_2_0.getViewsForBankAccount :: + Implementations2_2_0.root :: Implementations2_2_0.createViewForBankAccount :: Implementations2_2_0.updateViewForBankAccount :: Implementations2_2_0.getCurrentFxRate :: @@ -201,8 +202,7 @@ object OBPAPI2_2_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w // Filter the possible endpoints by the disabled / enabled Props settings and add them together val routes : List[OBPEndpoint] = - List(Implementations1_2_1.root(version, versionStatus)) ::: // For now we make this mandatory - getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) ::: + getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) ::: getAllowedEndpoints(endpointsOf1_3_0, Implementations1_3_0.resourceDocs) ::: getAllowedEndpoints(endpointsOf1_4_0, Implementations1_4_0.resourceDocs) ::: getAllowedEndpoints(endpointsOf2_0_0, Implementations2_0_0.resourceDocs) ::: diff --git a/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala b/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala index 2a3feab834..387ff149ac 100644 --- a/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala +++ b/obp-api/src/main/scala/code/api/v3_0_0/APIMethods300.scala @@ -16,7 +16,7 @@ import code.api.util.FutureUtil.EndpointContext import code.api.util.NewStyle.HttpCode import code.api.util._ import code.api.v1_2_1.JSONFactory -import code.api.v2_0_0.JSONFactory200 +import code.api.v2_0_0.{JSONFactory200, OBPAPI2_0_0} import code.api.v3_0_0.JSONFactory300._ import code.bankconnectors._ import code.consumer.Consumers @@ -27,7 +27,7 @@ import code.scope.Scope import code.search.elasticsearchWarehouse import code.users.Users import code.util.Helper -import code.util.Helper.{booleanToBox, booleanToFuture,ObpS} +import code.util.Helper.{ObpS, booleanToBox, booleanToFuture} import code.views.Views import code.views.system.ViewDefinition import com.github.dwickern.macros.NameOf.nameOf @@ -66,6 +66,37 @@ trait APIMethods300 { val apiRelations = ArrayBuffer[ApiRelation]() val codeContext = CodeContext(resourceDocs, apiRelations) + + + resourceDocs += ResourceDoc( + root, + implementedInApiVersion, + "root", + "GET", + "/root", + "Get API Info (root)", + """Returns information about: + | + |* API version + |* Hosted by information + |* Git Commit""", + emptyObjectJson, + apiInfoJSON, + List(UnknownError, "no connector set"), + apiTagApi :: Nil) + + lazy val root : OBPEndpoint = { + case (Nil | "root" :: Nil) JsonGet _ => { + cc => + implicit val ec = EndpointContext(Some(cc)) + for { + _ <- Future() // Just start async call + } yield { + (JSONFactory.getApiInfoJSON(OBPAPI3_0_0.version, OBPAPI3_0_0.versionStatus), HttpCode.`200`(cc.callContext)) + } + } + } + resourceDocs += ResourceDoc( getViewsForBankAccount, implementedInApiVersion, diff --git a/obp-api/src/main/scala/code/api/v3_0_0/OBPAPI3_0_0.scala b/obp-api/src/main/scala/code/api/v3_0_0/OBPAPI3_0_0.scala index c2eea2b63f..89678b1961 100644 --- a/obp-api/src/main/scala/code/api/v3_0_0/OBPAPI3_0_0.scala +++ b/obp-api/src/main/scala/code/api/v3_0_0/OBPAPI3_0_0.scala @@ -226,6 +226,7 @@ object OBPAPI3_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w // Possible Endpoints from 3.0.0 val endpointsOf3_0_0 = Implementations3_0_0.getCoreTransactionsForBankAccount :: + Implementations3_0_0.root :: Implementations3_0_0.getTransactionsForBankAccount :: Implementations3_0_0.getPrivateAccountById :: Implementations3_0_0.getPublicAccountById :: @@ -288,8 +289,7 @@ object OBPAPI3_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w // Filter the possible endpoints by the disabled / enabled Props settings and add them together val routes : List[OBPEndpoint] = - List(Implementations1_2_1.root(version, versionStatus)) ::: // For now we make this mandatory - getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) ::: + getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) ::: getAllowedEndpoints(endpointsOf1_3_0, Implementations1_3_0.resourceDocs) ::: getAllowedEndpoints(endpointsOf1_4_0, Implementations1_4_0.resourceDocs) ::: getAllowedEndpoints(endpointsOf2_0_0, Implementations2_0_0.resourceDocs) ::: diff --git a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala index 9e2bccf12b..3ba00314f9 100644 --- a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala +++ b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala @@ -81,6 +81,36 @@ trait APIMethods310 { val apiRelations = ArrayBuffer[ApiRelation]() val codeContext = CodeContext(resourceDocs, apiRelations) + + resourceDocs += ResourceDoc( + root, + implementedInApiVersion, + "root", + "GET", + "/root", + "Get API Info (root)", + """Returns information about: + | + |* API version + |* Hosted by information + |* Git Commit""", + emptyObjectJson, + apiInfoJSON, + List(UnknownError, "no connector set"), + apiTagApi :: Nil) + + lazy val root : OBPEndpoint = { + case (Nil | "root" :: Nil) JsonGet _ => { + cc => + implicit val ec = EndpointContext(Some(cc)) + for { + _ <- Future() // Just start async call + } yield { + (JSONFactory.getApiInfoJSON(OBPAPI3_1_0.version, OBPAPI3_1_0.versionStatus), HttpCode.`200`(cc.callContext)) + } + } + } + resourceDocs += ResourceDoc( getCheckbookOrders, implementedInApiVersion, diff --git a/obp-api/src/main/scala/code/api/v3_1_0/OBPAPI3_1_0.scala b/obp-api/src/main/scala/code/api/v3_1_0/OBPAPI3_1_0.scala index 545ae72520..9881be60bd 100644 --- a/obp-api/src/main/scala/code/api/v3_1_0/OBPAPI3_1_0.scala +++ b/obp-api/src/main/scala/code/api/v3_1_0/OBPAPI3_1_0.scala @@ -291,8 +291,7 @@ object OBPAPI3_1_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w // Filter the possible endpoints by the disabled / enabled Props settings and add them together val routes : List[OBPEndpoint] = - List(Implementations1_2_1.root(version, versionStatus)) ::: // For now we make this mandatory - getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) ::: + getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) ::: getAllowedEndpoints(endpointsOf1_3_0, Implementations1_3_0.resourceDocs) ::: getAllowedEndpoints(endpointsOf1_4_0, Implementations1_4_0.resourceDocs) ::: getAllowedEndpoints(endpointsOf2_0_0, Implementations2_0_0.resourceDocs) ::: diff --git a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala index b617501b91..0ea0bd02ae 100644 --- a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala +++ b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala @@ -2647,38 +2647,7 @@ trait APIMethods400 { } - - private 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 hostedBy = new HostedBy400(organisation, email, phone, organisationWebsite) - - val organisationHostedAt = APIUtil.getPropsValue("hosted_at.organisation", "") - val organisationWebsiteHostedAt = APIUtil.getPropsValue("hosted_at.organisation_website", "") - val hostedAt = new HostedAt400(organisationHostedAt, organisationWebsiteHostedAt) - - val organisationEnergySource = APIUtil.getPropsValue("energy_source.organisation", "") - val organisationWebsiteEnergySource = APIUtil.getPropsValue("energy_source.organisation_website", "") - val energySource = new EnergySource400(organisationEnergySource, organisationWebsiteEnergySource) - - val connector = APIUtil.getPropsValue("connector").openOrThrowException("no connector set") - val resourceDocsRequiresRole = APIUtil.getPropsAsBoolValue("resource_docs_requires_role", false) - - APIInfoJson400( - apiVersion.vDottedApiVersion, - apiVersionStatus, - gitCommit, - connector, - Constant.HostName, - Constant.localIdentityProvider, - hostedBy, - hostedAt, - energySource, - resourceDocsRequiresRole - ) - } + staticResourceDocs += ResourceDoc( @@ -2707,7 +2676,7 @@ trait APIMethods400 { for { _ <- Future() // Just start async call } yield { - (getApiInfoJSON(OBPAPI4_0_0.version,OBPAPI4_0_0.versionStatus), HttpCode.`200`(cc.callContext)) + (JSONFactory400.getApiInfoJSON(OBPAPI4_0_0.version,OBPAPI4_0_0.versionStatus), HttpCode.`200`(cc.callContext)) } } } diff --git a/obp-api/src/main/scala/code/api/v4_0_0/JSONFactory4.0.0.scala b/obp-api/src/main/scala/code/api/v4_0_0/JSONFactory4.0.0.scala index c171321160..61730a237a 100644 --- a/obp-api/src/main/scala/code/api/v4_0_0/JSONFactory4.0.0.scala +++ b/obp-api/src/main/scala/code/api/v4_0_0/JSONFactory4.0.0.scala @@ -28,10 +28,11 @@ package code.api.v4_0_0 import java.text.SimpleDateFormat import java.util.Date + import code.api.Constant import code.api.attributedefinition.AttributeDefinition import code.api.util.APIUtil -import code.api.util.APIUtil.{DateWithDay, DateWithSeconds, stringOptionOrNull, stringOrNull} +import code.api.util.APIUtil.{DateWithDay, DateWithSeconds, gitCommit, stringOptionOrNull, stringOrNull} import code.api.v1_2_1.JSONFactory.{createAmountOfMoneyJSON, createOwnersJSON} import code.api.v1_2_1.{BankRoutingJsonV121, JSONFactory, UserJSONV121, ViewJSONV121} import code.api.v1_4_0.JSONFactory1_4_0.{LocationJsonV140, MetaJsonV140, TransactionRequestAccountJsonV140, transformToLocationFromV140, transformToMetaFromV140} @@ -60,6 +61,7 @@ import code.views.system.AccountAccess import code.webhook.{AccountWebhook, BankAccountNotificationWebhookTrait, SystemAccountNotificationWebhookTrait} import com.openbankproject.commons.model.enums.ChallengeType import com.openbankproject.commons.model.{DirectDebitTrait, ProductFeeTrait, _} +import com.openbankproject.commons.util.ApiVersion import net.liftweb.common.{Box, Full} import net.liftweb.json.JValue import net.liftweb.mapper.By @@ -1089,6 +1091,38 @@ 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 hostedBy = new HostedBy400(organisation, email, phone, organisationWebsite) + + val organisationHostedAt = APIUtil.getPropsValue("hosted_at.organisation", "") + val organisationWebsiteHostedAt = APIUtil.getPropsValue("hosted_at.organisation_website", "") + val hostedAt = new HostedAt400(organisationHostedAt, organisationWebsiteHostedAt) + + val organisationEnergySource = APIUtil.getPropsValue("energy_source.organisation", "") + val organisationWebsiteEnergySource = APIUtil.getPropsValue("energy_source.organisation_website", "") + val energySource = new EnergySource400(organisationEnergySource, organisationWebsiteEnergySource) + + val connector = APIUtil.getPropsValue("connector").openOrThrowException("no connector set") + val resourceDocsRequiresRole = APIUtil.getPropsAsBoolValue("resource_docs_requires_role", false) + + APIInfoJson400( + apiVersion.vDottedApiVersion, + apiVersionStatus, + gitCommit, + connector, + Constant.HostName, + Constant.localIdentityProvider, + hostedBy, + hostedAt, + energySource, + resourceDocsRequiresRole + ) + } + def createCustomerMessageJson(cMessage : CustomerMessage) : CustomerMessageJsonV400 = { CustomerMessageJsonV400( id = cMessage.messageId, diff --git a/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala b/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala index a3ef0cc79c..d3f144ce6e 100644 --- a/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala +++ b/obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala @@ -16,7 +16,7 @@ import code.api.v2_1_0.JSONFactory210 import code.api.v3_0_0.JSONFactory300 import code.api.v3_1_0._ import code.api.v4_0_0.JSONFactory400.createCustomersMinimalJson -import code.api.v4_0_0.{JSONFactory400, PutProductJsonV400} +import code.api.v4_0_0.{JSONFactory400, OBPAPI4_0_0, PutProductJsonV400} import code.api.v5_0_0.JSONFactory500.{createPhysicalCardJson, createViewJsonV500, createViewsIdsJsonV500, createViewsJsonV500} import code.bankconnectors.Connector import code.consent.{ConsentRequest, ConsentRequests, Consents} @@ -44,7 +44,7 @@ import java.util.concurrent.ThreadLocalRandom import code.accountattribute.AccountAttributeX import code.api.Constant.SYSTEM_OWNER_VIEW_ID -import code.api.util.FutureUtil.{EndpointContext} +import code.api.util.FutureUtil.EndpointContext import code.util.Helper.booleanToFuture import code.views.system.{AccountAccess, ViewDefinition} @@ -83,6 +83,37 @@ trait APIMethods500 { val codeContext = CodeContext(staticResourceDocs, apiRelations) + staticResourceDocs += ResourceDoc( + root, + implementedInApiVersion, + "root", + "GET", + "/root", + "Get API Info (root)", + """Returns information about: + | + |* API version + |* Hosted by information + |* Hosted at information + |* Energy source information + |* Git Commit""", + EmptyBody, + apiInfoJson400, + List(UnknownError, "no connector set"), + apiTagApi :: Nil) + + lazy val root: OBPEndpoint = { + case (Nil | "root" :: Nil) JsonGet _ => { + cc => + implicit val ec = EndpointContext(Some(cc)) + for { + _ <- Future() // Just start async call + } yield { + (JSONFactory400.getApiInfoJSON(OBPAPI5_0_0.version,OBPAPI5_0_0.versionStatus), HttpCode.`200`(cc.callContext)) + } + } + } + staticResourceDocs += ResourceDoc( getBank, implementedInApiVersion, diff --git a/obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala b/obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala index 3af8599e77..b424dc291b 100644 --- a/obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala +++ b/obp-api/src/main/scala/code/api/v5_0_0/JSONFactory5.0.0.scala @@ -29,7 +29,9 @@ package code.api.v5_0_0 import java.lang import java.util.Date -import code.api.util.APIUtil.{nullToString, stringOptionOrNull, stringOrNull} +import code.api.Constant +import code.api.util.APIUtil +import code.api.util.APIUtil.{gitCommit, nullToString, stringOptionOrNull, stringOrNull} import code.api.v1_2_1.BankRoutingJsonV121 import code.api.v1_3_0.JSONFactory1_3_0.{cardActionsToString, createAccountJson, createPinResetJson, createReplacementJson} import code.api.v1_3_0.{PinResetJSON, ReplacementJSON} @@ -37,11 +39,12 @@ import code.api.v1_4_0.JSONFactory1_4_0.{CustomerFaceImageJson, MetaJsonV140} import code.api.v2_1_0.CustomerCreditRatingJSON import code.api.v3_0_0.{AdapterInfoJsonV300, CustomerAttributeResponseJsonV300, JSONFactory300} import code.api.v3_1_0.{AccountAttributeResponseJson, AccountBasicV310, CustomerWithAttributesJsonV310, PhysicalCardWithAttributesJsonV310, PostConsentEntitlementJsonV310} -import code.api.v4_0_0.BankAttributeBankResponseJsonV400 +import code.api.v4_0_0.{APIInfoJson400, BankAttributeBankResponseJsonV400, EnergySource400, HostedAt400, HostedBy400} import code.bankattribute.BankAttribute import code.consent.ConsentRequest import code.customeraccountlinks.CustomerAccountLinkTrait import com.openbankproject.commons.model.{AccountAttribute, AccountRouting, AccountRoutingJsonV121, AmountOfMoneyJsonV121, Bank, BankAccount, CardAttribute, CreateViewJson, Customer, CustomerAttribute, InboundAdapterInfoInternal, InboundStatusMessage, PhysicalCardTrait, UpdateViewJSON, User, UserAuthContext, UserAuthContextUpdate, View, ViewBasic} +import com.openbankproject.commons.util.ApiVersion import net.liftweb.json.JsonAST.JValue import net.liftweb.util.Helpers @@ -527,6 +530,38 @@ case class ViewJsonV500( object JSONFactory500 { + 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 hostedBy = new HostedBy400(organisation, email, phone, organisationWebsite) + + val organisationHostedAt = APIUtil.getPropsValue("hosted_at.organisation", "") + val organisationWebsiteHostedAt = APIUtil.getPropsValue("hosted_at.organisation_website", "") + val hostedAt = new HostedAt400(organisationHostedAt, organisationWebsiteHostedAt) + + val organisationEnergySource = APIUtil.getPropsValue("energy_source.organisation", "") + val organisationWebsiteEnergySource = APIUtil.getPropsValue("energy_source.organisation_website", "") + val energySource = new EnergySource400(organisationEnergySource, organisationWebsiteEnergySource) + + val connector = APIUtil.getPropsValue("connector").openOrThrowException("no connector set") + val resourceDocsRequiresRole = APIUtil.getPropsAsBoolValue("resource_docs_requires_role", false) + + APIInfoJson400( + apiVersion.vDottedApiVersion, + apiVersionStatus, + gitCommit, + connector, + Constant.HostName, + Constant.localIdentityProvider, + hostedBy, + hostedAt, + energySource, + resourceDocsRequiresRole + ) + } + def createUserAuthContextJson(userAuthContext: UserAuthContext): UserAuthContextJsonV500 = { UserAuthContextJsonV500( user_auth_context_id= userAuthContext.userAuthContextId, diff --git a/obp-api/src/main/scala/code/api/v5_0_0/OBPAPI5_0_0.scala b/obp-api/src/main/scala/code/api/v5_0_0/OBPAPI5_0_0.scala index d416dd19de..24110ea73c 100644 --- a/obp-api/src/main/scala/code/api/v5_0_0/OBPAPI5_0_0.scala +++ b/obp-api/src/main/scala/code/api/v5_0_0/OBPAPI5_0_0.scala @@ -81,8 +81,7 @@ object OBPAPI5_0_0 extends OBPRestHelper private val endpoints: List[OBPEndpoint] = OBPAPI4_0_0.routes ++ endpointsOf5_0_0 // Filter the possible endpoints by the disabled / enabled Props settings and add them together - val routes : List[OBPEndpoint] = Implementations4_0_0.root :: // For now we make this mandatory - getAllowedEndpoints(endpoints, allResourceDocs) + val routes : List[OBPEndpoint] = getAllowedEndpoints(endpoints, allResourceDocs) // register v5.0.0 apis first, Make them available for use! registerRoutes(routes, allResourceDocs, apiPrefix, true)