Skip to content

Commit

Permalink
Don't automatically guess datatypes rundeck#353 rundeck#356
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Apr 23, 2013
1 parent 2697d19 commit ab2793a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class ScheduledExecution extends ExecutionContext {
se.multipleExecutions=data.multipleExecutions?true:false
}
if(data.nodefilters){
se.nodeThreadcount = data.nodefilters.dispatch.threadcount ? data.nodefilters.dispatch.threadcount : 1
se.nodeThreadcount = data.nodefilters.dispatch.threadcount ?: 1
if(data.nodefilters.dispatch.containsKey('keepgoing')){
se.nodeKeepgoing = data.nodefilters.dispatch.keepgoing
}
Expand Down
34 changes: 31 additions & 3 deletions rundeckapp/grails-app/utils/rundeck/codecs/JobsXMLCodec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class JobsXMLCodec {
*
*/
static convertToJobMap={ data->
final Object object = XmlParserUtil.toObject(data)
final Object object = XmlParserUtil.toObject(data,false)
if(!(object instanceof Map)){
throw new JobXMLException("Expected map data")
}
Expand Down Expand Up @@ -157,8 +157,11 @@ class JobsXMLCodec {
} else if (optm.values) {
optm.values = [optm.values.toString()]
}
if(null!=optm.enforcedvalues){
optm.enforced=optm.remove('enforcedvalues')
if(null!=optm.enforcedvalues) {
optm.enforced = Boolean.parseBoolean(optm.remove('enforcedvalues'))
}
if(null!=optm.required) {
optm.required = Boolean.parseBoolean(optm.remove('required'))
}
if(ndx>-1){
optm.sortIndex=ndx++;
Expand All @@ -175,6 +178,25 @@ class JobsXMLCodec {
if(null!=map.nodefilters.excludeprecedence){
map.nodefilters.dispatch['excludePrecedence']=map.nodefilters.remove('excludeprecedence')
}
if(null!=map.nodefilters.dispatch.threadcount && ""!= map.nodefilters.dispatch.threadcount){
//convert to integer
def value= map.nodefilters.dispatch.threadcount
try{
map.nodefilters.dispatch.threadcount=Integer.parseInt(value)
}catch (NumberFormatException e){
throw new JobXMLException("Not a valid threadcount: "+value)
}
}
if(null!=map.nodefilters.dispatch.keepgoing){
//convert to boolean
def value= map.nodefilters.dispatch.keepgoing
map.nodefilters.dispatch.keepgoing=Boolean.parseBoolean(value)
}
if(null!=map.nodefilters.dispatch.excludePrecedence){
//convert to boolean
def value= map.nodefilters.dispatch.excludePrecedence
map.nodefilters.dispatch.excludePrecedence=Boolean.parseBoolean(value)
}
}
if(map.schedule){
if(map.schedule.month?.day){
Expand Down Expand Up @@ -304,6 +326,9 @@ class JobsXMLCodec {
cmd.configuration = parsePluginConfig(plugin.configuration)
}
}
if(null!= cmd.keepgoingOnSuccess){
cmd.keepgoingOnSuccess=Boolean.parseBoolean(cmd.keepgoingOnSuccess)
}
}
data.commands.each(fixup)
data.commands.each {
Expand All @@ -312,6 +337,9 @@ class JobsXMLCodec {
}
}
}
if(null!=data.keepgoing && data.keepgoing instanceof String){
data.keepgoing = Boolean.parseBoolean(data.keepgoing)
}
}
/**
* Convert structure returned by job.toMap into correct structure for jobs xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class XmlParserUtil {
/**
* Generate data object from the node, not including the node name
*/
static Object toObject(Node data) {
static Object toObject(Node data, boolean analyze=true) {
if (null == data) {
return null
}
Expand All @@ -57,23 +57,23 @@ public class XmlParserUtil {
def attrs = data.attributes()
def map = [:]
if (data.text()) {
map['<text>'] = XmlParserUtil.analyzeText(text)
map['<text>'] = analyze?XmlParserUtil.analyzeText(text):text
}
if (attrs) {
attrs.keySet().each{
map.put(it,analyzeText(attrs[it]))
map.put(it,analyze?analyzeText(attrs[it]):attrs[it])
}
}
if (null != childs && childs instanceof Collection) {
childs.each {gp ->
if (gp instanceof Node) {
if (null != map[gp.name()] && !(map[gp.name()] instanceof Collection)) {
def v = map[gp.name()]
map[gp.name()] = [v, toObject(gp)]
map[gp.name()] = [v, toObject(gp,analyze)]
} else if (map[gp.name()] instanceof Collection) {
map[gp.name()] << toObject(gp)
map[gp.name()] << toObject(gp, analyze)
} else {
map[gp.name()] = toObject(gp)
map[gp.name()] = toObject(gp, analyze)
}
}
}
Expand All @@ -93,4 +93,4 @@ public class XmlParserUtil {
}
return text
}
}
}

0 comments on commit ab2793a

Please sign in to comment.