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 Accept Rule
37 public class AcceptRule extends Rule {
39 AcceptRule(Set<VNFOperation> inclusions,Set<VNFOperation> exclusions){
40 super(inclusions,exclusions);
44 public RuleResult executeRule(String action, List<VNFOperation> inProgressActionList) {
46 if(inclusions!=null && !inclusions.isEmpty()){
47 /* new action (action-received) should be rejected,
48 if any of the in-progress request action
49 is mentioned in the in-progress-exclusion list*/
50 if(logger.isDebugEnabled()){
51 logger.debug("Executing accept rule for action-received = "+action+" and in-progress-actions-inclusions = "+ inProgressActionList.toString());
53 Set<String> inProgressActionSet = inProgressActionList.stream().map(VNFOperation::name).collect(Collectors.toSet());
54 inProgressActionSet.removeAll(inclusions.stream().map(VNFOperation::name).collect(Collectors.toList()));
55 if(!inProgressActionSet.isEmpty()){
56 return RuleResult.REJECT;
58 return RuleResult.ACCEPT;
60 else if(exclusions!=null && !exclusions.isEmpty()){
61 /* new action (action-received) should be accepted,
62 if all of the in-progress request actions
63 are mentioned in the in-progress-inclusion list */
64 if(logger.isDebugEnabled()){
65 logger.debug("Executing accept rule for action-received = %s and in-progress-actions-exclusions = %s",action,inProgressActionList.toString());
67 Set<String> inProgressActionSet = inProgressActionList.stream().map(VNFOperation::name).collect(Collectors.toSet());
68 inProgressActionSet.retainAll(exclusions.stream().map(VNFOperation::name).collect(Collectors.toList()));
69 if(!inProgressActionSet.isEmpty()){
70 return RuleResult.REJECT;
72 return RuleResult.ACCEPT;
74 return RuleResult.ACCEPT;