update link to upper-constraints.txt
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / ExpiryRecord.java
1 /*******************************************************************************\r
2  * ============LICENSE_START==================================================\r
3  * * org.onap.dmaap\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
10  * *\r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * *\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
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 \r
24 \r
25 package org.onap.dmaap.datarouter.provisioning.beans;\r
26 \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
33 \r
34 import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;\r
35 \r
36 \r
37 /**\r
38  * The representation of a Expiry Record, as retrieved from the DB.\r
39  *\r
40  * @author Robert Eby\r
41  * @version $Id: ExpiryRecord.java,v 1.4 2013/10/28 18:06:52 eby Exp $\r
42  */\r
43 public class ExpiryRecord extends BaseLogRecord {\r
44 \r
45     public static final String EXPIRY_REASON = "expiryReason";\r
46     public static final String ATTEMPTS = "attempts";\r
47     private int subid;\r
48     private String fileid;\r
49     private int deliveryAttempts;\r
50     private String reason;\r
51 \r
52     /**\r
53      * ExpiryRecord constructor.\r
54      * @param pp string array of ExpiryRecord attributes\r
55      * @throws ParseException in case of parse error\r
56      */\r
57     public ExpiryRecord(String[] pp) throws ParseException {\r
58         super(pp);\r
59         String thisFileid = pp[5];\r
60         if (thisFileid.lastIndexOf('/') >= 0) {\r
61             thisFileid = thisFileid.substring(thisFileid.lastIndexOf('/') + 1);\r
62         }\r
63         this.subid = Integer.parseInt(pp[4]);\r
64         this.fileid = thisFileid;\r
65         this.deliveryAttempts = Integer.parseInt(pp[10]);\r
66         this.reason = pp[9];\r
67         if (!"notRetryable".equals(reason) && !"retriesExhausted".equals(reason) && !"diskFull".equals(reason)) {\r
68             this.reason = "other";\r
69         }\r
70     }\r
71 \r
72     /**\r
73      * ExpiryRecord constructor from ResultSet.\r
74      * @param rs ResultSet of ExpiryREcord attributes\r
75      * @throws SQLException in case of error with SQL statement\r
76      */\r
77     public ExpiryRecord(ResultSet rs) throws SQLException {\r
78         super(rs);\r
79         this.subid = rs.getInt("DELIVERY_SUBID");\r
80         this.fileid = rs.getString("DELIVERY_FILEID");\r
81         this.deliveryAttempts = rs.getInt("ATTEMPTS");\r
82         this.reason = rs.getString("REASON");\r
83     }\r
84 \r
85     public int getSubid() {\r
86         return subid;\r
87     }\r
88 \r
89     public void setSubid(int subid) {\r
90         this.subid = subid;\r
91     }\r
92 \r
93     public String getFileid() {\r
94         return fileid;\r
95     }\r
96 \r
97     public void setFileid(String fileid) {\r
98         this.fileid = fileid;\r
99     }\r
100 \r
101     public int getDeliveryAttempts() {\r
102         return deliveryAttempts;\r
103     }\r
104 \r
105     public void setDeliveryAttempts(int deliveryAttempts) {\r
106         this.deliveryAttempts = deliveryAttempts;\r
107     }\r
108 \r
109     public String getReason() {\r
110         return reason;\r
111     }\r
112 \r
113     public void setReason(String reason) {\r
114         this.reason = reason;\r
115     }\r
116 \r
117     /**\r
118      * Method to reorder LOGJSONObject.\r
119      * @param jo LOGJSONObject\r
120      * @return LOGJSONObject\r
121      */\r
122     public LOGJSONObject reOrderObject(LOGJSONObject jo) {\r
123         LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<>();\r
124 \r
125         logrecordObj.put(EXPIRY_REASON, jo.get(EXPIRY_REASON));\r
126         logrecordObj.put("publishId", jo.get("publishId"));\r
127         logrecordObj.put(ATTEMPTS, jo.get(ATTEMPTS));\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
134 \r
135         return new LOGJSONObject(logrecordObj);\r
136     }\r
137 \r
138     @Override\r
139     public LOGJSONObject asJSONObject() {\r
140         LOGJSONObject jo = super.asJSONObject();\r
141         jo.put("type", "exp");\r
142         jo.put(EXPIRY_REASON, reason);\r
143         jo.put(ATTEMPTS, deliveryAttempts);\r
144 \r
145         return reOrderObject(jo);\r
146     }\r
147 \r
148     @Override\r
149     public void load(PreparedStatement ps) throws SQLException {\r
150         ps.setString(1, "exp");        // field 1: type\r
151         super.load(ps);                // loads fields 2-8\r
152         ps.setNull(9, Types.VARCHAR);\r
153         ps.setNull(10, Types.VARCHAR);\r
154         ps.setNull(11, Types.VARCHAR);\r
155         ps.setNull(12, Types.INTEGER);\r
156         ps.setInt(13, getSubid());\r
157         ps.setString(14, getFileid());\r
158         ps.setNull(15, Types.INTEGER);\r
159         ps.setInt(16, getDeliveryAttempts());\r
160         ps.setString(17, getReason());\r
161         ps.setNull(19, Types.BIGINT);\r
162         ps.setNull(20, Types.VARCHAR);\r
163     }\r
164 }\r