88d48826d3e7ce538884b1c6ec89dbbab0e75c38
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / PubFailRecord.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 package org.onap.dmaap.datarouter.provisioning.beans;\r
25 \r
26 import java.sql.PreparedStatement;\r
27 import java.sql.ResultSet;\r
28 import java.sql.SQLException;\r
29 import java.sql.Types;\r
30 import java.text.ParseException;\r
31 \r
32 /**\r
33  * The representation of a Publish Failure (PBF) Record, as retrieved from the DB.\r
34  *\r
35  * @author Robert Eby\r
36  * @version $Id: PubFailRecord.java,v 1.1 2013/10/28 18:06:53 eby Exp $\r
37  */\r
38 public class PubFailRecord extends BaseLogRecord {\r
39     private long contentLengthReceived;\r
40     private String sourceIP;\r
41     private String user;\r
42     private String error;\r
43 \r
44     public PubFailRecord(String[] pp) throws ParseException {\r
45         super(pp);\r
46         this.contentLengthReceived = Long.parseLong(pp[8]);\r
47         this.sourceIP = pp[9];\r
48         this.user = pp[10];\r
49         this.error = pp[11];\r
50     }\r
51 \r
52     public PubFailRecord(ResultSet rs) throws SQLException {\r
53         super(rs);\r
54         // Note: because this record should be "rare" these fields are mapped to unconventional fields in the DB\r
55         this.contentLengthReceived = rs.getLong("CONTENT_LENGTH_2");\r
56         this.sourceIP = rs.getString("REMOTE_ADDR");\r
57         this.user = rs.getString("USER");\r
58         this.error = rs.getString("FEED_FILEID");\r
59     }\r
60 \r
61     public long getContentLengthReceived() {\r
62         return contentLengthReceived;\r
63     }\r
64 \r
65     public String getSourceIP() {\r
66         return sourceIP;\r
67     }\r
68 \r
69     public String getUser() {\r
70         return user;\r
71     }\r
72 \r
73     public String getError() {\r
74         return error;\r
75     }\r
76 \r
77     @Override\r
78     public void load(PreparedStatement ps) throws SQLException {\r
79         ps.setString(1, "pbf");        // field 1: type\r
80         super.load(ps);                // loads fields 2-8\r
81         ps.setString(9, getError());\r
82         ps.setString(10, getSourceIP());\r
83         ps.setString(11, getUser());\r
84         ps.setNull(12, Types.INTEGER);\r
85         ps.setNull(13, Types.INTEGER);\r
86         ps.setNull(14, Types.VARCHAR);\r
87         ps.setNull(15, Types.INTEGER);\r
88         ps.setNull(16, Types.INTEGER);\r
89         ps.setNull(17, Types.VARCHAR);\r
90         ps.setLong(19, getContentLengthReceived());\r
91         ps.setNull(20, Types.VARCHAR);\r
92     }\r
93 }\r