adding FILENAME value to LOG_RECORDS table.
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / PublishRecord.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 import java.util.LinkedHashMap;\r
32 \r
33 import org.apache.commons.lang3.StringUtils;\r
34 import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;\r
35 \r
36 \r
37 /**\r
38  * The representation of a Publish Record, as retrieved from the DB.\r
39  *\r
40  * @author Robert Eby\r
41  * @version $Id: PublishRecord.java,v 1.6 2013/10/28 18:06:53 eby Exp $\r
42  */\r
43 public class PublishRecord extends BaseLogRecord {\r
44     private String feedFileid;\r
45     private String remoteAddr;\r
46     private String user;\r
47     private int status;\r
48     private String fileName;\r
49 \r
50     public PublishRecord(String[] pp) throws ParseException {\r
51         super(pp);\r
52         int ix = pp[4].indexOf("/publish/");\r
53         if (ix < 0)\r
54             throw new ParseException("bad pattern", 0);\r
55         ix = pp[4].indexOf('/', ix + 9);\r
56         if (ix < 0)\r
57             throw new ParseException("bad pattern", 0);\r
58         this.feedFileid = pp[4].substring(ix + 1);\r
59         this.remoteAddr = pp[8];\r
60         this.user = pp[9];\r
61         this.status = Integer.parseInt(pp[10]);\r
62         this.fileName = StringUtils.substringAfterLast(this.getRequestUri(), "/");\r
63     }\r
64 \r
65     public PublishRecord(ResultSet rs) throws SQLException {\r
66         super(rs);\r
67         this.feedFileid = rs.getString("FEED_FILEID");\r
68         this.remoteAddr = rs.getString("REMOTE_ADDR");\r
69         this.user = rs.getString("USER");\r
70         this.status = rs.getInt("STATUS");\r
71         this.fileName = StringUtils.substringAfterLast(this.getRequestUri(), "/");\r
72     }\r
73 \r
74     public String getFeedFileid() {\r
75         return feedFileid;\r
76     }\r
77 \r
78     public void setFeedFileid(String feedFileid) {\r
79         this.feedFileid = feedFileid;\r
80     }\r
81 \r
82     public String getRemoteAddr() {\r
83         return remoteAddr;\r
84     }\r
85 \r
86     public void setRemoteAddr(String remoteAddr) {\r
87         this.remoteAddr = remoteAddr;\r
88     }\r
89 \r
90     public String getUser() {\r
91         return user;\r
92     }\r
93 \r
94     public void setUser(String user) {\r
95         this.user = user;\r
96     }\r
97 \r
98     public int getStatus() {\r
99         return status;\r
100     }\r
101 \r
102     public void setStatus(int status) {\r
103         this.status = status;\r
104     }\r
105 \r
106     public String getFileName() { return fileName;}\r
107 \r
108     public void setFileName(String fileName) { this.fileName = fileName; }\r
109 \r
110 \r
111     public LOGJSONObject reOrderObject(LOGJSONObject jo) {\r
112         LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<String, Object>();\r
113 \r
114 \r
115         logrecordObj.put("statusCode", jo.get("statusCode"));\r
116         logrecordObj.put("publishId", jo.get("publishId"));\r
117         logrecordObj.put("requestURI", jo.get("requestURI"));\r
118         logrecordObj.put("sourceIP", jo.get("sourceIP"));\r
119         logrecordObj.put("method", jo.get("method"));\r
120         logrecordObj.put("contentType", jo.get("contentType"));\r
121         logrecordObj.put("endpointId", jo.get("endpointId"));\r
122         logrecordObj.put("type", jo.get("type"));\r
123         logrecordObj.put("date", jo.get("date"));\r
124         logrecordObj.put("contentLength", jo.get("contentLength"));\r
125         logrecordObj.put("fileName", jo.get("fileName"));\r
126 \r
127         LOGJSONObject newjo = new LOGJSONObject(logrecordObj);\r
128         return newjo;\r
129     }\r
130 \r
131     @Override\r
132     public LOGJSONObject asJSONObject() {\r
133         LOGJSONObject jo = super.asJSONObject();\r
134         jo.put("type", "pub");\r
135         jo.put("feedFileid", feedFileid);\r
136         jo.put("remoteAddr", remoteAddr);\r
137         jo.put("user", user);\r
138         jo.put("sourceIP", remoteAddr);\r
139         jo.put("endpointId", user);\r
140         jo.put("statusCode", status);\r
141         jo.put("fileName", fileName);\r
142 \r
143         LOGJSONObject newjo = this.reOrderObject(jo);\r
144 \r
145         return newjo;\r
146     }\r
147 \r
148     @Override\r
149     public void load(PreparedStatement ps) throws SQLException {\r
150         ps.setString(1, "pub");        // field 1: type\r
151         super.load(ps);                // loads fields 2-8\r
152         ps.setString(9, getFeedFileid());\r
153         ps.setString(10, getRemoteAddr());\r
154         ps.setString(11, getUser());\r
155         ps.setInt(12, getStatus());\r
156         ps.setNull(13, Types.INTEGER);\r
157         ps.setNull(14, Types.VARCHAR);\r
158         ps.setNull(15, Types.INTEGER);\r
159         ps.setNull(16, Types.INTEGER);\r
160         ps.setNull(17, Types.VARCHAR);\r
161         ps.setNull(19, Types.BIGINT);\r
162         ps.setString(20, getFileName());\r
163     }\r
164 }\r