1 | package dbnp.studycapturing |
---|
2 | /** |
---|
3 | * 888 888 888 888 8888888888 8888888b. 8888888888 |
---|
4 | * 888 o 888 888 888 888 888 Y88b 888 |
---|
5 | * 888 d8b 888 888 888 888 888 888 888 |
---|
6 | * 888 d888b 888 8888888888 8888888 888 d88P 8888888 |
---|
7 | * 888d88888b888 888 888 888 8888888P" 888 |
---|
8 | * 88888P Y88888 888 888 888 888 T88b 888 |
---|
9 | * 8888P Y8888 888 888 888 888 T88b 888 |
---|
10 | * 888P Y888 888 888 8888888888 888 T88b 8888888888 |
---|
11 | * |
---|
12 | * 8888888 .d8888b. 88888888888 888 888 8888888888 |
---|
13 | * 888 d88P Y88b 888 888 888 888 |
---|
14 | * 888 Y88b. 888 888 888 888 |
---|
15 | * 888 "Y888b. 888 8888888888 8888888 |
---|
16 | * 888 "Y88b. 888 888 888 888 |
---|
17 | * 888 "888 888 888 888 888 |
---|
18 | * 888 Y88b d88P 888 888 888 888 |
---|
19 | * 8888888 "Y8888P" 888 888 888 8888888888 |
---|
20 | * |
---|
21 | * 888888 d8888 888 888 d8888 8888888b. .d88888b. .d8888b. |
---|
22 | * "88b d88888 888 888 d88888 888 "Y88b d88P" "Y88b d88P Y88b |
---|
23 | * 888 d88P888 888 888 d88P888 888 888 888 888 888 888 |
---|
24 | * 888 d88P 888 Y88b d88P d88P 888 888 888 888 888 888 |
---|
25 | * 888 d88P 888 Y88b d88P d88P 888 888 888 888 888 888 |
---|
26 | * 888 d88P 888 Y88o88P d88P 888 888 888 888 888 888 888 |
---|
27 | * 88P d8888888888 Y888P d8888888888 888 .d88P Y88b. .d88P Y88b d88P |
---|
28 | * 888 d88P 888 Y8P d88P 888 8888888P" "Y88888P" "Y8888P" |
---|
29 | * .d88P |
---|
30 | * .d88P" |
---|
31 | * 888P" |
---|
32 | * |
---|
33 | * .d8888b. 888 .d8888b. 888 .d8888b. 888 |
---|
34 | * d88P Y88b 888 d88P Y88b 888 d88P Y88b 888 |
---|
35 | * .d88P 888 .d88P 888 .d88P 888 |
---|
36 | * .d88P" 888 .d88P" 888 .d88P" 888 |
---|
37 | * 888" 888 888" 888 888" 888 |
---|
38 | * 888 Y8P 888 Y8P 888 Y8P |
---|
39 | * " " " |
---|
40 | * 888 888 888 888 888 888 |
---|
41 | * |
---|
42 | * |
---|
43 | * TODO: add PROPER class and method documentation, just like have |
---|
44 | * agreed upon hundreds of times!!!! |
---|
45 | */ |
---|
46 | class PersonAffiliationController { |
---|
47 | |
---|
48 | static allowedMethods = [save: "POST", update: "POST", delete: "POST"] |
---|
49 | |
---|
50 | def index = { |
---|
51 | redirect(action: "list", params: params) |
---|
52 | } |
---|
53 | |
---|
54 | def list = { |
---|
55 | params.max = Math.min(params.max ? params.int('max') : 10, 100) |
---|
56 | [personAffiliationInstanceList: PersonAffiliation.list(params), personAffiliationInstanceTotal: PersonAffiliation.count()] |
---|
57 | } |
---|
58 | |
---|
59 | def create = { |
---|
60 | def personAffiliationInstance = new PersonAffiliation() |
---|
61 | personAffiliationInstance.properties = params |
---|
62 | return [personAffiliationInstance: personAffiliationInstance] |
---|
63 | } |
---|
64 | |
---|
65 | def save = { |
---|
66 | def personAffiliationInstance = new PersonAffiliation(params) |
---|
67 | if (personAffiliationInstance.save(flush: true)) { |
---|
68 | flash.message = "${message(code: 'default.created.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), personAffiliationInstance])}" |
---|
69 | redirect(action: "show", id: personAffiliationInstance.id) |
---|
70 | } |
---|
71 | else { |
---|
72 | render(view: "create", model: [personAffiliationInstance: personAffiliationInstance]) |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | def show = { |
---|
77 | def personAffiliationInstance = PersonAffiliation.get(params.id) |
---|
78 | if (!personAffiliationInstance) { |
---|
79 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), params.id])}" |
---|
80 | redirect(action: "list") |
---|
81 | } |
---|
82 | else { |
---|
83 | [personAffiliationInstance: personAffiliationInstance] |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | def edit = { |
---|
88 | def personAffiliationInstance = PersonAffiliation.get(params.id) |
---|
89 | if (!personAffiliationInstance) { |
---|
90 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), params.id])}" |
---|
91 | redirect(action: "list") |
---|
92 | } |
---|
93 | else { |
---|
94 | return [personAffiliationInstance: personAffiliationInstance] |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | def update = { |
---|
99 | def personAffiliationInstance = PersonAffiliation.get(params.id) |
---|
100 | if (personAffiliationInstance) { |
---|
101 | if (params.version) { |
---|
102 | def version = params.version.toLong() |
---|
103 | if (personAffiliationInstance.version > version) { |
---|
104 | |
---|
105 | personAffiliationInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'personAffiliation.label', default: 'Affiliation')] as Object[], "Another user has updated this PersonAffiliation while you were editing") |
---|
106 | render(view: "edit", model: [personAffiliationInstance: personAffiliationInstance]) |
---|
107 | return |
---|
108 | } |
---|
109 | } |
---|
110 | personAffiliationInstance.properties = params |
---|
111 | if (!personAffiliationInstance.hasErrors() && personAffiliationInstance.save(flush: true)) { |
---|
112 | flash.message = "${message(code: 'default.updated.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), personAffiliationInstance])}" |
---|
113 | redirect(action: "show", id: personAffiliationInstance.id) |
---|
114 | } |
---|
115 | else { |
---|
116 | render(view: "edit", model: [personAffiliationInstance: personAffiliationInstance]) |
---|
117 | } |
---|
118 | } |
---|
119 | else { |
---|
120 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), params.id])}" |
---|
121 | redirect(action: "list") |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | def delete = { |
---|
126 | def personAffiliationInstance = PersonAffiliation.get(params.id) |
---|
127 | if (personAffiliationInstance) { |
---|
128 | def affiliationName = personAffiliationInstance.toString() |
---|
129 | try { |
---|
130 | personAffiliationInstance.delete(flush: true) |
---|
131 | flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), affiliationName])}" |
---|
132 | redirect(action: "list") |
---|
133 | } |
---|
134 | catch (org.springframework.dao.DataIntegrityViolationException e) { |
---|
135 | flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), affiliationName])}" |
---|
136 | redirect(action: "show", id: params.id) |
---|
137 | } |
---|
138 | } |
---|
139 | else { |
---|
140 | flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'personAffiliation.label', default: 'Affiliation'), params.id])}" |
---|
141 | redirect(action: "list") |
---|
142 | } |
---|
143 | } |
---|
144 | } |
---|