Merge remote-tracking branch 'Simon/develop' into develop

This commit is contained in:
hongwei 2023-03-07 20:40:01 +01:00
commit 49cbec1767
7 changed files with 58 additions and 38 deletions

View File

@ -1132,7 +1132,7 @@ personal_data_collection_consent_country_waiver_list = Austria, Belgium, Bulgari
# Local identity provider url
# it defaults to the hostname props value
# local_identity_provider=this is the hostname of the local obp server including scheme
# local_identity_provider=strongly recomended to use top level domain name so that all nodes in the cluster share same provider name
# enable dynamic code sandbox, default is false, this will make sandbox works for code running in Future, will make performance lower than disable

View File

@ -5,6 +5,7 @@ import code.api.Constant.PARAM_LOCALE
import java.util.{Date, Locale}
import code.webuiprops.MappedWebUiPropsProvider.getWebUiPropsValue
import com.openbankproject.commons.model.enums.I18NResourceDocField
import net.liftweb.common.Full
import net.liftweb.http.S
import net.liftweb.http.provider.HTTPCookie
@ -48,19 +49,11 @@ object I18NUtil {
}
object ResourceDocTranslation {
def summary(operationId: String, locale: Option[String], default: String): String = {
def translate(fieldName: I18NResourceDocField.Value, operationId: String, locale: Option[String], default: String): String = {
locale match {
case Some(locale) =>
val webUiKey = s"webui_resource_doc_operation_id_${operationId}_summary_${locale}"
getWebUiPropsValue(webUiKey, default)
case None =>
default
}
}
def description(operationId: String, language: Option[String], default: String): String = {
language match {
case Some(locale) =>
val webUiKey = s"webui_resource_doc_operation_id_${operationId}_description_${locale}"
case Some(locale)=>
val webUiKeyString = "webui_resource_doc_operation_id_"
val webUiKey = s"$webUiKeyString${operationId}_${fieldName.toString.toLowerCase}_${locale}"
getWebUiPropsValue(webUiKey, default)
case None =>
default

View File

@ -12,6 +12,7 @@ import com.openbankproject.commons.model.ListResult
import code.crm.CrmEvent.CrmEvent
import com.openbankproject.commons.model.TransactionRequestTypeCharge
import com.openbankproject.commons.model.{Product, _}
import com.openbankproject.commons.model.enums.I18NResourceDocField
import com.openbankproject.commons.util.{EnumValue, JsonUtils, OBPEnumeration, ReflectUtils}
import net.liftweb.common.Full
import net.liftweb.json
@ -423,7 +424,7 @@ object JSONFactory1_4_0 extends MdcLoggable{
* **URL Parameters**:
* [BANK_ID](/glossary#Bank.bank_id):gh.29.uk
*/
def prepareUrlParameterDescription(requestUrl: String): String = {
def prepareUrlParameterDescription(requestUrl: String, urlParametersI18n: String): String = {
val noQueryParamUrl = StringUtils.substringBefore(requestUrl, "?")
//1rd: get the parameters from URL:
val findMatches = StringUtils.split(noQueryParamUrl, "/")
@ -432,7 +433,7 @@ object JSONFactory1_4_0 extends MdcLoggable{
if(findMatches.nonEmpty) {
val urlParameters: List[String] = findMatches.toList.sorted
val parametersDescription: List[String] = urlParameters.map(i => prepareDescription(i, Nil))
parametersDescription.mkString("\n\n\n**URL Parameters:**", "", "\n")
parametersDescription.mkString(s"\n\n\n**$urlParametersI18n**", "", "\n")
} else {
""
}
@ -497,7 +498,7 @@ object JSONFactory1_4_0 extends MdcLoggable{
}
def prepareJsonFieldDescription(jsonBody: scala.Product, jsonType: String): String = {
def prepareJsonFieldDescription(jsonBody: scala.Product, jsonType: String, jsonRequestBodyFieldsI18n: String, jsonResponseBodyFieldsI18n: String): String = {
val allFields = getAllFields(jsonBody)
val (jsonBodyJValue: json.JValue, allFieldsAndOptionStatus) = checkFieldOption(jsonBody, allFields)
// Group by is mandatory criteria and sort those 2 groups by name of the field
@ -509,14 +510,14 @@ object JSONFactory1_4_0 extends MdcLoggable{
val jsonFieldsDescription = jsonBodyFields.map(i => prepareDescription(i, allFieldsAndOptionStatus))
val jsonTitleType = if (jsonType.contains("request")) "\n\n\n**JSON request body fields:**\n\n" else "\n\n\n**JSON response body fields:**\n\n"
val jsonTitleType = if (jsonType.contains("request")) s"\n\n\n**$jsonRequestBodyFieldsI18n**\n\n" else s"\n\n\n**$jsonResponseBodyFieldsI18n**\n\n"
jsonFieldsDescription.mkString(jsonTitleType,"","\n")
}
private val createResourceDocJsonMemo = new ConcurrentHashMap[ResourceDoc, ResourceDocJson]
def createResourceDocJson(rd: ResourceDoc, isVersion4OrHigher:Boolean, locale: Option[String]) : ResourceDocJson = {
def createResourceDocJson(rd: ResourceDoc, isVersion4OrHigher:Boolean, locale: Option[String], urlParametersI18n:String ,jsonRequestBodyFieldsI18n:String, jsonResponseBodyFieldsI18n:String) : ResourceDocJson = {
// We MUST recompute all resource doc values due to translation via Web UI props
val endpointTags = getAllEndpointTagsBox(rd.operationId).map(endpointTag =>ResourceDocTag(endpointTag.tagName))
val resourceDocUpdatedTags: ResourceDoc = rd.copy(tags = endpointTags++ rd.tags)
@ -539,28 +540,29 @@ object JSONFactory1_4_0 extends MdcLoggable{
""
} else{
//1st: prepare the description from URL
val urlParametersDescription: String = prepareUrlParameterDescription(resourceDocUpdatedTags.requestUrl)
val urlParametersDescription: String = prepareUrlParameterDescription(resourceDocUpdatedTags.requestUrl, urlParametersI18n)
//2rd: get the fields description from the post json body:
val exampleRequestBodyFieldsDescription =
if (resourceDocUpdatedTags.requestVerb=="POST" ){
prepareJsonFieldDescription(resourceDocUpdatedTags.exampleRequestBody,"request")
prepareJsonFieldDescription(resourceDocUpdatedTags.exampleRequestBody,"request", jsonRequestBodyFieldsI18n, jsonResponseBodyFieldsI18n)
} else {
""
}
//3rd: get the fields description from the response body:
//response body can be a nest class, need to loop all the fields.
val responseFieldsDescription = prepareJsonFieldDescription(resourceDocUpdatedTags.successResponseBody,"response")
val responseFieldsDescription = prepareJsonFieldDescription(resourceDocUpdatedTags.successResponseBody,"response", jsonRequestBodyFieldsI18n, jsonResponseBodyFieldsI18n)
urlParametersDescription ++ exampleRequestBodyFieldsDescription ++ responseFieldsDescription
}
val resourceDocDescription = I18NUtil.ResourceDocTranslation.description(
val resourceDocDescription = I18NUtil.ResourceDocTranslation.translate(
I18NResourceDocField.DESCRIPTION,
resourceDocUpdatedTags.operationId,
locale,
resourceDocUpdatedTags.description.stripMargin.trim
)
val description = resourceDocDescription ++ fieldsDescription
val summary = resourceDocUpdatedTags.summary.replaceFirst("""\.(\s*)$""", "$1") // remove the ending dot in summary
val translatedSummary = I18NUtil.ResourceDocTranslation.summary(resourceDocUpdatedTags.operationId, locale, summary)
val translatedSummary = I18NUtil.ResourceDocTranslation.translate(I18NResourceDocField.SUMMARY, resourceDocUpdatedTags.operationId, locale, summary)
ResourceDocJson(
operation_id = resourceDocUpdatedTags.operationId,
@ -588,13 +590,33 @@ object JSONFactory1_4_0 extends MdcLoggable{
}
def createResourceDocsJson(resourceDocList: List[ResourceDoc], isVersion4OrHigher:Boolean, locale: Option[String]) : ResourceDocsJson = {
val urlParametersI18n = I18NUtil.ResourceDocTranslation.translate(
I18NResourceDocField.URL_PARAMETERS,
"resourceDocUrlParametersString_i180n",
locale,
"URL Parameters:"
)
val jsonRequestBodyFields = I18NUtil.ResourceDocTranslation.translate(
I18NResourceDocField.JSON_REQUEST_BODY_FIELDS,
"resourceDocJsonRequestBodyFieldsString_i180n",
locale,
"JSON request body fields:"
)
val jsonResponseBodyFields = I18NUtil.ResourceDocTranslation.translate(
I18NResourceDocField.JSON_RESPONSE_BODY_FIELDS,
"resourceDocJsonResponseBodyFieldsString_i180n",
locale,
"JSON response body fields:"
)
if(isVersion4OrHigher){
ResourceDocsJson(
resourceDocList.map(createResourceDocJson(_,isVersion4OrHigher, locale)),
resourceDocList.map(createResourceDocJson(_,isVersion4OrHigher, locale, urlParametersI18n, jsonRequestBodyFields, jsonResponseBodyFields)),
meta=Some(ResourceDocMeta(new Date(), resourceDocList.length))
)
} else {
ResourceDocsJson(resourceDocList.map(createResourceDocJson(_,false, locale)))
ResourceDocsJson(resourceDocList.map(createResourceDocJson(_,false, locale, urlParametersI18n, jsonRequestBodyFields, jsonResponseBodyFields)))
}
}

View File

@ -322,15 +322,13 @@ class AuthUser extends MegaProtoUser[AuthUser] with CreatedUpdated with MdcLogga
override def displayName = S.?("provider")
override val fieldId = Some(Text("txtProvider"))
override def validations = validUri(this) _ :: super.validations
override def defaultValue: String = Constant.HostName
override def defaultValue: String = Constant.localIdentityProvider
}
def getProvider() = {
if(provider.get == null) {
Constant.HostName
} else if ( provider.get == "" || provider.get == Constant.HostName ) {
Constant.HostName
if(provider.get == null || provider.get == "") {
Constant.localIdentityProvider
} else {
provider.get
}
@ -1062,7 +1060,7 @@ def restoreSomeSessions(): Unit = {
}
def isObpProvider(user: AuthUser) = {
user.getProvider() == Constant.HostName
user.getProvider() == Constant.localIdentityProvider
}
def obpUserIsValidatedAndNotLocked(usernameFromGui: String, user: AuthUser) = {

View File

@ -69,7 +69,7 @@ class ResourceUser extends LongKeyedMapper[ResourceUser] with User with ManyToMa
override def defaultValue = ""
}
object provider_ extends MappedString(this, 100){
override def defaultValue = Constant.HostName
override def defaultValue: String = Constant.localIdentityProvider
}
/**

View File

@ -54,7 +54,7 @@ class JSONFactory1_4_0Test extends V140ServerSetup with DefaultUsers {
scenario("prepareJsonFieldDescription should work well - users object") {
val usersJson = usersJsonV400
val description = JSONFactory1_4_0.prepareJsonFieldDescription(usersJson, "response")
val description = JSONFactory1_4_0.prepareJsonFieldDescription(usersJson, "response", "JSON request body fields:", "JSON response body fields:")
description.contains(
"""
|JSON response body fields:
@ -85,19 +85,20 @@ class JSONFactory1_4_0Test extends V140ServerSetup with DefaultUsers {
) should be (false)
println(description)
}
val urlParameters = "URL Parameters:"
scenario("PrepareUrlParameterDescription should work well, extract the parameters from URL") {
val requestUrl1 = "/obp/v4.0.0/banks/BANK_ID/accounts/account_ids/private"
val requestUrl1Description = JSONFactory1_4_0.prepareUrlParameterDescription(requestUrl1)
val requestUrl1Description = JSONFactory1_4_0.prepareUrlParameterDescription(requestUrl1,urlParameters)
requestUrl1Description contains ("[BANK_ID]") should be (true)
val requestUrl2 = "/obp/v4.0.0/banks/BANK_ID/accounts/ACCOUNT_ID/VIEW_ID"
val requestUrl2Description = JSONFactory1_4_0.prepareUrlParameterDescription(requestUrl2)
val requestUrl2Description = JSONFactory1_4_0.prepareUrlParameterDescription(requestUrl2, urlParameters)
requestUrl2Description contains ("[BANK_ID]") should be (true)
requestUrl2Description contains ("[ACCOUNT_ID]") should be (true)
requestUrl2Description contains ("[VIEW_ID]") should be (true)
val requestUrl3 = "/obp/v4.0.0/banks/BANK_ID/accounts/ACCOUNT_ID/VIEW_ID?date=2020-11-11"
val requestUrl3Description = JSONFactory1_4_0.prepareUrlParameterDescription(requestUrl3)
val requestUrl3Description = JSONFactory1_4_0.prepareUrlParameterDescription(requestUrl3, urlParameters)
requestUrl2Description shouldEqual(requestUrl3Description)
}
@ -114,7 +115,8 @@ class JSONFactory1_4_0Test extends V140ServerSetup with DefaultUsers {
scenario("createResourceDocJson should work well, no exception is good enough") {
val resourceDoc: ResourceDoc = OBPAPI3_0_0.allResourceDocs(5)
val result: ResourceDocJson = JSONFactory1_4_0.createResourceDocJson(resourceDoc,false, None)
val result: ResourceDocJson = JSONFactory1_4_0.createResourceDocJson(resourceDoc,false, None,
urlParameters, "JSON request body fields:", "JSON response body fields:")
}
scenario("createResourceDocsJson should work well, no exception is good enough") {

View File

@ -227,6 +227,11 @@ object AccountRoutingScheme extends Enumeration {
}
object I18NResourceDocField extends Enumeration {
type I18NResourceDocsField = Value
val SUMMARY, DESCRIPTION, URL_PARAMETERS, JSON_REQUEST_BODY_FIELDS, JSON_RESPONSE_BODY_FIELDS = Value
}
//-------------------simple enum definition, just some sealed trait way, start-------------
trait SimpleEnum extends JsonAble {
override def toJValue(implicit format: Formats): JValue = {