Autopsy  4.9.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-2016 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;
25 import org.sleuthkit.datamodel.BlackboardArtifact;
26 
32 public class IngestMessage {
33 
37  public enum MessageType {
38 
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;
48  private BlackboardArtifact data;
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 {
66  this.uniqueKey = uniqueKey;
67  }
68  datePosted = new Date();
69  }
70 
71  //getters
72  public long getID() {
73  return ID;
74  }
75 
76  public String getSource() {
77  return source;
78  }
79 
80  public String getSubject() {
81  return subject;
82  }
83 
84  public String getDetails() {
85  return detailsHtml;
86  }
87 
88  public String getUniqueKey() {
89  return uniqueKey;
90  }
91 
92  public BlackboardArtifact getData() {
93  return data;
94  }
95 
97  return messageType;
98  }
99 
100  public Date getDatePosted() {
101  return datePosted;
102  }
103 
104  @Override
105  public String toString() {
106  StringBuilder sb = new StringBuilder();
107  sb.append(Long.toString(ID)).append(": ");
108  sb.append(NbBundle.getMessage(this.getClass(), "IngestMessage.toString.type.text", messageType.name()));
109  if (source != null) //can be null for manager messages
110  {
111  sb.append(source);
112  }
113  sb.append(
114  NbBundle.getMessage(this.getClass(), "IngestMessage.toString.date.text", dateFormat.format(datePosted)));
115  sb.append(NbBundle.getMessage(this.getClass(), "IngestMessage.toString.subject.text", subject));
116  if (detailsHtml != null) {
117  sb.append(NbBundle.getMessage(this.getClass(), "IngestMessage.toString.details.text", detailsHtml));
118  }
119  if (data != null) {
120  sb.append(NbBundle.getMessage(this.getClass(), "IngestMessage.toString.data.text", data.toString()));
121  }
122  return sb.toString();
123  }
124 
125  @Override
126  public boolean equals(Object obj) {
127  if (obj == null) {
128  return false;
129  }
130  if (getClass() != obj.getClass()) {
131  return false;
132  }
133  final IngestMessage other = (IngestMessage) obj;
134  if (this.ID != other.ID) {
135  return false;
136  }
137  if (this.messageType != other.messageType) {
138  return false;
139  }
140  if (this.source != other.source && (this.source == null || !this.source.equals(other.source))) {
141  return false;
142  }
143  if ((this.subject == null) ? (other.subject != null) : !this.subject.equals(other.subject)) {
144  return false;
145  }
146  if ((this.detailsHtml == null) ? (other.detailsHtml != null) : !this.detailsHtml.equals(other.detailsHtml)) {
147  return false;
148  }
149  if ((this.uniqueKey == null) ? (other.uniqueKey != null) : !this.uniqueKey.equals(other.uniqueKey)) {
150  return false;
151  }
152  if (this.data != other.data && (this.data == null || !this.data.equals(other.data))) {
153  return false;
154  }
155  return true;
156  }
157 
158  @Override
159  public int hashCode() {
160  int hash = 7;
161  hash = 59 * hash + (int) (this.ID ^ (this.ID >>> 32));
162  hash = 59 * hash + (this.messageType != null ? this.messageType.hashCode() : 0);
163  hash = 59 * hash + (this.source != null ? this.source.hashCode() : 0);
164  hash = 59 * hash + (this.subject != null ? this.subject.hashCode() : 0);
165  hash = 59 * hash + (this.detailsHtml != null ? this.detailsHtml.hashCode() : 0);
166  hash = 59 * hash + (this.uniqueKey != null ? this.uniqueKey.hashCode() : 0);
167  hash = 59 * hash + (this.data != null ? this.data.hashCode() : 0);
168  return hash;
169  }
170 
183  public static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml) {
184  if (messageType == null || source == null || subject == null) {
185  throw new IllegalArgumentException(
186  NbBundle.getMessage(IngestMessage.class, "IngestMessage.exception.typeSrcSubjNotNull.msg"));
187  }
188  long ID = nextMessageID.getAndIncrement();
189  return new IngestMessage(ID, messageType, source, subject, detailsHtml, null);
190  }
191 
201  public static IngestMessage createMessage(MessageType messageType, String source, String subject) {
202  return createMessage(messageType, source, subject, null);
203  }
204 
216  public static IngestMessage createErrorMessage(String source, String subject, String detailsHtml) {
217  if (source == null || subject == null) {
218  throw new IllegalArgumentException(
219  NbBundle.getMessage(IngestMessage.class, "IngestMessage.exception.srcSubjNotNull.msg"));
220  }
221  long ID = nextMessageID.getAndIncrement();
222  return new IngestMessage(ID, MessageType.ERROR, source, subject, detailsHtml, null);
223  }
224 
236  public static IngestMessage createWarningMessage(String source, String subject, String detailsHtml) {
237  if (source == null || subject == null) {
238  throw new IllegalArgumentException(
239  NbBundle.getMessage(IngestMessage.class, "IngestMessage.exception.srcSubjNotNull.msg"));
240  }
241  long ID = nextMessageID.getAndIncrement();
242  return new IngestMessage(ID, MessageType.WARNING, source, subject, detailsHtml, null);
243  }
244 
261  public static IngestMessage createDataMessage(String source, String subject, String detailsHtml, String uniqueKey, BlackboardArtifact data) {
262  if (source == null || subject == null || detailsHtml == null || data == null) {
263  throw new IllegalArgumentException(
264  NbBundle.getMessage(IngestMessage.class, "IngestMessage.exception.srcSubjDetailsDataNotNull.msg"));
265  }
266 
267  long ID = nextMessageID.getAndIncrement();
268  IngestMessage im = new IngestMessage(ID, MessageType.DATA, source, subject, detailsHtml, uniqueKey);
269  im.data = data;
270  return im;
271  }
272 
282  static IngestMessage createManagerMessage(String subject, String detailsHtml) {
283  return new IngestMessage(++managerMessageId, MessageType.INFO, null, subject, detailsHtml, null);
284  }
285 
289  static IngestMessage createManagerErrorMessage(String subject, String detailsHtml) {
290  return new IngestMessage(++managerMessageId, MessageType.ERROR, null, subject, detailsHtml, null);
291  }
292 }
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-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.