-
Notifications
You must be signed in to change notification settings - Fork 0
/
interim_parser.groovy
65 lines (46 loc) · 1.88 KB
/
interim_parser.groovy
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
package Groovy_Scripts
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
def fileName = "./test_data/draft.xml"
def xmlFile = getClass().getResourceAsStream(fileName)
Node ovalParts = new XmlParser().parse(xmlFile)
def total = 0
def changelist =[]
//Parts to remove
def testNode = ovalParts.tests
def objectNode = ovalParts.objects
def stateNode = ovalParts.states
def variableNode = ovalParts.variables
ovalParts.remove(testNode)
ovalParts.remove(objectNode)
ovalParts.remove(stateNode)
ovalParts.remove(variableNode)
ovalParts.definitions.definition.each {
def it -> {
Node statusNode = it.metadata.oval_repository.status[0] as Node
NodeList statusChanges = it.metadata.oval_repository.dates.status_change
NodeList dates = it.metadata.oval_repository.dates
println statusChanges
def status = statusNode.text().replaceAll("\\s","")
ZonedDateTime from = ZonedDateTime.now()
if (statusChanges.last() != null) {
from = ZonedDateTime.parse((String)statusChanges.last().@date, DateTimeFormatter.ISO_DATE_TIME)
}
ZonedDateTime to = ZonedDateTime.now();
long days = ChronoUnit.DAYS.between(from, to)
boolean correctStatus = status == 'INTERIM'
boolean olderThanTwoWeeks = days >= 13
if (correctStatus && olderThanTwoWeeks) {
changelist << "$it.metadata.title"
total++
def newStatusChange = new NodeBuilder().status_change(date: "${to.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME).toString()}", 'ACCEPTED')
// println newStatusChange
dates[0].children().add(dates.size() + 1, newStatusChange)
statusNode.value = 'ACCEPTED'
}
}
}
new XmlNodePrinter(new PrintWriter(new FileWriter(fileName))).print(ovalParts)
changelist.each {println(it)}
println(total)