-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__classes__RestController.java
More file actions
252 lines (221 loc) · 9.13 KB
/
__classes__RestController.java
File metadata and controls
252 lines (221 loc) · 9.13 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#header()
#set( $className = ${classObject.getName()} )
#set( $lowercaseClassName = ${Utils.lowercaseFirstLetter( ${className} )} )
#set( $pk = "${className}Id" )
##set( $pkExpression = "${className}Id" )
##set( $pkExpression = "${lowercaseClassName}.${pk.getName()}" )
package ${aib.getRootPackageName(true)}.#getRestControllerPackageName();
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.logging.Level;
import java.util.logging.Logger;
#set( $imports = [ "api", "delegate", "entity", "exception", "handler" ] )
#importStatements( $imports )
/**
* Implements Struts action processing for business entity ${className}.
*
* @author $aib.getAuthor()
*/
@CrossOrigin
@RestController
@RequestMapping("/${className}")
##if ( $classObject.hasParent() == true )
## #set( $parentController = "${classObject.getParentName()}RestController" )
## #set( $parentName = $classObject.getParentName() )
##else
#set( $parentController = "BaseSpringRestController" )
##end
public class ${className}RestController extends $parentController {
/**
* Handles create a ${className}. if not key provided, calls create, otherwise calls save
* @param ${className} ${lowercaseClassName}
* @return CompletableFuture<UUID>
*/
@PostMapping("/create")
public CompletableFuture<UUID> create( @RequestBody(required=true) ${classObject.getCreateCommandAlias()} command ) {
CompletableFuture<UUID> completableFuture = null;
try {
completableFuture = ${className}BusinessDelegate.get${className}Instance().create${className}( command );
}
catch( Throwable exc ) {
LOGGER.log( Level.WARNING, exc.getMessage(), exc );
}
return completableFuture;
}
/**
* Handles updating a ${className}. if no key provided, calls create, otherwise calls save
* @param ${className} $lowercaseClassName
* @return CompletableFuture<Void>
*/
@PutMapping("/update")
public CompletableFuture<Void> update( @RequestBody(required=true) ${classObject.getUpdateCommandAlias()} command ) {
CompletableFuture<Void> completableFuture = null;
try {
// -----------------------------------------------
// delegate the ${classObject.getUpdateCommandAlias()}
// -----------------------------------------------
completableFuture = ${className}BusinessDelegate.get${className}Instance().update${className}(command);;
}
catch( Throwable exc ) {
LOGGER.log( Level.WARNING, "${className}Controller:update() - successfully update ${className} - " + exc.getMessage());
}
return completableFuture;
}
/**
* Handles deleting a ${className} entity
* @param command ${class.getDeleteCommandAlias()}
* @return CompletableFuture<Void>
*/
@DeleteMapping("/delete")
public CompletableFuture<Void> delete( @RequestBody(required=true) ${classObject.getDeleteCommandAlias()} command ) {
CompletableFuture<Void> completableFuture = null;
try {
${className}BusinessDelegate delegate = ${className}BusinessDelegate.get${className}Instance();
completableFuture = delegate.delete( command );
LOGGER.log( Level.WARNING, "Successfully deleted ${className} with key " + command.get${className}Id() );
}
catch( Throwable exc ) {
LOGGER.log( Level.WARNING, exc.getMessage() );
}
return completableFuture;
}
/**
* Handles loading a ${className} using a UUID
* @param UUID uuid
* @return ${className}
*/
@GetMapping("/load")
public ${className} load( @RequestParam(required=true) UUID uuid ) {
${className} entity = null;
try {
entity = ${className}BusinessDelegate.get${className}Instance().get${className}( new ${className}FetchOneSummary( uuid ) );
}
catch( Throwable exc ) {
LOGGER.log( Level.WARNING, "failed to load ${className} using Id " + uuid );
return null;
}
return entity;
}
/**
* Handles loading all ${className} business objects
* @return Set<${className}>
*/
@GetMapping("/")
public List<${className}> loadAll() {
List<${className}> ${lowercaseClassName}List = null;
try {
// load the ${className}
${lowercaseClassName}List = ${className}BusinessDelegate.get${className}Instance().getAll${className}();
if ( ${lowercaseClassName}List != null )
LOGGER.log( Level.INFO, "successfully loaded all ${className}s" );
}
catch( Throwable exc ) {
LOGGER.log( Level.WARNING, "failed to load all ${className}s ", exc );
return null;
}
return ${lowercaseClassName}List;
}
#set( $includeComposites = false )
#foreach( $singleAssociation in $classObject.getSingleAssociations( ${includeComposites} ) )
#set( $roleName = $singleAssociation.getRoleName() )
#set( $childType = $singleAssociation.getType() )
#set( $alias = ${singleAssociation.getAssignToCommandAlias()} )
/**
* save ${roleName} on ${className}
* @param command $alias
*/
@PutMapping("/assign${roleName}")
public void assign${roleName}( @RequestBody ${alias} command ) {
try {
${className}BusinessDelegate.get${className}Instance().assign${roleName}( command );
}
catch( Throwable exc ) {
LOGGER.log( Level.WARNING, "Failed to assign ${roleName}", exc );
}
}
#set( $alias = ${singleAssociation.getUnAssignFromCommandAlias()} )
/**
* unassign ${roleName} on ${className}
* @param command ${alias}
*/
@PutMapping("/unAssign${roleName}")
public void unAssign${roleName}( @RequestBody(required=true) ${alias} command ) {
try {
${className}BusinessDelegate.get${className}Instance().unAssign${roleName}( command );
}
catch( Exception exc ) {
LOGGER.log( Level.WARNING, "Failed to unassign ${roleName}", exc );
}
}
#end
#foreach( $multiAssociation in $classObject.getMultipleAssociations() )
#set( $roleName = $multiAssociation.getRoleName() )
#set( $childType = $multiAssociation.getType() )
#set( $alias = ${multiAssociation.getAddToCommandAlias()} )
/**
* save ${roleName} on ${className}
* @param command ${alias}
*/
@PutMapping("/addTo${roleName}")
public void addTo${roleName}( @RequestBody(required=true) ${alias} command ) {
try {
${className}BusinessDelegate.get${className}Instance().addTo${roleName}( command );
}
catch( Exception exc ) {
LOGGER.log( Level.WARNING, "Failed to add to Set $roleName", exc );
}
}
#set( $alias = ${multiAssociation.getRemoveFromCommandAlias()} )
/**
* remove ${roleName} on ${className}
* @param command ${alias}
*/
@PutMapping("/removeFrom${roleName}")
public void removeFrom${roleName}( @RequestBody(required=true) ${alias} command )
{
try {
${className}BusinessDelegate.get${className}Instance().removeFrom${roleName}( command );
}
catch( Exception exc ) {
LOGGER.log( Level.WARNING, "Failed to remove from Set ${roleName}", exc );
}
}
#end
#foreach( $query in $aib.getQueriesToGenerate(${className}) )
#foreach( $handler in $query.getHandlers() )
#set( $method = $handler.getMethodObject() )
#if ( ${method.hasArguments()} )
#set( $queryName = $Utils.capitalizeFirstLetter( $handler.getName() ) )
#set( $argType = ${method.getArguments().getArgs().get(0).getType()} )
#set( $argName = ${method.getArguments().getArgs().get(0).getName()} )
#set( $returnType = ${method.getArguments().getReturnType()} )
/**
* finder method to ${method.getName()}
* @param $argType $argName
* @return $returnType
*/
@PostMapping("/${method.getName()}")
public ${returnType} ${method.getName()}( @RequestBody(required=true) ${queryName}Query query ) {
${returnType} result = null;
try {
// call the delegate directly
result = new ${className}BusinessDelegate().${method.getName()}(query);
if ( result != null )
LOGGER.log( Level.WARNING, "successfully executed ${method.getName()}" );
}
catch( Throwable exc ) {
LOGGER.log( Level.WARNING, "failed to execute ${method.getName()}" );
}
return result;
}
#end##if ( ${method.hasArguments()} )
#end##foreach( $handler in $query.getHandlers() )
#end##foreach( $query in $aib.getQueriesToGenerate() )
//************************************************************************
// Attributes
//************************************************************************
protected ${className} $lowercaseClassName = null;
private static final Logger LOGGER = Logger.getLogger(${className}RestController.class.getName());
}