X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdatarouter.git;a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Fbeans%2FExpiryRecord.java;h=d812036ab2e631f568b46f9a8cb09aaffe9be4b8;hp=bfe63e4650d8a7c910cb2c070a7bb27b59c16bdc;hb=bc1df610cddfb558cf6bde90c269b4af59768648;hpb=aaf18107cc25a4cbde2b1d28f37682d40e955e1c diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/ExpiryRecord.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/ExpiryRecord.java index bfe63e46..d812036a 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/ExpiryRecord.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/ExpiryRecord.java @@ -7,9 +7,9 @@ * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at - * * + * * * * http://www.apache.org/licenses/LICENSE-2.0 - * * + * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -36,107 +36,126 @@ import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject; /** * The representation of a Expiry Record, as retrieved from the DB. + * * @author Robert Eby * @version $Id: ExpiryRecord.java,v 1.4 2013/10/28 18:06:52 eby Exp $ */ public class ExpiryRecord extends BaseLogRecord { - private int subid; - private String fileid; - private int attempts; - private String reason; - - public ExpiryRecord(String[] pp) throws ParseException { - super(pp); - String fileid = pp[5]; - if (fileid.lastIndexOf('/') >= 0) - fileid = fileid.substring(fileid.lastIndexOf('/')+1); - this.subid = Integer.parseInt(pp[4]); - this.fileid = fileid; - this.attempts = Integer.parseInt(pp[10]); - this.reason = pp[9]; - if (!reason.equals("notRetryable") && !reason.equals("retriesExhausted") && !reason.equals("diskFull")) - this.reason = "other"; - } - public ExpiryRecord(ResultSet rs) throws SQLException { - super(rs); - this.subid = rs.getInt("DELIVERY_SUBID"); - this.fileid = rs.getString("DELIVERY_FILEID"); - this.attempts = rs.getInt("ATTEMPTS"); - this.reason = rs.getString("REASON"); - } - - public int getSubid() { - return subid; - } - - public void setSubid(int subid) { - this.subid = subid; - } - - public String getFileid() { - return fileid; - } - - public void setFileid(String fileid) { - this.fileid = fileid; - } - - public int getAttempts() { - return attempts; - } - - public void setAttempts(int attempts) { - this.attempts = attempts; - } - - public String getReason() { - return reason; - } - - public void setReason(String reason) { - this.reason = reason; - } - - public LOGJSONObject reOrderObject(LOGJSONObject jo) { - LinkedHashMap logrecordObj = new LinkedHashMap(); - - logrecordObj.put("expiryReason", jo.get("expiryReason")); - logrecordObj.put("publishId", jo.get("publishId")); - logrecordObj.put("attempts", jo.get("attempts")); - logrecordObj.put("requestURI", jo.get("requestURI")); - logrecordObj.put("method", jo.get("method")); - logrecordObj.put("contentType", jo.get("contentType")); - logrecordObj.put("type", jo.get("type")); - logrecordObj.put("date", jo.get("date")); - logrecordObj.put("contentLength", jo.get("contentLength")); - - LOGJSONObject newjo = new LOGJSONObject(logrecordObj); - return newjo; - } - - @Override - public LOGJSONObject asJSONObject() { - LOGJSONObject jo = super.asJSONObject(); - jo.put("type", "exp"); - jo.put("expiryReason", reason); - jo.put("attempts", attempts); - - LOGJSONObject newjo = this.reOrderObject(jo); - return newjo; - } - @Override - public void load(PreparedStatement ps) throws SQLException { - ps.setString(1, "exp"); // field 1: type - super.load(ps); // loads fields 2-8 - ps.setNull (9, Types.VARCHAR); - ps.setNull (10, Types.VARCHAR); - ps.setNull (11, Types.VARCHAR); - ps.setNull (12, Types.INTEGER); - ps.setInt (13, getSubid()); - ps.setString(14, getFileid()); - ps.setNull (15, Types.INTEGER); - ps.setInt (16, getAttempts()); - ps.setString(17, getReason()); - ps.setNull (19, Types.BIGINT); - } + private int subid; + private String fileid; + private int attempts; + private String reason; + + /** + * ExpiryRecord constructor. + * @param pp string array of ExpiryRecord attributes + * @throws ParseException in case of parse error + */ + public ExpiryRecord(String[] pp) throws ParseException { + super(pp); + String fileid = pp[5]; + if (fileid.lastIndexOf('/') >= 0) { + fileid = fileid.substring(fileid.lastIndexOf('/') + 1); + } + this.subid = Integer.parseInt(pp[4]); + this.fileid = fileid; + this.attempts = Integer.parseInt(pp[10]); + this.reason = pp[9]; + if (!reason.equals("notRetryable") && !reason.equals("retriesExhausted") && !reason.equals("diskFull")) { + this.reason = "other"; + } + } + + /** + * ExpiryRecord constructor from ResultSet. + * @param rs ResultSet of ExpiryREcord attributes + * @throws SQLException in case of error with SQL statement + */ + public ExpiryRecord(ResultSet rs) throws SQLException { + super(rs); + this.subid = rs.getInt("DELIVERY_SUBID"); + this.fileid = rs.getString("DELIVERY_FILEID"); + this.attempts = rs.getInt("ATTEMPTS"); + this.reason = rs.getString("REASON"); + } + + public int getSubid() { + return subid; + } + + public void setSubid(int subid) { + this.subid = subid; + } + + public String getFileid() { + return fileid; + } + + public void setFileid(String fileid) { + this.fileid = fileid; + } + + public int getAttempts() { + return attempts; + } + + public void setAttempts(int attempts) { + this.attempts = attempts; + } + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + /** + * Method to reorder LOGJSONObject. + * @param jo LOGJSONObject + * @return LOGJSONObject + */ + public LOGJSONObject reOrderObject(LOGJSONObject jo) { + LinkedHashMap logrecordObj = new LinkedHashMap<>(); + + logrecordObj.put("expiryReason", jo.get("expiryReason")); + logrecordObj.put("publishId", jo.get("publishId")); + logrecordObj.put("attempts", jo.get("attempts")); + logrecordObj.put("requestURI", jo.get("requestURI")); + logrecordObj.put("method", jo.get("method")); + logrecordObj.put("contentType", jo.get("contentType")); + logrecordObj.put("type", jo.get("type")); + logrecordObj.put("date", jo.get("date")); + logrecordObj.put("contentLength", jo.get("contentLength")); + + return new LOGJSONObject(logrecordObj); + } + + @Override + public LOGJSONObject asJSONObject() { + LOGJSONObject jo = super.asJSONObject(); + jo.put("type", "exp"); + jo.put("expiryReason", reason); + jo.put("attempts", attempts); + + return reOrderObject(jo); + } + + @Override + public void load(PreparedStatement ps) throws SQLException { + ps.setString(1, "exp"); // field 1: type + super.load(ps); // loads fields 2-8 + ps.setNull(9, Types.VARCHAR); + ps.setNull(10, Types.VARCHAR); + ps.setNull(11, Types.VARCHAR); + ps.setNull(12, Types.INTEGER); + ps.setInt(13, getSubid()); + ps.setString(14, getFileid()); + ps.setNull(15, Types.INTEGER); + ps.setInt(16, getAttempts()); + ps.setString(17, getReason()); + ps.setNull(19, Types.BIGINT); + ps.setNull(20, Types.VARCHAR); + } }