Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestMessage.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.ingest;
20 
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
23 import java.util.concurrent.atomic.AtomicLong;
24 import org.openide.util.NbBundle;
26 
33 public class IngestMessage {
34 
38  public enum MessageType {
39  DATA, INFO, WARNING, ERROR
40  };
41 
42  private long ID;
44  private String source;
45  private String subject;
46  private String detailsHtml;
47  private String uniqueKey;
49  private Date datePosted;
50  private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
51  private static int managerMessageId = 0;
52  private static AtomicLong nextMessageID = new AtomicLong(0);
53 
57  private IngestMessage(long ID, MessageType messageType, String source, String subject, String detailsHtml, String uniqueKey) {
58  this.ID = ID;
59  this.source = source;
60  this.messageType = messageType;
61  this.subject = subject;
62  this.detailsHtml = detailsHtml;
63  if (uniqueKey == null)
64  this.uniqueKey = "";
65  else this.uniqueKey = uniqueKey;
66  datePosted = new Date();
67  }
68 
69  //getters
70  public long getID() {
71  return ID;
72  }
73 
74  public String getSource() {
75  return source;
76  }
77 
78  public String getSubject() {
79  return subject;
80  }
81 
82  public String getDetails() {
83  return detailsHtml;
84  }
85 
86  public String getUniqueKey() {
87  return uniqueKey;
88  }
89 
91  return data;
92  }
93 
95  return messageType;
96  }
97 
98  public Date getDatePosted() {
99  return datePosted;
100  }
101 
102  @Override
103  public String toString() {
104  StringBuilder sb = new StringBuilder();
105  sb.append(Long.toString(ID)).append(": ");
106  sb.append(NbBundle.getMessage(this.getClass(), "IngestMessage.toString.type.text", messageType.name()));
107  if (source != null) //can be null for manager messages
108  {
109  sb.append(source);
110  }
111  sb.append(
112  NbBundle.getMessage(this.getClass(), "IngestMessage.toString.date.text", dateFormat.format(datePosted)));
113  sb.append(NbBundle.getMessage(this.getClass(), "IngestMessage.toString.subject.text", subject));
114  if (detailsHtml != null) {
115  sb.append(NbBundle.getMessage(this.getClass(), "IngestMessage.toString.details.text", detailsHtml));
116  }
117  if (data != null) {
118  sb.append(NbBundle.getMessage(this.getClass(), "IngestMessage.toString.data.text", data.toString()));
119  }
120  return sb.toString();
121  }
122 
123  @Override
124  public boolean equals(Object obj) {
125  if (obj == null) {
126  return false;
127  }
128  if (getClass() != obj.getClass()) {
129  return false;
130  }
131  final IngestMessage other = (IngestMessage) obj;
132  if (this.ID != other.ID) {
133  return false;
134  }
135  if (this.messageType != other.messageType) {
136  return false;
137  }
138  if (this.source != other.source && (this.source == null || !this.source.equals(other.source))) {
139  return false;
140  }
141  if ((this.subject == null) ? (other.subject != null) : !this.subject.equals(other.subject)) {
142  return false;
143  }
144  if ((this.detailsHtml == null) ? (other.detailsHtml != null) : !this.detailsHtml.equals(other.detailsHtml)) {
145  return false;
146  }
147  if ((this.uniqueKey == null) ? (other.uniqueKey != null) : !this.uniqueKey.equals(other.uniqueKey)) {
148  return false;
149  }
150  if (this.data != other.data && (this.data == null || !this.data.equals(other.data))) {
151  return false;
152  }
153  return true;
154  }
155 
156  @Override
157  public int hashCode() {
158  int hash = 7;
159  hash = 59 * hash + (int) (this.ID ^ (this.ID >>> 32));
160  hash = 59 * hash + (this.messageType != null ? this.messageType.hashCode() : 0);
161  hash = 59 * hash + (this.source != null ? this.source.hashCode() : 0);
162  hash = 59 * hash + (this.subject != null ? this.subject.hashCode() : 0);
163  hash = 59 * hash + (this.detailsHtml != null ? this.detailsHtml.hashCode() : 0);
164  hash = 59 * hash + (this.uniqueKey != null ? this.uniqueKey.hashCode() : 0);
165  hash = 59 * hash + (this.data != null ? this.data.hashCode() : 0);
166  return hash;
167  }
168 
169  //factory methods
170 
180  public static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml) {
181  if (messageType == null || source == null || subject == null) {
182  throw new IllegalArgumentException(
183  NbBundle.getMessage(IngestMessage.class, "IngestMessage.exception.typeSrcSubjNotNull.msg"));
184  }
185  long ID = nextMessageID.getAndIncrement();
186  return new IngestMessage(ID, messageType, source, subject, detailsHtml, null);
187  }
188 
197  public static IngestMessage createMessage(MessageType messageType, String source, String subject) {
198  return createMessage(messageType, source, subject, null);
199  }
200 
201 
210  public static IngestMessage createErrorMessage(String source, String subject, String detailsHtml) {
211  if (source == null || subject == null) {
212  throw new IllegalArgumentException(
213  NbBundle.getMessage(IngestMessage.class, "IngestMessage.exception.srcSubjNotNull.msg"));
214  }
215  long ID = nextMessageID.getAndIncrement();
216  return new IngestMessage(ID, MessageType.ERROR, source, subject, detailsHtml, null);
217  }
218 
227  public static IngestMessage createWarningMessage(String source, String subject, String detailsHtml) {
228  if (source == null || subject == null) {
229  throw new IllegalArgumentException(
230  NbBundle.getMessage(IngestMessage.class, "IngestMessage.exception.srcSubjNotNull.msg"));
231  }
232  long ID = nextMessageID.getAndIncrement();
233  return new IngestMessage(ID, MessageType.WARNING, source, subject, detailsHtml, null);
234  }
235 
246  public static IngestMessage createDataMessage(String source, String subject, String detailsHtml, String uniqueKey, BlackboardArtifact data) {
247  if (source == null || subject == null || detailsHtml == null || data == null) {
248  throw new IllegalArgumentException(
249  NbBundle.getMessage(IngestMessage.class, "IngestMessage.exception.srcSubjDetailsDataNotNull.msg"));
250  }
251 
252  long ID = nextMessageID.getAndIncrement();
253  IngestMessage im = new IngestMessage(ID, MessageType.DATA, source, subject, detailsHtml, uniqueKey);
254  im.data = data;
255  return im;
256  }
257 
264  static IngestMessage createManagerMessage(String subject, String detailsHtml) {
265  return new IngestMessage(++managerMessageId, MessageType.INFO, null, subject, detailsHtml, null);
266  }
267 
271  static IngestMessage createManagerErrorMessage(String subject, String detailsHtml) {
272  return new IngestMessage(++managerMessageId, MessageType.ERROR, null, subject, detailsHtml, null);
273  }
274 }
static IngestMessage createDataMessage(String source, String subject, String detailsHtml, String uniqueKey, BlackboardArtifact data)
static IngestMessage createErrorMessage(String source, String subject, String detailsHtml)
static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml)
IngestMessage(long ID, MessageType messageType, String source, String subject, String detailsHtml, String uniqueKey)
static IngestMessage createMessage(MessageType messageType, String source, String subject)
static IngestMessage createWarningMessage(String source, String subject, String detailsHtml)

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.