This repository has been archived by the owner on Jun 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathfindObjectsSample.dsl
88 lines (79 loc) · 2.79 KB
/
findObjectsSample.dsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Imports needed for invoking findObjects in the DSL script
import com.electriccloud.query.Filter
import com.electriccloud.query.CompositeFilter
import com.electriccloud.query.PropertyFilter
import com.electriccloud.query.Operator
import com.electriccloud.query.SelectSpec
import com.electriccloud.util.SortOrder
import com.electriccloud.util.SortSpec
/**
* Sample filter definition for:
* projectName equals "project-0"
* AND
* (
* pipelineName equals "pipeline-0"
* or
* pipelineName equals "pipeline-1"
* )
*/
def filters = [[
propertyName: "projectName",
operator: "equals",
operand1: "project-0"
],
[ filters: [[
propertyName: "pipelineName",
operator: "equals",
operand1: "pipeline-0"
],[
propertyName: "pipelineName",
operator: "equals",
operand1: "pipeline-1"
]],
operator: "or"
]]
/**
* Simple selects can be specified simply as strings
* Use the object structure if recurse option needs to be controlled.
* The above 2 forms can be completed in the same list of selects.
*/
def selects = ["testprop1", [propertyName: "testprop2", recurse: true]]
/**
* Sort columns
*/
def sorts = [[propertyName: "pipelineName", order: "descending"], [propertyName: "projectName"]]
// make the call
findObjects(objectType: 'pipeline', filter: constructFilters(filters), select: constructSelects(selects), sort: constructSorts(sorts))
/**
* Helper function to convert the list of filters to a filter structure
* recognized by findObjects for DSL evaluation.
*/
def constructFilters(def filters) {
filters.collect {
def op = Operator.valueOf(it.operator)
if (op.isBoolean()) {
assert it.filters
new CompositeFilter(op, constructFilters(it.filters) as Filter[])
} else {
new PropertyFilter(it.propertyName, op, it.operand1, it.operand2)
}
}
}
/**
* Helper function to convert the list of select strings to a list of SelectSpec
* recognized by findObjects for DSL evaluation.
*/
def constructSelects(def selects) {
selects.collect {
it instanceof String ? new SelectSpec(it, false) : new SelectSpec(it.propertyName, it.recurse)
}
}
/**
* Helper function to convert the list of sort instances to a list of SortSpec
* recognized by findObjects for DSL evaluation.
*/
def constructSorts(def sorts) {
sorts.collect {
new SortSpec(it.propertyName, SortOrder.valueOf(it.order?:"ascending"))
}
}