Skip to content

Commit

Permalink
Remove old ApiQuery stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Feb 16, 2011
1 parent 2a1bea6 commit 528a3ab
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 270 deletions.
105 changes: 0 additions & 105 deletions rundeckapp/grails-app/controllers/ReportsController.groovy
Expand Up @@ -319,111 +319,6 @@ class ReportsController {
return model
}



def query = {ApiQuery query ->
if (request.getParameterMap().containsKey('action')) {
query.actionStr = request.getParameter('action')
}
if (request.getParameterMap().containsKey('controller')) {
query.controllerStr = request.getParameter('controller')
}
def result
if (query.hasErrors()) {
def StringBuffer sb = new StringBuffer()
query.errors.allErrors.each{ it ->
// sb << it.toString()
sb << g.message(error:it)
}
result = ['error': sb.toString()]
} else {
result = reportService.getApiQuery(query)
}

if (result.error) {
render(contentType: "text/xml", encoding: "UTF-8") {
'reports-query-result'(error: "true") {
errors() {
error(result.error)
}
}
}
return
}

def xmlclos = {
'reports-query-result'(matchTotal: result.total) {
reports(count: result.reports.size()) {
result.reports.each() {res ->
'report-entry'(itemType: (res instanceof ExecReport ? 'commandExec' :""),
actionType: (res instanceof ExecReport ? res.status : "succeed")) {
date(time: res.dateCompleted.getTime(), res.dateCompleted.toString())
author(res.author)
project(res.ctxProject)
itemType(res instanceof ExecReport ? 'commandExec' : "")
resourceType(res.ctxType)
resourceName(res.ctxName)
controller(res.ctxType)
if (res instanceof ExecReport) {
commandName(res.ctxCommand)
}
maprefUri(res.maprefUri)
if (res instanceof ExecReport) {
nodename(res.node)
}
reportId(res.reportId)
actionType(res.status)
action(res.title)
message(res.message)
}

}
}
}
}

def jsonclos = {
matchTotal( result.total)
count(result.reports.size())
reports() {
result.reports.each() {res ->
reports(time: res.dateCompleted.getTime(), date:res.dateCompleted.toString(),
author:res.author,
project:res.ctxProject,
itemType:(res instanceof ExecReport ? 'commandExec' : ""),
resourceType:res.ctxType,
resourceName:res.ctxName,
controller:res.ctxType,
commandName:((res instanceof ExecReport)?res.ctxCommand:''),
maprefUri:res.maprefUri,
nodename:((res instanceof ExecReport)?res.node:''),
reportId:res.reportId,
actionType:res.actionType,
action:res.title,
message:res.message
)

}

}
}

//change closure resolvestrategy so that the 'message' call doesn't cause StackOverflowError
xmlclos.resolveStrategy = Closure.DELEGATE_FIRST
switch (query.format) {
case 'json':
render(contentType: "text/json", encoding: "UTF-8",jsonclos)
break
// case 'yaml':
// render(contentType: "text/yaml", encoding: "UTF-8",jsonclos)
// break
case 'xml':
default:
render(contentType: "text/xml", encoding: "UTF-8", xmlclos)
}

}

/**
* API actions
*
Expand Down
90 changes: 0 additions & 90 deletions rundeckapp/grails-app/services/ReportService.groovy
Expand Up @@ -484,94 +484,4 @@ class ReportService implements ReportAcceptor {
]
}


def getApiQuery(ApiQuery query) {
def eqfilters = ['project', 'maprefUri','actionType','itemType','commandName','controller','status']


def fieldmap = [
commandName:'ctxCommand',
nodename:'node',
actionType:'actionType',
status:'status',
project:'ctxProject',
resourceType:'ctxType',
resourceName:'ctxName',
actionStr:'title',
controllerStr:'ctxType',
message:'message',

author:'author',
date:'dateCompleted',
maprefUri:'maprefUri',
reportId:'reportId',
// String patternName
]
def allfields = [:]

if(!query.status && query.actionType && (query.actionType=='succeed' || query.actionType=='fail')){
query.status=query.actionType
query.actionType=null
}


def crit
//itemType query paramter doesn't map to a field, it selects between report subclass
switch(query.itemType){
case 'commandExec':
crit = ExecReport.createCriteria()
break
default:
crit = BaseReport.createCriteria()
}


def fieldclos= { key,val ->
if(query[key]){
if(eqfilters.contains(key)){
eq(val,query[key])
}else{
if(query[key].indexOf("*")>=0 || query[key].indexOf("?")>=0){
def x = query[key].replaceAll("\\*","%")
x = x.replaceAll("\\?","_")
ilike(val,x)
}else{
eq(val,query[key])
}
}
}
}
def runlist = crit.list{
if(query.max){
maxResults(query.max)
}
if(query.offset){
firstResult(query.offset)
}
fieldclos.delegate=delegate
fieldmap.each(fieldclos)
if(query.sortBy && fieldmap[query.sortBy]){
order(fieldmap[query.sortBy],query.sortOrder=='ascending'?'asc':'desc')
}else{
order("dateCompleted",'desc')
}
};

def crit2
switch(query.itemType){
case 'commandExec':
crit2 = ExecReport.createCriteria()
break
default:
crit2 = BaseReport.createCriteria()
}
def total = crit2.count{
fieldclos.delegate=delegate
fieldmap.each(fieldclos)

};

return [query: query, reports: runlist, total: total]

}
}
75 changes: 0 additions & 75 deletions rundeckapp/src/groovy/ApiQuery.groovy

This file was deleted.

0 comments on commit 528a3ab

Please sign in to comment.