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
25 package org.onap.dmaap.datarouter.provisioning.beans;
\r
27 import java.sql.PreparedStatement;
\r
28 import java.sql.ResultSet;
\r
29 import java.sql.SQLException;
\r
30 import java.text.ParseException;
\r
31 import java.text.SimpleDateFormat;
\r
32 import java.util.Calendar;
\r
33 import java.util.Date;
\r
34 import java.util.GregorianCalendar;
\r
36 import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;
\r
39 * Define the common fields used by the three types of records generated by DR nodes.
\r
41 * @author Robert Eby
\r
42 * @version $Id: BaseLogRecord.java,v 1.10 2013/10/29 16:57:57 eby Exp $
\r
44 public class BaseLogRecord implements LOGJSONable, Loadable {
\r
45 protected static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
\r
47 private long eventTime;
\r
48 private String publishId;
\r
50 private String requestUri;
\r
51 private String method;
\r
52 private String contentType;
\r
53 private long contentLength;
\r
55 protected BaseLogRecord(String[] pp) throws ParseException {
\r
56 // This throws exceptions occasionally - don't know why.
\r
58 // synchronized (sdf) {
\r
59 // d = sdf.parse(pp[0]);
\r
61 Date d = parseDate(pp[0]);
\r
62 this.eventTime = d.getTime();
\r
63 this.publishId = pp[2];
\r
64 this.feedid = Integer.parseInt(pp[3]);
\r
65 if (pp[1].equals("DLX")) {
\r
66 this.requestUri = "";
\r
67 this.method = "GET"; // Note: we need a valid value in this field, even though unused
\r
68 this.contentType = "";
\r
69 this.contentLength = Long.parseLong(pp[5]);
\r
70 } else if (pp[1].equals("PUB") || pp[1].equals("LOG") || pp[1].equals("PBF")) {
\r
71 this.requestUri = pp[4];
\r
72 this.method = pp[5];
\r
73 this.contentType = pp[6];
\r
74 this.contentLength = Long.parseLong(pp[7]);
\r
76 this.requestUri = pp[5];
\r
77 this.method = pp[6];
\r
78 this.contentType = pp[7];
\r
79 this.contentLength = Long.parseLong(pp[8]);
\r
82 protected BaseLogRecord(ResultSet rs) throws SQLException {
\r
83 this.eventTime = rs.getLong("EVENT_TIME");
\r
84 this.publishId = rs.getString("PUBLISH_ID");
\r
85 this.feedid = rs.getInt("FEEDID");
\r
86 this.requestUri = rs.getString("REQURI");
\r
87 this.method = rs.getString("METHOD");
\r
88 this.contentType = rs.getString("CONTENT_TYPE");
\r
89 this.contentLength = rs.getLong("CONTENT_LENGTH");
\r
91 protected Date parseDate(final String s) throws ParseException {
\r
92 int[] n = new int[7];
\r
94 for (int i = 0; i < s.length(); i++) {
\r
95 char c = s.charAt(i);
\r
96 if (c < '0' || c > '9') {
\r
100 throw new ParseException("parseDate()", 0);
\r
101 n[p] = (n[p] * 10) + (c - '0');
\r
105 throw new ParseException("parseDate()", 1);
\r
106 Calendar cal = new GregorianCalendar();
\r
107 cal.set(Calendar.YEAR, n[0]);
\r
108 cal.set(Calendar.MONTH, n[1]-1);
\r
109 cal.set(Calendar.DAY_OF_MONTH, n[2]);
\r
110 cal.set(Calendar.HOUR_OF_DAY, n[3]);
\r
111 cal.set(Calendar.MINUTE, n[4]);
\r
112 cal.set(Calendar.SECOND, n[5]);
\r
113 cal.set(Calendar.MILLISECOND, n[6]);
\r
114 return cal.getTime();
\r
116 public long getEventTime() {
\r
119 public void setEventTime(long eventTime) {
\r
120 this.eventTime = eventTime;
\r
122 public String getPublishId() {
\r
125 public void setPublishId(String publishId) {
\r
126 this.publishId = publishId;
\r
128 public int getFeedid() {
\r
131 public void setFeedid(int feedid) {
\r
132 this.feedid = feedid;
\r
134 public String getRequestUri() {
\r
137 public void setRequestUri(String requestUri) {
\r
138 this.requestUri = requestUri;
\r
140 public String getMethod() {
\r
143 public void setMethod(String method) {
\r
144 this.method = method;
\r
146 public String getContentType() {
\r
147 return contentType;
\r
149 public void setContentType(String contentType) {
\r
150 this.contentType = contentType;
\r
152 public long getContentLength() {
\r
153 return contentLength;
\r
155 public void setContentLength(long contentLength) {
\r
156 this.contentLength = contentLength;
\r
159 public LOGJSONObject asJSONObject() {
\r
160 LOGJSONObject jo = new LOGJSONObject();
\r
162 synchronized (sdf) {
\r
163 t = sdf.format(eventTime);
\r
166 jo.put("publishId", publishId);
\r
167 jo.put("requestURI", requestUri);
\r
168 jo.put("method", method);
\r
169 if (method.equals("PUT")) {
\r
170 jo.put("contentType", contentType);
\r
171 jo.put("contentLength", contentLength);
\r
176 public void load(PreparedStatement ps) throws SQLException {
\r
177 ps.setLong (2, getEventTime());
\r
178 ps.setString(3, getPublishId());
\r
179 ps.setInt (4, getFeedid());
\r
180 ps.setString(5, getRequestUri());
\r
181 ps.setString(6, getMethod());
\r
182 ps.setString(7, getContentType());
\r
183 ps.setLong (8, getContentLength());
\r