1 package pk.lucidxpo.ynami.controller.sample;
2
3 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.stereotype.Controller;
5 import org.springframework.ui.Model;
6 import org.springframework.web.bind.annotation.GetMapping;
7 import org.springframework.web.bind.annotation.RequestMapping;
8 import org.springframework.web.bind.annotation.ResponseBody;
9 import pk.lucidxpo.ynami.service.sample.ToggleableService;
10 import pk.lucidxpo.ynami.spring.aspect.FeatureAssociation;
11 import pk.lucidxpo.ynami.spring.features.FeatureManagerWrappable;
12
13 import static pk.lucidxpo.ynami.spring.features.FeatureToggles.CONDITIONAL_STATEMENTS_EXECUTION;
14 import static pk.lucidxpo.ynami.spring.features.FeatureToggles.METHOD_EXECUTION;
15
16 @Controller
17 public class SampleFeatureController {
18 private final ToggleableService toggleableService;
19 private final FeatureManagerWrappable featureManager;
20
21 @Autowired
22 public SampleFeatureController(final ToggleableService toggleableService,
23 final FeatureManagerWrappable featureManager) {
24 this.featureManager = featureManager;
25 this.toggleableService = toggleableService;
26 }
27
28 @RequestMapping("/feature-test")
29 @FeatureAssociation(value = METHOD_EXECUTION)
30 public String welcome(Model model) {
31 if (featureManager.isActive(CONDITIONAL_STATEMENTS_EXECUTION)) {
32 model.addAttribute("message", CONDITIONAL_STATEMENTS_EXECUTION.name() + " is enabled.");
33 } else {
34 model.addAttribute("message", CONDITIONAL_STATEMENTS_EXECUTION.name() + " is disabled.");
35 }
36 return "welcome";
37 }
38
39 @ResponseBody
40 @GetMapping(value = "/some-service")
41 public String getToggleableService() {
42 return toggleableService.getSomeValue();
43 }
44 }