1 /*******************************************************************************
\r
2 * ============LICENSE_START==================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
25 package org.onap.dmaap.datarouter.provisioning.beans;
\r
27 import java.sql.PreparedStatement;
\r
28 import java.sql.ResultSet;
\r
29 import java.sql.SQLException;
\r
30 import java.sql.Types;
\r
31 import java.text.ParseException;
\r
32 import java.util.LinkedHashMap;
\r
34 import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;
\r
38 * The representation of a Delivery Record, as retrieved from the DB.
\r
40 * @author Robert Eby
\r
41 * @version $Id: DeliveryRecord.java,v 1.9 2014/03/12 19:45:41 eby Exp $
\r
43 public class DeliveryRecord extends BaseLogRecord {
\r
45 private static final String STATUS_CODE = "statusCode";
\r
46 private static final String DELIVERY_ID = "deliveryId";
\r
48 private String fileid;
\r
50 private String user;
\r
53 * Constructor for DeliverRecord.
\r
54 * @param pp string array of DeliverRecord attributes
\r
55 * @throws ParseException in case of parse error
\r
57 public DeliveryRecord(String[] pp) throws ParseException {
\r
59 String thisFileid = pp[5];
\r
60 if (thisFileid.lastIndexOf('/') >= 0) {
\r
61 thisFileid = thisFileid.substring(thisFileid.lastIndexOf('/') + 1);
\r
63 this.subid = Integer.parseInt(pp[4]);
\r
64 this.fileid = thisFileid;
\r
65 this.result = Integer.parseInt(pp[10]);
\r
67 if (this.user != null && this.user.length() > 50) {
\r
68 this.user = this.user.substring(0, 50);
\r
73 * DeliverRecord constructor from ResultSet.
\r
74 * @param rs ResultSet
\r
75 * @throws SQLException in case of get error from SQL statement
\r
77 public DeliveryRecord(ResultSet rs) throws SQLException {
\r
79 this.subid = rs.getInt("DELIVERY_SUBID");
\r
80 this.fileid = rs.getString("DELIVERY_FILEID");
\r
81 this.result = rs.getInt("RESULT");
\r
82 this.user = rs.getString("USER");
\r
85 public int getSubid() {
\r
89 public void setSubid(int subid) {
\r
93 public String getFileid() {
\r
97 public void setFileid(String fileid) {
\r
98 this.fileid = fileid;
\r
101 public int getResult() {
\r
105 public void setResult(int result) {
\r
106 this.result = result;
\r
109 public String getUser() {
\r
113 public void setUser(String user) {
\r
118 * Method to reorder LOGJSONObject.
\r
119 * @param jo LOGJSONObject
\r
120 * @return new LOGJSONObject
\r
122 public LOGJSONObject reOrderObject(LOGJSONObject jo) {
\r
123 LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<>();
\r
125 logrecordObj.put(STATUS_CODE, jo.get(STATUS_CODE));
\r
126 logrecordObj.put(DELIVERY_ID, jo.get(DELIVERY_ID));
\r
127 logrecordObj.put("publishId", jo.get("publishId"));
\r
128 logrecordObj.put("requestURI", jo.get("requestURI"));
\r
129 logrecordObj.put("method", jo.get("method"));
\r
130 logrecordObj.put("contentType", jo.get("contentType"));
\r
131 logrecordObj.put("type", jo.get("type"));
\r
132 logrecordObj.put("date", jo.get("date"));
\r
133 logrecordObj.put("contentLength", jo.get("contentLength"));
\r
136 return new LOGJSONObject(logrecordObj);
\r
140 public LOGJSONObject asJSONObject() {
\r
141 LOGJSONObject jo = super.asJSONObject();
\r
142 jo.put("type", "del");
\r
143 jo.put(DELIVERY_ID, user);
\r
144 jo.put(STATUS_CODE, result);
\r
146 return this.reOrderObject(jo);
\r
150 public void load(PreparedStatement ps) throws SQLException {
\r
151 ps.setString(1, "del"); // field 1: type
\r
152 super.load(ps); // loads fields 2-8
\r
153 ps.setNull(9, Types.VARCHAR);
\r
154 ps.setNull(10, Types.VARCHAR);
\r
155 ps.setString(11, getUser());
\r
156 ps.setNull(12, Types.INTEGER);
\r
157 ps.setInt(13, getSubid());
\r
158 ps.setString(14, getFileid());
\r
159 ps.setInt(15, getResult());
\r
160 ps.setNull(16, Types.INTEGER);
\r
161 ps.setNull(17, Types.VARCHAR);
\r
162 ps.setNull(19, Types.BIGINT);
\r
163 ps.setNull(20, Types.VARCHAR);
\r