1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
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
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=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package org.onap.dmaap.dmf.mr.transaction;
24 import org.json.JSONObject;
27 * This is the class which will have the transaction enabled logging object
30 * @author nilanjana.maity
33 public class TransactionObj implements DMaaPTransactionObj {
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";
45 * Initializing constructor
46 * put the json data for transaction enabled logging
50 public TransactionObj(JSONObject data) {
53 // check for required fields (these throw if not present)
55 getTotalMessageCount();
56 getSuccessMessageCount();
57 getFailureMessageCount();
59 // make sure we've got an aux data object
60 final JSONObject aux = fData.optJSONObject(kAuxData);
62 fData.put(kAuxData, new JSONObject());
67 * this constructor will have the details of transaction id,
68 * totalMessageCount successMessageCount, failureMessageCount to get the
72 * @param totalMessageCount
73 * @param successMessageCount
74 * @param failureMessageCount
76 public TransactionObj(String id, long totalMessageCount, long successMessageCount, long failureMessageCount) {
78 this.totalMessageCount = totalMessageCount;
79 this.successMessageCount = successMessageCount;
80 this.failureMessageCount = failureMessageCount;
85 * The constructor passing only transaction id
89 public TransactionObj(String id) {
94 * Wrapping the data into json object
98 public JSONObject asJsonObject() {
99 final JSONObject full = new JSONObject(fData, JSONObject.getNames(fData));
104 * To get the transaction id
106 public String getId() {
111 * To set the transaction id
113 public void setId(String id) {
121 public String getCreateTime() {
129 public void setCreateTime(String createTime) {
130 this.createTime = createTime;
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();
142 public long getTotalMessageCount() {
143 return totalMessageCount;
146 public void setTotalMessageCount(long totalMessageCount) {
147 this.totalMessageCount = totalMessageCount;
150 public long getSuccessMessageCount() {
151 return successMessageCount;
154 public void setSuccessMessageCount(long successMessageCount) {
155 this.successMessageCount = successMessageCount;
158 public long getFailureMessageCount() {
159 return failureMessageCount;
163 * @param failureMessageCount
165 public void setFailureMessageCount(long failureMessageCount) {
166 this.failureMessageCount = failureMessageCount;
171 * @return JSOnObject fData
173 public JSONObject getfData() {
178 * set the json object into data
182 public void setfData(JSONObject fData) {
190 public TrnRequest getTrnRequest() {
198 public void setTrnRequest(TrnRequest trnRequest) {
199 this.trnRequest = trnRequest;