/
generateRootServicesService.mtl
138 lines (127 loc) · 6.95 KB
/
generateRootServicesService.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
[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 generateRootServicesService('http://org.eclipse.lyo/oslc4j/adaptorInterface')]
[import org::eclipse::lyo::oslc4j::codegenerator::services::services/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::serviceProviderCatalogServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::adaptorInterfaceServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::jspServices/]
[template public generateImports(anAdaptorInterface : AdaptorInterface)]
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;
import org.eclipse.lyo.oslc4j.core.OSLC4JUtils;
import [javaInterfaceFullNameForAdaptorConstants(anAdaptorInterface) /];
import [anAdaptorInterface.serviceProviderCatalog.javaClassFullNameForSingleton() /];
[anAdaptorInterface.generateAuthenticationImports()/];
// [protected ('imports')]
// [/protected]
[/template]
[template public generateAuthenticationImports(anAdaptorInterface : AdaptorInterface)]
import [anAdaptorInterface.javaClassFullNameForAuthenticationApplication()/];
[/template]
[template public generateRootServicesService(anAdaptorInterface : AdaptorInterface)]
[if (anAdaptorInterface.authenticationEnabled())]
[file (anAdaptorInterface.javaClassFullFileNameForRootServicesService(), 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
*
* This file is generated by Lyo Designer (https://www.eclipse.org/lyo/)
*/
// [/protected]
package [anAdaptorInterface.javaClassPackageNameForRootServicesService()/];
[generateImports(anAdaptorInterface)/]
/**
* Jazz Root Services Service, see:
* https://jazz.net/wiki/bin/view/Main/RootServicesSpec
* https://jazz.net/wiki/bin/view/Main/RootServicesSpecAddendum2
*/
@Path("rootservices")
public class [anAdaptorInterface.javaClassNameForRootServicesService() /] {
@Context private HttpServletRequest httpServletRequest;
@Context private HttpServletResponse httpServletResponse;
@Context private UriInfo uriInfo;
/**
* Return a Rational Jazz compliant root services document
*
* See https://jazz.net/wiki/bin/view/Main/RootServicesSpec
*/
@GET
@Produces({ OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML })
public Response getRootServices() {
String about = UriBuilder.fromUri(OSLC4JUtils.getServletURI()).path("rootservices").build().toString();
String serviceProviderCatalog = [anAdaptorInterface.serviceProviderCatalog.javaClassNameForSingleton()/].getUri().toString();
String oauthRequestConsumerKeyUrl = UriBuilder.fromUri(OSLC4JUtils.getServletURI()).path("oauth/requestKey").build().toString();
String oauthApprovalModuleUrl = UriBuilder.fromUri(OSLC4JUtils.getServletURI()).path("oauth/approveKey").build().toString();
String oauthRequestTokenUrl = UriBuilder.fromUri(OSLC4JUtils.getServletURI()).path("oauth/requestToken").build().toString();
String oauthUserAuthorizationUrl = UriBuilder.fromUri(OSLC4JUtils.getServletURI()).path("oauth/authorize").build().toString();
String oauthAccessTokenUrl = UriBuilder.fromUri(OSLC4JUtils.getServletURI()).path("oauth/accessToken").build().toString();
// [protected ('init')]
// [/protected]
String response = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" +
"<rdf:Description \n" +
" xmlns:oslc_cm=\"http://open-services.net/xmlns/cm/1.0/\"" + "\n" +
" xmlns:oslc_am=\"http://open-services.net/ns/am#\"" + "\n" +
" xmlns:oslc_rm=\"http://open-services.net/xmlns/rm/1.0/\"" + "\n" +
" xmlns:dc=\"http://purl.org/dc/terms/\"" + "\n" +
" xmlns:jfs=\"http://jazz.net/xmlns/prod/jazz/jfs/1.0/\"" + "\n" +
" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n" +
" rdf:about=\"" + about + "\">\n" +
" <dc:title>Root Services</dc:title>" + "\n" +
" <oslc_am:amServiceProviders rdf:resource=\"" + serviceProviderCatalog + "\" />" + "\n" +
" <oslc_rm:rmServiceProviders rdf:resource=\"" + serviceProviderCatalog + "\" />" + "\n" +
" <oslc_cm:cmServiceProviders rdf:resource=\"" + serviceProviderCatalog + "\" />" + "\n" +
" <jfs:oauthRealmName>" + [anAdaptorInterface.javaClassNameForAuthenticationApplication()/].getApplication().getRealm(httpServletRequest) + "</jfs:oauthRealmName>" + "\n" +
" <jfs:oauthDomain>" + OSLC4JUtils.getPublicURI() + "</jfs:oauthDomain>" + "\n" +
" <jfs:oauthRequestConsumerKeyUrl rdf:resource=\"" + oauthRequestConsumerKeyUrl + "\"/>" + "\n" +
" <jfs:oauthApprovalModuleUrl rdf:resource=\"" + oauthApprovalModuleUrl + "\"/>" + "\n" +
" <jfs:oauthRequestTokenUrl rdf:resource=\"" + oauthRequestTokenUrl + "\"/>" + "\n" +
" <jfs:oauthUserAuthorizationUrl rdf:resource=\"" + oauthUserAuthorizationUrl + "\"/>" + "\n" +
" <jfs:oauthAccessTokenUrl rdf:resource=\"" + oauthAccessTokenUrl + "\"/>" + "\n" +
" </rdf:Description>" + "\n";
// [protected ('pre_response')]
// [/protected]
MediaType mediaType = MediaType.valueOf("application/rdf+xml");
ResponseBuilder builder = Response.ok(response, mediaType);
builder.type("application/rdf+xml; charset=UTF-8");
builder.header([javaInterfaceNameForAdaptorConstants(anAdaptorInterface)/].HDR_OSLC_VERSION, [javaInterfaceNameForAdaptorConstants(anAdaptorInterface)/].OSLC_VERSION_V2);
// [protected ('final')]
// [/protected]
return builder.build();
}
}
[/file]
[/if]
[/template]