Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:dtolabs/yana
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonor committed Aug 11, 2011
2 parents 2b19562 + eef47a2 commit f7249ba
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8,987 deletions.
61 changes: 48 additions & 13 deletions grails-app/controllers/yana/node/NodeRestController.groovy
Expand Up @@ -92,7 +92,12 @@ class NodeRestController {
// Forbidden. The node already exists.
render status:403, contentType:"text/xml", encoding:"utf-8", {
errors {
message("Node already exists. id: "+ nodeMap.id)
error {
message("Node already exists")
references {
node(id:nodeMap.id)
}
}
}
}
} else {
Expand All @@ -103,16 +108,23 @@ class NodeRestController {
if (nodeInstance && !nodeInstance.hasErrors()) {
render status:201, contentType:"text/xml", encoding:"utf-8", {
results {
result("Created new node. id: " + nodeInstance.id)
result {
message("Created new node")
references {
node(id:nodeInstance.id)
}
}
}
}
} else {
// Bad request.
render status:400, contentType:"text/xml", encoding:"utf-8", {
errors {
nodeInstance?.errors?.fieldErrors?.each { err ->
field(err.field)
message(g.message(error: err))
error {
field(err.field)
message(g.message(error: err))
}
}
}
}
Expand All @@ -137,15 +149,19 @@ class NodeRestController {
if (!nodeInstance.hasErrors() && nodeInstance.save(flush:true)) {
render status:200, contentType:"text/xml", encoding:"utf-8", {
results {
result("saved node data")
result {
message("saved node data")
}
}
}
} else {
render status:403, contentType:"text/xml", encoding:"utf-8", {
errors {
nodeInstance?.errors?.fieldErrors?.each { err ->
field(err.field)
message(g.message(error: err))
error {
field(err.field)
message(g.message(error: err))
}
}
}
}
Expand All @@ -154,24 +170,33 @@ class NodeRestController {
// Not Found.
render status:404, contentType:"text/xml", encoding:"utf-8", {
errors {
message("Node not found. id: " + params.id)
error {
message("Node not found")
references {
node(id:params.id)
}
}
}
}
}

if (nodeInstance && !nodeInstance.hasErrors()) {
render status:202, contentType: "text/xml", encoding: "utf-8", {
results {
result("Node info saved")
result {
message("Node info saved")
}
}
}
} else {
// Bad request.
render status:400, contentType:"text/xml", encoding:"utf-8", {
errors {
nodeInstance?.errors?.fieldErrors?.each { err ->
field(err.field)
message(g.message(error: err))
error {
field(err.field)
message(g.message(error: err))
}
}
}
}
Expand All @@ -190,14 +215,24 @@ class NodeRestController {
// Ok.
render status:200, contentType:"text/xml", encoding:"utf-8", {
results {
result("Node removed. id: " + params.id)
result {
message("Node removed")
references {
node(id:params.id)
}
}
}
}
} else {
// Accepted.
render status:202, contentType:"text/xml", encoding:"utf-8", {
results {
result("Node not found. id: " + params.id)
result {
message("Node not found")
references {
node(id:params.id)
}
}
}
}
}
Expand Down

0 comments on commit f7249ba

Please sign in to comment.