1 /*******************************************************************************
\r
2 * ============LICENSE_START==================================================
\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
11 * * http://www.apache.org/licenses/LICENSE-2.0
\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
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
24 package org.onap.dmaap.datarouter.provisioning.beans;
\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
33 import org.apache.commons.lang3.StringUtils;
\r
34 import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;
\r
38 * The representation of a Publish Record, as retrieved from the DB.
\r
40 * @author Robert Eby
\r
41 * @version $Id: PublishRecord.java,v 1.6 2013/10/28 18:06:53 eby Exp $
\r
44 public class PublishRecord extends BaseLogRecord {
\r
45 private String feedFileid;
\r
46 private String remoteAddr;
\r
47 private String user;
\r
49 private String fileName;
\r
52 * Publish record constructor.
\r
53 * @param pp string array of attributes
\r
54 * @throws ParseException in case of parse error
\r
56 public PublishRecord(String[] pp) throws ParseException {
\r
58 int ix = pp[4].indexOf("/publish/");
\r
60 throw new ParseException("bad pattern", 0);
\r
62 ix = pp[4].indexOf('/', ix + 9);
\r
64 throw new ParseException("bad pattern", 0);
\r
66 this.feedFileid = pp[4].substring(ix + 1);
\r
67 this.remoteAddr = pp[8];
\r
69 this.status = Integer.parseInt(pp[10]);
\r
70 this.fileName = StringUtils.substringAfterLast(this.getRequestUri(), "/");
\r
74 * Publish record constructor.
\r
75 * @param rs ResultSet from DB
\r
76 * @throws SQLException in case of SQL error
\r
78 public PublishRecord(ResultSet rs) throws SQLException {
\r
80 this.feedFileid = rs.getString("FEED_FILEID");
\r
81 this.remoteAddr = rs.getString("REMOTE_ADDR");
\r
82 this.user = rs.getString("USER");
\r
83 this.status = rs.getInt("STATUS");
\r
84 this.fileName = rs.getString("FILENAME");
\r
87 public String getFeedFileid() {
\r
91 public void setFeedFileid(String feedFileid) {
\r
92 this.feedFileid = feedFileid;
\r
95 public String getRemoteAddr() {
\r
99 public void setRemoteAddr(String remoteAddr) {
\r
100 this.remoteAddr = remoteAddr;
\r
103 public String getUser() {
\r
107 public void setUser(String user) {
\r
111 public int getStatus() {
\r
115 public void setStatus(int status) {
\r
116 this.status = status;
\r
119 public String getFileName() {
\r
123 public void setFileName(String fileName) {
\r
124 this.fileName = fileName;
\r
129 * Method to reorder json object.
\r
130 * @param jo LOGJSONObject
\r
131 * @return LOGJSONObject
\r
133 public LOGJSONObject reOrderObject(LOGJSONObject jo) {
\r
134 LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<>();
\r
137 logrecordObj.put("statusCode", jo.get("statusCode"));
\r
138 logrecordObj.put("publishId", jo.get("publishId"));
\r
139 logrecordObj.put("requestURI", jo.get("requestURI"));
\r
140 logrecordObj.put("sourceIP", jo.get("sourceIP"));
\r
141 logrecordObj.put("method", jo.get("method"));
\r
142 logrecordObj.put("contentType", jo.get("contentType"));
\r
143 logrecordObj.put("endpointId", jo.get("endpointId"));
\r
144 logrecordObj.put("type", jo.get("type"));
\r
145 logrecordObj.put("date", jo.get("date"));
\r
146 logrecordObj.put("contentLength", jo.get("contentLength"));
\r
147 logrecordObj.put("fileName", jo.get("fileName"));
\r
149 return new LOGJSONObject(logrecordObj);
\r
154 public LOGJSONObject asJSONObject() {
\r
155 LOGJSONObject jo = super.asJSONObject();
\r
156 jo.put("type", "pub");
\r
157 jo.put("feedFileid", feedFileid);
\r
158 jo.put("remoteAddr", remoteAddr);
\r
159 jo.put("user", user);
\r
160 jo.put("sourceIP", remoteAddr);
\r
161 jo.put("endpointId", user);
\r
162 jo.put("statusCode", status);
\r
163 jo.put("fileName", fileName);
\r
165 return this.reOrderObject(jo);
\r
169 public void load(PreparedStatement ps) throws SQLException {
\r
170 ps.setString(1, "pub"); // field 1: type
\r
171 super.load(ps); // loads fields 2-8
\r
172 ps.setString(9, getFeedFileid());
\r
173 ps.setString(10, getRemoteAddr());
\r
174 ps.setString(11, getUser());
\r
175 ps.setInt(12, getStatus());
\r
176 ps.setNull(13, Types.INTEGER);
\r
177 ps.setNull(14, Types.VARCHAR);
\r
178 ps.setNull(15, Types.INTEGER);
\r
179 ps.setNull(16, Types.INTEGER);
\r
180 ps.setNull(17, Types.VARCHAR);
\r
181 ps.setNull(19, Types.BIGINT);
\r
182 ps.setString(20, getFileName());
\r