Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слева Предыдущая версия
Следующая версия
Предыдущая версия
develop:mule:dataweave [2024/02/25 18:51] – [indexOf] mirocowdevelop:mule:dataweave [2024/03/06 22:19] (текущий) – [Ссылки] mirocow
Строка 19: Строка 19:
  
 <note tip>IDE https://dataweave.mulesoft.com/learn/playground</note> <note tip>IDE https://dataweave.mulesoft.com/learn/playground</note>
 +===== Oprators =====
 +
 +  * using: For initializing local variables in a DataWeave script.
 +  * Unary DataWeave operators at this level:
 +    * .^: Schema selector.
 +    * .#: Namespace selector.
 +    * ..: Descendants selector. 
 +    * not: Logical operator for negation.
 +    * .@: All attribute selector, for example, in a case that uses the expression payload.root.a.@ to return the attributes and values of the input payload <root> <a attr1="foo" attr2="bar" /></root> within the array of objects { "attr1": "foo", "attr2": "bar" }.                                                                                                                                                                                                                                              
 ==== Condition ==== ==== Condition ====
  
Строка 279: Строка 288:
   * **takeWhile** Selects elements from the array while the condition is met but stops the selection process when it reaches an element that fails to satisfy the condition.   * **takeWhile** Selects elements from the array while the condition is met but stops the selection process when it reaches an element that fails to satisfy the condition.
  
 +=== divideBy ===
 +
 +<code>
 +%dw 2.0
 +import divideBy from dw::core::Objects
 +output application/json
 +---
 +{ "a": 1, "b": true, "a": 2, "b": false, "c": 3 } divideBy 2 
 +</code>
 === drop === === drop ===
  
Строка 303: Строка 321:
 </code> </code>
  
 +=== join ===
 +
 +<code>
 +%dw 2.0
 +import * from dw::core::Arrays
 + 
 +var items = [{id: "12", name:"Tea"},{id: "22", name:"Salt"},{id: "3", name:"Soap"},{id: "5", name:"Butter"}]
 + 
 +var Prices = [{Id: "12", price:123},{Id: "3", price:24}, {Id: "22", price:20}, {Id: "4", price:456}]
 + 
 +output application/json
 +---
 +join(items, Prices, (item) -> item.id, (price) -> price.Id)
 +
 +</code>
 === takeWhile === === takeWhile ===
  
Строка 315: Строка 348:
 arr takeWhile $ &lt;= 2 arr takeWhile $ &lt;= 2
  
 +</code>
 +
 +<code>
 +%dw 2.0
 +import * from dw::core::Objects
 +output application/json
 +var obj = {
 +  "a": 1,
 +  "b": 2,
 +  "c": 5,
 +  "d": 1
 +}
 +---
 +obj takeWhile ((value, key) ->  value < 3)
 </code> </code>
 ==== dw::Core ==== ==== dw::Core ====
Строка 329: Строка 376:
 --- ---
 payload distinctBy $.id payload distinctBy $.id
 +</code>
 +
 +<code>
 +%dw 2.0
 +output application/json
 +var str = [1,2,3,4,5,6,7]
 +var str1= [4,5,6,7,1]
 +---
 +(str ++ str1) distinctBy ((item, index) ->item )
 </code> </code>
  
Строка 596: Строка 652:
 </code> </code>
  
 +<code>
 +%dw 2.0
 +output application/json  
 +---
 +payload filterObject ((value, key) -> 
 +    (key as String != "first name"
 +    and (key as String != "last name")
 +)
 +</code>
 === flatten === === flatten ===
  
Строка 714: Строка 779:
 </code> </code>
  
 +<code>
 +%dw 2.0
 +output application/java
 +fun process(obj: Object) = obj mapObject ((value, key) -> {
 +    (key): key match {
 +        case "description" -> vars.descriptionValue
 +        else -> value
 +    }
 +})
 +---
 +payload map ((item, index) -> 
 +    process(item)
 +)
 +</code>
 === mapObject === === mapObject ===
  
Строка 867: Строка 946:
  
 So result will be 9 So result will be 9
 +</code>
 +
 +<code>
 +%dw 2.0
 +output application/json
 +
 +var data = {"xyz": {"abc":["account":[{"value":"savings"}]]}}
 +---
 +data..value reduce $
 </code> </code>
  
Строка 1024: Строка 1112:
   * **valueSet** Returns an array of the values from key-value pairs in an object.   * **valueSet** Returns an array of the values from key-value pairs in an object.
  
 +=== everyEntry ===
 +
 +<code>
 +%dw 2.0
 +import everyEntry from dw::core::Objects
 +output application/json
 +---
 +{
 +    a: {} everyEntry (value, key) -> value is String,
 +    b: {a: "", b: "123"} everyEntry (value, key) -> value is String,
 +    c: {a: "", b: 123} everyEntry (value, key) -> value is String,
 +    d: {a: "", b: 123} everyEntry (value, key) -> key as String == "a",
 +    e: {a: ""} everyEntry (value, key) -> key as String == "a",
 +    f: null everyEntry ((value, key) -> key as String == "a")
 +}
 +</code>
 +
 +=== mergeWith ===
 +
 +<code>
 +%dw 2.0
 +import mergeWith from dw::core::Objects
 +output application/json
 +---
 +{ "a" : true, "b" : 1} mergeWith { "a" : false, "c" : "Test"
 +</code>
 +
 +=== someEntry ===
 +
 +<code>
 +%dw 2.0
 +import someEntry from dw::core::Objects
 +output application/json
 +---
 +{
 +    a: {} someEntry (value, key) -> value is String,
 +    b: {a: "", b: "123"} someEntry (value, key) -> value is String,
 +    c: {a: "", b: 123} someEntry (value, key) -> value is String,
 +    d: {a: "", b: 123} someEntry (value, key) -> key as String == "a",
 +    e: {a: ""} someEntry (value, key) -> key as String == "b",
 +    f: null someEntry (value, key) -> key as String == "a"
 +}
 +</code>
 ==== dw::util::Values ==== ==== dw::util::Values ====
  
Строка 1160: Строка 1291:
  
   * https://docs.mulesoft.com/dataweave/latest/   * https://docs.mulesoft.com/dataweave/latest/
 +  * https://mulesy.com/1-mulesoft-as-middleware-solution/
 +  * https://reddeveloper.ru/tags/mule
 +  * https://questu.ru/tag/mule/