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=========================================================
20 package org.openecomp.sdc.be.components.impl;
22 import java.util.Arrays;
24 import java.util.stream.Collectors;
25 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
26 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
27 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
28 import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
29 import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
30 import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
31 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
32 import org.openecomp.sdc.be.togglz.ToggleableFeature;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
35 import org.togglz.core.Feature;
36 import org.togglz.core.context.FeatureContext;
37 import org.togglz.core.repository.FeatureState;
38 import org.togglz.core.util.NamedFeature;
40 @Component("togglingBusinessLogic")
41 public class TogglingBusinessLogic extends BaseBusinessLogic {
44 public TogglingBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
45 IGroupTypeOperation groupTypeOperation, InterfaceOperation interfaceOperation,
46 InterfaceLifecycleOperation interfaceLifecycleTypeOperation, ArtifactsOperations artifactToscaOperation) {
47 super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation,
48 artifactToscaOperation);
51 public Map<String, Boolean> getAllFeatureStates() {
52 return Arrays.stream(ToggleableFeature.values()).collect(Collectors.toMap(Enum::name, ToggleableFeature::isActive));
55 public boolean getFeatureState(String featureName) {
56 return ToggleableFeature.valueOf(featureName).isActive();
59 public void setAllFeatures(boolean state) {
60 Arrays.asList(ToggleableFeature.values()).forEach(toggleableFeature -> updateFeatureState(toggleableFeature.name(), state));
63 public void updateFeatureState(String featureName, boolean state) {
64 Feature feature = new NamedFeature(featureName);
65 FeatureState featureState = new FeatureState(feature, state);
66 FeatureContext.getFeatureManager().setFeatureState(featureState);