2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Modifications Copyright (c) 2019 Samsung
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END============================================
22 * ===================================================================
26 package org.onap.clamp.clds.client;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
31 import org.apache.camel.Exchange;
32 import org.apache.camel.Handler;
33 import org.onap.clamp.clds.client.req.policy.GuardPolicyAttributesConstructor;
34 import org.onap.clamp.clds.client.req.policy.PolicyClient;
35 import org.onap.clamp.clds.model.CldsEvent;
36 import org.onap.clamp.clds.model.properties.ModelProperties;
37 import org.onap.clamp.clds.model.properties.Policy;
38 import org.onap.clamp.clds.model.properties.PolicyChain;
39 import org.onap.clamp.clds.model.properties.PolicyItem;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.stereotype.Component;
44 * Delete Operational Policy via policy api.
47 public class GuardPolicyDeleteDelegate {
49 protected static final EELFLogger logger = EELFManager.getInstance()
50 .getLogger(GuardPolicyDeleteDelegate.class);
51 protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
52 private final PolicyClient policyClient;
55 public GuardPolicyDeleteDelegate(PolicyClient policyClient) {
56 this.policyClient = policyClient;
60 * Perform activity. Delete Operational Policy via policy api.
62 * @param camelExchange The Camel Exchange object containing the properties
65 public void execute(Exchange camelExchange) {
66 ModelProperties prop = ModelProperties.create(camelExchange);
67 Policy policy = prop.getType(Policy.class);
69 String eventAction = (String) camelExchange.getProperty("eventAction");
70 if (!eventAction.equalsIgnoreCase(CldsEvent.ACTION_CREATE) && policy.isFound()) {
71 for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) {
72 for (PolicyItem policyItem : GuardPolicyAttributesConstructor
73 .getAllPolicyGuardsFromPolicyChain(policyChain)) {
74 prop.setCurrentModelElementId(policy.getId());
75 prop.setPolicyUniqueId(policyChain.getPolicyId());
76 prop.setGuardUniqueId(policyItem.getId());
77 policyClient.deleteGuard(prop);