DMAAP-MR - Merge MR repos
[dmaap/messagerouter/messageservice.git] / src / main / java / org / onap / dmaap / dmf / mr / beans / DMaaPContext.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
4  *  ================================================================================
5  *  Copyright © 2017 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  *        http://www.apache.org/licenses/LICENSE-2.0
11 *  
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *  ============LICENSE_END=========================================================
18  *  
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22 package org.onap.dmaap.dmf.mr.beans;
23
24 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import javax.servlet.http.HttpSession;
29 import java.text.SimpleDateFormat;
30 import java.util.Date;
31
32 /**
33  * DMaaPContext provide and maintain all the configurations , Http request/response
34  * Session and consumer Request Time
35  * @author nilanjana.maity
36  *
37  */
38 public class DMaaPContext {
39
40     private ConfigurationReader configReader;
41     private HttpServletRequest request;
42     private HttpServletResponse response;
43     private HttpSession session;
44     private String consumerRequestTime;
45     static int i=0;
46     
47     public synchronized static long getBatchID() {
48         try{
49                 final long metricsSendTime = System.currentTimeMillis();
50                 final Date d = new Date(metricsSendTime);
51                 final String text = new SimpleDateFormat("ddMMyyyyHHmmss").format(d);
52                 long dt= Long.valueOf(text)+i;
53                 i++;
54                 return dt;
55         }
56         catch(NumberFormatException ex){
57                 return 0;
58         }
59     }
60     
61     public HttpServletRequest getRequest() {
62         return request;
63     }
64
65     public void setRequest(HttpServletRequest request) {
66         this.request = request;
67     }
68
69     public HttpServletResponse getResponse() {
70         return response;
71     }
72
73     public void setResponse(HttpServletResponse response) {
74         this.response = response;
75     }
76
77     public HttpSession getSession() {
78         this.session = request.getSession();
79         return session;
80     }
81
82     public void setSession(HttpSession session) {
83         this.session = session;
84     }
85
86     public ConfigurationReader getConfigReader() {
87           return configReader;
88     }
89
90     public void setConfigReader(ConfigurationReader configReader) {
91         this.configReader = configReader;
92     }
93
94     public String getConsumerRequestTime() {
95         return consumerRequestTime;
96     }
97
98     public void setConsumerRequestTime(String consumerRequestTime) {
99         this.consumerRequestTime = consumerRequestTime;
100     }
101     
102     
103 }