关于请求的小背景:
Process API 旨在使用过滤后的数据进行响应。API 使用 HTTP GET 调用并在查询参数中传递要求,有两组数据(1)用于基本查询对象的数据和(2)具有过滤条件的数据以最终确定响应。此 API 调用系统 API 以使用动态查询从 RDBMS 表中检索数据。
有时调用应用程序可能包含不适用于响应的过滤器,例如Pants 上的“味道”或“有效期”。因此,响应应该应用与请求参数相关的尽可能多的过滤条件。
由于 Mule API 规范在处理动态键方面的限制,过滤条件作为带有静态键的字符串传递e.g., {"condition": "Title: Harry P*"}
。
下面是示例:
API Specification-RAML,PropertyName:String
用于传递数据库fieldName和propertyValue是该数据库 field 中的值。"filter"
是一个数组对象,对象名称是"condition"
,值是一个有限制的字符串,即“pattern: .{3,}(?<=:\s).{1,}$”(正则表达式的英文翻译:最少 3 个字符分别在“:”之前和之后至少 1 个字符)。
输入查询参数: propertyName=Title&propertyValue=Harry&filter={"condition": "description: Travel"}&filter={"condition": "MEDIA: Audio*"}&filter={"condition": "Type: Series"}&filter={"condition": "Quality: 4K"}
将查询参数中的过滤器对象复制到一个数组中:FilterArray1: [ "{"condition": "Author: JK*"}", "{"condition": "description: Travel"}", "{"condition": "媒体:音频*"}","{"条件":"类型:系列"}","{"条件":"质量:4K"}"],
无效/可忽略的过滤条件是:
(i) "Author: JK*" & (ii) "Quality: 4K"
过滤条件的值可以接受通配符搜索但不能是字符串的第一个字符,可以参考过滤“MEDIA: Audio*”
系统 API 响应对象有固定的结构,它有字段:Type, Title, Description & Availables
(Availables 是一个有两个字段的 Array 对象Name & Media
)
系统 API 输出:
[
{
"Type": "Series",
"Title": "Harry Potter and the Half-Blood Prince",
"Description": "Harry Potter and his encounter with Dark Lord",
"Availables": [
{
"Name": "HarryPotter_HBP.pdf",
"Media": "Paper Back"
},
{
"Name": "HarryPotter_HBP.wmv",
"Media": "Audio Book"
},
{
"Name": "HarryPotter_HBP.XMI",
"Media": "Movie"
}
]
},{
"Type": "Series",
"Title": "Harry Potter and the Order of Phoenix",
"Description": "Harry Potter and his God Father",
"Availables": [
{
"Name": "HarryPotter_TOP.wmv",
"Media": "Audio Book"
}
]
},{
"Type": "Series",
"Title": "Harry Potter and the Deathly Hallows",
"Description": "Harry Potter and his priorities",
"Availables": [
{
"Name": "HarryPotter_DH_1.mov",
"Media": "Movie"
},
{
"Name": "HarryPotter_DH_2.mov",
"Media": "Movie"
}
]
},
{
"Type": "Kids",
"Title": "Harry Kitten and Tucker Mouse",
"Description": "Travel to Chester Cricket in Times Square",
"Availables": [
{
"Name": "HarryKitten&TuckerMouse.pdf",
"Media": "Paper Back"
}
]
},
{
"Type": "Novel",
"Title": "Harry, A History",
"Description": "Boy Wizard phenomenon and his fan boys",
"Availables": [
{
"Name": "HarryPotter&HisFans.wmv",
"Media": "Audio Book"
}
]
},{
"Type": "Novel",
"Title": "Harry Hole The Bat",
"Description": "Crime Inspector to observe a murder case..",
"Availables": [
{
"Name": "HarryHole_1.pdf",
"Media": "Paper Back"
},
{
"Name": "HarryHole_1.wmv",
"Media": "Audio Book"
}
]
},
]
responseObject 列表应该是从 System API 调用中过滤掉所有与主列表和子列表中的条件不匹配的数据后的最终数据,即过滤条件应该应用于Availables
每个响应对象中的列表,例如,所有对象引用应该{"Media": "Movie"}
从响应对象中删除。
最终响应应如下所示:
[
{
"Type": "Series",
"Title": "Harry Potter and the Half-Blood Prince",
"Description": "Harry Potter and his encounter with Dark Lord",
"Availables": [
{
"Name": "HarryPotter_HBP.wmv",
"Media": "Audio Book"
}
],
requestedPropertyName: "Title",
requestedPropertyValue: "Harry",
appliedFilters: "description: Travel|MEDIA: Audio*|Type: Series"
},{
"Type": "Series",
"Title": "Harry Potter and the Order of Phoenix",
"Description": "Harry Potter and his God Father",
"Availables": [
{
"Name": "HarryPotter_TOP.wmv",
"Media": "Audio Book"
}
],
requestedPropertyName: "Title",
requestedPropertyValue: "Harry",
appliedFilters: "description: Travel|MEDIA: Audio*|Type: Series"
},
{
"Type": "Novel",
"Title": "Harry, A History",
"Description": "Boy Wizard phenomenon and his fan boys",
"Availables": [
{
"Name": "HarryPotter&HisFans.wmv",
"Media": "Audio Book"
}
],
requestedPropertyName: "Title",
requestedPropertyValue: "Harry",
appliedFilters: "description: Travel|MEDIA: Audio*|Type: Series"
}
]
我确信我们可以使用 Java 以更好、更快的方式实现它,但由于我对 Mulesoft 和 Dataweave 2.0 的了解有限,它所花费的时间比预期的要长。
请不要介意伸出援手,向所有帮助者致敬。非常感谢这里的任何帮助!