d8c8601865cdf4502926c5d55a065753148ba249
[so.git] / bpmn / MSOCommonBPMN / src / main / java / org / onap / so / bpmn / common / validation / WorkflowValidatorRunner.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.common.validation;
22
23 import java.lang.annotation.Annotation;
24 import java.util.ArrayList;
25 import java.util.Comparator;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Optional;
29 import java.util.stream.Collectors;
30
31 import javax.annotation.PostConstruct;
32 import javax.annotation.Priority;
33
34 import org.camunda.bpm.engine.delegate.DelegateExecution;
35 import org.javatuples.Pair;
36 import org.onap.so.client.exception.ExceptionBuilder;
37 import org.reflections.Reflections;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.context.ApplicationContext;
42 import org.springframework.stereotype.Component;
43
44
45 /**
46  * Controls running all pre and post validation for workflows.
47  * 
48  * To define a validation you must make it a spring bean and implement either {@link org.onap.so.bpmn.common.validation.PreWorkflowValidator} or 
49  * {@link org.onap.so.bpmn.common.validation.PostWorkflowValidator} your validation will automatically be
50  * run by this class.
51  *
52  */
53 @Component
54 public class WorkflowValidatorRunner extends FlowValidatorRunner<PreWorkflowValidator, PostWorkflowValidator> {
55
56         @PostConstruct
57         protected void init() {
58                 
59                 preFlowValidators = new ArrayList<>(
60                                 Optional.ofNullable(context.getBeansOfType(PreWorkflowValidator.class)).orElse(new HashMap<>()).values());
61                 postFlowValidators = new ArrayList<>(
62                                 Optional.ofNullable(context.getBeansOfType(PostWorkflowValidator.class)).orElse(new HashMap<>()).values());
63         }
64
65         protected List<PreWorkflowValidator> getPreFlowValidators() {
66                 return this.preFlowValidators;
67         }
68         
69         protected List<PostWorkflowValidator> getPostFlowValidators() {
70                 return this.postFlowValidators;
71         }
72         
73 }