2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.impl;
23 import java.util.Arrays;
25 import java.util.stream.Collectors;
26 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
27 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
28 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
29 import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
30 import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
31 import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
32 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
33 import org.openecomp.sdc.be.togglz.ToggleableFeature;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Component;
36 import org.togglz.core.Feature;
37 import org.togglz.core.context.FeatureContext;
38 import org.togglz.core.repository.FeatureState;
39 import org.togglz.core.util.NamedFeature;
41 @Component("togglingBusinessLogic")
42 public class TogglingBusinessLogic extends BaseBusinessLogic {
45 public TogglingBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation,
46 IGroupInstanceOperation groupInstanceOperation, IGroupTypeOperation groupTypeOperation,
47 InterfaceOperation interfaceOperation, InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
48 ArtifactsOperations artifactToscaOperation) {
49 super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation,
50 interfaceLifecycleTypeOperation, artifactToscaOperation);
53 public Map<String, Boolean> getAllFeatureStates() {
54 return Arrays.stream(ToggleableFeature.values()).collect(Collectors.toMap(Enum::name,
55 ToggleableFeature::isActive));
58 public boolean getFeatureState(String featureName) {
59 return ToggleableFeature.valueOf(featureName).isActive();
62 public void setAllFeatures(boolean state) {
63 Arrays.asList(ToggleableFeature.values())
64 .forEach(toggleableFeature -> updateFeatureState(toggleableFeature.name(), state));
67 public void updateFeatureState(String featureName, boolean state) {
68 Feature feature = new NamedFeature(featureName);
69 FeatureState featureState = new FeatureState(feature, state);
70 FeatureContext.getFeatureManager().setFeatureState(featureState);