Code style cleanup for prov authz and beans
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / DeliveryRecord.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 Delivery Record, as retrieved from the DB.\r
39  *\r
40  * @author Robert Eby\r
41  * @version $Id: DeliveryRecord.java,v 1.9 2014/03/12 19:45:41 eby Exp $\r
42  */\r
43 public class DeliveryRecord extends BaseLogRecord {\r
44     private int subid;\r
45     private String fileid;\r
46     private int result;\r
47     private String user;\r
48 \r
49     /**\r
50      * Constructor for DeliverRecord.\r
51      * @param pp string array of DeliverRecord attributes\r
52      * @throws ParseException in case of parse error\r
53      */\r
54     public DeliveryRecord(String[] pp) throws ParseException {\r
55         super(pp);\r
56         String fileid = pp[5];\r
57         if (fileid.lastIndexOf('/') >= 0) {\r
58             fileid = fileid.substring(fileid.lastIndexOf('/') + 1);\r
59         }\r
60         this.subid = Integer.parseInt(pp[4]);\r
61         this.fileid = fileid;\r
62         this.result = Integer.parseInt(pp[10]);\r
63         this.user = pp[9];\r
64         if (this.user != null && this.user.length() > 50) {\r
65             this.user = this.user.substring(0, 50);\r
66         }\r
67     }\r
68 \r
69     /**\r
70      * DeliverRecord constructor from ResultSet.\r
71      * @param rs ResultSet\r
72      * @throws SQLException in case of get error from SQL statement\r
73      */\r
74     public DeliveryRecord(ResultSet rs) throws SQLException {\r
75         super(rs);\r
76         this.subid = rs.getInt("DELIVERY_SUBID");\r
77         this.fileid = rs.getString("DELIVERY_FILEID");\r
78         this.result = rs.getInt("RESULT");\r
79         this.user = rs.getString("USER");\r
80     }\r
81 \r
82     public int getSubid() {\r
83         return subid;\r
84     }\r
85 \r
86     public void setSubid(int subid) {\r
87         this.subid = subid;\r
88     }\r
89 \r
90     public String getFileid() {\r
91         return fileid;\r
92     }\r
93 \r
94     public void setFileid(String fileid) {\r
95         this.fileid = fileid;\r
96     }\r
97 \r
98     public int getResult() {\r
99         return result;\r
100     }\r
101 \r
102     public void setResult(int result) {\r
103         this.result = result;\r
104     }\r
105 \r
106     public String getUser() {\r
107         return user;\r
108     }\r
109 \r
110     public void setUser(String user) {\r
111         this.user = user;\r
112     }\r
113 \r
114     /**\r
115      * Method to reorder LOGJSONObject.\r
116      * @param jo LOGJSONObject\r
117      * @return new LOGJSONObject\r
118      */\r
119     public LOGJSONObject reOrderObject(LOGJSONObject jo) {\r
120         LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<>();\r
121 \r
122         logrecordObj.put("statusCode", jo.get("statusCode"));\r
123         logrecordObj.put("deliveryId", jo.get("deliveryId"));\r
124         logrecordObj.put("publishId", jo.get("publishId"));\r
125         logrecordObj.put("requestURI", jo.get("requestURI"));\r
126         //logrecordObj.put("sourceIP", jo.get("sourceIP"));\r
127         logrecordObj.put("method", jo.get("method"));\r
128         logrecordObj.put("contentType", jo.get("contentType"));\r
129         //logrecordObj.put("endpointId", jo.get("endpointId"));\r
130         logrecordObj.put("type", jo.get("type"));\r
131         logrecordObj.put("date", jo.get("date"));\r
132         logrecordObj.put("contentLength", jo.get("contentLength"));\r
133 \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", "del");\r
142         jo.put("deliveryId", user);\r
143         jo.put("statusCode", result);\r
144 \r
145         return this.reOrderObject(jo);\r
146     }\r
147 \r
148     @Override\r
149     public void load(PreparedStatement ps) throws SQLException {\r
150         ps.setString(1, "del");        // 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.setString(11, getUser());\r
155         ps.setNull(12, Types.INTEGER);\r
156         ps.setInt(13, getSubid());\r
157         ps.setString(14, getFileid());\r
158         ps.setInt(15, getResult());\r
159         ps.setNull(16, Types.INTEGER);\r
160         ps.setNull(17, Types.VARCHAR);\r
161         ps.setNull(19, Types.BIGINT);\r
162         ps.setNull(20, Types.VARCHAR);\r
163     }\r
164 }\r