Include impacted changes for APPC-346,APPC-348
[appc.git] / appc-dispatcher / appc-request-handler / appc-request-handler-core / src / main / java / org / onap / appc / validationpolicy / rules / RejectRule.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.validationpolicy.rules;
26
27 import org.onap.appc.domainmodel.lcm.VNFOperation;
28 import org.onap.appc.validationpolicy.objects.RuleResult;
29
30 import java.util.List;
31 import java.util.Set;
32 import java.util.stream.Collectors;
33
34 /**
35  * Implementation of Reject Rule
36  */
37 public class RejectRule extends Rule {
38
39     RejectRule(Set<VNFOperation> inclusions, Set<VNFOperation> exclusions){
40         super(inclusions, exclusions);
41     }
42
43     @Override
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());
51             }
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;
56             }
57             return RuleResult.ACCEPT;
58         }
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());
65             }
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;
70             }
71             return RuleResult.REJECT;
72         }
73         return RuleResult.REJECT;
74     }
75 }