bump the version
[dmaap/messagerouter/msgrtr.git] / src / main / java / com / att / 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 com.att.dmf.mr.beans;
23
24 import java.text.SimpleDateFormat;
25 import java.util.Date;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29 import javax.servlet.http.HttpSession;
30
31 import com.att.dmf.mr.utils.ConfigurationReader;
32
33 /**
34  * DMaaPContext provide and maintain all the configurations , Http request/response
35  * Session and consumer Request Time
36  * @author nilanjana.maity
37  *
38  */
39 public class DMaaPContext {
40
41     private ConfigurationReader configReader;
42     private HttpServletRequest request;
43     private HttpServletResponse response;
44     private HttpSession session;
45     private String consumerRequestTime;
46     static int i=0;
47     
48     public synchronized static long getBatchID() {
49         try{
50                 final long metricsSendTime = System.currentTimeMillis();
51                 final Date d = new Date(metricsSendTime);
52                 final String text = new SimpleDateFormat("ddMMyyyyHHmmss").format(d);
53                 long dt= Long.valueOf(text)+i;
54                 i++;
55                 return dt;
56         }
57         catch(NumberFormatException ex){
58                 return 0;
59         }
60     }
61     
62     public HttpServletRequest getRequest() {
63         return request;
64     }
65
66     public void setRequest(HttpServletRequest request) {
67         this.request = request;
68     }
69
70     public HttpServletResponse getResponse() {
71         return response;
72     }
73
74     public void setResponse(HttpServletResponse response) {
75         this.response = response;
76     }
77
78     public HttpSession getSession() {
79         this.session = request.getSession();
80         return session;
81     }
82
83     public void setSession(HttpSession session) {
84         this.session = session;
85     }
86
87     public ConfigurationReader getConfigReader() {
88           return configReader;
89     }
90
91     public void setConfigReader(ConfigurationReader configReader) {
92         this.configReader = configReader;
93     }
94
95     public String getConsumerRequestTime() {
96         return consumerRequestTime;
97     }
98
99     public void setConsumerRequestTime(String consumerRequestTime) {
100         this.consumerRequestTime = consumerRequestTime;
101     }
102     
103     
104 }