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 Expiry Record, as retrieved from the DB.
\r
40 * @author Robert Eby
\r
41 * @version $Id: ExpiryRecord.java,v 1.4 2013/10/28 18:06:52 eby Exp $
\r
43 public class ExpiryRecord extends BaseLogRecord {
\r
45 private String fileid;
\r
46 private int attempts;
\r
47 private String reason;
\r
50 * ExpiryRecord constructor.
\r
51 * @param pp string array of ExpiryRecord attributes
\r
52 * @throws ParseException in case of parse error
\r
54 public ExpiryRecord(String[] pp) throws ParseException {
\r
56 String fileid = pp[5];
\r
57 if (fileid.lastIndexOf('/') >= 0) {
\r
58 fileid = fileid.substring(fileid.lastIndexOf('/') + 1);
\r
60 this.subid = Integer.parseInt(pp[4]);
\r
61 this.fileid = fileid;
\r
62 this.attempts = Integer.parseInt(pp[10]);
\r
63 this.reason = pp[9];
\r
64 if (!reason.equals("notRetryable") && !reason.equals("retriesExhausted") && !reason.equals("diskFull")) {
\r
65 this.reason = "other";
\r
70 * ExpiryRecord constructor from ResultSet.
\r
71 * @param rs ResultSet of ExpiryREcord attributes
\r
72 * @throws SQLException in case of error with SQL statement
\r
74 public ExpiryRecord(ResultSet rs) throws SQLException {
\r
76 this.subid = rs.getInt("DELIVERY_SUBID");
\r
77 this.fileid = rs.getString("DELIVERY_FILEID");
\r
78 this.attempts = rs.getInt("ATTEMPTS");
\r
79 this.reason = rs.getString("REASON");
\r
82 public int getSubid() {
\r
86 public void setSubid(int subid) {
\r
90 public String getFileid() {
\r
94 public void setFileid(String fileid) {
\r
95 this.fileid = fileid;
\r
98 public int getAttempts() {
\r
102 public void setAttempts(int attempts) {
\r
103 this.attempts = attempts;
\r
106 public String getReason() {
\r
110 public void setReason(String reason) {
\r
111 this.reason = reason;
\r
115 * Method to reorder LOGJSONObject.
\r
116 * @param jo LOGJSONObject
\r
117 * @return LOGJSONObject
\r
119 public LOGJSONObject reOrderObject(LOGJSONObject jo) {
\r
120 LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<>();
\r
122 logrecordObj.put("expiryReason", jo.get("expiryReason"));
\r
123 logrecordObj.put("publishId", jo.get("publishId"));
\r
124 logrecordObj.put("attempts", jo.get("attempts"));
\r
125 logrecordObj.put("requestURI", jo.get("requestURI"));
\r
126 logrecordObj.put("method", jo.get("method"));
\r
127 logrecordObj.put("contentType", jo.get("contentType"));
\r
128 logrecordObj.put("type", jo.get("type"));
\r
129 logrecordObj.put("date", jo.get("date"));
\r
130 logrecordObj.put("contentLength", jo.get("contentLength"));
\r
132 return new LOGJSONObject(logrecordObj);
\r
136 public LOGJSONObject asJSONObject() {
\r
137 LOGJSONObject jo = super.asJSONObject();
\r
138 jo.put("type", "exp");
\r
139 jo.put("expiryReason", reason);
\r
140 jo.put("attempts", attempts);
\r
142 return reOrderObject(jo);
\r
146 public void load(PreparedStatement ps) throws SQLException {
\r
147 ps.setString(1, "exp"); // field 1: type
\r
148 super.load(ps); // loads fields 2-8
\r
149 ps.setNull(9, Types.VARCHAR);
\r
150 ps.setNull(10, Types.VARCHAR);
\r
151 ps.setNull(11, Types.VARCHAR);
\r
152 ps.setNull(12, Types.INTEGER);
\r
153 ps.setInt(13, getSubid());
\r
154 ps.setString(14, getFileid());
\r
155 ps.setNull(15, Types.INTEGER);
\r
156 ps.setInt(16, getAttempts());
\r
157 ps.setString(17, getReason());
\r
158 ps.setNull(19, Types.BIGINT);
\r
159 ps.setNull(20, Types.VARCHAR);
\r