1- package com . oembedler . moon .altair .boot ;
1+ package graphql . kickstart .altair .boot ;
22
33import com .fasterxml .jackson .core .JsonProcessingException ;
44import com .fasterxml .jackson .databind .ObjectMapper ;
5+ import java .io .IOException ;
6+ import java .io .InputStream ;
7+ import java .nio .charset .Charset ;
8+ import java .util .HashMap ;
9+ import java .util .Map ;
10+ import java .util .Properties ;
11+ import javax .annotation .PostConstruct ;
12+ import javax .servlet .http .HttpServletRequest ;
13+ import javax .servlet .http .HttpServletResponse ;
514import org .apache .commons .lang3 .StringUtils ;
615import org .apache .commons .lang3 .text .StrSubstitutor ;
716import org .springframework .beans .factory .annotation .Autowired ;
8- import org .springframework .beans .factory .annotation .Value ;
917import org .springframework .core .env .Environment ;
1018import org .springframework .core .io .ClassPathResource ;
1119import org .springframework .http .MediaType ;
1523import org .springframework .web .bind .annotation .RequestMapping ;
1624import org .springframework .web .bind .annotation .RequestParam ;
1725
18- import javax .annotation .PostConstruct ;
19- import javax .servlet .http .HttpServletRequest ;
20- import javax .servlet .http .HttpServletResponse ;
21- import java .io .IOException ;
22- import java .io .InputStream ;
23- import java .nio .charset .Charset ;
24- import java .util .HashMap ;
25- import java .util .Map ;
26- import java .util .Properties ;
27-
2826/**
2927 * @author Moncef AOUDIA
3028 */
@@ -34,23 +32,8 @@ public class AltairController {
3432 private static final String CDN_UNPKG = "//unpkg.com/" ;
3533 private static final String ALTAIR = "altair-static" ;
3634
37- @ Value ("${altair.endpoint.graphql:/graphql}" )
38- private String graphqlEndpoint ;
39-
40- @ Value ("${altair.endpoint.subscriptions:/subscriptions}" )
41- private String subscriptionsEndpoint ;
42-
43- @ Value ("${altair.static.basePath:}" )
44- private String staticBasePath ;
45-
46- @ Value ("${altair.pageTitle:Altair}" )
47- private String pageTitle ;
48-
49- @ Value ("${altair.cdn.enabled:false}" )
50- private Boolean altairCdnEnabled ;
51-
52- @ Value ("${altair.cdn.version:2.1.7}" )
53- private String altairCdnVersion ;
35+ @ Autowired
36+ private AltairProperties altairProperties ;
5437
5538 @ Autowired
5639 private Environment environment ;
@@ -97,7 +80,7 @@ public void altair(HttpServletRequest request, HttpServletResponse response, @Pa
9780
9881 Map <String , String > replacements = getReplacements (
9982 constructGraphQlEndpoint (request , params ),
100- request .getContextPath () + subscriptionsEndpoint
83+ request .getContextPath () + altairProperties . getEndpoint (). getSubscriptions ()
10184 );
10285
10386 String populatedTemplate = StrSubstitutor .replace (template , replacements );
@@ -108,10 +91,10 @@ private Map<String, String> getReplacements(String graphqlEndpoint, String subsc
10891 Map <String , String > replacements = new HashMap <>();
10992 replacements .put ("graphqlEndpoint" , graphqlEndpoint );
11093 replacements .put ("subscriptionsEndpoint" , subscriptionsEndpoint );
111- replacements .put ("pageTitle" , pageTitle );
94+ replacements .put ("pageTitle" , altairProperties . getPageTitle () );
11295 replacements .put ("pageFavicon" , getResourceUrl ("favicon.ico" , "favicon.ico" ));
113- replacements .put ("altairBaseUrl" , getResourceUrl (StringUtils .join (staticBasePath , "/vendor/altair/" ),
114- joinJsUnpkgPath (ALTAIR , altairCdnVersion , "build/dist/" )));
96+ replacements .put ("altairBaseUrl" , getResourceUrl (StringUtils .join (altairProperties . getSTATIC (). getBasePath () , "/vendor/altair/" ),
97+ joinJsUnpkgPath (ALTAIR , altairProperties . getCdn (). getVersion () , "build/dist/" )));
11598 replacements .put ("altairLogoUrl" , getResourceUrl ("assets/img/logo_350.svg" , "assets/img/logo_350.svg" ));
11699 replacements .put ("altairCssUrl" , getResourceUrl ("styles.css" , "styles.css" ));
117100 replacements .put ("altairMainJsUrl" , getResourceUrl ("main.js" , "main.js" ));
@@ -123,7 +106,7 @@ private Map<String, String> getReplacements(String graphqlEndpoint, String subsc
123106 }
124107
125108 private String getResourceUrl (String staticFileName , String cdnUrl ) {
126- if (altairCdnEnabled && StringUtils .isNotBlank (cdnUrl )) {
109+ if (altairProperties . getCdn (). isEnabled () && StringUtils .isNotBlank (cdnUrl )) {
127110 return cdnUrl ;
128111 }
129112 return staticFileName ;
@@ -134,7 +117,7 @@ private String joinJsUnpkgPath(String library, String cdnVersion, String cdnFile
134117 }
135118
136119 private String constructGraphQlEndpoint (HttpServletRequest request , @ RequestParam Map <String , String > params ) {
137- String endpoint = graphqlEndpoint ;
120+ String endpoint = altairProperties . getEndpoint (). getGraphql () ;
138121 for (Map .Entry <String , String > param : params .entrySet ()) {
139122 endpoint = endpoint .replaceAll ("\\ {" + param .getKey () + "}" , param .getValue ());
140123 }
0 commit comments