bump the version
[dmaap/messagerouter/msgrtr.git] / src / main / java / com / att / dmf / mr / transaction / TransactionObj.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.transaction;
23
24 import org.json.JSONObject;
25
26 /**
27  * This is the class which will have the transaction enabled logging object
28  * details
29  * 
30  * @author nilanjana.maity
31  *
32  */
33 public class TransactionObj implements DMaaPTransactionObj {
34
35         private String id;
36         private String createTime;
37         private long totalMessageCount;
38         private long successMessageCount;
39         private long failureMessageCount;
40         private JSONObject fData = new JSONObject();
41         private TrnRequest trnRequest;
42         private static final String kAuxData = "transaction";
43
44         /**
45          * Initializing constructor  
46          * put the json data for transaction enabled logging
47          * 
48          * @param data
49          */
50         public TransactionObj(JSONObject data) {
51                 fData = data;
52
53                 // check for required fields (these throw if not present)
54                 getId();
55                 getTotalMessageCount();
56                 getSuccessMessageCount();
57                 getFailureMessageCount();
58
59                 // make sure we've got an aux data object
60                 final JSONObject aux = fData.optJSONObject(kAuxData);
61                 if (aux == null) {
62                         fData.put(kAuxData, new JSONObject());
63                 }
64         }
65
66         /**
67          * this constructor will have the details of transaction id,
68          * totalMessageCount successMessageCount, failureMessageCount to get the
69          * transaction object
70          * 
71          * @param id
72          * @param totalMessageCount
73          * @param successMessageCount
74          * @param failureMessageCount
75          */
76         public TransactionObj(String id, long totalMessageCount, long successMessageCount, long failureMessageCount) {
77                 this.id = id;
78                 this.totalMessageCount = totalMessageCount;
79                 this.successMessageCount = successMessageCount;
80                 this.failureMessageCount = failureMessageCount;
81
82         }
83
84         /**
85          * The constructor passing only transaction id
86          * 
87          * @param id
88          */
89         public TransactionObj(String id) {
90                 this.id = id;
91         }
92
93         /**
94          * Wrapping the data into json object
95          * 
96          * @return JSONObject
97          */
98         public JSONObject asJsonObject() {
99                 final JSONObject full = new JSONObject(fData, JSONObject.getNames(fData));
100                 return full;
101         }
102
103         /**
104          * To get the transaction id
105          */
106         public String getId() {
107                 return id;
108         }
109
110         /**
111          * To set the transaction id
112          */
113         public void setId(String id) {
114                 this.id = id;
115         }
116
117         /**
118          * 
119          * @return
120          */
121         public String getCreateTime() {
122                 return createTime;
123         }
124
125         /**
126          * 
127          * @param createTime
128          */
129         public void setCreateTime(String createTime) {
130                 this.createTime = createTime;
131         }
132
133         @Override
134         public String serialize() {
135                 fData.put("transactionId", id);
136                 fData.put("totalMessageCount", totalMessageCount);
137                 fData.put("successMessageCount", successMessageCount);
138                 fData.put("failureMessageCount", failureMessageCount);
139                 return fData.toString();
140         }
141
142         public long getTotalMessageCount() {
143                 return totalMessageCount;
144         }
145
146         public void setTotalMessageCount(long totalMessageCount) {
147                 this.totalMessageCount = totalMessageCount;
148         }
149
150         public long getSuccessMessageCount() {
151                 return successMessageCount;
152         }
153
154         public void setSuccessMessageCount(long successMessageCount) {
155                 this.successMessageCount = successMessageCount;
156         }
157
158         public long getFailureMessageCount() {
159                 return failureMessageCount;
160         }
161
162         /**
163          * @param failureMessageCount
164          */
165         public void setFailureMessageCount(long failureMessageCount) {
166                 this.failureMessageCount = failureMessageCount;
167         }
168
169         /**
170          * 
171          * @return JSOnObject fData
172          */
173         public JSONObject getfData() {
174                 return fData;
175         }
176
177         /**
178          * set the json object into data
179          * 
180          * @param fData
181          */
182         public void setfData(JSONObject fData) {
183                 this.fData = fData;
184         }
185
186         /**
187          * 
188          * @return
189          */
190         public TrnRequest getTrnRequest() {
191                 return trnRequest;
192         }
193
194         /**
195          * 
196          * @param trnRequest
197          */
198         public void setTrnRequest(TrnRequest trnRequest) {
199                 this.trnRequest = trnRequest;
200         }
201
202 }