Skip to content

Commit

Permalink
Merge pull request #2269 from constantine2nd/develop
Browse files Browse the repository at this point in the history
New Style, Request Timeout
  • Loading branch information
simonredfern authored Sep 14, 2023
2 parents 2662972 + e15cb5a commit 705c62d
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,9 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth
case "resource-docs" :: requestedApiVersionString :: "obp" :: Nil JsonGet _ => {
val (tags, partialFunctions, locale, contentParam, apiCollectionIdParam, cacheModifierParam) = ResourceDocsAPIMethodsUtil.getParams()
cc =>
getApiLevelResourceDocs(cc,requestedApiVersionString, tags, partialFunctions, locale, contentParam, apiCollectionIdParam, cacheModifierParam, false, false)
implicit val ec = EndpointContext(Some(cc))
val resourceDocs = getApiLevelResourceDocs(cc,requestedApiVersionString, tags, partialFunctions, locale, contentParam, apiCollectionIdParam, cacheModifierParam, false, false)
resourceDocs
}
}

Expand All @@ -519,7 +521,9 @@ trait ResourceDocsAPIMethods extends MdcLoggable with APIMethods220 with APIMeth
case "resource-docs" :: requestedApiVersionString :: "obp" :: Nil JsonGet _ => {
val (tags, partialFunctions, locale, contentParam, apiCollectionIdParam, cacheModifierParam) = ResourceDocsAPIMethodsUtil.getParams()
cc =>
getApiLevelResourceDocs(cc,requestedApiVersionString, tags, partialFunctions, locale, contentParam, apiCollectionIdParam, cacheModifierParam, true, false)
implicit val ec = EndpointContext(Some(cc))
val resourceDocs = getApiLevelResourceDocs(cc,requestedApiVersionString, tags, partialFunctions, locale, contentParam, apiCollectionIdParam, cacheModifierParam, true, false)
resourceDocs
}
}

Expand Down
15 changes: 15 additions & 0 deletions obp-api/src/main/scala/code/api/util/NewStyle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,21 @@ object NewStyle extends MdcLoggable{
}
}

def updateConsumer(id: Long,
key: Option[String],
secret: Option[String],
isActive: Option[Boolean],
name: Option[String],
appType: Option[AppType],
description: Option[String],
developerEmail: Option[String],
redirectURL: Option[String],
createdByUserId: Option[String],
callContext: Option[CallContext]): Future[Consumer] = {
Future(Consumers.consumers.vend.updateConsumer(id, key, secret, isActive, name, appType, description, developerEmail, redirectURL, createdByUserId)) map {
unboxFullOrFail(_, callContext, UpdateConsumerError, 404)
}
}
def getConsumerByPrimaryId(id: Long, callContext: Option[CallContext]): Future[Consumer] = {
Consumers.consumers.vend.getConsumerByPrimaryIdFuture(id) map {
unboxFullOrFail(_, callContext, ConsumerNotFoundByConsumerId, 404)
Expand Down
4 changes: 2 additions & 2 deletions obp-api/src/main/scala/code/api/v1_2_1/APIMethods121.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ trait APIMethods121 {
val apiVersionStatus : String = "STABLE"

resourceDocs += ResourceDoc(
root(apiVersion, apiVersionStatus),
root,
apiVersion,
"root",
"GET",
Expand All @@ -154,7 +154,7 @@ trait APIMethods121 {
List(UnknownError, "no connector set"),
apiTagApi :: Nil)

def root(apiVersion : ApiVersion, apiVersionStatus: String) : OBPEndpoint = {
lazy val root : OBPEndpoint = {
case (Nil | "root" :: Nil) JsonGet _ => {
cc =>
implicit val ec = EndpointContext(Some(cc))
Expand Down
30 changes: 19 additions & 11 deletions obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1575,28 +1575,36 @@ trait APIMethods210 {
UserHasMissingRoles,
UnknownError
),
List(apiTagConsumer, apiTagOldStyle),
List(apiTagConsumer),
Some(List(canUpdateConsumerRedirectUrl))
)

lazy val updateConsumerRedirectUrl: OBPEndpoint = {
case "management" :: "consumers" :: consumerId :: "consumer" :: "redirect_url" :: Nil JsonPut json -> _ => {
cc =>
implicit val ec = EndpointContext(Some(cc))
for {
u <- cc.user ?~ UserNotLoggedIn
_ <- if(APIUtil.getPropsAsBoolValue("consumers_enabled_by_default", false)) Full(Unit)
else NewStyle.function.ownEntitlement("", u.userId, ApiRole.canUpdateConsumerRedirectUrl, cc.callContext)

postJson <- tryo {json.extract[ConsumerRedirectUrlJSON]} ?~! InvalidJsonFormat
consumerIdToLong <- tryo{consumerId.toLong} ?~! InvalidConsumerId
consumer <- Consumers.consumers.vend.getConsumerByPrimaryId(consumerIdToLong) ?~! {ConsumerNotFoundByConsumerId}
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- APIUtil.getPropsAsBoolValue("consumers_enabled_by_default", false) match {
case true => Future(Full(Unit))
case false => NewStyle.function.hasEntitlement("", u.userId, ApiRole.canUpdateConsumerRedirectUrl, callContext)
}
postJson <- NewStyle.function.tryons(InvalidJsonFormat, 400, callContext) {
json.extract[ConsumerRedirectUrlJSON]
}
consumerIdToLong <- NewStyle.function.tryons(InvalidConsumerId, 400, callContext) {
consumerId.toLong
}
consumer <- NewStyle.function.getConsumerByPrimaryId(consumerIdToLong, callContext)
//only the developer that created the Consumer should be able to edit it
_ <- tryo(assert(consumer.createdByUserId.equals(cc.user.openOrThrowException(attemptedToOpenAnEmptyBox).userId)))?~! UserNoPermissionUpdateConsumer
_ <- Helper.booleanToFuture(UserNoPermissionUpdateConsumer, 400, callContext) {
consumer.createdByUserId.equals(u.userId)
}
//update the redirectURL and isactive (set to false when change redirectUrl) field in consumer table
updatedConsumer <- Consumers.consumers.vend.updateConsumer(consumer.id.get, None, None, Some(APIUtil.getPropsAsBoolValue("consumers_enabled_by_default", false)), None, None, None, None, Some(postJson.redirect_url), None) ?~! UpdateConsumerError
updatedConsumer <- NewStyle.function.updateConsumer(consumer.id.get, None, None, Some(APIUtil.getPropsAsBoolValue("consumers_enabled_by_default", false)), None, None, None, None, Some(postJson.redirect_url), None, callContext)
} yield {
val json = JSONFactory210.createConsumerJSON(updatedConsumer)
createdJsonResponse(Extraction.decompose(json))
(json, HttpCode.`200`(callContext))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2682,7 +2682,7 @@ trait APIMethods400 {


staticResourceDocs += ResourceDoc(
root(OBPAPI4_0_0.version, OBPAPI4_0_0.versionStatus),
root,
implementedInApiVersion,
"root",
"GET",
Expand All @@ -2700,14 +2700,14 @@ trait APIMethods400 {
List(UnknownError, "no connector set"),
apiTagApi :: Nil)

def root (apiVersion : ApiVersion, apiVersionStatus: String): OBPEndpoint = {
lazy val root: OBPEndpoint = {
case (Nil | "root" :: Nil) JsonGet _ => {
cc =>
implicit val ec = EndpointContext(Some(cc))
for {
_ <- Future() // Just start async call
} yield {
(getApiInfoJSON(apiVersion,apiVersionStatus), HttpCode.`200`(cc.callContext))
(getApiInfoJSON(OBPAPI4_0_0.version,OBPAPI4_0_0.versionStatus), HttpCode.`200`(cc.callContext))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion obp-api/src/main/scala/code/api/v4_0_0/OBPAPI4_0_0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ object OBPAPI4_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w
private val endpoints: List[OBPEndpoint] = OBPAPI3_1_0.routes ++ endpointsOf4_0_0

// Filter the possible endpoints by the disabled / enabled Props settings and add them together
val routes : List[OBPEndpoint] = Implementations4_0_0.root(version, versionStatus) :: // For now we make this mandatory
val routes : List[OBPEndpoint] = Implementations4_0_0.root :: // For now we make this mandatory
getAllowedEndpoints(endpoints, allResourceDocs)

// register v4.0.0 apis first, Make them available for use!
Expand Down
2 changes: 1 addition & 1 deletion obp-api/src/main/scala/code/api/v5_0_0/OBPAPI5_0_0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +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(version, versionStatus) :: // For now we make this mandatory
val routes : List[OBPEndpoint] = Implementations4_0_0.root :: // For now we make this mandatory
getAllowedEndpoints(endpoints, allResourceDocs)

// register v5.0.0 apis first, Make them available for use!
Expand Down
6 changes: 3 additions & 3 deletions obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ trait APIMethods510 {


staticResourceDocs += ResourceDoc(
root(OBPAPI5_1_0.version, OBPAPI5_1_0.versionStatus),
root,
implementedInApiVersion,
"root",
"GET",
Expand All @@ -84,13 +84,13 @@ trait APIMethods510 {
List(UnknownError, "no connector set"),
apiTagApi :: Nil)

def root (apiVersion : ApiVersion, apiVersionStatus: String) : OBPEndpoint = {
lazy val root: OBPEndpoint = {
case (Nil | "root" :: Nil) JsonGet _ => {
cc => implicit val ec = EndpointContext(Some(cc))
for {
_ <- Future() // Just start async call
} yield {
(JSONFactory510.getApiInfoJSON(apiVersion,apiVersionStatus), HttpCode.`200`(cc.callContext))
(JSONFactory510.getApiInfoJSON(OBPAPI5_1_0.version,OBPAPI5_1_0.versionStatus), HttpCode.`200`(cc.callContext))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion obp-api/src/main/scala/code/api/v5_1_0/OBPAPI5_1_0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ object OBPAPI5_1_0 extends OBPRestHelper
private val endpoints: List[OBPEndpoint] = OBPAPI5_0_0.routes ++ endpointsOf5_1_0

// Filter the possible endpoints by the disabled / enabled Props settings and add them together
val routes : List[OBPEndpoint] = Implementations5_1_0.root(version, versionStatus) :: // For now we make this mandatory
val routes : List[OBPEndpoint] = Implementations5_1_0.root :: // For now we make this mandatory
getAllowedEndpoints(endpoints, allResourceDocs)

// register v5.1.0 apis first, Make them available for use!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class UpdateConsumerRedirectUrlTest extends V210ServerSetup with DefaultUsers {
val requestPut = (v2_1Request / "management" / "consumers" / testConsumer.id.get / "consumer" / "redirect_url" ).PUT <@ (user1)
val responsePut = makePutRequest(requestPut, write(consumerRedirectUrlJSON))

Then("We should get a 201")
Then("We should get a 200")
println(responsePut.body)
responsePut.code should equal(201)
responsePut.code should equal(200)

val field = (responsePut.body \ "redirect_url" ) match {
case JString(i) => i
Expand Down

0 comments on commit 705c62d

Please sign in to comment.