Skip to content

Commit

Permalink
mulesoft-consulting#22 - added isBlank checks for mimeType and if isB…
Browse files Browse the repository at this point in the history
…lank then will just return the initial inputData
  • Loading branch information
bcoveny committed Feb 1, 2021
1 parent e48def4 commit 5dc7952
Showing 1 changed file with 52 additions and 40 deletions.
92 changes: 52 additions & 40 deletions json-logger/src/main/resources/modules/JSONLoggerModule.dwl
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
%dw 2.0
fun stringifyAny(inputData: Any) = if (inputData.^mimeType == "application/xml" or
inputData.^mimeType == "application/dw" or
inputData.^mimeType == "application/json")
write(inputData,inputData.^mimeType,{indent:false})
else if (inputData.^mimeType == "*/*")
inputData
else
write(inputData,inputData.^mimeType)
fun stringifyAny(inputData: Any) =
if (isBlank(inputData.^mimeType) or
inputData.^mimeType == "*/*")
inputData
else if (inputData.^mimeType == "application/xml" or
inputData.^mimeType == "application/dw" or
inputData.^mimeType == "application/json")
write(inputData,inputData.^mimeType,{indent:false})
else
write(inputData,inputData.^mimeType)

fun stringifyNonJSON(inputData: Any) = if (inputData.^mimeType == "application/xml" or
inputData.^mimeType == "application/dw")
write(inputData,inputData.^mimeType,{indent:false})
else if (inputData.^mimeType == "application/json" or inputData.^mimeType == "*/*")
inputData
else
write(inputData,inputData.^mimeType)
fun stringifyNonJSON(inputData: Any) =
if (isBlank(inputData.^mimeType) or
inputData.^mimeType == "*/*" or
inputData.^mimeType == "application/json")
inputData
else if (inputData.^mimeType == "application/xml" or
inputData.^mimeType == "application/dw")
write(inputData,inputData.^mimeType,{indent:false})
else
write(inputData,inputData.^mimeType)

fun stringifyAnyWithMetadata(inputData: Any) = {
data: if (inputData.^mimeType == "application/xml" or
inputData.^mimeType == "application/dw" or
inputData.^mimeType == "application/json")
write(inputData,inputData.^mimeType,{indent:false})
else if (inputData.^mimeType == "*/*")
inputData
else
write(inputData,inputData.^mimeType),
(contentLength: inputData.^contentLength) if (inputData.^contentLength != null),
(dataType: inputData.^mimeType) if (inputData.^mimeType != null),
(class: inputData.^class) if (inputData.^class != null)
}
fun stringifyAnyWithMetadata(inputData: Any) =
{
data: if (isBlank(inputData.^mimeType) or
inputData.^mimeType == "*/*")
inputData
else if (inputData.^mimeType == "application/xml" or
inputData.^mimeType == "application/dw" or
inputData.^mimeType == "application/json")
write(inputData,inputData.^mimeType,{indent:false})
else
write(inputData,inputData.^mimeType),

(contentLength: inputData.^contentLength) if (inputData.^contentLength != null),
(dataType: inputData.^mimeType) if (inputData.^mimeType != null),
(class: inputData.^class) if (inputData.^class != null)
}

fun stringifyNonJSONWithMetadata(inputData: Any) = {
data: if (inputData.^mimeType == "application/xml" or
inputData.^mimeType == "application/dw")
write(inputData,inputData.^mimeType,{indent:false})
else if (inputData.^mimeType == "application/json" or inputData.^mimeType == "*/*")
inputData
else
write(inputData,inputData.^mimeType),
(contentLength: inputData.^contentLength) if (inputData.^contentLength != null),
(dataType: inputData.^mimeType) if (inputData.^mimeType != null),
(class: inputData.^class) if (inputData.^class != null)
}
fun stringifyNonJSONWithMetadata(inputData: Any) =
{
data: if (isBlank(inputData.^mimeType) or
inputData.^mimeType == "*/*" or
inputData.^mimeType == "application/json")
inputData
else if (inputData.^mimeType == "application/xml" or
inputData.^mimeType == "application/dw")
write(inputData,inputData.^mimeType,{indent:false})
else
write(inputData,inputData.^mimeType),

(contentLength: inputData.^contentLength) if (inputData.^contentLength != null),
(dataType: inputData.^mimeType) if (inputData.^mimeType != null),
(class: inputData.^class) if (inputData.^class != null)
}

0 comments on commit 5dc7952

Please sign in to comment.