-
Notifications
You must be signed in to change notification settings - Fork 10
/
generateAdaptorManager.mtl
333 lines (305 loc) · 17.8 KB
/
generateAdaptorManager.mtl
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
[comment encoding = UTF-8 /]
[comment
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License 1.0
* which is available at http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Simple
*/
/]
[module generateAdaptorManager('http://org.eclipse.lyo/oslc4j/adaptorInterface')]
[import org::eclipse::lyo::oslc4j::codegenerator::services::services/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::resourceServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::serviceServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::webServiceServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::adaptorInterfaceServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::serviceProviderServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::serviceProviderCatalogServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::storeServices/]
[query public backendCode(backendCodeTemplate : String, resourceClassName : String, resourceInstanceName : String, compositeID : Sequence(String)) : String =
(if (not backendCodeTemplate.oclIsUndefined()) then
backendCodeTemplate
.substituteAll('[ResourceClassName/]', resourceClassName)
.substituteAll('[ResourceInstanceName/]', resourceInstanceName)
.substituteAll('[Parameter1/]', (if (compositeID->size() >=1) then compositeID->at(1) else '' endif))
.substituteAll('[Parameter2/]', (if (compositeID->size() >=2) then compositeID->at(2) else '' endif))
.substituteAll('[Parameter3/]', (if (compositeID->size() >=3) then compositeID->at(3) else '' endif))
.substituteAll('[Parameter4/]', (if (compositeID->size() >=4) then compositeID->at(4) else '' endif))
.substituteAll('[Parameter5/]', (if (compositeID->size() >=5) then compositeID->at(5) else '' endif))
else
''
endif)
/]
[query public backendCode(backendCodeTemplate : String) : String =
(if (not backendCodeTemplate.oclIsUndefined()) then
backendCodeTemplate
else
''
endif)
/]
[template public generateAdaptorManager(anAdaptorInterface : AdaptorInterface)]
[file (javaClassFullFileNameForAdaptorManager(anAdaptorInterface), false, 'UTF-8')]
// [protected ('Copyright')]
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Simple
*/
// [/protected]
package [javaClassPackageNameForAdaptorManager(anAdaptorInterface) /];
[if oldJavaClassNameForAdaptorManagerIsUsed(anAdaptorInterface)]
// [protected ('Notice')]
//Note: The Lyo code generator is migrating the name of this class from '[oldJavaClassNameForAdaptorManager(anAdaptorInterface)/]' to the new shorter name '[newJavaClassNameForAdaptorManager(anAdaptorInterface)/]'.
//You are still using the old name. The generator will continue to use this old name until you actively trigger the change.
//To migrate to the new class name:
//1. Rename your class to [newJavaClassNameForAdaptorManager(anAdaptorInterface)/]
// * Please rename and do not simply create a copy of the file. The generator needs to detect the file deletion in order to activate the name change.
//2. Regenerate the code.
// * The generator will generate this class with the new name.
// * Besides the class name, the code - including the user clode blocks - remain intact.
// * All other class references to the new class name are updated.
//3. Delete this notice
// [/protected]
[/if]
import jakarta.inject.Inject;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.ServletContextEvent;
import java.util.List;
import java.util.ArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.lyo.oslc4j.core.model.ServiceProvider;
import org.eclipse.lyo.oslc4j.core.OSLC4JUtils;
import org.eclipse.lyo.oslc4j.core.model.AbstractResource;
[if (not anAdaptorInterface.serviceProviderCatalog.oclIsUndefined())]
import [javaClassFullNameForSingleton(anAdaptorInterface.serviceProviderCatalog) /];
[/if]
[for (aServiceProvider: ServiceProvider | anAdaptorInterface.serviceProviders())]
import [javaClassFullName(aServiceProvider) /];
[/for]
[for (aResource: Resource | relevantResources(anAdaptorInterface)->sortedBy(name))]
import [javaClassFullName(aResource, anAdaptorInterface, null) /];
[/for]
[if (anAdaptorInterface.storeEnabled())][anAdaptorInterface.storeImportsForDelegate()/][/if]
[if (anAdaptorInterface.trsServiceEnabled())]
import org.eclipse.lyo.oslc4j.trs.server.TrsEventHandler;
[/if]
[backendCode(anAdaptorInterface.backendCodeTemplate_classImports)/]
// [protected ('imports')]
// [/protected]
// [protected ('pre_class_code')]
// [/protected]
public class [javaClassNameForAdaptorManager(anAdaptorInterface) /] {
private static final Logger log = LoggerFactory.getLogger([anAdaptorInterface.javaClassNameForAdaptorManager()/].class);
[if (anAdaptorInterface.storeEnabled())]@Inject StorePool storePool;[/if]
[if (anAdaptorInterface.trsServiceEnabled())]@Inject TrsEventHandler trsEventHandler;[/if]
@Inject [anAdaptorInterface.javaClassNameForResourcesFactory()/] resourcesFactory;
// [protected ('class_attributes')]
// [/protected]
public [javaClassNameForAdaptorManager(anAdaptorInterface)/]() {
log.trace("Delegate is initialized");
}
[backendCode(anAdaptorInterface.backendCodeTemplate_classMethods)/]
// [protected ('class_methods')]
// [/protected]
//The methods contextInitializeServletListener() and contextDestroyServletListener() no longer exits
//Migrate any user-specific code blocks to the class [anAdaptorInterface.javaClassFullNameForAdaptorServletListener()/]
//Any user-specific code should be found in *.lost files.
[for (aServiceProvider: ServiceProvider | anAdaptorInterface.serviceProviders())]
public static [aServiceProvider.javaClassName()/]['[' ']'/] get[aServiceProvider.javaClassName()/]s(HttpServletRequest httpServletRequest)
{
[aServiceProvider.javaClassName() /][ '[' ']' /] serviceProviderInfos = {};
[backendCode(anAdaptorInterface.backendCodeTemplate_getServiceProviders)/]
// [protected ('"'.concat(aServiceProvider.javaClassName()).concat('[] get'.concat(aServiceProvider.javaClassName()).concat('s(...)"')))]
// TODO Implement code to return the set of ServiceProviders
// [/protected]
return serviceProviderInfos;
}
[/for]
[for (aService: Service | anAdaptorInterface.serviceProviders().services)]
[for (aQueryCapability: QueryCapability | aService.queryCapabilities)]
public List<[queryMethodResourceType(aQueryCapability)/]> [queryMethodName(aQueryCapability, true)/](HttpServletRequest httpServletRequest[commaSeparate(queryMethodSignature(aQueryCapability, false), true, false)/], String where, String prefix, boolean paging, int page, int limit)
{
List<[queryMethodResourceType(aQueryCapability)/]> resources = null;
[backendCode(anAdaptorInterface.backendCodeTemplate_getResources, queryMethodResourceType(aQueryCapability), 'resources', queryCompositeID(aQueryCapability))/]
[queryResourcesFromStore(aQueryCapability)/]
// [protected (queryMethodName(aQueryCapability, true))]
// TODO Implement code to return a set of resources.
// An empty List should imply that no resources where found.
// If you encounter problems, consider throwing the runtime exception WebApplicationException(message, cause, final httpStatus)
// [/protected]
return resources;
}
[/for]
[for (aSelectionDialog: Dialog | aService.selectionDialogs)]
public List<[dialogMethodResourceType(aSelectionDialog)/]> [dialogMethodName(aSelectionDialog, true)/](HttpServletRequest httpServletRequest[commaSeparate(dialogMethodSignature(aSelectionDialog, true, false), true, false)/], String terms)
{
List<[dialogMethodResourceType(aSelectionDialog)/]> resources = null;
[backendCode(anAdaptorInterface.backendCodeTemplate_searchResources, dialogMethodResourceType(aSelectionDialog), 'resources', dialogCompositeID(aSelectionDialog, true))/]
[searchResourcesFromStore(aSelectionDialog)/]
// [protected (dialogMethodName(aSelectionDialog, true))]
// TODO Implement code to return a set of resources, based on search criteria
// An empty List should imply that no resources where found.
// If you encounter problems, consider throwing the runtime exception WebApplicationException(message, cause, final httpStatus)
// [/protected]
return resources;
}
[/for]
[for (aCreationFactory: CreationFactory | aService.creationFactories)]
public [creationMethodResourceType(aCreationFactory)/] [creationMethodName(aCreationFactory)/](HttpServletRequest httpServletRequest, final [creationMethodResourceType(aCreationFactory)/] aResource[commaSeparate(creationMethodSignature(aCreationFactory, false), true, false)/])
{
[creationMethodResourceType(aCreationFactory)/] newResource = null;
[backendCode(anAdaptorInterface.backendCodeTemplate_createResource, creationMethodResourceType(aCreationFactory), 'newResource', creationCompositeID(aCreationFactory))/]
[createResourceFromStore(aCreationFactory)/]
// [protected (creationMethodName(aCreationFactory))]
// TODO Implement code to create a resource
// If you encounter problems, consider throwing the runtime exception WebApplicationException(message, cause, final httpStatus)
// [/protected]
return newResource;
}
[/for]
[for (aCreationDialog: Dialog | aService.creationDialogs)]
public [creationMethodResourceType(aCreationDialog)/] [creationMethodName(aCreationDialog)/](HttpServletRequest httpServletRequest, final [creationMethodResourceType(aCreationDialog)/] aResource[commaSeparate(dialogMethodSignature(aCreationDialog, false, false), true, false)/])
{
[creationMethodResourceType(aCreationDialog)/] newResource = null;
[backendCode(anAdaptorInterface.backendCodeTemplate_createResource, creationMethodResourceType(aCreationDialog), 'newResource', dialogCompositeID(aCreationDialog, false))/]
[createResourceFromStore(aCreationDialog)/]
// [protected (creationMethodName(aCreationDialog))]
// TODO Implement code to create a resource
// If you encounter problems, consider throwing the runtime exception WebApplicationException(message, cause, final httpStatus)
// [/protected]
return newResource;
}
[/for]
[for (aBasicCapability: BasicCapability | aService.basicCapabilities)]
[if (aBasicCapability.read)]
[for (aResource: Resource | aBasicCapability.resourceTypes)]
public [getResourceMethodResourceType(aBasicCapability, aResource)/] [getResourceMethodName(aBasicCapability, aResource, true)/](HttpServletRequest httpServletRequest[commaSeparate(instanceMethodSignature(aResource, aBasicCapability, false), true, false)/])
{
[getResourceMethodResourceType(aBasicCapability, aResource)/] aResource = null;
[backendCode(anAdaptorInterface.backendCodeTemplate_getResource, getResourceMethodResourceType(aBasicCapability, aResource), 'aResource', instanceCompositeID(aResource, aBasicCapability))/]
// [protected (getResourceMethodName(aBasicCapability, aResource, true))]
// TODO Implement code to return a resource
// return 'null' if the resource was not found.
// If you encounter problems, consider throwing the runtime exception WebApplicationException(message, cause, final httpStatus)
// [/protected]
return aResource;
}
[/for]
[/if]
[if (aBasicCapability.delete)]
[for (aResource: Resource | aBasicCapability.resourceTypes)]
public Boolean [deleteResourceMethodName(aBasicCapability, aResource)/](HttpServletRequest httpServletRequest[commaSeparate(instanceMethodSignature(aResource, aBasicCapability, false), true, false)/])
{
Boolean deleted = false;
// [protected (deleteResourceMethodName(aBasicCapability, aResource))]
// TODO Implement code to delete a resource
// If you encounter problems, consider throwing the runtime exception WebApplicationException(message, cause, final httpStatus)
// [/protected]
return deleted;
}
[/for]
[/if]
[if (aBasicCapability.update)]
[for (aResource: Resource | aBasicCapability.resourceTypes)]
public [updateResourceMethodResourceType(aBasicCapability, aResource)/] [updateResourceMethodName(aBasicCapability, aResource)/](HttpServletRequest httpServletRequest, final [updateResourceMethodResourceType(aBasicCapability, aResource)/] aResource[commaSeparate(instanceMethodSignature(aResource, aBasicCapability, false), true, false)/]) {
[updateResourceMethodResourceType(aBasicCapability, aResource)/] updatedResource = null;
// [protected (updateResourceMethodName(aBasicCapability, aResource))]
// TODO Implement code to update and return a resource
// If you encounter problems, consider throwing the runtime exception WebApplicationException(message, cause, final httpStatus)
// [/protected]
return updatedResource;
}
[/for]
[/if]
[/for]
[/for]
[for (aWebService: WebService | anAdaptorInterface.webServices)]
[if (aWebService.read)]
[for (aResource: Resource | aWebService.resourceTypes)]
public [getResourceMethodResourceType(aResource)/] [getResourceMethodName(aResource, true)/](HttpServletRequest httpServletRequest[commaSeparate(instanceMethodSignature(aResource, aWebService, false), true, false)/])
{
[getResourceMethodResourceType(aResource)/] aResource = null;
[backendCode(anAdaptorInterface.backendCodeTemplate_getResource, getResourceMethodResourceType(aResource), 'aResource', instanceCompositeID(aResource, aWebService))/]
[aWebService.getResourceFromStore(aResource)/]
// [protected (getResourceMethodName(aResource, true))]
// TODO Implement code to return a resource
// return 'null' if the resource was not found.
// If you encounter problems, consider throwing the runtime exception WebApplicationException(message, cause, final httpStatus)
// [/protected]
return aResource;
}
[/for]
[/if]
[if (aWebService.delete)]
[for (aResource: Resource | aWebService.resourceTypes)]
public Boolean [deleteResourceMethodName(aResource)/](HttpServletRequest httpServletRequest[commaSeparate(instanceMethodSignature(aResource, aWebService, false), true, false)/])
{
Boolean deleted = false;
[aWebService.deleteResourceFromStore(aResource)/]
// [protected (deleteResourceMethodName(aResource))]
// TODO Implement code to delete a resource
// If you encounter problems, consider throwing the runtime exception WebApplicationException(message, cause, final httpStatus)
// [/protected]
return deleted;
}
[/for]
[/if]
[if (aWebService.update)]
[for (aResource: Resource | aWebService.resourceTypes)]
public [updateResourceMethodResourceType(aResource)/] [updateResourceMethodName(aResource)/](HttpServletRequest httpServletRequest, final [updateResourceMethodResourceType(aResource)/] aResource[commaSeparate(instanceMethodSignature(aResource, aWebService, false), true, false)/]) {
[updateResourceMethodResourceType(aResource)/] updatedResource = null;
[aWebService.updateResourceFromStore(aResource)/]
// [protected (updateResourceMethodName(aResource))]
// TODO Implement code to update and return a resource
// If you encounter problems, consider throwing the runtime exception WebApplicationException(message, cause, final httpStatus)
// [/protected]
return updatedResource;
}
[/for]
[/if]
[/for]
[for (aResource: Resource | servicedResources(anAdaptorInterface)->sortedBy(name))]
public String [getResourceETagMethodName(aResource)/](final [javaClassName(aResource)/] aResource)
{
String eTag = null;
// [protected (getResourceETagMethodName(aResource))]
// TODO Implement code to return an ETag for a particular resource
// If you encounter problems, consider throwing the runtime exception WebApplicationException(message, cause, final httpStatus)
// [/protected]
return eTag;
}
[/for]
[comment creationFactories that need to handle more than 1 resource need a special ETag method. See the method calls from the ServiceProvider Services classes./]
[for (aService: Service | anAdaptorInterface.serviceProviders().services)]
[for (aCreationFactory: CreationFactory | aService.creationFactories)]
[if (aCreationFactory.resourceTypes->size() > 1 )]
public String [getResourceETagMethodName(aCreationFactory.resourceTypes)/](final [creationMethodResourceType(aCreationFactory)/] aResource)
{
String eTag = null;
// [protected (getResourceETagMethodName(aCreationFactory.resourceTypes))]
// TODO Implement code to return an ETag for a particular resource
// If you encounter problems, consider throwing the runtime exception WebApplicationException(message, cause, final httpStatus)
// [/protected]
return eTag;
}
[/if]
[/for]
[/for]
}
[/file]
[/template]