root / hci / trunk / eneraptor-web-app / grails-app / controllers / com / eneraptor / hci / SysStateController.groovy @ 66
History | View | Annotate | Download (3.76 KB)
1 | 3 | alexbesir | package com.eneraptor.hci
|
---|---|---|---|
2 | |||
3 | class SysStateController { |
||
4 | 6 | alexbesir | |
5 | def reportService
|
||
6 | def hciLogicCommService
|
||
7 | 3 | alexbesir | |
8 | 6 | alexbesir | def main = {
|
9 | |||
10 | 66 | alexbesir | def crit1 = DeviceInfo.createCriteria()
|
11 | List inDevices = crit1 {
|
||
12 | and { |
||
13 | eq("inputDevice",true) |
||
14 | eq("hwSet",session.hwSet)
|
||
15 | } |
||
16 | order("friendlyName","asc") |
||
17 | } |
||
18 | |||
19 | 6 | alexbesir | List inDevicesData = new ArrayList() |
20 | inDevices.each { |
||
21 | Map inDeviceDataEntry = new HashMap() |
||
22 | inDeviceDataEntry['friendlyName'] = it.friendlyName |
||
23 | inDeviceDataEntry['icon'] = it.iconPath |
||
24 | inDeviceDataEntry['loggedData'] = LoggedData.findByDeviceId(it.deviceId, [sort:'dateRecieved', order:'desc']) |
||
25 | inDevicesData << inDeviceDataEntry |
||
26 | } |
||
27 | |||
28 | 66 | alexbesir | def crit2 = DeviceInfo.createCriteria()
|
29 | List outDevices = crit2 {
|
||
30 | and { |
||
31 | eq("outputDevice",true) |
||
32 | eq("hwSet",session.hwSet)
|
||
33 | } |
||
34 | order("friendlyName","asc") |
||
35 | } |
||
36 | |||
37 | 6 | alexbesir | List outDevicesData = new ArrayList() |
38 | outDevices.each { |
||
39 | Map outDeviceDataEntry = new HashMap() |
||
40 | outDeviceDataEntry['friendlyName'] = it.friendlyName |
||
41 | outDeviceDataEntry['icon'] = it.iconPath |
||
42 | outDeviceDataEntry['loggedData'] = LoggedData.findByDeviceId(it.deviceId, [sort:'dateRecieved', order:'desc']) |
||
43 | outDevicesData << outDeviceDataEntry |
||
44 | } |
||
45 | |||
46 | [inDevicesData: inDevicesData, outDevicesData: outDevicesData] |
||
47 | |||
48 | } |
||
49 | |||
50 | def measure = {
|
||
51 | |||
52 | 66 | alexbesir | def crit1 = DeviceInfo.createCriteria()
|
53 | List inDevices = crit1 {
|
||
54 | and { |
||
55 | eq("inputDevice",true) |
||
56 | eq("hwSet",session.hwSet)
|
||
57 | } |
||
58 | order("friendlyName","asc") |
||
59 | } |
||
60 | |||
61 | 6 | alexbesir | List inDevicesData = new ArrayList() |
62 | inDevices.each { |
||
63 | Map inDeviceDataEntry = new HashMap() |
||
64 | inDeviceDataEntry['deviceId'] = it.deviceId |
||
65 | inDeviceDataEntry['friendlyName'] = it.friendlyName |
||
66 | inDeviceDataEntry['icon'] = it.iconPath |
||
67 | inDeviceDataEntry['loggedData'] = LoggedData.findByDeviceId(it.deviceId, [sort:'dateRecieved', order:'desc']) |
||
68 | inDevicesData << inDeviceDataEntry |
||
69 | } |
||
70 | |||
71 | [inDevicesData: inDevicesData]
|
||
72 | |||
73 | } |
||
74 | |||
75 | def measureUpdate = {
|
||
76 | |||
77 | List devices = new ArrayList() |
||
78 | |||
79 | DeviceInfo.findAllByInputDevice(true).each {
|
||
80 | if(params[it.deviceId] == "on") |
||
81 | devices << it.deviceId
|
||
82 | } |
||
83 | |||
84 | def output = ""; |
||
85 | |||
86 | if(devices.size == 0) { |
||
87 | flash['errors'] = "<p>No device was selected. At least one device must be selected.</p>" |
||
88 | redirect(action: 'measure') |
||
89 | return false |
||
90 | } |
||
91 | |||
92 | output += reportService.println("Trying to update measurements manually for devices")
|
||
93 | devices.each { |
||
94 | output += reportService.println(" - " + it) |
||
95 | } |
||
96 | output += reportService.println("Generating request xml")
|
||
97 | |||
98 | // generate request xml
|
||
99 | def reqXML = "<todo />" |
||
100 | |||
101 | output += reportService.println("Request xml generated")
|
||
102 | output += reportService.println("Sending request")
|
||
103 | |||
104 | // send request
|
||
105 | Map rspXML = hciLogicCommService.getReplyToRequest(reqXML)
|
||
106 | |||
107 | if(rspXML['status'] == "error") { |
||
108 | output += reportService.println("<span style='color:red;'>Error: " + rspXML['content'] + "</span>") |
||
109 | } else {
|
||
110 | output += reportService.println("<span style='color:red;'>Error: implementation missing - TODO.</span>")
|
||
111 | } |
||
112 | |||
113 | [errorExplanation: output]
|
||
114 | |||
115 | } |
||
116 | |||
117 | def actions = {
|
||
118 | |||
119 | 66 | alexbesir | def crit2 = DeviceInfo.createCriteria()
|
120 | List outDevices = crit2 {
|
||
121 | and { |
||
122 | eq("outputDevice",true) |
||
123 | eq("hwSet",session.hwSet)
|
||
124 | } |
||
125 | order("friendlyName","asc") |
||
126 | } |
||
127 | |||
128 | 6 | alexbesir | List outDevicesData = new ArrayList() |
129 | outDevices.each { |
||
130 | Map outDeviceDataEntry = new HashMap() |
||
131 | outDeviceDataEntry['deviceId'] = it.deviceId |
||
132 | outDeviceDataEntry['friendlyName'] = it.friendlyName |
||
133 | outDeviceDataEntry['icon'] = it.iconPath |
||
134 | outDeviceDataEntry['loggedData'] = LoggedData.findByDeviceId(it.deviceId, [sort:'dateRecieved', order:'desc']) |
||
135 | outDevicesData << outDeviceDataEntry |
||
136 | } |
||
137 | |||
138 | [outDevicesData: outDevicesData]
|
||
139 | |||
140 | } |
||
141 | |||
142 | 3 | alexbesir | } |