X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdatarouter.git;a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Fbeans%2FBaseLogRecord.java;h=8cb4c1534cc5909f794ed44177adff32fbf30da9;hp=8534bc035c1cd7fe058d119f55d01eeb504c19f9;hb=bc1df610cddfb558cf6bde90c269b4af59768648;hpb=a60d80ff7bfae8a152c950486d9a1877628e13a4 diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/BaseLogRecord.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/BaseLogRecord.java index 8534bc03..8cb4c153 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/BaseLogRecord.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/BaseLogRecord.java @@ -53,13 +53,9 @@ public class BaseLogRecord implements LOGJSONable, Loadable { private long contentLength; protected BaseLogRecord(String[] pp) throws ParseException { -// This throws exceptions occasionally - don't know why. -// Date d = null; -// synchronized (sdf) { -// d = sdf.parse(pp[0]); -// } - Date d = parseDate(pp[0]); - this.eventTime = d.getTime(); + + Date dt = parseDate(pp[0]); + this.eventTime = dt.getTime(); this.publishId = pp[2]; this.feedid = Integer.parseInt(pp[3]); if (pp[1].equals("DLX")) { @@ -79,6 +75,7 @@ public class BaseLogRecord implements LOGJSONable, Loadable { this.contentLength = Long.parseLong(pp[8]); } } + protected BaseLogRecord(ResultSet rs) throws SQLException { this.eventTime = rs.getLong("EVENT_TIME"); this.publishId = rs.getString("PUBLISH_ID"); @@ -88,81 +85,99 @@ public class BaseLogRecord implements LOGJSONable, Loadable { this.contentType = rs.getString("CONTENT_TYPE"); this.contentLength = rs.getLong("CONTENT_LENGTH"); } - protected Date parseDate(final String s) throws ParseException { - int[] n = new int[7]; - int p = 0; - for (int i = 0; i < s.length(); i++) { - char c = s.charAt(i); - if (c < '0' || c > '9') { - p++; + + protected Date parseDate(final String str) throws ParseException { + int[] num = new int[7]; + int place = 0; + for (int i = 0; i < str.length(); i++) { + char chr = str.charAt(i); + if (chr < '0' || chr > '9') { + place++; } else { - if (p > n.length) + if (place > num.length) { throw new ParseException("parseDate()", 0); - n[p] = (n[p] * 10) + (c - '0'); + } + num[place] = (num[place] * 10) + (chr - '0'); } } - if (p != 7) + if (place != 7) { throw new ParseException("parseDate()", 1); + } Calendar cal = new GregorianCalendar(); - cal.set(Calendar.YEAR, n[0]); - cal.set(Calendar.MONTH, n[1]-1); - cal.set(Calendar.DAY_OF_MONTH, n[2]); - cal.set(Calendar.HOUR_OF_DAY, n[3]); - cal.set(Calendar.MINUTE, n[4]); - cal.set(Calendar.SECOND, n[5]); - cal.set(Calendar.MILLISECOND, n[6]); + cal.set(Calendar.YEAR, num[0]); + cal.set(Calendar.MONTH, num[1] - 1); + cal.set(Calendar.DAY_OF_MONTH, num[2]); + cal.set(Calendar.HOUR_OF_DAY, num[3]); + cal.set(Calendar.MINUTE, num[4]); + cal.set(Calendar.SECOND, num[5]); + cal.set(Calendar.MILLISECOND, num[6]); return cal.getTime(); } + public long getEventTime() { return eventTime; } + public void setEventTime(long eventTime) { this.eventTime = eventTime; } + public String getPublishId() { return publishId; } + public void setPublishId(String publishId) { this.publishId = publishId; } + public int getFeedid() { return feedid; } + public void setFeedid(int feedid) { this.feedid = feedid; } + public String getRequestUri() { return requestUri; } + public void setRequestUri(String requestUri) { this.requestUri = requestUri; } + public String getMethod() { return method; } + public void setMethod(String method) { this.method = method; } + public String getContentType() { return contentType; } + public void setContentType(String contentType) { this.contentType = contentType; } + public long getContentLength() { return contentLength; } + public void setContentLength(long contentLength) { this.contentLength = contentLength; } + @Override public LOGJSONObject asJSONObject() { LOGJSONObject jo = new LOGJSONObject(); - String t = ""; + String str = ""; synchronized (sdf) { - t = sdf.format(eventTime); + str = sdf.format(eventTime); } - jo.put("date", t); + jo.put("date", str); jo.put("publishId", publishId); jo.put("requestURI", requestUri); jo.put("method", method); @@ -172,14 +187,16 @@ public class BaseLogRecord implements LOGJSONable, Loadable { } return jo; } + @Override public void load(PreparedStatement ps) throws SQLException { - ps.setLong (2, getEventTime()); + ps.setLong(2, getEventTime()); ps.setString(3, getPublishId()); - ps.setInt (4, getFeedid()); + ps.setInt(4, getFeedid()); ps.setString(5, getRequestUri()); ps.setString(6, getMethod()); ps.setString(7, getContentType()); - ps.setLong (8, getContentLength()); + ps.setLong(8, getContentLength()); } } +