2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.validationpolicy.rules;
27 import org.onap.appc.domainmodel.lcm.VNFOperation;
28 import org.onap.appc.validationpolicy.objects.RuleResult;
30 import java.util.List;
32 import java.util.stream.Collectors;
35 * Implementation of Reject Rule
37 public class RejectRule extends Rule {
39 RejectRule(Set<VNFOperation> inclusions, Set<VNFOperation> exclusions){
40 super(inclusions, exclusions);
44 public RuleResult executeRule(String action, List<VNFOperation> inProgressActionList) {
45 if(inclusions!= null && !inclusions.isEmpty()){
46 /* new action (action-received) should be rejected,
47 if any of the in-progress request actions
48 are mentioned in the in-progress-inclusion list*/
49 if(logger.isDebugEnabled()){
50 logger.debug("Executing reject rule for action-received = " + action+ " and in-progress-actions-inclusions =" + inProgressActionList.toString());
52 Set<String> inProgressActionSet = inProgressActionList.stream().map(VNFOperation::name).collect(Collectors.toSet());
53 inProgressActionSet.retainAll(inclusions.stream().map(VNFOperation::name).collect(Collectors.toList()));
54 if(!inProgressActionSet.isEmpty()){
55 return RuleResult.REJECT;
57 return RuleResult.ACCEPT;
59 else if(exclusions != null && !exclusions.isEmpty()){
60 /* new action (action-received) should be accepted,
61 if all of the in-progress request actions
62 are mentioned in the in-progress-exclusion list*/
63 if(logger.isDebugEnabled()){
64 logger.debug("Executing reject rule for action-received = " + action + " and in-progress-actions-inclusions = " + inProgressActionList.toString());
66 Set<String> inProgressActionSet = inProgressActionList.stream().map(VNFOperation::name).collect(Collectors.toSet());
67 inProgressActionSet.removeAll(exclusions.stream().map(VNFOperation::name).collect(Collectors.toList()));
68 if(inProgressActionSet.isEmpty()){
69 return RuleResult.ACCEPT;
71 return RuleResult.REJECT;
73 return RuleResult.REJECT;