Skip to content

Commit

Permalink
Merge pull request #5 from rundeck-plugins/enhancements
Browse files Browse the repository at this point in the history
Enhancements
  • Loading branch information
ltamaster authored Dec 12, 2019
2 parents 1b3ebb8 + c581e5c commit de569fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/groovy/com/rundeck/plugins/logging/JsonLogFilter.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rundeck.plugins.logging

import com.dtolabs.rundeck.core.dispatcher.DataContextUtils
import com.dtolabs.rundeck.core.execution.workflow.OutputContext
import com.dtolabs.rundeck.core.logging.LogEventControl
import com.dtolabs.rundeck.core.logging.LogLevel
Expand Down Expand Up @@ -48,6 +49,7 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre
OutputContext outputContext
Map<String, String> allData
private ObjectMapper mapper
private String replacedFilter


@Override
Expand All @@ -56,7 +58,7 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre
buffer = new StringBuffer()
mapper = new ObjectMapper()
allData = [:]

replacedFilter = DataContextUtils.replaceDataReferences(filter,context.getDataContext())
}

@Override
Expand Down Expand Up @@ -93,7 +95,7 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre

Scope rootScope = Scope.newEmptyScope()
rootScope.loadFunctions(Scope.class.getClassLoader())
JsonQuery q = JsonQuery.compile(filter)
JsonQuery q = JsonQuery.compile(replacedFilter)
JsonNode inData = mapper.readTree(buffer.toString());

List<JsonNode> out = q.apply(rootScope, inData)
Expand All @@ -108,7 +110,9 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre
}else{
if(it.getNodeType()==JsonNodeType.ARRAY){
this.iterateArray(it.elements())
}else{
} else if(it.getNodeType()==JsonNodeType.STRING) {
allData.put(prefix, it.asText())
} else {
allData.put(prefix, it.toString())
}
}
Expand All @@ -126,7 +130,7 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre
Integer i=0
list.each{it->
if(it.getNodeType() == JsonNodeType.STRING){
allData.put(prefix +"."+ i.toString(),it.textValue())
allData.put(prefix +"."+ i.toString(),it.asText())
}else{
allData.put(prefix +"."+ i.toString(),it.toString())
}
Expand Down Expand Up @@ -154,7 +158,7 @@ See [here](https://github.com/eiiches/jackson-jq#implementation-status-and-curre
}else{
def extractValue
if(value.getNodeType() == JsonNodeType.STRING){
extractValue=value.textValue()
extractValue=value.asText()
}else{
extractValue = value.toString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class JsonLogFilterSpec extends Specification {
'test' : 'value',
'something2' : 'value1'
]
false | ".id" | ['{"id":"abc12345"}'] | [result: 'abc12345']
}

def "array test"() {
Expand Down

0 comments on commit de569fa

Please sign in to comment.