Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions obp-api/src/main/scala/bootstrap/liftweb/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import code.api.util._
import code.api.util.migration.Migration
import code.api.util.migration.Migration.DbFunction
import code.apicollection.ApiCollection
import code.featuredapicollection.FeaturedApiCollection
import code.apicollectionendpoint.ApiCollectionEndpoint
import code.atmattribute.AtmAttribute
import code.atms.MappedAtm
Expand Down Expand Up @@ -1118,6 +1119,7 @@ object ToSchemify {
MappedUserRefreshes,
ApiCollection,
ApiCollectionEndpoint,
FeaturedApiCollection,
JsonSchemaValidation,
AuthenticationTypeValidation,
ConnectorMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5176,6 +5176,12 @@ object SwaggerDefinitionsJSON {
lazy val apiCollectionEndpointJson400 = ApiCollectionEndpointJson400(apiCollectionEndpointIdExample.value, apiCollectionIdExample.value, operationIdExample.value)
lazy val apiCollectionEndpointsJson400 = ApiCollectionEndpointsJson400(List(apiCollectionEndpointJson400))

// Featured API Collections (v6.0.0)
lazy val postFeaturedApiCollectionJsonV600 = PostFeaturedApiCollectionJsonV600(apiCollectionIdExample.value, 1)
lazy val putFeaturedApiCollectionJsonV600 = PutFeaturedApiCollectionJsonV600(1)
lazy val featuredApiCollectionJsonV600 = FeaturedApiCollectionJsonV600(featuredApiCollectionIdExample.value, apiCollectionIdExample.value, 1)
lazy val featuredApiCollectionsJsonV600 = FeaturedApiCollectionsJsonV600(List(featuredApiCollectionJsonV600))

lazy val jsonScalaConnectorMethod = JsonConnectorMethod(Some(connectorMethodIdExample.value),"getBank", connectorMethodBodyScalaExample.value, "Scala")
lazy val jsonScalaConnectorMethodMethodBody = JsonConnectorMethodMethodBody(connectorMethodBodyScalaExample.value, "Scala")

Expand Down
5 changes: 4 additions & 1 deletion obp-api/src/main/scala/code/api/util/ApiRole.scala
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ object ApiRole extends MdcLoggable{

case class CanGetAllApiCollections(requiresBankId: Boolean = false) extends ApiRole
lazy val canGetAllApiCollections = CanGetAllApiCollections()


case class CanManageFeaturedApiCollections(requiresBankId: Boolean = false) extends ApiRole
lazy val canManageFeaturedApiCollections = CanManageFeaturedApiCollections()

case class CanGetCounterpartyAtAnyBank(requiresBankId: Boolean = false) extends ApiRole
lazy val canGetCounterpartyAtAnyBank = CanGetCounterpartyAtAnyBank()

Expand Down
6 changes: 6 additions & 0 deletions obp-api/src/main/scala/code/api/util/ErrorMessages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,12 @@ object ErrorMessages {
val ApiCollectionEndpointAlreadyExists = "OBP-30085: The ApiCollectionEndpoint is already exists."
val ApiCollectionAlreadyExists = "OBP-30086: The ApiCollection is already exists."

val FeaturedApiCollectionNotFound = "OBP-30400: FeaturedApiCollection not found. Please specify a valid value for API_COLLECTION_ID."
val CreateFeaturedApiCollectionError = "OBP-30401: Could not create FeaturedApiCollection."
val UpdateFeaturedApiCollectionError = "OBP-30402: Could not update FeaturedApiCollection."
val DeleteFeaturedApiCollectionError = "OBP-30403: Could not delete FeaturedApiCollection."
val FeaturedApiCollectionAlreadyExists = "OBP-30404: The ApiCollection is already featured."

val DoubleEntryTransactionNotFound = "OBP-30087: Double Entry Transaction not found."

val InvalidAuthContextUpdateRequestKey = "OBP-30088: Invalid Auth Context Update Request Key."
Expand Down
8 changes: 7 additions & 1 deletion obp-api/src/main/scala/code/api/util/ExampleValue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,13 @@ object ExampleValue {

lazy val apiCollectionEndpointIdExample = ConnectorField("8uy8a7e4-6d02-40e3-a129-0b2bf89de8uh", "A string that MUST uniquely identify the session on this OBP instance, can be used in all cache.")
glossaryItems += makeGlossaryItem("ApiCollectionEndpoint.apiCollectionEndpointId", apiCollectionEndpointIdExample)


lazy val featuredApiCollectionIdExample = ConnectorField("9uy8a7e4-6d02-40e3-a129-0b2bf89de8uh", "A string that uniquely identifies this featured API collection entry.")
glossaryItems += makeGlossaryItem("FeaturedApiCollection.featuredApiCollectionId", featuredApiCollectionIdExample)

lazy val sortOrderExample = ConnectorField("1", "The sort order for displaying featured API collections. Lower numbers appear first.")
glossaryItems += makeGlossaryItem("FeaturedApiCollection.sortOrder", sortOrderExample)

lazy val operationIdExample = ConnectorField("OBPv4.0.0-getBanks", "A uniquely identify the obp endpoint on OBP instance, you can get it from Get Resource endpoints.")
glossaryItems += makeGlossaryItem("ApiCollectionEndpoint.operationId", operationIdExample)

Expand Down
98 changes: 93 additions & 5 deletions obp-api/src/main/scala/code/api/util/NewStyle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import code.api.util.ErrorMessages.{InsufficientAuthorisationToCreateTransaction
import code.api.{APIFailureNewStyle, Constant, JsonResponseException}
import code.apicollection.{ApiCollectionTrait, MappedApiCollectionsProvider}
import code.apicollectionendpoint.{ApiCollectionEndpointTrait, MappedApiCollectionEndpointsProvider}
import code.featuredapicollection.{FeaturedApiCollectionTrait, MappedFeaturedApiCollectionsProvider}
import code.atmattribute.AtmAttribute
import code.authtypevalidation.{AuthenticationTypeValidationProvider, JsonAuthTypeValidation}
import code.bankattribute.BankAttribute
Expand Down Expand Up @@ -3715,11 +3716,35 @@ object NewStyle extends MdcLoggable{
}

def getFeaturedApiCollections(callContext: Option[CallContext]) : OBPReturnType[List[ApiCollectionTrait]] = {
//we get the getFeaturedApiCollectionIds from props, and remove the deplication there.
val featuredApiCollectionIds = APIUtil.getPropsValue("featured_api_collection_ids","").split(",").map(_.trim).toSet.toList
//We filter the isDefined and is isSharable collections.
val apiCollections = featuredApiCollectionIds.map(MappedApiCollectionsProvider.getApiCollectionById).filter(_.isDefined).filter(_.head.isSharable).map(_.head)
Future{(apiCollections.sortBy(_.apiCollectionName), callContext)}
// First get featured collections from database, sorted by sortOrder
val dbFeaturedApiCollections = MappedFeaturedApiCollectionsProvider.getAllFeaturedApiCollections()
val dbApiCollectionIds = dbFeaturedApiCollections.map(_.apiCollectionId).toSet

// Get actual ApiCollections for database featured entries
val dbApiCollections = dbFeaturedApiCollections
.map(f => MappedApiCollectionsProvider.getApiCollectionById(f.apiCollectionId))
.filter(_.isDefined)
.filter(_.head.isSharable)
.map(_.head)

// Get props-based featured IDs that are NOT in database
val propsApiCollectionIds = APIUtil.getPropsValue("featured_api_collection_ids", "")
.split(",")
.map(_.trim)
.filter(_.nonEmpty)
.toList
.filterNot(dbApiCollectionIds.contains)

// Get actual ApiCollections for props entries and sort them by name
val propsApiCollections = propsApiCollectionIds
.map(MappedApiCollectionsProvider.getApiCollectionById)
.filter(_.isDefined)
.filter(_.head.isSharable)
.map(_.head)
.sortBy(_.apiCollectionName)

// Merge: database entries first (preserve sortOrder), then props entries (sorted by name)
Future{(dbApiCollections ++ propsApiCollections, callContext)}
}

def createApiCollection(
Expand Down Expand Up @@ -3813,6 +3838,69 @@ object NewStyle extends MdcLoggable{
}
}

// Featured API Collections functions
def createFeaturedApiCollection(
apiCollectionId: String,
sortOrder: Int,
callContext: Option[CallContext]
): OBPReturnType[FeaturedApiCollectionTrait] = {
Future(MappedFeaturedApiCollectionsProvider.createFeaturedApiCollection(apiCollectionId, sortOrder)) map {
i => (unboxFullOrFail(i, callContext, CreateFeaturedApiCollectionError), callContext)
}
}

def getFeaturedApiCollectionByApiCollectionId(
apiCollectionId: String,
callContext: Option[CallContext]
): OBPReturnType[FeaturedApiCollectionTrait] = {
Future(MappedFeaturedApiCollectionsProvider.getFeaturedApiCollectionByApiCollectionId(apiCollectionId)) map {
i => (unboxFullOrFail(i, callContext, s"$FeaturedApiCollectionNotFound Current API_COLLECTION_ID($apiCollectionId)"), callContext)
}
}

def getAllFeaturedApiCollectionsAdmin(callContext: Option[CallContext]): OBPReturnType[List[FeaturedApiCollectionTrait]] = {
Future(MappedFeaturedApiCollectionsProvider.getAllFeaturedApiCollections(), callContext)
}

def updateFeaturedApiCollection(
apiCollectionId: String,
sortOrder: Int,
callContext: Option[CallContext]
): OBPReturnType[FeaturedApiCollectionTrait] = {
Future {
val featured = MappedFeaturedApiCollectionsProvider.getFeaturedApiCollectionByApiCollectionId(apiCollectionId)
featured.flatMap { f =>
MappedFeaturedApiCollectionsProvider.updateFeaturedApiCollection(f.featuredApiCollectionId, sortOrder)
}
} map {
i => (unboxFullOrFail(i, callContext, s"$UpdateFeaturedApiCollectionError Current API_COLLECTION_ID($apiCollectionId)"), callContext)
}
}

def deleteFeaturedApiCollectionByApiCollectionId(
apiCollectionId: String,
callContext: Option[CallContext]
): OBPReturnType[Boolean] = {
Future(MappedFeaturedApiCollectionsProvider.deleteFeaturedApiCollectionByApiCollectionId(apiCollectionId)) map {
i => (unboxFullOrFail(i, callContext, s"$DeleteFeaturedApiCollectionError Current API_COLLECTION_ID($apiCollectionId)"), callContext)
}
}

def checkFeaturedApiCollectionDoesNotExist(
apiCollectionId: String,
callContext: Option[CallContext]
): OBPReturnType[Boolean] = {
Future {
val existing = MappedFeaturedApiCollectionsProvider.getFeaturedApiCollectionByApiCollectionId(apiCollectionId)
existing match {
case net.liftweb.common.Full(_) =>
throw new RuntimeException(FeaturedApiCollectionAlreadyExists)
case _ =>
(true, callContext)
}
}
}

def createJsonSchemaValidation(validation: JsonValidation, callContext: Option[CallContext]): OBPReturnType[JsonValidation] =
Future {
val newValidation = JsonSchemaValidationProvider.validationProvider.vend.create(validation)
Expand Down
Loading