/rdf/AuditTrailRDF/src/com/rift/coad/rdf/objmapping/audit/LogEntry.java

https://github.com/brettchaldecott/dipforge · Java · 427 lines · 182 code · 63 blank · 182 comment · 8 complexity · aa5b5ddcd07d90ac73d6d2d0f58116a0 MD5 · raw file

  1. /*
  2. * AuditTrail: The audit trail log object.
  3. * Copyright (C) 2009 2015 Burntjam
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. * LogEntry.java
  20. */
  21. // package path
  22. package com.rift.coad.rdf.objmapping.audit;
  23. // java imports
  24. import java.util.Date;
  25. import java.net.InetAddress;
  26. import java.util.ArrayList;
  27. import java.util.List;
  28. // rdf imports
  29. import thewebsemantic.Namespace;
  30. import thewebsemantic.RdfType;
  31. import thewebsemantic.RdfProperty;
  32. import thewebsemantic.Identifier;
  33. // coadunation rdf imports
  34. import com.rift.coad.lib.common.RandomGuid;
  35. import com.rift.coad.rdf.objmapping.base.DataType;
  36. /**
  37. * This object represents an audit log entry.
  38. *
  39. * @author brett chaldecott
  40. */
  41. @Namespace("http://www.coadunation.net/schema/rdf/1.0/audit#")
  42. @RdfType("LogEntry")
  43. public class LogEntry extends DataType {
  44. /**
  45. * This enum represents the status of the log entry object.
  46. */
  47. public enum Status { COMPLETE, INFO, FAILURE, CRITICAL_FAILURE };
  48. // private member variables
  49. private String id;
  50. private String hostname;
  51. private String source;
  52. private String user;
  53. private Date time = new Date();
  54. private String status;
  55. private String correlationId = "";
  56. private String externalId = "";
  57. private String request;
  58. private List<DataType> associated = new ArrayList<DataType>();
  59. /**
  60. * The default constructor.
  61. */
  62. public LogEntry() {
  63. try {
  64. id = RandomGuid.getInstance().getGuid();
  65. } catch (Exception ex) {
  66. // ignore
  67. }
  68. try {
  69. this.hostname = InetAddress.getLocalHost().getHostName();
  70. } catch (Exception ex) {
  71. this.hostname = "Unknown";
  72. }
  73. }
  74. /**
  75. * This constructor sets all the relevant member variables.
  76. *
  77. * @param source The source name of the log entry.
  78. * @param status The status of the log entry.
  79. * @param user The name of the user.
  80. * @param correlationId The correlation id for the log entry.
  81. * @param externalId The external id for the the log entry.
  82. * @param request The request.
  83. */
  84. public LogEntry(String source, String status, String user,
  85. String correlationId, String externalId, String request) {
  86. try {
  87. id = RandomGuid.getInstance().getGuid();
  88. } catch (Exception ex) {
  89. // ignore
  90. }
  91. try {
  92. this.hostname = InetAddress.getLocalHost().getHostName();
  93. } catch (Exception ex) {
  94. this.hostname = "Unknown";
  95. }
  96. this.source = source;
  97. this.user = user;
  98. this.status = Status.valueOf(status).name();
  99. this.correlationId = correlationId;
  100. this.externalId = externalId;
  101. this.request = request;
  102. }
  103. /**
  104. * The constructor that sets all internal member variables.
  105. *
  106. * @param hostname The name of the host that the request came from.
  107. * @param source The string containing the source object information.
  108. * @param user The name of the user.
  109. * @param time The time the event occurred.
  110. * @param status The status of the event.
  111. * @param correlationId The correlation id to attache the log entries together.
  112. * @param externalId The external id.
  113. * @param request The request.
  114. */
  115. public LogEntry(String hostname, String source, String user, Date time,
  116. String status, String correlationId, String externalId, String request,
  117. List<DataType> associated) {
  118. try {
  119. id = RandomGuid.getInstance().getGuid();
  120. } catch (Exception ex) {
  121. // ignore
  122. }
  123. this.hostname = hostname;
  124. this.source = source;
  125. this.user = user;
  126. this.time = time;
  127. this.status = Status.valueOf(status).name();
  128. this.correlationId = correlationId;
  129. this.externalId = externalId;
  130. this.request = request;
  131. this.associated = associated;
  132. }
  133. /**
  134. * This method gets the id of the of the log entry.
  135. *
  136. * @return The string containing the audit id.
  137. */
  138. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#LogEntryId")
  139. @Identifier()
  140. public String getId() {
  141. return id;
  142. }
  143. /**
  144. * This method sets the id of the log entry.
  145. *
  146. * @param id The string containing the id of the log entry.
  147. */
  148. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#LogEntryId")
  149. public void setId(String id) {
  150. this.id = id;
  151. }
  152. /**
  153. * This method returns the correlation id.
  154. *
  155. * @return The correlation id.
  156. */
  157. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#CorrelationId")
  158. public String getCorrelationId() {
  159. return correlationId;
  160. }
  161. /**
  162. * This method sets the correlation id.
  163. *
  164. * @param correlationId The correlation id.
  165. */
  166. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#CorrelationId")
  167. public void setCorrelationId(String correlationId) {
  168. this.correlationId = correlationId;
  169. }
  170. /**
  171. * This method sets the external id.
  172. *
  173. * @return The external id.
  174. */
  175. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#ExternalId")
  176. public String getExternalId() {
  177. return externalId;
  178. }
  179. /**
  180. * This method sets the external id for the log entry.
  181. *
  182. * @param externalId The external id for the log entry.
  183. */
  184. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#ExternalId")
  185. public void setExternalId(String externalId) {
  186. this.externalId = externalId;
  187. }
  188. /**
  189. * This method returns the name of the host.
  190. *
  191. * @return The string containing the host name.
  192. */
  193. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#Hostname")
  194. public String getHostname() {
  195. return hostname;
  196. }
  197. /**
  198. * This method sets the name of the host
  199. *
  200. * @param hostname The string containing the host name.
  201. */
  202. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#Hostname")
  203. public void setHostname(String hostname) {
  204. this.hostname = hostname;
  205. }
  206. /**
  207. * The string containing the request information that is being logged.
  208. *
  209. * @return The string containing the log information.
  210. */
  211. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#Request")
  212. public String getRequest() {
  213. return request;
  214. }
  215. /**
  216. * This method sets the request information.
  217. *
  218. * @param request The string containing the request information.
  219. */
  220. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#Request")
  221. public void setRequest(String request) {
  222. this.request = request;
  223. }
  224. /**
  225. * The string containing the source information.
  226. *
  227. * @return This method returns the string containing the source information.
  228. */
  229. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#Source")
  230. public String getSource() {
  231. return source;
  232. }
  233. /**
  234. * This method sets the source information for this log object.
  235. *
  236. * @param source The string containing the source information.
  237. */
  238. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#Source")
  239. public void setSource(String source) {
  240. this.source = source;
  241. }
  242. /**
  243. * This method returns the status information.
  244. *
  245. * @return The status information.
  246. */
  247. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#Status")
  248. public String getStatus() {
  249. return status;
  250. }
  251. /**
  252. * This method sets the status of the log entry.
  253. *
  254. * @param status The status of the log entry.
  255. */
  256. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#Status")
  257. public void setStatus(String status) {
  258. this.status = Status.valueOf(status).name();
  259. }
  260. /**
  261. * This method retrieves the time for the audit entry.
  262. *
  263. * @return The time date object.
  264. */
  265. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#Time")
  266. public Date getTime() {
  267. return time;
  268. }
  269. /**
  270. * This method sets the time for the log event.
  271. *
  272. * @param time The object containing the time information
  273. */
  274. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#Time")
  275. public void setTime(Date time) {
  276. this.time = time;
  277. }
  278. /**
  279. * This method retrieves the user information for this log entry.
  280. *
  281. * @return The string containing the log entry.
  282. */
  283. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#User")
  284. public String getUser() {
  285. return user;
  286. }
  287. /**
  288. * This method sets the user information for the log.
  289. *
  290. * @param user The string containing the user information.
  291. */
  292. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#User")
  293. public void setUser(String user) {
  294. this.user = user;
  295. }
  296. /**
  297. * Theis method retrieves the objects associated with this audit trail event.
  298. *
  299. * @return The data object associaited with this.
  300. */
  301. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#Associated")
  302. public List<DataType> getAssociated() {
  303. return associated;
  304. }
  305. /**
  306. * This method sets the objects associated with this audit entry.
  307. *
  308. * @param associated The associated audit entry objects.
  309. */
  310. @RdfProperty("http://www.coadunation.net/schema/rdf/1.0/audit#Associated")
  311. public void setAssociated(List<DataType> associated) {
  312. this.associated = associated;
  313. }
  314. /**
  315. * This method performs an equals check on the log entry.
  316. *
  317. * @param obj The object to perform the equals check on.
  318. * @return The return result.
  319. */
  320. @Override
  321. public boolean equals(Object obj) {
  322. if (obj == null) {
  323. return false;
  324. }
  325. if (getClass() != obj.getClass()) {
  326. return false;
  327. }
  328. final LogEntry other = (LogEntry) obj;
  329. if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) {
  330. return false;
  331. }
  332. return true;
  333. }
  334. /**
  335. * This method returns the hash code for the log entry.
  336. *
  337. * @return The hash code for the log entry.
  338. */
  339. @Override
  340. public int hashCode() {
  341. int hash = 7;
  342. hash = 43 * hash + (this.id != null ? this.id.hashCode() : 0);
  343. return hash;
  344. }
  345. /**
  346. * This method returns the string representation of the entry.
  347. *
  348. * @return The string result for this log entry.
  349. */
  350. @Override
  351. public String toString() {
  352. return String.format("%s %s %s %s %s %s %s \"%s\" %s%n", hostname,source,user,time.toString(),
  353. status,correlationId,externalId,request, this.associated.toString());
  354. }
  355. /**
  356. * This method returns the id of this object.
  357. *
  358. * @return The string containing the id of this object.
  359. */
  360. @Override
  361. public String getObjId() {
  362. return this.id;
  363. }
  364. }