2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.policy.operational;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import java.util.List;
30 import java.util.stream.Collectors;
31 import org.onap.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport;
32 import org.onap.clamp.loop.Loop;
33 import org.onap.clamp.loop.template.PolicyModelsRepository;
34 import org.onap.clamp.policy.PolicyService;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Service;
39 public class OperationalPolicyService implements PolicyService<OperationalPolicy> {
41 private final OperationalPolicyRepository operationalPolicyRepository;
43 private final PolicyModelsRepository policyModelsRepository;
45 private static final EELFLogger logger = EELFManager.getInstance().getLogger(OperationalPolicyService.class);
48 public OperationalPolicyService(OperationalPolicyRepository repository,
49 PolicyModelsRepository policyModelsRepository) {
50 this.operationalPolicyRepository = repository;
51 this.policyModelsRepository = policyModelsRepository;
55 public Set<OperationalPolicy> updatePolicies(Loop loop, List<OperationalPolicy> operationalPolicies) {
56 return operationalPolicies
59 operationalPolicyRepository
60 .findById(policy.getName())
61 .map(p -> setConfiguration(p, policy))
62 .orElse(initializeMissingFields(loop, policy)))
63 .collect(Collectors.toSet());
67 public boolean isExisting(String policyName) {
68 return operationalPolicyRepository.existsById(policyName);
71 private OperationalPolicy initializeMissingFields(Loop loop, OperationalPolicy policy) {
76 private OperationalPolicy setConfiguration(OperationalPolicy policy, OperationalPolicy newPolicy) {
77 policy.setConfigurationsJson(newPolicy.getConfigurationsJson());
78 policy.setPdpGroup(newPolicy.getPdpGroup());
79 policy.setPdpSubgroup(newPolicy.getPdpSubgroup());
84 * Api to refresh the Operational Policy UI window.
86 * @param operationalPolicy The operational policy object
87 * @param toscaConverter the tosca converter required to convert the tosca model to json schema
89 public void refreshOperationalPolicyJsonRepresentation(OperationalPolicy operationalPolicy,
90 ToscaConverterWithDictionarySupport toscaConverter) {
91 operationalPolicy.updateJsonRepresentation(toscaConverter, operationalPolicy.getLoop().getModelService());
92 this.operationalPolicyRepository.saveAndFlush(operationalPolicy);