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.apache.commons.lang3.StringUtils;
\r
34 import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;
\r
38 * The representation of a Publish Record, as retrieved from the DB.
\r
40 * @author Robert Eby
\r
41 * @version $Id: PublishRecord.java,v 1.6 2013/10/28 18:06:53 eby Exp $
\r
44 public class PublishRecord extends BaseLogRecord {
\r
46 public static final String STATUS_CODE = "statusCode";
\r
47 public static final String SOURCE_IP = "sourceIP";
\r
48 public static final String ENDPOINT_ID = "endpointId";
\r
49 public static final String FILE_NAME = "fileName";
\r
50 private String feedFileid;
\r
51 private String remoteAddr;
\r
52 private String user;
\r
54 private String fileName;
\r
57 * Publish record constructor.
\r
58 * @param pp string array of attributes
\r
59 * @throws ParseException in case of parse error
\r
61 public PublishRecord(String[] pp) throws ParseException {
\r
63 int ix = pp[4].indexOf("/publish/");
\r
65 throw new ParseException("bad pattern", 0);
\r
67 ix = pp[4].indexOf('/', ix + 9);
\r
69 throw new ParseException("bad pattern", 0);
\r
71 this.feedFileid = pp[4].substring(ix + 1);
\r
72 this.remoteAddr = pp[8];
\r
74 this.status = Integer.parseInt(pp[10]);
\r
75 this.fileName = StringUtils.substringAfterLast(this.getRequestUri(), "/");
\r
79 * Publish record constructor.
\r
80 * @param rs ResultSet from DB
\r
81 * @throws SQLException in case of SQL error
\r
83 public PublishRecord(ResultSet rs) throws SQLException {
\r
85 this.feedFileid = rs.getString("FEED_FILEID");
\r
86 this.remoteAddr = rs.getString("REMOTE_ADDR");
\r
87 this.user = rs.getString("USER");
\r
88 this.status = rs.getInt("STATUS");
\r
89 this.fileName = rs.getString("FILENAME");
\r
92 public String getFeedFileid() {
\r
96 public void setFeedFileid(String feedFileid) {
\r
97 this.feedFileid = feedFileid;
\r
100 public String getRemoteAddr() {
\r
104 public void setRemoteAddr(String remoteAddr) {
\r
105 this.remoteAddr = remoteAddr;
\r
108 public String getUser() {
\r
112 public void setUser(String user) {
\r
116 public int getStatus() {
\r
120 public void setStatus(int status) {
\r
121 this.status = status;
\r
124 public String getFileName() {
\r
128 public void setFileName(String fileName) {
\r
129 this.fileName = fileName;
\r
134 * Method to reorder json object.
\r
135 * @param jo LOGJSONObject
\r
136 * @return LOGJSONObject
\r
138 public LOGJSONObject reOrderObject(LOGJSONObject jo) {
\r
139 LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<>();
\r
142 logrecordObj.put(STATUS_CODE, jo.get(STATUS_CODE));
\r
143 logrecordObj.put("publishId", jo.get("publishId"));
\r
144 logrecordObj.put("requestURI", jo.get("requestURI"));
\r
145 logrecordObj.put(SOURCE_IP, jo.get(SOURCE_IP));
\r
146 logrecordObj.put("method", jo.get("method"));
\r
147 logrecordObj.put("contentType", jo.get("contentType"));
\r
148 logrecordObj.put(ENDPOINT_ID, jo.get(ENDPOINT_ID));
\r
149 logrecordObj.put("type", jo.get("type"));
\r
150 logrecordObj.put("date", jo.get("date"));
\r
151 logrecordObj.put("contentLength", jo.get("contentLength"));
\r
152 logrecordObj.put(FILE_NAME, jo.get(FILE_NAME));
\r
154 return new LOGJSONObject(logrecordObj);
\r
159 public LOGJSONObject asJSONObject() {
\r
160 LOGJSONObject jo = super.asJSONObject();
\r
161 jo.put("type", "pub");
\r
162 jo.put("feedFileid", feedFileid);
\r
163 jo.put("remoteAddr", remoteAddr);
\r
164 jo.put("user", user);
\r
165 jo.put(SOURCE_IP, remoteAddr);
\r
166 jo.put(ENDPOINT_ID, user);
\r
167 jo.put(STATUS_CODE, status);
\r
168 jo.put(FILE_NAME, fileName);
\r
170 return this.reOrderObject(jo);
\r
174 public void load(PreparedStatement ps) throws SQLException {
\r
175 ps.setString(1, "pub"); // field 1: type
\r
176 super.load(ps); // loads fields 2-8
\r
177 ps.setString(9, getFeedFileid());
\r
178 ps.setString(10, getRemoteAddr());
\r
179 ps.setString(11, getUser());
\r
180 ps.setInt(12, getStatus());
\r
181 ps.setNull(13, Types.INTEGER);
\r
182 ps.setNull(14, Types.VARCHAR);
\r
183 ps.setNull(15, Types.INTEGER);
\r
184 ps.setNull(16, Types.INTEGER);
\r
185 ps.setNull(17, Types.VARCHAR);
\r
186 ps.setNull(19, Types.BIGINT);
\r
187 ps.setString(20, getFileName());
\r