X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Fbeans%2FPublishRecord.java;h=2cde3971626c74295d1b7536706e7ce5ae69d955;hb=5da50e90e6c78700d48d7468849d4a1599a249b3;hp=74a97cccbadb74e4eb61ef6ea1819d50c7e8b988;hpb=070b01cc6eb66cec5c8131b2f3d6f2d50879754f;p=dmaap%2Fdatarouter.git diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PublishRecord.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PublishRecord.java index 74a97ccc..2cde3971 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PublishRecord.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PublishRecord.java @@ -7,9 +7,9 @@ * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at - * * + * * * * http://www.apache.org/licenses/LICENSE-2.0 - * * + * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,125 +30,135 @@ import java.sql.Types; import java.text.ParseException; import java.util.LinkedHashMap; +import org.apache.commons.lang3.StringUtils; import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject; /** * The representation of a Publish Record, as retrieved from the DB. + * * @author Robert Eby * @version $Id: PublishRecord.java,v 1.6 2013/10/28 18:06:53 eby Exp $ */ public class PublishRecord extends BaseLogRecord { - private String feedFileid; - private String remoteAddr; - private String user; - private int status; - - public PublishRecord(String[] pp) throws ParseException { - super(pp); -// This is too slow! -// Matcher m = Pattern.compile(".*/publish/(\\d+)/(.*)$").matcher(pp[4]); -// if (!m.matches()) -// throw new ParseException("bad pattern", 0); -// this.feedFileid = m.group(2); - int ix = pp[4].indexOf("/publish/"); - if (ix < 0) - throw new ParseException("bad pattern", 0); - ix = pp[4].indexOf('/', ix+9); - if (ix < 0) - throw new ParseException("bad pattern", 0); - this.feedFileid = pp[4].substring(ix+1); - this.remoteAddr = pp[8]; - this.user = pp[9]; - this.status = Integer.parseInt(pp[10]); - } - public PublishRecord(ResultSet rs) throws SQLException { - super(rs); - this.feedFileid = rs.getString("FEED_FILEID"); - this.remoteAddr = rs.getString("REMOTE_ADDR"); - this.user = rs.getString("USER"); - this.status = rs.getInt("STATUS"); - } - public String getFeedFileid() { - return feedFileid; - } - - public void setFeedFileid(String feedFileid) { - this.feedFileid = feedFileid; - } - - public String getRemoteAddr() { - return remoteAddr; - } - - public void setRemoteAddr(String remoteAddr) { - this.remoteAddr = remoteAddr; - } - - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - } - - public int getStatus() { - return status; - } - - public void setStatus(int status) { - this.status = status; - } - - - public LOGJSONObject reOrderObject(LOGJSONObject jo) { - LinkedHashMap logrecordObj = new LinkedHashMap(); - - - logrecordObj.put("statusCode", jo.get("statusCode")); - logrecordObj.put("publishId", jo.get("publishId")); - logrecordObj.put("requestURI", jo.get("requestURI")); - logrecordObj.put("sourceIP", jo.get("sourceIP")); - logrecordObj.put("method", jo.get("method")); - logrecordObj.put("contentType", jo.get("contentType")); - logrecordObj.put("endpointId", jo.get("endpointId")); - logrecordObj.put("type", jo.get("type")); - logrecordObj.put("date", jo.get("date")); - logrecordObj.put("contentLength", jo.get("contentLength")); - - LOGJSONObject newjo = new LOGJSONObject(logrecordObj); - return newjo; - } - - @Override - public LOGJSONObject asJSONObject() { - LOGJSONObject jo = super.asJSONObject(); - jo.put("type", "pub"); -// jo.put("feedFileid", feedFileid); -// jo.put("remoteAddr", remoteAddr); -// jo.put("user", user); - jo.put("sourceIP", remoteAddr); - jo.put("endpointId", user); - jo.put("statusCode", status); - - LOGJSONObject newjo = this.reOrderObject(jo); - - return newjo; - } - @Override - public void load(PreparedStatement ps) throws SQLException { - ps.setString(1, "pub"); // field 1: type - super.load(ps); // loads fields 2-8 - ps.setString( 9, getFeedFileid()); - ps.setString(10, getRemoteAddr()); - ps.setString(11, getUser()); - ps.setInt (12, getStatus()); - ps.setNull (13, Types.INTEGER); - ps.setNull (14, Types.VARCHAR); - ps.setNull (15, Types.INTEGER); - ps.setNull (16, Types.INTEGER); - ps.setNull (17, Types.VARCHAR); - ps.setNull (19, Types.BIGINT); - } + private String feedFileid; + private String remoteAddr; + private String user; + private int status; + private String fileName; + + public PublishRecord(String[] pp) throws ParseException { + super(pp); + int ix = pp[4].indexOf("/publish/"); + if (ix < 0) + throw new ParseException("bad pattern", 0); + ix = pp[4].indexOf('/', ix + 9); + if (ix < 0) + throw new ParseException("bad pattern", 0); + this.feedFileid = pp[4].substring(ix + 1); + this.remoteAddr = pp[8]; + this.user = pp[9]; + this.status = Integer.parseInt(pp[10]); + this.fileName = StringUtils.substringAfterLast(this.getRequestUri(), "/"); + } + + public PublishRecord(ResultSet rs) throws SQLException { + super(rs); + this.feedFileid = rs.getString("FEED_FILEID"); + this.remoteAddr = rs.getString("REMOTE_ADDR"); + this.user = rs.getString("USER"); + this.status = rs.getInt("STATUS"); + this.fileName = StringUtils.substringAfterLast(this.getRequestUri(), "/"); + } + + public String getFeedFileid() { + return feedFileid; + } + + public void setFeedFileid(String feedFileid) { + this.feedFileid = feedFileid; + } + + public String getRemoteAddr() { + return remoteAddr; + } + + public void setRemoteAddr(String remoteAddr) { + this.remoteAddr = remoteAddr; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getFileName() { return fileName;} + + public void setFileName(String fileName) { this.fileName = fileName; } + + + public LOGJSONObject reOrderObject(LOGJSONObject jo) { + LinkedHashMap logrecordObj = new LinkedHashMap(); + + + logrecordObj.put("statusCode", jo.get("statusCode")); + logrecordObj.put("publishId", jo.get("publishId")); + logrecordObj.put("requestURI", jo.get("requestURI")); + logrecordObj.put("sourceIP", jo.get("sourceIP")); + logrecordObj.put("method", jo.get("method")); + logrecordObj.put("contentType", jo.get("contentType")); + logrecordObj.put("endpointId", jo.get("endpointId")); + logrecordObj.put("type", jo.get("type")); + logrecordObj.put("date", jo.get("date")); + logrecordObj.put("contentLength", jo.get("contentLength")); + logrecordObj.put("fileName", jo.get("fileName")); + + LOGJSONObject newjo = new LOGJSONObject(logrecordObj); + return newjo; + } + + @Override + public LOGJSONObject asJSONObject() { + LOGJSONObject jo = super.asJSONObject(); + jo.put("type", "pub"); + jo.put("feedFileid", feedFileid); + jo.put("remoteAddr", remoteAddr); + jo.put("user", user); + jo.put("sourceIP", remoteAddr); + jo.put("endpointId", user); + jo.put("statusCode", status); + jo.put("fileName", fileName); + + LOGJSONObject newjo = this.reOrderObject(jo); + + return newjo; + } + + @Override + public void load(PreparedStatement ps) throws SQLException { + ps.setString(1, "pub"); // field 1: type + super.load(ps); // loads fields 2-8 + ps.setString(9, getFeedFileid()); + ps.setString(10, getRemoteAddr()); + ps.setString(11, getUser()); + ps.setInt(12, getStatus()); + ps.setNull(13, Types.INTEGER); + ps.setNull(14, Types.VARCHAR); + ps.setNull(15, Types.INTEGER); + ps.setNull(16, Types.INTEGER); + ps.setNull(17, Types.VARCHAR); + ps.setNull(19, Types.BIGINT); + ps.setString(20, getFileName()); + } }