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.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;
\r
37 * The representation of a Publish Record, as retrieved from the DB.
\r
39 * @author Robert Eby
\r
40 * @version $Id: PublishRecord.java,v 1.6 2013/10/28 18:06:53 eby Exp $
\r
42 public class PublishRecord extends BaseLogRecord {
\r
43 private String feedFileid;
\r
44 private String remoteAddr;
\r
45 private String user;
\r
48 public PublishRecord(String[] pp) throws ParseException {
\r
50 // This is too slow!
\r
51 // Matcher m = Pattern.compile(".*/publish/(\\d+)/(.*)$").matcher(pp[4]);
\r
52 // if (!m.matches())
\r
53 // throw new ParseException("bad pattern", 0);
\r
54 // this.feedFileid = m.group(2);
\r
55 int ix = pp[4].indexOf("/publish/");
\r
57 throw new ParseException("bad pattern", 0);
\r
58 ix = pp[4].indexOf('/', ix + 9);
\r
60 throw new ParseException("bad pattern", 0);
\r
61 this.feedFileid = pp[4].substring(ix + 1);
\r
62 this.remoteAddr = pp[8];
\r
64 this.status = Integer.parseInt(pp[10]);
\r
67 public PublishRecord(ResultSet rs) throws SQLException {
\r
69 this.feedFileid = rs.getString("FEED_FILEID");
\r
70 this.remoteAddr = rs.getString("REMOTE_ADDR");
\r
71 this.user = rs.getString("USER");
\r
72 this.status = rs.getInt("STATUS");
\r
75 public String getFeedFileid() {
\r
79 public void setFeedFileid(String feedFileid) {
\r
80 this.feedFileid = feedFileid;
\r
83 public String getRemoteAddr() {
\r
87 public void setRemoteAddr(String remoteAddr) {
\r
88 this.remoteAddr = remoteAddr;
\r
91 public String getUser() {
\r
95 public void setUser(String user) {
\r
99 public int getStatus() {
\r
103 public void setStatus(int status) {
\r
104 this.status = status;
\r
108 public LOGJSONObject reOrderObject(LOGJSONObject jo) {
\r
109 LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<String, Object>();
\r
112 logrecordObj.put("statusCode", jo.get("statusCode"));
\r
113 logrecordObj.put("publishId", jo.get("publishId"));
\r
114 logrecordObj.put("requestURI", jo.get("requestURI"));
\r
115 logrecordObj.put("sourceIP", jo.get("sourceIP"));
\r
116 logrecordObj.put("method", jo.get("method"));
\r
117 logrecordObj.put("contentType", jo.get("contentType"));
\r
118 logrecordObj.put("endpointId", jo.get("endpointId"));
\r
119 logrecordObj.put("type", jo.get("type"));
\r
120 logrecordObj.put("date", jo.get("date"));
\r
121 logrecordObj.put("contentLength", jo.get("contentLength"));
\r
123 LOGJSONObject newjo = new LOGJSONObject(logrecordObj);
\r
128 public LOGJSONObject asJSONObject() {
\r
129 LOGJSONObject jo = super.asJSONObject();
\r
130 jo.put("type", "pub");
\r
131 // jo.put("feedFileid", feedFileid);
\r
132 // jo.put("remoteAddr", remoteAddr);
\r
133 // jo.put("user", user);
\r
134 jo.put("sourceIP", remoteAddr);
\r
135 jo.put("endpointId", user);
\r
136 jo.put("statusCode", status);
\r
138 LOGJSONObject newjo = this.reOrderObject(jo);
\r
144 public void load(PreparedStatement ps) throws SQLException {
\r
145 ps.setString(1, "pub"); // field 1: type
\r
146 super.load(ps); // loads fields 2-8
\r
147 ps.setString(9, getFeedFileid());
\r
148 ps.setString(10, getRemoteAddr());
\r
149 ps.setString(11, getUser());
\r
150 ps.setInt(12, getStatus());
\r
151 ps.setNull(13, Types.INTEGER);
\r
152 ps.setNull(14, Types.VARCHAR);
\r
153 ps.setNull(15, Types.INTEGER);
\r
154 ps.setNull(16, Types.INTEGER);
\r
155 ps.setNull(17, Types.VARCHAR);
\r
156 ps.setNull(19, Types.BIGINT);
\r