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
57 Date dt = parseDate(pp[0]);
\r
58 this.eventTime = dt.getTime();
\r
59 this.publishId = pp[2];
\r
60 this.feedid = Integer.parseInt(pp[3]);
\r
61 if (pp[1].equals("DLX")) {
\r
62 this.requestUri = "";
\r
63 this.method = "GET"; // Note: we need a valid value in this field, even though unused
\r
64 this.contentType = "";
\r
65 this.contentLength = Long.parseLong(pp[5]);
\r
66 } else if (pp[1].equals("PUB") || pp[1].equals("LOG") || pp[1].equals("PBF")) {
\r
67 this.requestUri = pp[4];
\r
68 this.method = pp[5];
\r
69 this.contentType = pp[6];
\r
70 this.contentLength = Long.parseLong(pp[7]);
\r
72 this.requestUri = pp[5];
\r
73 this.method = pp[6];
\r
74 this.contentType = pp[7];
\r
75 this.contentLength = Long.parseLong(pp[8]);
\r
79 protected BaseLogRecord(ResultSet rs) throws SQLException {
\r
80 this.eventTime = rs.getLong("EVENT_TIME");
\r
81 this.publishId = rs.getString("PUBLISH_ID");
\r
82 this.feedid = rs.getInt("FEEDID");
\r
83 this.requestUri = rs.getString("REQURI");
\r
84 this.method = rs.getString("METHOD");
\r
85 this.contentType = rs.getString("CONTENT_TYPE");
\r
86 this.contentLength = rs.getLong("CONTENT_LENGTH");
\r
89 protected Date parseDate(final String str) throws ParseException {
\r
90 int[] num = new int[7];
\r
92 for (int i = 0; i < str.length(); i++) {
\r
93 char chr = str.charAt(i);
\r
94 if (chr < '0' || chr > '9') {
\r
97 if (place > num.length) {
\r
98 throw new ParseException("parseDate()", 0);
\r
100 num[place] = (num[place] * 10) + (chr - '0');
\r
104 throw new ParseException("parseDate()", 1);
\r
106 Calendar cal = new GregorianCalendar();
\r
107 cal.set(Calendar.YEAR, num[0]);
\r
108 cal.set(Calendar.MONTH, num[1] - 1);
\r
109 cal.set(Calendar.DAY_OF_MONTH, num[2]);
\r
110 cal.set(Calendar.HOUR_OF_DAY, num[3]);
\r
111 cal.set(Calendar.MINUTE, num[4]);
\r
112 cal.set(Calendar.SECOND, num[5]);
\r
113 cal.set(Calendar.MILLISECOND, num[6]);
\r
114 return cal.getTime();
\r
117 public long getEventTime() {
\r
121 public void setEventTime(long eventTime) {
\r
122 this.eventTime = eventTime;
\r
125 public String getPublishId() {
\r
129 public void setPublishId(String publishId) {
\r
130 this.publishId = publishId;
\r
133 public int getFeedid() {
\r
137 public void setFeedid(int feedid) {
\r
138 this.feedid = feedid;
\r
141 public String getRequestUri() {
\r
145 public void setRequestUri(String requestUri) {
\r
146 this.requestUri = requestUri;
\r
149 public String getMethod() {
\r
153 public void setMethod(String method) {
\r
154 this.method = method;
\r
157 public String getContentType() {
\r
158 return contentType;
\r
161 public void setContentType(String contentType) {
\r
162 this.contentType = contentType;
\r
165 public long getContentLength() {
\r
166 return contentLength;
\r
169 public void setContentLength(long contentLength) {
\r
170 this.contentLength = contentLength;
\r
174 public LOGJSONObject asJSONObject() {
\r
175 LOGJSONObject jo = new LOGJSONObject();
\r
177 synchronized (sdf) {
\r
178 str = sdf.format(eventTime);
\r
180 jo.put("date", str);
\r
181 jo.put("publishId", publishId);
\r
182 jo.put("requestURI", requestUri);
\r
183 jo.put("method", method);
\r
184 if (method.equals("PUT")) {
\r
185 jo.put("contentType", contentType);
\r
186 jo.put("contentLength", contentLength);
\r
192 public void load(PreparedStatement ps) throws SQLException {
\r
193 ps.setLong(2, getEventTime());
\r
194 ps.setString(3, getPublishId());
\r
195 ps.setInt(4, getFeedid());
\r
196 ps.setString(5, getRequestUri());
\r
197 ps.setString(6, getMethod());
\r
198 ps.setString(7, getContentType());
\r
199 ps.setLong(8, getContentLength());
\r