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.resources.data.togglz;
23 import com.datastax.driver.mapping.annotations.Column;
24 import com.datastax.driver.mapping.annotations.PartitionKey;
25 import com.datastax.driver.mapping.annotations.Table;
26 import com.google.common.base.Joiner;
27 import com.google.common.base.Splitter;
29 import lombok.NoArgsConstructor;
31 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
32 import org.openecomp.sdc.be.togglz.ToggleableFeature;
33 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
34 import org.openecomp.sdc.common.log.wrappers.Logger;
35 import org.togglz.core.Feature;
36 import org.togglz.core.repository.FeatureState;
37 import com.datastax.driver.mapping.annotations.Transient;
44 @Table(keyspace = AuditingTypesConstants.REPO_KEYSPACE, name = AuditingTypesConstants.FEATURE_TOGGLE_STATE)
45 public class FeatureToggleEvent {
46 private static final Logger logger = Logger.getLogger(FeatureToggleEvent.class);
49 @Column(name = "feature_name")
50 private String featureName;
52 @Column(name = "enabled")
53 private String enabled;
55 @Column(name = "strategy_id")
56 private String strategyId;
58 @Column(name = "parameters")
59 private String parameters;
61 public FeatureToggleEvent(FeatureState featureState) {
63 this.featureName = featureState.getFeature().name();
64 this.enabled = String.valueOf(featureState.isEnabled());
65 this.strategyId = featureState.getStrategyId();
66 this.parameters = Joiner.on(",").withKeyValueSeparator("=").join(featureState.getParameterMap());
70 public FeatureState getFeatureState() {
71 Feature feature = ToggleableFeature.getFeatureByName(featureName);
72 if (feature == null) {
75 FeatureState featureState = new FeatureState(feature, Boolean.valueOf(enabled));
76 featureState.setStrategyId(strategyId);
78 setParameters(featureState);
83 private void setParameters(FeatureState featureState) {
85 Map<String, String> paramMap = Splitter.on(",").withKeyValueSeparator("=").split(parameters);
86 paramMap.keySet().forEach(p->featureState.setParameter(p, paramMap.get(p)));
88 catch(IllegalArgumentException e) {
89 logger.warn(EcompLoggerErrorCode.DATA_ERROR, "FeatureToggle",
90 "FeatureState Object generating", e.getMessage());