[POLICY-73] replace openecomp for policy-engine
[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.openecomp.portalapp.scheduler.LogRegistry;
26 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
27 import org.openecomp.portalsdk.core.scheduler.Registerable;
28 import org.openecomp.portalsdk.core.util.SystemProperties;
29 import org.quartz.Trigger;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.context.annotation.DependsOn;
32 import org.springframework.stereotype.Component;
33
34 @Component
35 @DependsOn({ "logRegistry", "systemProperties" })
36 public class Register implements Registerable {
37
38         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(Register.class);
39
40         private List<Trigger> scheduleTriggers = new ArrayList<>();
41         Trigger trigger[] = new Trigger[1];
42
43         @Autowired
44         private LogRegistry logRegistry;
45
46         @Override
47         public Trigger[] getTriggers() {
48                 return getScheduleTriggers().toArray(trigger);
49         }
50
51         @Override
52         public void registerTriggers() {
53                 // if the property value is not available; the cron will not be added
54                 // and can be ignored. its safe to ignore the exceptions
55                 try {
56                         if (SystemProperties.getProperty(SystemProperties.LOG_CRON) != null)
57                                 getScheduleTriggers().add(logRegistry.getTrigger());
58                 } catch (IllegalStateException ies) {
59                         logger.info(EELFLoggerDelegate.debugLogger, ("Log Cron not available") + ies);
60                 }
61
62         }
63
64         public List<Trigger> getScheduleTriggers() {
65                 return scheduleTriggers;
66         }
67
68         public void setScheduleTriggers(List<Trigger> scheduleTriggers) {
69                 this.scheduleTriggers = scheduleTriggers;
70         }
71
72 }