使用一个dataweave转换的输出作为另一个的输入

时间:2016-06-23 02:06:17

标签: dataweave

我有一个应该应用于flowVar输入的dataweave函数。输入应该是JSON。使用示例数据和预览,一切正常,但在实际执行时,我得到一个错误,我试图将该函数应用于二进制文件。 flowVar的内容是另一个dataweave转换的输出。我设置flowVar时的有效负载是com.mulesoft.weave.reader.ByteArraySeekableStream类型。如何将其转换为DataWeave可以使用的东西?

这是给出问题的功能:

%var theAttributes = flowVars.attributes
%function supervisorAttribute(id) (theAttributes[?$.id ~=id].attributes[0][?($ == "INDP" or $ == "THES" or $ == "UROP")][0])

错误是:

 Type mismatch for 'Value Selector' operator
 found :binary, :name
 required :datetime, :name or
 required :localdatetime, :name or
 required :object, :name or
 required :time, :name or
 required :array, :name or
 ...

我尝试添加一个Object To Json变换器,但得到了这个:

No serializer found for class com.mulesoft.weave.reader.ByteArraySeekableStream and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (org.codehaus.jackson.map.JsonMappingException). (org.mule.api.transformer.TransformerMessagingException).

我尝试将一个Byte数组添加到Object Transformer,一个Byte数组添加到Object Transformer,后跟一个Object to JSON Transformer,并将flowVar设置为#[message.payloadAs(java.lang.String)],但是得到了这个每个案例:

Type mismatch for 'Filter Selector ([?()])' operator
 found :string, :function
required :array, :function

这是可以作为预览输入正常工作的示例JSON数据:

[
  {
    "id": "111",
    "attributes": [
      "THES",
      "VARU",
      "ROTC",
      "CIH",
      "HH"
    ]
  },
  {
    "id": "222",
    "attributes": [
      "VARU",
      "BIOL",
      "HA2",
      "FSEM"
    ]
  }, 
  {
    "id": "2",
    "attributes": [
      "ROTC"
    ]
  }
]

这是创建JSON的转换:

%dw 1.0 
%output application/json
 ---
payload groupBy $.SUBJECT_VERSION_ID map {
    id: $[0].SUBJECT_VERSION_ID,
    attributes: $.ATTRIBUTE_CODE
}

转型本身似乎运作良好。如果我将输出作为响应返回,则结果如此。

[
  {
    "id": "35DE521C7A772317E053282701126511",
    "attributes": [
      "CAL1",
      "CON"
    ]
  },
  {
    "id": "35DE521C7A6C2317E053282701126511",
    "attributes": [
      "REST"
    ]
  },
  {
    "id": "35DE521C7A692317E053282701126511",
    "attributes": [
      "SUPR"
    ]
  }
]

这里有完整的流程:

<flow name="subjects-feedFlow">
    <db:select config-ref="Oracle_Configuration" doc:name="Database">
        <db:parameterized-query><![CDATA[select subject_version_id,   attribute_code from subject_version_attribute]]></db:parameterized-query>
    </db:select>
    <dw:transform-message doc:name="Transform Message">
        <dw:set-payload><![CDATA[%dw 1.0
            %output application/json
            ---
            payload groupBy $.SUBJECT_VERSION_ID map {
                id: $[0].SUBJECT_VERSION_ID,
                attributes: $.ATTRIBUTE_CODE
        } ]]></dw:set-payload>
    </dw:transform-message>
    <set-variable variableName="attributes" value="#[payload]"/>
    <db:select config-ref="Oracle_Configuration" doc:name="Database">
    <db:parameterized-query><![CDATA[select c.subject_container_id, 
         subject_level, variable_units, lecture_units, lab_units, subject_version_id
        from subject_container c, subject_version v
        where c.subject_container_id = v.subject_container_id 
        and v.effective_from_term = (select max(effective_from_term) from  subject_version where v.subject_container_id = subject_container_id)]]></db:parameterized-query>
    </db:select>
    <dw:transform-message>
        <dw:input-payload/>
        <dw:input-variable variableName="attributes"/>
        <dw:set-payload><![CDATA[%dw 1.0
           %output application/dw
           %var theAttributes = flowVars.attributes
           %function supervisorAttribute(id) (theAttributes[?$.id ~=id].attributes[0][?($ == "INDP" or $ == "THES" or $ == "UROP")][0])
           ---
             {
               subjects: {
                    (payload map ((payload01 , indexOfPayload01) -> {
                       subject @(containerId: payload01.SUBJECT_CONTAINER_ID as :string, versionNum: payload01.VERSION_NUM): {
                          units: {
                              (unitType: "FIXED") when payload01.VARIABLE_UNITS=='N',
                              (unitType: "ARRANGED") when payload01.VARIABLE_UNITS=='Y',
                              (lectureUnits: payload01.LECTURE_UNITS as :string) when payload01.VARIABLE_UNITS=='N',
                              (labUnits: payload01.LAB_UNITS as :string) when payload01.VARIABLE_UNITS=='N',
                              (prepUnits: payload01.PREP_UNITS as :string) when payload01.VARIABLE_UNITS=='N'
                          },
                          (supervisorAttribute: supervisorAttribute(payload01.SUBJECT_VERSION_ID)) when supervisorAttribute(payload01.SUBJECT_VERSION_ID) != null,
                    }
                  }
           }]]></dw:set-payload>
    </dw:transform-message>
 </flow>

0 个答案:

没有答案
相关问题