/Core/src/org/sleuthkit/autopsy/ingest/events/ContentChangedEvent.java

https://github.com/sleuthkit/autopsy · Java · 114 lines · 47 code · 10 blank · 57 comment · 2 complexity · c4b1576fe2d68d3cf9aaffeb58bee270 MD5 · raw file

  1. /*
  2. * Autopsy Forensic Browser
  3. *
  4. * Copyright 2011-2018 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.events;
  20. import java.io.Serializable;
  21. import java.util.logging.Level;
  22. import org.sleuthkit.autopsy.casemodule.Case;
  23. import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
  24. import org.sleuthkit.autopsy.coreutils.Logger;
  25. import org.sleuthkit.autopsy.events.AutopsyEvent;
  26. import org.sleuthkit.autopsy.ingest.IngestManager;
  27. import org.sleuthkit.autopsy.ingest.ModuleContentEvent;
  28. import org.sleuthkit.datamodel.Content;
  29. import org.sleuthkit.datamodel.TskCoreException;
  30. /**
  31. * Event published when new content is added to a case or there is a change a
  32. * recorded attribute of existing content. For example, a content changed event
  33. * should be published when an analysis (ingest) module adds an extracted or
  34. * carved file to a case. The "old" value is a legacy ModuleContentEvent object.
  35. * The "new" value is null.
  36. */
  37. public final class ContentChangedEvent extends AutopsyEvent implements Serializable {
  38. private static final long serialVersionUID = 1L;
  39. private static final Logger logger = Logger.getLogger(ContentChangedEvent.class.getName());
  40. private transient ModuleContentEvent eventData;
  41. /**
  42. * Constructs a event to be published when new content is added to a case or
  43. * there is a change a recorded attribute of existing content.
  44. *
  45. * @param eventData A ModuleContentEvent object containing the data
  46. * associated with the content addition or change.
  47. */
  48. public ContentChangedEvent(ModuleContentEvent eventData) {
  49. /**
  50. * Putting a serializable data holding object into newValue to allow for
  51. * lazy loading of the ModuleContent object. This bypasses the issues
  52. * related to the serialization and de-serialization of Content objects
  53. * when the event is published over a network.
  54. */
  55. super(
  56. IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString(),
  57. new SerializableEventData(eventData.getModuleName(), ((Content) eventData.getSource()).getId()),
  58. null
  59. );
  60. }
  61. /**
  62. * Gets the legacy ModuleContentEvent object associated with this event.
  63. * Note that the content object that was added or changed can be accessed
  64. * via the getSource() method of the ModuleContentEvent.
  65. *
  66. * @return The ModuleContentEvent.
  67. */
  68. @Override
  69. public Object getOldValue() {
  70. /**
  71. * The eventData field is set in the constructor, but it is transient so
  72. * it will become null when the event is serialized for publication over
  73. * a network. Doing a lazy load of the ModuleContentEvent object
  74. * bypasses the issues related to the serialization and de-serialization
  75. * of Content objects and may also save database round trips from other
  76. * nodes since subscribers to this event are often not interested in the
  77. * event data.
  78. */
  79. if (null != eventData) {
  80. return eventData;
  81. }
  82. try {
  83. SerializableEventData data = (SerializableEventData) super.getOldValue();
  84. Content content = Case.getCurrentCaseThrows().getSleuthkitCase().getContentById(data.contentId);
  85. eventData = new ModuleContentEvent(data.moduleName, content);
  86. return eventData;
  87. } catch (NoCurrentCaseException | TskCoreException ex) {
  88. logger.log(Level.SEVERE, "Error doing lazy load for remote event", ex); //NON-NLS
  89. return null;
  90. }
  91. }
  92. /**
  93. * Data holder class.
  94. */
  95. private static final class SerializableEventData implements Serializable {
  96. private static final long serialVersionUID = 1L;
  97. private final String moduleName;
  98. private final long contentId;
  99. private SerializableEventData(String moduleName, long contentId) {
  100. this.moduleName = moduleName;
  101. this.contentId = contentId;
  102. }
  103. }
  104. }