]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/features/PizzaFeatureWebApplicationBean.java
Please cherry-pick:
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / features / PizzaFeatureWebApplicationBean.java
1 /*
2  * Copyright (C) 2016 - 2022 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.pizzaapplication.beans.features;
18
19 import javax.enterprise.context.ApplicationScoped;
20 import javax.inject.Named;
21 import org.mxchange.pizzaapplication.beans.BasePizzaBean;
22
23 /**
24  * A feature bean
25  * <p>
26  * @author Roland Häder<roland@mxchange.org>
27  */
28 @Named ("featureController")
29 @ApplicationScoped
30 public class PizzaFeatureWebApplicationBean extends BasePizzaBean implements PizzaFeaturesWebApplicationController {
31
32         /**
33          * Serial number
34          */
35         private static final long serialVersionUID = 64_237_512_690_168_674L;
36
37         /**
38          * Default constructor
39          */
40         public PizzaFeatureWebApplicationBean () {
41                 // Call super constructor
42                 super();
43         }
44
45         @Override
46         public boolean isFeatureEnabled (final String feature) {
47                 // The parameter must be set
48                 if (null == feature) {
49                         // Throw NPE
50                         throw new NullPointerException("feature is null"); //NOI18N
51                 } else if (feature.isEmpty()) {
52                         // Is empty
53                         throw new IllegalArgumentException("feature is empty"); //NOI18N
54                 }
55
56                 // Get value from property
57                 final String contextParameter = this.getStringContextParameter(String.format("is_feature_%s_enabled", feature)); //NOI18N
58
59                 // Default is not enabled
60                 final boolean isEnabled = (Boolean.parseBoolean(contextParameter) == Boolean.TRUE);
61
62                 // Return status
63                 return isEnabled;
64         }
65
66 }