NotificationCleanupConfig class fix
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / config / NotificationCleanupConfig.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  *
7  * 
8  * Modifications Copyright © 2018 IBM.
9  * ===================================================================
10  *
11  * Unless otherwise specified, all software contained herein is licensed
12  * under the Apache License, Version 2.0 (the "License");
13  * you may not use this software except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *             http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  * Unless otherwise specified, all documentation contained herein is licensed
25  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
26  * you may not use this documentation except in compliance with the License.
27  * You may obtain a copy of the License at
28  *
29  *             https://creativecommons.org/licenses/by/4.0/
30  *
31  * Unless required by applicable law or agreed to in writing, documentation
32  * distributed under the License is distributed on an "AS IS" BASIS,
33  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34  * See the License for the specific language governing permissions and
35  * limitations under the License.
36  *
37  * ============LICENSE_END============================================
38  *
39  * 
40  */
41 package org.onap.portalapp.config;
42
43 import org.springframework.beans.BeansException;
44 import org.springframework.context.ApplicationContext;
45 import org.springframework.context.ApplicationContextAware;
46 import org.springframework.context.annotation.Bean;
47 import org.springframework.context.annotation.Configuration;
48
49 import javax.annotation.PostConstruct;
50 import java.util.Timer;
51 import java.util.TimerTask;
52
53 @Configuration
54 public class NotificationCleanupConfig implements ApplicationContextAware {
55
56         // Once every 10 minutes should be adequate
57         private static final int CLEANUP_PERIOD_MINUTES = 10;
58
59         private static ApplicationContext applicationContext;
60
61
62         @Override
63         public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
64                 NotificationCleanupConfig.applicationContext = applicationContext;
65         }
66
67         static ApplicationContext getApplicationContext() {
68                 return applicationContext;
69
70         }
71
72         @PostConstruct
73         public void startSchedular() {
74                 TimerTask task = new NotificationCleanup();
75                 Timer timer = new Timer();
76                 timer.schedule(task, 1000, (long) CLEANUP_PERIOD_MINUTES * 60 * 1000);
77         }
78
79         @Bean
80         public NotificationCleanupConfig getConfig() {
81                 return new NotificationCleanupConfig();
82         }
83 }