CodeCoverage improvement for dcaegen2-platform-mod-genprocessor
[dcaegen2/platform.git] / mod / genprocessor / src / main / java / org / onap / dcae / genprocessor / DCAEProcessor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  */
18 package org.onap.dcae.genprocessor;
19
20 import java.util.List;
21 import java.util.Set;
22
23 import org.apache.nifi.components.PropertyDescriptor;
24 import org.apache.nifi.processor.AbstractProcessor;
25 import org.apache.nifi.processor.ProcessContext;
26 import org.apache.nifi.processor.ProcessSession;
27 import org.apache.nifi.processor.Relationship;
28 import org.apache.nifi.processor.exception.ProcessException;
29
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34 public abstract class DCAEProcessor extends AbstractProcessor {
35
36     static final Logger LOG = LoggerFactory.getLogger(DCAEProcessor.class);
37
38     // These are properties of the DCAE component that may be useful in the future..
39     abstract public String getName();
40     abstract public String getVersion();
41     abstract public String getComponentId();
42     abstract public String getComponentUrl();
43
44     public void ping() {
45         LOG.info("pong");
46     }
47
48     @Override
49     public void onTrigger(ProcessContext arg0, ProcessSession arg1) throws ProcessException {
50         LOG.info("Bang you triggered DCAEProcessor!");
51         return;
52     }
53
54     /**
55      * This function gets implemented by the ProcessorBuilder magic to build a new custom list of
56      * PropertyDescriptor every time. This is to be used by getSupportedPropertyDescriptors() which
57      * *should* only call this method once to initially fill the cache.
58      * 
59      * @return list of PropertyDescriptor
60      */
61     abstract protected List<PropertyDescriptor> buildSupportedPropertyDescriptors();
62
63     // Cache of PropertyDescriptors which should be static
64     private List<PropertyDescriptor> properties;
65
66     /**
67      * This is the critical Nifi function that is used to populate the configuration parameters
68      * in the UI and drive all the other configuration related functions in the ConfigurableComponent
69      * base class
70      */
71     @Override
72     protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
73         if (this.properties == null) {
74             this.properties = buildSupportedPropertyDescriptors();
75         }
76         return this.properties;
77     }
78
79     abstract protected Set<Relationship> buildRelationships();
80
81     // Cache of Relationships which should be static
82     private Set<Relationship> relationships;
83
84     @Override
85     public Set<Relationship> getRelationships() {
86         if (this.relationships == null) {
87             this.relationships = buildRelationships();
88         }
89         return this.relationships;
90     }
91
92 }
93