-
Notifications
You must be signed in to change notification settings - Fork 19
/
ApplicationController.groovy
113 lines (99 loc) · 3.43 KB
/
ApplicationController.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import org.hyperic.hq.hqapi1.ErrorCode
import org.hyperic.hq.appdef.server.session.ApplicationManagerEJBImpl as AppMan
import org.hyperic.hq.bizapp.server.session.AppdefBossEJBImpl as ABoss
import org.hyperic.util.pager.PageControl
import org.hyperic.hq.auth.shared.SessionManager
import org.hyperic.hq.appdef.shared.AppdefGroupValue
import org.hyperic.hq.appdef.shared.ServiceValue
class ApplicationController extends ApiController {
def appMan = AppMan.one
def aBoss = ABoss.one
private Closure getApplicationXML(a) {
{ doc ->
Application(id : a.id,
name : a.name,
location : a.location,
description : a.description,
engContact : a.engContact,
opsContact : a.opsContact,
bizContact : a.businessContact) {
def sessionId = SessionManager.instance.put(user)
for (appService in aBoss.findServiceInventoryByApplication(sessionId, a.id, PageControl.PAGE_ALL)) {
if (appService instanceof ServiceValue) {
def resource = resourceHelper.find('service':appService.id)
Resource(id : resource.id,
name : resource.name,
description : resource.description)
} else {
Group(id : appService.id,
name : appService.name,
description : appService.description,
location : appService.location)
}
}
}
}
}
def list(params) {
def failureXml = null
renderXml() {
out << ApplicationsResponse() {
if (failureXml) {
out << failureXml
} else {
out << getSuccessXML()
for (app in appMan.getAllApplications(user, PageControl.PAGE_ALL)) {
out << getApplicationXML(app)
}
}
}
}
}
def create(params) {
def failureXml = null
renderXml() {
ApplicationResponse() {
if (failureXml) {
out << failureXml
} else {
out << getSuccessXML()
}
}
}
}
def update(params) {
def failureXml = null
renderXml() {
ApplicationResponse() {
if (failureXml) {
out << failureXml
} else {
out << getSuccessXML()
}
}
}
}
def delete(params) {
def id = params.getOne('id')?.toInteger()
if (id == null) {
renderXml() {
out << StatusResponse() {
out << getFailureXML(ErrorCode.INVALID_PARAMETERS)
}
}
return
}
def failureXml = null
// TODO: remove next debugging line
print "ID: " + id
renderXml() {
StatusResponse() {
if (failureXml) {
out << failureXml
} else {
out << getSuccessXML()
}
}
}
}
}