Merge "Refactor to provide Common Policy Validation"
[policy/engine.git] / ONAP-SDK-APP / src / main / java / org / onap / portalapp / scheduler / Register.java
1 /*-
2  * ================================================================================
3  * ONAP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
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  * ================================================================================
19  */
20 package org.onap.portalapp.scheduler;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
26 import org.onap.portalsdk.core.scheduler.Registerable;
27 import org.onap.portalsdk.core.util.SystemProperties;
28 import org.quartz.Trigger;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.context.annotation.DependsOn;
31 import org.springframework.stereotype.Component;
32
33 @Component
34 @DependsOn({ "logRegistry", "systemProperties" })
35 public class Register implements Registerable {
36
37         private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(Register.class);
38
39         private List<Trigger> scheduleTriggers = new ArrayList<>();
40         Trigger[] trigger = new Trigger[1];
41
42         @Autowired
43         private LogRegistry logRegistry;
44
45         @Override
46         public Trigger[] getTriggers() {
47                 return getScheduleTriggers().toArray(trigger);
48         }
49
50         @Override
51         public void registerTriggers() {
52                 // if the property value is not available; the cron will not be added.
53                 if (SystemProperties.containsProperty(SystemProperties.LOG_CRON)) {
54                         logger.debug(EELFLoggerDelegate.debugLogger,
55                                         "Adding log registry for cron property {}", SystemProperties.getProperty(SystemProperties.LOG_CRON));
56                         getScheduleTriggers().add(logRegistry.getTrigger());
57                 }
58         }
59
60         public List<Trigger> getScheduleTriggers() {
61                 return scheduleTriggers;
62         }
63
64         public void setScheduleTriggers(List<Trigger> scheduleTriggers) {
65                 this.scheduleTriggers = scheduleTriggers;
66         }
67
68 }