Skip to content

Commit

Permalink
refactor/Reactor function isNewStyleEndpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
constantine2nd committed Sep 8, 2023
1 parent 43e27a7 commit 747e30b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 122 deletions.
51 changes: 8 additions & 43 deletions obp-api/src/main/scala/code/api/OBPRestHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -303,51 +303,16 @@ trait OBPRestHelper extends RestHelper with MdcLoggable {
/**
* Function which inspect does an Endpoint use Akka's Future in non-blocking way i.e. without using Await.result
* @param rd Resource Document which contains all description of an Endpoint
* @return true if some endpoint can get User from Authorization Header
* @return true if some endpoint is written as a new style one
*/
def newStyleEndpoints(rd: Option[ResourceDoc]) : Boolean = {
// TODO Remove Option type in case of Resource Doc
def isNewStyleEndpoint(rd: Option[ResourceDoc]) : Boolean = {
rd match {
// Versions that precede the 3.0.0 are mostly written as Old Style endpoint.
// In this case we assume all are written as Old Style and explicitly list NewStyle endpoints.
case Some(e) if NewStyle.endpoints.exists(_ == (e.partialFunctionName, e.implementedInApiVersion.toString())) =>
true
// Since the 3.0.0 we assume that endpoints are written in New Style.
// In this case we list all endpoints as New Style and explicitly exclude Old ones.
case Some(e) if APIMethods300.newStyleEndpoints.exists {
(_ == (e.partialFunctionName, e.implementedInApiVersion.toString()))
} =>
true
// Since the 3.0.0 we assume that endpoints are written in New Style.
// In this case we list all endpoints as New Style and explicitly exclude Old ones.
case Some(e) if APIMethods310.newStyleEndpoints.exists {
(_ == (e.partialFunctionName, e.implementedInApiVersion.toString()))
} =>
true
// Since the 3.0.0 we assume that endpoints are written in New Style.
// In this case we list all endpoints as New Style and explicitly exclude Old ones.
case Some(e) if APIMethods400.newStyleEndpoints.exists {
(_ == (e.partialFunctionName, e.implementedInApiVersion.toString()))
} =>
true
// Berlin Group endpoints are written in New Style
case Some(e) if APIMethods_AccountInformationServiceAISApi.newStyleEndpoints.exists {
(_ == (e.partialFunctionName, e.implementedInApiVersion.toString()))
} =>
true
case Some(e) if List(
ApiVersion.v1_2_1.toString,
ApiVersion.v1_3_0.toString,
ApiVersion.v1_4_0.toString,
ApiVersion.v2_0_0.toString,
ApiVersion.v2_1_0.toString,
ApiVersion.v2_2_0.toString,
ApiVersion.b1.toString, //apiBuilder is the old style.
).exists(_ == e.implementedInApiVersion.toString()) =>
false
case Some(e) if APIMethods300.oldStyleEndpoints.exists(_ == e.partialFunctionName) =>
false
case None => //added the None resource doc endpoint is the false
case Some(e) if e.tags.exists(_ == ApiTag.apiTagOldStyle) =>
false
case None =>
logger.error("Function isNewStyleEndpoint received empty resource doc")
true
case _ =>
true
}
Expand Down Expand Up @@ -398,7 +363,7 @@ trait OBPRestHelper extends RestHelper with MdcLoggable {

if(maybeJsonResponse.isDefined) {
maybeJsonResponse
} else if(newStyleEndpoints(rd)) {
} else if(isNewStyleEndpoint(rd)) {
fn(cc)
} else if (APIUtil.hasConsentJWT(reqHeaders)) {
val (usr, callContext) = Consent.applyRulesOldStyle(APIUtil.getConsentJWT(reqHeaders), cc)
Expand Down
79 changes: 0 additions & 79 deletions obp-api/src/main/scala/code/api/util/NewStyle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,85 +81,6 @@ import code.views.system.AccountAccess
import net.liftweb.mapper.By

object NewStyle extends MdcLoggable{
lazy val endpoints: List[(String, String)] = List(
(nameOf(ImplementationsResourceDocs.getResourceDocsObp), ApiVersion.v1_4_0.toString),
(nameOf(Implementations1_2_1.deleteWhereTagForViewOnTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.getOtherAccountForTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.getOtherAccountMetadata), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.getCounterpartyPublicAlias), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.addCounterpartyMoreInfo), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.updateCounterpartyMoreInfo), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.deleteCounterpartyMoreInfo), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.addCounterpartyPublicAlias), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.addCounterpartyUrl), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.updateCounterpartyUrl), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.deleteCounterpartyUrl), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.deleteCounterpartyCorporateLocation), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.deleteCounterpartyPhysicalLocation), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.addCounterpartyImageUrl), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.updateCounterpartyImageUrl), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.deleteCounterpartyImageUrl), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.addCounterpartyOpenCorporatesUrl), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.updateCounterpartyOpenCorporatesUrl), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.deleteCounterpartyOpenCorporatesUrl), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.addOtherAccountPrivateAlias), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.updateCounterpartyPrivateAlias), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.deleteCounterpartyPrivateAlias), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.updateCounterpartyPublicAlias), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.deleteCounterpartyPublicAlias), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.getOtherAccountPrivateAlias), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.addWhereTagForViewOnTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.updateWhereTagForViewOnTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.updateAccountLabel), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.getWhereTagForViewOnTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.addImageForViewOnTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.deleteImageForViewOnTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.getImagesForViewOnTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.addTagForViewOnTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.deleteTagForViewOnTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.getTagsForViewOnTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.addCommentForViewOnTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.deleteCommentForViewOnTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.getCommentsForViewOnTransaction), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.deleteTransactionNarrative), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.updateTransactionNarrative), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.addTransactionNarrative), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.getTransactionNarrative), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.deleteViewForBankAccount), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_2_1.addPermissionForUserForBankAccountForOneView), ApiVersion.v1_2_1.toString),
(nameOf(Implementations1_4_0.getTransactionRequestTypes), ApiVersion.v1_4_0.toString),
(nameOf(Implementations1_4_0.addCustomerMessage), ApiVersion.v1_4_0.toString),
(nameOf(Implementations2_0_0.getAllEntitlements), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.publicAccountsAtOneBank), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.privateAccountsAtOneBank), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.corePrivateAccountsAtOneBank), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.getKycDocuments), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.getKycMedia), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.getKycStatuses), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.getKycChecks), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.addKycDocument), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.addKycMedia), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.addKycStatus), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.addKycCheck), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.addEntitlement), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.deleteEntitlement), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.getTransactionTypes), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.getPermissionsForBankAccount), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_0_0.publicAccountsAllBanks), ApiVersion.v2_0_0.toString),
(nameOf(Implementations2_1_0.getEntitlementsByBankAndUser), ApiVersion.v2_1_0.toString),
(nameOf(Implementations2_1_0.getRoles), ApiVersion.v2_1_0.toString),
(nameOf(Implementations2_1_0.getCustomersForCurrentUserAtBank), ApiVersion.v2_1_0.toString),
(nameOf(Implementations2_1_0.getMetrics), ApiVersion.v2_1_0.toString),
(nameOf(Implementations2_1_0.createTransactionType), ApiVersion.v2_1_0.toString),
(nameOf(Implementations2_1_0.getTransactionRequestTypesSupportedByBank), ApiVersion.v2_1_0.toString),
(nameOf(Implementations2_2_0.config), ApiVersion.v2_2_0.toString),
(nameOf(Implementations2_2_0.getMessageDocs), ApiVersion.v2_2_0.toString),
(nameOf(Implementations2_2_0.getViewsForBankAccount), ApiVersion.v2_2_0.toString),
(nameOf(Implementations2_2_0.getCurrentFxRate), ApiVersion.v2_2_0.toString),
(nameOf(Implementations2_2_0.getExplictCounterpartiesForAccount), ApiVersion.v2_2_0.toString),
(nameOf(Implementations2_2_0.getExplictCounterpartyById), ApiVersion.v2_2_0.toString),
(nameOf(Implementations2_2_0.createAccount), ApiVersion.v2_2_0.toString)
)

object HttpCode {
def `200`(callContext: Option[CallContext]): Option[CallContext] = {
Expand Down

0 comments on commit 747e30b

Please sign in to comment.