diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index b2790bd8ec..06809bffa8 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -432,7 +432,7 @@ public class Case { * OSAccount associated with the current case added. Call getOsAccount * to get the added account; */ - OS_ACCOUNT_ADDED, + OS_ACCOUNTS_ADDED, /** * OSAccount associated with the current case has changed. Call * getOsAccount to get the changed account; @@ -441,7 +441,7 @@ public class Case { /** * OSAccount associated with the current case has been deleted. */ - OS_ACCOUNT_REMOVED, + OS_ACCOUNTS_DELETED, /** * Hosts associated with the current case added. */ @@ -449,7 +449,7 @@ public class Case { /** * Hosts associated with the current case has changed. */ - HOSTS_CHANGED, + HOSTS_UPDATED, /** * Hosts associated with the current case has been deleted. */ @@ -461,11 +461,20 @@ public class Case { /** * Persons associated with the current case has changed. */ - PERSONS_CHANGED, + PERSONS_UPDATED, /** * Persons associated with the current case has been deleted. */ - PERSONS_DELETED; + PERSONS_DELETED, + /** + * Hosts have been added to a person. + */ + HOSTS_ADDED_TO_PERSON, + /** + * Hosts have been removed from a person. + */ + HOSTS_REMOVED_FROM_PERSON; + }; /** @@ -511,7 +520,7 @@ public class Case { @Subscribe public void publishOsAccountsDeletedEvent(TskEvent.OsAccountsDeletedTskEvent event) { - eventPublisher.publish(new OsAccountsDeletedEvent(event.getObjectIds())); + eventPublisher.publish(new OsAccountsDeletedEvent(event.getOsAccountObjectIds())); } /** @@ -544,7 +553,7 @@ public class Case { */ @Subscribe public void publishHostsDeletedEvent(TskEvent.HostsDeletedTskEvent event) { - eventPublisher.publish(new HostsDeletedEvent(event.getObjectIds())); + eventPublisher.publish(new HostsDeletedEvent(event.getHostIds())); } /** @@ -577,7 +586,7 @@ public class Case { */ @Subscribe public void publishPersonsDeletedEvent(TskEvent.PersonsDeletedTskEvent event) { - eventPublisher.publish(new PersonsDeletedEvent(event.getObjectIds())); + eventPublisher.publish(new PersonsDeletedEvent(event.getPersonIds())); } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java index c10b66face..bf355b66b7 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java @@ -23,17 +23,21 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.datamodel.Host; /** - * Event fired when new hosts are added. + * An application event published when hosts have been added to the Sleuth Kit + * data model for a case. */ -public class HostsAddedEvent extends HostsEvent { - +public final class HostsAddedEvent extends HostsEvent { + private static final long serialVersionUID = 1L; - + /** - * Main constructor. - * @param dataModelObjects The hosts that have been added. + * Constructs an application event published when hosts have been added to + * the Sleuth Kit data model for a case. + * + * @param persons The hosts that have been added. */ - public HostsAddedEvent(List dataModelObjects) { - super(Case.Events.HOSTS_ADDED.name(), dataModelObjects); + public HostsAddedEvent(List hosts) { + super(Case.Events.HOSTS_ADDED.name(), hosts); } + } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java new file mode 100755 index 0000000000..8b1b9da8a3 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java @@ -0,0 +1,39 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2021 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.casemodule.events; + +import java.util.Collections; +import java.util.List; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.Host; +import org.sleuthkit.datamodel.Person; + +/** + * + * @author rcordovano + */ +public final class HostsAddedToPersonEvent extends PersonHostsEvent { + + private static final long serialVersionUID = 1L; + + HostsAddedToPersonEvent(Person person, List hosts) { + super(Case.Events.HOSTS_ADDED_TO_PERSON.toString(), person, hosts); + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsDeletedEvent.java index 3d62b78405..24c2ae091b 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsDeletedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsDeletedEvent.java @@ -18,34 +18,34 @@ */ package org.sleuthkit.autopsy.casemodule.events; -import java.util.Collections; import java.util.List; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.datamodel.Host; -import org.sleuthkit.datamodel.SleuthkitCase; -import org.sleuthkit.datamodel.TskCoreException; /** - * Event fired when hosts are deleted. + * Application events published when hosts have been deleted from the Sleuth + * Kit data model for a case. */ -public class HostsDeletedEvent extends TskDataModelChangedEvent { +public final class HostsDeletedEvent extends TskDataModelObjectsDeletedEvent { private static final long serialVersionUID = 1L; /** - * Main constructor. + * Constructs an application event published when hosts have been deleted + * from the Sleuth Kit data model for a case. * - * @param dataModelObjectIds The unique numeric IDs (TSK object IDs, case - * database row IDs, etc.) of the Hosts that have - * been deleted. + * @param hostIds The host IDs of the deleted hosts. */ - public HostsDeletedEvent(List dataModelObjectIds) { - super(Case.Events.HOSTS_DELETED.name(), dataModelObjectIds); + public HostsDeletedEvent(List hostIds) { + super(Case.Events.HOSTS_DELETED.name(), hostIds); } - @Override - protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { - return Collections.emptyList(); + /** + * Gets the host IDs of the hosts that have been deleted. + * + * @return The host IDs. + */ + public List getHostIds() { + return getOldValue(); } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsEvent.java index 69f68c0b4e..1ac350c272 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsEvent.java @@ -22,44 +22,48 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; import org.sleuthkit.datamodel.Host; -import org.sleuthkit.datamodel.HostManager; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; /** - * Base event class for when something pertaining to hosts changes. + * A base class for application events published when hosts in the Sleuth Kit + * data model for a case have been added or updated. */ -public class HostsEvent extends TskDataModelChangedEvent { +public class HostsEvent extends TskDataModelChangedEvent { private static final long serialVersionUID = 1L; /** - * Main constructor. + * Constructs the base class part of an application event published when + * hosts in the Sleuth Kit data model for a case have been added or updated. * * @param eventName The name of the Case.Events enum value for the event - * type. - * @param dataModelObjects The list of hosts for the event. + * type. + * @param hosts The hosts. */ - protected HostsEvent(String eventName, List dataModelObjects) { - super(eventName, dataModelObjects, Host::getHostId); + protected HostsEvent(String eventName, List hosts) { + super(eventName, null, null, hosts, Host::getHostId); + } + + /** + * Gets the hosts that have been added or updated. + * + * @return The hosts. + */ + public List getHosts() { + return getNewValue(); } @Override - protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { - HostManager hostManager = caseDb.getHostManager(); - List toRet = new ArrayList<>(); - if (ids != null) { - for (Long id : ids) { - if (id == null) { - continue; - } - - Optional thisHostOpt = hostManager.getHostById(id); - thisHostOpt.ifPresent((h) -> toRet.add(h)); + protected List getNewValueObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { + List hosts = new ArrayList<>(); + for (Long id : ids) { + Optional host = caseDb.getHostManager().getHostById(id); + if (host.isPresent()) { + hosts.add(host.get()); } } - - return toRet; + return hosts; } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedFromPersonEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedFromPersonEvent.java new file mode 100755 index 0000000000..eaf200368d --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedFromPersonEvent.java @@ -0,0 +1,25 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.sleuthkit.autopsy.casemodule.events; + +import java.util.List; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.Host; +import org.sleuthkit.datamodel.Person; + +/** + * + * @author rcordovano + */ +public class HostsRemovedFromPersonEvent extends PersonHostsEvent { + + private static final long serialVersionUID = 1L; + + HostsRemovedFromPersonEvent(Person person, List hosts) { + super(Case.Events.HOSTS_REMOVED_FROM_PERSON.toString(), person, hosts); + } + +} \ No newline at end of file diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsUpdatedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsUpdatedEvent.java index 6b06382c0a..ec00fc5ad6 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsUpdatedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsUpdatedEvent.java @@ -23,19 +23,21 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.datamodel.Host; /** - * Event fired when hosts are changed. + * Application events published when hosts in the Sleuth Kit data model for + * a case have been updated. */ public class HostsUpdatedEvent extends HostsEvent { private static final long serialVersionUID = 1L; /** - * Main constructor. + * Constructs an application event published when hosts in the Sleuth Kit + * data model for a case have been updated. * - * @param dataModelObjects The new values for the hosts that have been - * changed. + * @param hosts The updated persons. */ - public HostsUpdatedEvent(List dataModelObjects) { - super(Case.Events.HOSTS_CHANGED.name(), dataModelObjects); + public HostsUpdatedEvent(List hosts) { + super(Case.Events.HOSTS_UPDATED.name(), hosts); } + } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsAddedEvent.java index 49a722062b..f4273408c6 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsAddedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsAddedEvent.java @@ -19,22 +19,25 @@ package org.sleuthkit.autopsy.casemodule.events; import java.util.List; -import org.sleuthkit.autopsy.casemodule.Case; +import static org.sleuthkit.autopsy.casemodule.Case.Events.OS_ACCOUNTS_ADDED; import org.sleuthkit.datamodel.OsAccount; /** - * Event published when OS accounts are added to a case. + * An application event published when OS accounts are added to the Sleuth Kit + * data model for a case. */ public final class OsAccountsAddedEvent extends OsAccountsEvent { private static final long serialVersionUID = 1L; - + /** - * Constructs an event published when OS accounts are added to a case. - * @param accounts + * Constructs an application event published when OS accounts are added to + * the Sleuth Kit data model for a case. + * + * @param osAccounts The OS accounts that were added. */ - public OsAccountsAddedEvent(List accounts) { - super(Case.Events.OS_ACCOUNT_ADDED.toString(), accounts); + public OsAccountsAddedEvent(List osAccounts) { + super(OS_ACCOUNTS_ADDED.toString(), osAccounts); } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsDeletedEvent.java index 52fe8d49a8..f3f65a0aed 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsDeletedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsDeletedEvent.java @@ -18,32 +18,34 @@ */ package org.sleuthkit.autopsy.casemodule.events; -import java.util.Collections; import java.util.List; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.datamodel.OsAccount; -import org.sleuthkit.datamodel.SleuthkitCase; -import org.sleuthkit.datamodel.TskCoreException; /** - * An event published when OS accounts are deleted from a case. + * An application event published when OS accounts have been deleted from the + * Sleuth Kit data model for a case. */ -public final class OsAccountsDeletedEvent extends TskDataModelChangedEvent { +public final class OsAccountsDeletedEvent extends TskDataModelObjectsDeletedEvent { private static final long serialVersionUID = 1L; /** - * Constructs an event published when OS accounts are deleted from a case. + * Constructs an application event published when OS accounts have been + * deleted from the Sleuth Kit data model for a case. * - * @param osAccountObjectIds The object IDs of the deleted accounts. + * @param osAccountObjectIds TSK object IDs of the deleted accounts. */ public OsAccountsDeletedEvent(List osAccountObjectIds) { - super(Case.Events.OS_ACCOUNT_REMOVED.toString(), osAccountObjectIds); + super(Case.Events.OS_ACCOUNTS_DELETED.toString(), osAccountObjectIds); } - @Override - protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { - return Collections.emptyList(); + /** + * Gets the Sleuth Kit object IDs of the deleted OS accounts. + * + * @return The object IDs. + */ + List getOsAccountObjectIds() { + return getOldValue(); } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsEvent.java index af214776a8..434d8c8f60 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsEvent.java @@ -20,45 +20,47 @@ package org.sleuthkit.autopsy.casemodule.events; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.sleuthkit.datamodel.OsAccount; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; /** - * Parent class for specific OsAccount event classes. + * A base class for application events published when OS accounts in the Sleuth + * Kit data model for a case have been added or updated. */ -class OsAccountsEvent extends TskDataModelChangedEvent { +class OsAccountsEvent extends TskDataModelChangedEvent { private static final long serialVersionUID = 1L; - + /** - * Construct a new OsAccountEvent. - * - * @param eventName The name of the event. - * @param account The OsAccount the event applies to. + * Constructs the base class part of an application event published when + * OS accounts in the Sleuth Kit data model for a case have been added or + * updated. + * + * @param eventName The name of the Case.Events enum value for the event + * type. + * @param account The OS accounts. */ - OsAccountsEvent(String eventName, List accounts) { - super(eventName, accounts, OsAccount::getId); + OsAccountsEvent(String eventName, List osAccounts) { + super(eventName, null, null, osAccounts, OsAccount::getId); } - + /** - * Returns the OsAccount that changed. - * - * @return The OsAccount that was changed. + * Gets the OS accounts that have been added or updated. + * + * @return The OS accounts. */ - public OsAccount getOsAccount() { - List accounts = getNewValue(); - return accounts.get(0); + public List getOsAccounts() { + return getNewValue(); } @Override - protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { - Long id = ids.get(0); - OsAccount account = caseDb.getOsAccountManager().getOsAccountByObjectId(id); - List accounts = new ArrayList<>(); - accounts.add(account); - return accounts; - } + protected List getNewValueObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { + List osAccounts = new ArrayList<>(); + for (Long id : ids) { + osAccounts.add(caseDb.getOsAccountManager().getOsAccountByObjectId(id)); + } + return osAccounts; + } + } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java index 22ef19584b..9795f055d6 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java @@ -23,19 +23,21 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.datamodel.OsAccount; /** - * Event published when OS accounts in the case have been updated. + * An application event published when OS accounts in the Sleuth Kit data model + * for a case have been updated. */ public final class OsAccountsUpdatedEvent extends OsAccountsEvent { private static final long serialVersionUID = 1L; /** - * Constructs an event published when OS accounts in the case have been - * updated. + * Constructs an application event published when OS accounts in the Sleuth + * Kit data model for a case have been updated. * - * @param accounts The accounts. + * @param osAccounts The OS accounts that were updated. */ - public OsAccountsUpdatedEvent(List accounts) { - super(Case.Events.OS_ACCOUNT_CHANGED.toString(), accounts); + public OsAccountsUpdatedEvent(List osAccounts) { + super(Case.Events.OS_ACCOUNT_CHANGED.toString(), osAccounts); } + } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonHostsEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonHostsEvent.java new file mode 100755 index 0000000000..f1426e38e4 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonHostsEvent.java @@ -0,0 +1,75 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.sleuthkit.autopsy.casemodule.events; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import org.sleuthkit.datamodel.Host; +import org.sleuthkit.datamodel.Person; +import org.sleuthkit.datamodel.SleuthkitCase; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * + * @author rcordovano + */ +public abstract class PersonHostsEvent extends TskDataModelChangedEvent { + + private static final long serialVersionUID = 1L; + + /** + * + * @param eventName + * @param person + * @param hosts + */ + PersonHostsEvent(String eventName, Person person, List hosts) { + super(eventName, Collections.singletonList(person), Person::getPersonId, hosts, Host::getHostId); + } + + /** + * + * @return + */ + Person getPerson() { + return getOldValue().get(0); + } + + /** + * + * @return + */ + List getHosts() { + return getNewValue(); + } + + @Override + protected List getOldValueObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { + List persons = new ArrayList<>(); + for (Long id : ids) { + Optional person = caseDb.getPersonManager().getPerson(id); + if (person.isPresent()) { + persons.add(person.get()); + } + } + return persons; + } + + @Override + protected List getNewValueObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { + List hosts = new ArrayList<>(); + for (Long id : ids) { + Optional host = caseDb.getHostManager().getHostById(id); + if (host.isPresent()) { + hosts.add(host.get()); + } + } + return hosts; + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsAddedEvent.java index c61bc177f3..afd101eac3 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsAddedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsAddedEvent.java @@ -23,19 +23,21 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.datamodel.Person; /** - * Event fired when new persons are added to a case. + * An application event published when persons have been added to the Sleuth Kit + * data model for a case. */ public class PersonsAddedEvent extends PersonsEvent { private static final long serialVersionUID = 1L; /** - * Constructs an event fired when new persons are added to a case. + * Constructs an application event published when persons have been added to + * the Sleuth Kit data model for a case. * * @param persons The persons that have been added. */ public PersonsAddedEvent(List persons) { super(Case.Events.PERSONS_ADDED.name(), persons); } - + } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsDeletedEvent.java index db80759214..46c024b7dd 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsDeletedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsDeletedEvent.java @@ -18,33 +18,34 @@ */ package org.sleuthkit.autopsy.casemodule.events; -import java.util.Collections; import java.util.List; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.datamodel.Person; -import org.sleuthkit.datamodel.SleuthkitCase; -import org.sleuthkit.datamodel.TskCoreException; /** - * An event fired when persons are deleted from the case. + * Application events published when persons have been deleted from the Sleuth + * Kit data model for a case. */ -public class PersonsDeletedEvent extends TskDataModelChangedEvent { +public class PersonsDeletedEvent extends TskDataModelObjectsDeletedEvent { private static final long serialVersionUID = 1L; /** - * Constructs an event fired when persons are deleted from the case. + * Constructs an application event published when persons have been deleted + * from the Sleuth Kit data model for a case. * - * @param dataModelObjectIds The unique numeric IDs (case database row IDs) - * of the persons that have been deleted. + * @param personIds The IDs of the persons that have been deleted. */ - public PersonsDeletedEvent(List dataModelObjectIds) { - super(Case.Events.PERSONS_DELETED.name(), dataModelObjectIds); + public PersonsDeletedEvent(List personIds) { + super(Case.Events.PERSONS_DELETED.name(), personIds); } - @Override - protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { - return Collections.emptyList(); + /** + * Gets the person IDs of the persons that have been deleted. + * + * @return The person IDs. + */ + List getPersonIds() { + return getOldValue(); } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsEvent.java index 5380ee4874..2d3b322ea7 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsEvent.java @@ -22,44 +22,49 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; import org.sleuthkit.datamodel.Person; -import org.sleuthkit.datamodel.PersonManager; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; /** - * Base event class for when something pertaining to persons changes. + * A base class for application events published when persons in the Sleuth Kit + * data model for a case have been added or updated. */ -public class PersonsEvent extends TskDataModelChangedEvent { +public class PersonsEvent extends TskDataModelChangedEvent { private static final long serialVersionUID = 1L; - + /** - * Main constructor. + * Constructs the base class part of an application event published when + * persons in the Sleuth Kit data model for a case have been added or + * updated. * * @param eventName The name of the Case.Events enum value for the event - * type. - * @param dataModelObjects The list of persons for the event. + * type. + * @param persons The persons. */ - PersonsEvent(String eventName, List dataModelObjects) { - super(eventName, dataModelObjects, Person::getPersonId); + PersonsEvent(String eventName, List persons) { + super(eventName, null, null, persons, Person::getPersonId); } - - @Override - protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { - PersonManager personManager = caseDb.getPersonManager(); - List toRet = new ArrayList<>(); - if (ids != null) { - for (Long id : ids) { - if (id == null) { - continue; - } - Optional thisPersonOpt = personManager.getPerson(id); - thisPersonOpt.ifPresent((h) -> toRet.add(h)); + /** + * Gets the persons that have been added or updated. + * + * @return The persons. + */ + public List getPersons() { + return getNewValue(); + } + + @Override + protected List getNewValueObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { + List persons = new ArrayList<>(); + for (Long id : ids) { + Optional person = caseDb.getPersonManager().getPerson(id); + if (person.isPresent()) { + persons.add(person.get()); } } - - return toRet; + return persons; } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsUpdatedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsUpdatedEvent.java index cb5308d7ce..572b832688 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsUpdatedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsUpdatedEvent.java @@ -23,19 +23,21 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.datamodel.Person; /** - * An event fired when persons in a case are updated. + * Application events published when persons in the Sleuth Kit data model for + * a case have been updated. */ public class PersonsUpdatedEvent extends PersonsEvent { private static final long serialVersionUID = 1L; /** - * Constructs an event fired when persons in a case are updated. + * Constructs an application event published when persons in the Sleuth Kit + * data model for a case have been updated. * * @param persons The updated persons. */ public PersonsUpdatedEvent(List persons) { - super(Case.Events.PERSONS_CHANGED.name(), persons); + super(Case.Events.PERSONS_UPDATED.name(), persons); } - + } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/ReportAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/ReportAddedEvent.java index 47c5a30d5d..9da76a4366 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/ReportAddedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/ReportAddedEvent.java @@ -28,33 +28,38 @@ import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; /** - * Event published when a report is added to a case. + * An application event published when a report is added to a case. */ -public final class ReportAddedEvent extends TskDataModelChangedEvent { +public final class ReportAddedEvent extends TskDataModelChangedEvent { private static final long serialVersionUID = 1L; /** - * Constructs an event published when a report is added to a case. + * Constructs an application event published when a report is added to a + * case. * - * @param report The data source that was added. + * @param report The report that was added. */ public ReportAddedEvent(Report report) { - super(Case.Events.REPORT_ADDED.toString(), Stream.of(report).collect(Collectors.toList()), Report::getId); + super(Case.Events.REPORT_ADDED.toString(), null, null, Stream.of(report).collect(Collectors.toList()), Report::getId); } + /** + * Gets the reoprt that was added to the case. + * + * @return The report. + */ public Report getReport() { List reports = getNewValue(); return reports.get(0); } - + @Override - protected List getDataModelObjects(SleuthkitCase caseD, List ids) throws TskCoreException { + protected List getNewValueObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { Long id = ids.get(0); - Report report = caseD.getReportById(id); List reports = new ArrayList<>(); - reports.add(report); + reports.add(caseDb.getReportById(id)); return reports; } - + } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java index d0d8953e92..07ed7166d7 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java @@ -32,123 +32,142 @@ import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; /** - * An abstract base class for application events published when Sleuth Kit Data - * Model objects for a case are added, updated, or deleted. + * An abstract base class for application events published when one or more + * Sleuth Kit Data Model objects for a case change in some way. * - * @param A Sleuth Kit Data Model object type. + * This class extends AutopsyEvent. The AutopsyEvent class extends + * PropertyChangeEvent to integrate with legacy use of JavaBeans + * PropertyChangeEvents and PropertyChangeListeners as an application event + * publisher-subcriber mechanism. Subclasses need to decide what constitutes + * "old" and "new" objects for them and are encouraged to provide getters for + * these values that do not require clients to cast the return values. + * + * The AutopsyEvent class implements Serializable to allow local event instances + * to be published to other Autopsy nodes over a network in serialized form. TSK + * Data Model objects are generally not serializable because they encapsulate a + * reference to a SleuthkitCase object that represents the case database and + * which has local JDBC Connection objects. For this reason, this class supports + * serialization of the unique numeric IDs (TSK object IDs, case database row + * IDs, etc.) of the subject TSK Data Model objects and the "reconstruction" of + * those objects on other Autopsy nodes by querying the case database by unique + * ID. + * + * @param The Sleuth Kit Data Model object type of the "old" data model + * objects. + * @param The Sleuth Kit Data Model object type of the "new" data model + * objects. */ -public abstract class TskDataModelChangedEvent extends AutopsyEvent { +public abstract class TskDataModelChangedEvent extends AutopsyEvent { private static final long serialVersionUID = 1L; private static final Logger logger = Logger.getLogger(TskDataModelChangedEvent.class.getName()); - private final boolean isDeletionEvent; - private final List dataModelObjectIds; - private transient List dataModelObjects; + private final boolean hasOldValue; + private final List oldValueIds; + private transient List oldValueObjects; + private final boolean hasNewValue; + private final List newValueIds; + private transient List newValueObjects; /** - * Constructs an instance of an abstract base class for application events - * published when Sleuth Kit Data Model objects for a case are added or - * updated. The getNewValue() method of this event will return the objects - * and the getOldValue() method will return an empty list. + * Constructs the base class part for application events published when one + * or more Sleuth Kit Data Model objects for a case change in some way. * - * @param eventName The event name. - * @param dataModelObjects The Sleuth Kit Data Model objects that have been - * added or updated. - * @param getIdMethod A method that can be applied to the data model - * objects to get their unique numeric IDs (TSK - * object IDs, case database row IDs, etc.). + * @param eventName The event name. + * @param oldValueObjects A list of he Data Model objects that have been + * designated as the "old" objects in the event. + * May be null. + * @param oldValueGetIdMethod A method that can be applied to the "old" data + * model objects to get their unique numeric IDs + * (TSK object IDs, case database row IDs, etc.). + * May be null if there are no "old" objects. + * @param newValueObjects A list of he Data Model objects that have been + * designated as the "new" objects in the event. + * May be null. + * @param newValueGetIdMethod A method that can be applied to the "new" data + * model objects to get their unique numeric IDs + * (TSK object IDs, case database row IDs, etc.). + * May be null if there are no "new" objects. */ - protected TskDataModelChangedEvent(String eventName, List dataModelObjects, Function getIdMethod) { + protected TskDataModelChangedEvent(String eventName, List oldValueObjects, Function oldValueGetIdMethod, List newValueObjects, Function newValueGetIdMethod) { super(eventName, null, null); - isDeletionEvent = false; - this.dataModelObjectIds = new ArrayList<>(); - this.dataModelObjectIds.addAll(dataModelObjects.stream().map(o -> getIdMethod.apply(o)).collect(Collectors.toList())); - this.dataModelObjects = new ArrayList<>(); - this.dataModelObjects.addAll(dataModelObjects); - } - - /** - * Constructs an instance of an abstract base class for application events - * published when Sleuth Kit Data Model objects for a case are added or - * updated. The getOldValue() method of this event will return the object - * IDs and the getNewValue() method will return an empty list. - * - * @param eventName The event name. - * @param dataModelObjectIds The unique numeric IDs (TSK object IDs, case - * database row IDs, etc.) of the Sleuth Kit Data - * Model objects that have been deleted. - */ - protected TskDataModelChangedEvent(String eventName, List dataModelObjectIds) { - super(eventName, null, null); - isDeletionEvent = true; - this.dataModelObjectIds = new ArrayList<>(); - this.dataModelObjectIds.addAll(dataModelObjectIds); - dataModelObjects = Collections.emptyList(); - } - - /** - * Gets the the unique numeric IDs (TSK object IDs, case database row IDs, - * etc.) of the Sleuth Kit Data Model objects that were deleted. - * - * @return The unique IDs. - */ - @Override - public List getOldValue() { - if (isDeletionEvent) { - return getDataModelObjectIds(); + oldValueIds = new ArrayList<>(); + this.oldValueObjects = new ArrayList<>(); + if (oldValueObjects != null) { + hasOldValue = true; + oldValueIds.addAll(oldValueObjects.stream() + .map(o -> oldValueGetIdMethod.apply(o)) + .collect(Collectors.toList())); + this.oldValueObjects.addAll(oldValueObjects); } else { - return Collections.emptyList(); + hasOldValue = false; + } + newValueIds = new ArrayList<>(); + this.newValueObjects = new ArrayList<>(); + if (oldValueObjects != null) { + hasNewValue = true; + newValueIds.addAll(newValueObjects.stream() + .map(o -> newValueGetIdMethod.apply(o)) + .collect(Collectors.toList())); + this.newValueObjects.addAll(newValueObjects); + } else { + hasNewValue = false; } } /** - * Gets the Sleuth Kit Data Model objects that were added or updated. If - * this event came from another host collaborating on a multi-user case, the - * Sleuth Kit Data Model objects will be reconstructed on the current host. + * Gets a list of the Data Model objects that have been designated as the + * "old" objects in the event. * - * @return The objects. + * @return The list of the "old" data model objects. May be empty. */ @Override - public List getNewValue() { - if (!isDeletionEvent) { - if (dataModelObjects == null) { + public List getOldValue() { + if (hasOldValue) { + if (oldValueObjects == null) { try { Case currentCase = Case.getCurrentCaseThrows(); SleuthkitCase caseDb = currentCase.getSleuthkitCase(); - dataModelObjects = getDataModelObjects(caseDb, dataModelObjectIds); + oldValueObjects = getOldValueObjects(caseDb, oldValueIds); } catch (NoCurrentCaseException | TskCoreException ex) { - logger.log(Level.SEVERE, String.format("Error geting TSK Data Model objects for %s event (%s)", getPropertyName(), getSourceType()), ex); + logger.log(Level.SEVERE, String.format("Error getting oldValue() TSK Data Model objects for %s event (%s)", getPropertyName(), getSourceType()), ex); return Collections.emptyList(); } } - return Collections.unmodifiableList(dataModelObjects); + return Collections.unmodifiableList(oldValueObjects); } else { return Collections.emptyList(); } } + /** + * Gets a list of the Data Model objects that have been designated as the + * "new" objects in the event. + * + * @return The list of the "new" data model objects. May be empty. + */ + @Override + public List getNewValue() { + if (hasNewValue) { + if (newValueObjects == null) { + try { + Case currentCase = Case.getCurrentCaseThrows(); + SleuthkitCase caseDb = currentCase.getSleuthkitCase(); + newValueObjects = getNewValueObjects(caseDb, newValueIds); + } catch (NoCurrentCaseException | TskCoreException ex) { + logger.log(Level.SEVERE, String.format("Error getting newValue() TSK Data Model objects for %s event (%s)", getPropertyName(), getSourceType()), ex); + return Collections.emptyList(); + } + } + return Collections.unmodifiableList(newValueObjects); + } else { + return Collections.emptyList(); + } + } /** - * Gets the unique numeric IDs (TSK object IDs, case database row IDs, etc.) - * of the Sleuth Kit Data Model objects associated with this application - * event. - * - * This method is provided as an optimization that allows handling of an - * event that came from another host collaborating on a multi-user case - * without reconstructing the data model objects that are the subject s of - * the event. - * - * @return The unique IDs. - */ - public final List getDataModelObjectIds() { - return Collections.unmodifiableList(dataModelObjectIds); - } - - /** - * Gets the Sleuth Kit Data Model objects associated with this application - * event. If this event came from another host collaborating on a multi-user - * case, the Sleuth Kit Data Model objects, this method will be called to - * reconstruct the objects on the curartifactExists(), I think we should continue to use what we have and suppress the deprecation warnings.Bent host. + * Reconstructs the "old" Sleuth Kit Data Model objects associated with this + * application event, if any, using the given unique numeric IDs (TSK object + * IDs, case database row IDs, etc.) to query the given case database. * * @param caseDb The case database. * @param ids The unique, numeric IDs (TSK object IDs, case database row @@ -160,6 +179,27 @@ public abstract class TskDataModelChangedEvent extends AutopsyEvent { * getting the Sleuth Kit * Data Model objects. */ - abstract protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException; + protected List getOldValueObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { + return Collections.emptyList(); + } + + /** + * Reconstructs the "new" Sleuth Kit Data Model objects associated with this + * application event, if any, using the given unique numeric IDs (TSK object + * IDs, case database row IDs, etc.) to query the given case database. + * + * @param caseDb The case database. + * @param ids The unique, numeric IDs (TSK object IDs, case database row + * IDs, etc.) of the Sleuth Kit Data Model objects. + * + * @return The objects. + * + * @throws org.sleuthkit.datamodel.TskCoreException If there is an error + * getting the Sleuth Kit + * Data Model objects. + */ + protected List getNewValueObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { + return Collections.emptyList(); + } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelObjectsDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelObjectsDeletedEvent.java new file mode 100755 index 0000000000..7e5929e4a1 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelObjectsDeletedEvent.java @@ -0,0 +1,60 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2021 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.casemodule.events; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.sleuthkit.autopsy.events.AutopsyEvent; + +/** + * An abstract base class for application events published when one or more + * Sleuth Kit Data Model objects for a case have been deleted. + * + * This class extends AutopsyEvent. The AutopsyEvent class extends + * PropertyChangeEvent to integrate with legacy use of JavaBeans + * PropertyChangeEvents and PropertyChangeListeners as an application event + * publisher-subcriber mechanism. Subclasses need to decide what constitutes + * "old" and "new" objects for them. + * + * For this class the "old" values are the unique numeric IDs (TSK object IDs, + * case database row IDs, etc.) of the deleted TSK Data Model objects. There are + * no "new" values. Subclasses are encouraged to provide less generic getters + * with descriptive names for the unique IDs than the override of the inherited + * getOldValue() method below. These getters can be implemented by delegating to + * getOldValue(). + */ +public class TskDataModelObjectsDeletedEvent extends AutopsyEvent { + + private static final long serialVersionUID = 1L; + + private final List deletedObjectIds; + + protected TskDataModelObjectsDeletedEvent(String eventName, List deletedObjectIds) { + super(eventName, null, null); + this.deletedObjectIds = new ArrayList<>(); + this.deletedObjectIds.addAll(deletedObjectIds); + } + + @Override + public List getOldValue() { + return Collections.unmodifiableList(deletedObjectIds); + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/AutopsyTreeChildFactory.java b/Core/src/org/sleuthkit/autopsy/datamodel/AutopsyTreeChildFactory.java index 22b340d5f1..ca4368e1e4 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/AutopsyTreeChildFactory.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/AutopsyTreeChildFactory.java @@ -47,13 +47,12 @@ import org.sleuthkit.datamodel.TskCoreException; */ public final class AutopsyTreeChildFactory extends ChildFactory.Detachable { - private static final Set LISTENING_EVENTS = EnumSet.of( - Case.Events.DATA_SOURCE_ADDED, + private static final Set LISTENING_EVENTS = EnumSet.of(Case.Events.DATA_SOURCE_ADDED, Case.Events.HOSTS_ADDED, Case.Events.HOSTS_DELETED, Case.Events.PERSONS_ADDED, Case.Events.PERSONS_DELETED, - Case.Events.PERSONS_CHANGED + Case.Events.PERSONS_UPDATED ); private static final Set LISTENING_EVENT_NAMES = LISTENING_EVENTS.stream() diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesByTypeNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesByTypeNode.java index 1fab7774c7..700875d161 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesByTypeNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesByTypeNode.java @@ -50,11 +50,10 @@ public class DataSourcesByTypeNode extends DisplayableItemNode { */ public static class DataSourcesByTypeChildren extends ChildFactory.Detachable { - private static final Set UPDATE_EVTS = EnumSet.of( - Case.Events.DATA_SOURCE_ADDED, + private static final Set UPDATE_EVTS = EnumSet.of(Case.Events.DATA_SOURCE_ADDED, Case.Events.HOSTS_ADDED, Case.Events.HOSTS_DELETED, - Case.Events.HOSTS_CHANGED); + Case.Events.HOSTS_UPDATED); private static final Set UPDATE_EVT_STRS = UPDATE_EVTS.stream() .map(evt -> evt.name()) diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java index 57253ef60e..644e2b6b80 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java @@ -177,7 +177,7 @@ public class HostNode extends DisplayableItemNode { @Override public void propertyChange(PropertyChangeEvent evt) { String eventType = evt.getPropertyName(); - if (hostId != null && eventType.equals(Case.Events.HOSTS_CHANGED.toString()) && evt instanceof HostsUpdatedEvent) { + if (hostId != null && eventType.equals(Case.Events.HOSTS_UPDATED.toString()) && evt instanceof HostsUpdatedEvent) { ((HostsUpdatedEvent) evt).getNewValue().stream() .filter(h -> h != null && h.getHostId() == hostId) .findFirst() @@ -246,7 +246,7 @@ public class HostNode extends DisplayableItemNode { host == null ? Lookups.fixed(displayName) : Lookups.fixed(host, displayName)); hostId = host == null ? null : host.getHostId(); - Case.addEventTypeSubscriber(EnumSet.of(Case.Events.HOSTS_CHANGED), + Case.addEventTypeSubscriber(EnumSet.of(Case.Events.HOSTS_UPDATED), WeakListeners.propertyChange(hostChangePcl, this)); super.setName(displayName); super.setDisplayName(displayName); diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java b/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java index 42a69caa99..9472a65616 100755 --- a/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java @@ -124,8 +124,8 @@ public final class OsAccounts implements AutopsyVisitableItem { @Override public void propertyChange(PropertyChangeEvent evt) { String eventType = evt.getPropertyName(); - if (eventType.equals(Case.Events.OS_ACCOUNT_ADDED.toString()) - || eventType.equals(Case.Events.OS_ACCOUNT_REMOVED.toString())) { + if (eventType.equals(Case.Events.OS_ACCOUNTS_ADDED.toString()) + || eventType.equals(Case.Events.OS_ACCOUNTS_DELETED.toString())) { refresh(true); } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) { // case was closed. Remove listeners so that we don't get called with a stale case handle @@ -139,13 +139,13 @@ public final class OsAccounts implements AutopsyVisitableItem { @Override protected void addNotify() { - Case.addEventTypeSubscriber(EnumSet.of(Case.Events.OS_ACCOUNT_ADDED, Case.Events.OS_ACCOUNT_REMOVED), listener); + Case.addEventTypeSubscriber(EnumSet.of(Case.Events.OS_ACCOUNTS_ADDED, Case.Events.OS_ACCOUNTS_DELETED), listener); Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), listener); } @Override protected void removeNotify() { - Case.removeEventTypeSubscriber(Collections.singleton(Case.Events.OS_ACCOUNT_ADDED), listener); + Case.removeEventTypeSubscriber(Collections.singleton(Case.Events.OS_ACCOUNTS_ADDED), listener); Case.removeEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), listener); } @@ -184,10 +184,13 @@ public final class OsAccounts implements AutopsyVisitableItem { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(Case.Events.OS_ACCOUNT_CHANGED.name())) { - if (((OsAccountsUpdatedEvent) evt).getOsAccount().getId() == account.getId()) { - // Update the account node to the new one - account = ((OsAccountsUpdatedEvent) evt).getOsAccount(); - updateSheet(); + OsAccountsUpdatedEvent updateEvent = (OsAccountsUpdatedEvent) evt; + for (OsAccount acct : updateEvent.getOsAccounts()) { + if (acct.getId() == account.getId()) { + account = acct; + updateSheet(); + break; + } } } else if (evt.getPropertyName().equals(REALM_DATA_AVAILABLE_EVENT)) { OsAccountRealm realm = (OsAccountRealm) evt.getNewValue(); diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java index 3934ffa06c..736cab3028 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java @@ -68,10 +68,9 @@ public class PersonGroupingNode extends DisplayableItemNode { private static final Logger logger = Logger.getLogger(PersonChildren.class.getName()); - private static final Set CHILD_EVENTS = EnumSet.of( - Case.Events.HOSTS_ADDED, + private static final Set CHILD_EVENTS = EnumSet.of(Case.Events.HOSTS_ADDED, Case.Events.HOSTS_DELETED, - Case.Events.PERSONS_CHANGED); + Case.Events.PERSONS_UPDATED); private static final Set CHILD_EVENTS_STR = CHILD_EVENTS.stream() .map(ev -> ev.name()) @@ -145,7 +144,7 @@ public class PersonGroupingNode extends DisplayableItemNode { @Override public void propertyChange(PropertyChangeEvent evt) { String eventType = evt.getPropertyName(); - if (personId != null && eventType.equals(Case.Events.PERSONS_CHANGED.toString()) && evt instanceof PersonsUpdatedEvent) { + if (personId != null && eventType.equals(Case.Events.PERSONS_UPDATED.toString()) && evt instanceof PersonsUpdatedEvent) { ((PersonsUpdatedEvent) evt).getNewValue().stream() .filter(p -> p != null && p.getPersonId() == personId) .findFirst() @@ -192,7 +191,7 @@ public class PersonGroupingNode extends DisplayableItemNode { this.setIconBaseWithExtension(ICON_PATH); this.person = person; this.personId = person == null ? null : person.getPersonId(); - Case.addEventTypeSubscriber(EnumSet.of(Case.Events.PERSONS_CHANGED), + Case.addEventTypeSubscriber(EnumSet.of(Case.Events.PERSONS_UPDATED), WeakListeners.propertyChange(personChangePcl, this)); } diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociateNewPersonAction.java b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociateNewPersonAction.java index 2cb89995c6..ff86ea65db 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociateNewPersonAction.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociateNewPersonAction.java @@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.datamodel.hosts; import java.awt.Frame; import java.awt.event.ActionEvent; +import java.util.Collections; import java.util.logging.Level; import javax.swing.AbstractAction; import javax.swing.JOptionPane; @@ -66,7 +67,7 @@ public class AssociateNewPersonAction extends AbstractAction { newPersonName = getAddDialogName(); if (StringUtils.isNotBlank(newPersonName)) { Person person = Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().newPerson(newPersonName); - Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().setPerson(host, person); + Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().addHostsToPerson(person, Collections.singletonList(host)); } } catch (NoCurrentCaseException | TskCoreException ex) { String hostName = this.host == null || this.host.getName() == null ? "" : this.host.getName(); diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonAction.java b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonAction.java index 70b31a1ac7..e9ca92791e 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonAction.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonAction.java @@ -19,6 +19,7 @@ package org.sleuthkit.autopsy.datamodel.hosts; import java.awt.event.ActionEvent; +import java.util.Collections; import java.util.logging.Level; import javax.swing.AbstractAction; import javax.swing.JOptionPane; @@ -65,7 +66,7 @@ public class AssociatePersonAction extends AbstractAction { @Override public void actionPerformed(ActionEvent e) { try { - Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().setPerson(host, person); + Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().addHostsToPerson(person, Collections.singletonList(host)); } catch (NoCurrentCaseException | TskCoreException ex) { String hostName = this.host == null || this.host.getName() == null ? "" : this.host.getName(); String personName = this.person == null || this.person.getName() == null ? "" : this.person.getName(); diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/RemoveParentPersonAction.java b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/RemoveParentPersonAction.java index c8ae974bb0..f83d3bd874 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/RemoveParentPersonAction.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/RemoveParentPersonAction.java @@ -19,6 +19,7 @@ package org.sleuthkit.autopsy.datamodel.hosts; import java.awt.event.ActionEvent; +import java.util.Collections; import java.util.logging.Level; import javax.swing.AbstractAction; import javax.swing.JOptionPane; @@ -46,6 +47,7 @@ public class RemoveParentPersonAction extends AbstractAction { private static final Logger logger = Logger.getLogger(RemoveParentPersonAction.class.getName()); + private final Person person; private final Host host; /** @@ -59,12 +61,13 @@ public class RemoveParentPersonAction extends AbstractAction { person == null || person.getName() == null ? Bundle.RemoveParentPersonAction_unknownPerson() : person.getName())); this.host = host; + this.person = person; } @Override public void actionPerformed(ActionEvent e) { try { - Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().setPerson(host, null); + Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().removeHostsFromPerson(person, Collections.singletonList(host)); } catch (NoCurrentCaseException | TskCoreException ex) { String hostName = this.host == null || this.host.getName() == null ? "" : this.host.getName(); logger.log(Level.WARNING, String.format("Unable to remove parent from host: %s", hostName), ex); diff --git a/Core/src/org/sleuthkit/autopsy/events/AutopsyEvent.java b/Core/src/org/sleuthkit/autopsy/events/AutopsyEvent.java index c329a03549..7c3a16e5a3 100644 --- a/Core/src/org/sleuthkit/autopsy/events/AutopsyEvent.java +++ b/Core/src/org/sleuthkit/autopsy/events/AutopsyEvent.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2015 Basis Technology Corp. + * Copyright 2015-2021 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,12 +22,18 @@ import java.beans.PropertyChangeEvent; import java.io.Serializable; /** - * A base class for events to be published to registered subscribers on both - * this Autopsy node and other Autopsy nodes. The class extends - * PropertyChangeEvent to integrate with legacy use of JavaBeans - * PropertyChangeEvents and PropertyChangeListeners as an application event - * system, and implements Serializable to allow it to be published over a - * network in serialized form. + * A base class for application events that can be published to registered + * subscribers on both this Autopsy node and other Autopsy nodes. + * + * The class extends PropertyChangeEvent to integrate with legacy use of + * JavaBeans PropertyChangeEvents and PropertyChangeListeners as an application + * event publisher-subcriber mechanism. Subclasses need to decide what + * constitutes "old" and "new" objects for them and are encouraged to provide + * getters for these values that do not require clients to cast the return + * values. + * + * This class implements Serializable to allow it to be published over a network + * in serialized form. */ public class AutopsyEvent extends PropertyChangeEvent implements Serializable { @@ -36,17 +42,22 @@ public class AutopsyEvent extends PropertyChangeEvent implements Serializable { /** * Events have a source field set to local or remote to allow event - * subscribers to filter events by source type. + * subscribers to filter events by source type. For a multi-user case, a + * local event has happened on this Autopsy node, and a remote event has + * happened on another Autopsy node. + * + * Events are local by default and are changed to remote events by the event + * publishers on other Autopsy nodes upon event receipt. */ public enum SourceType { - LOCAL, REMOTE }; /** - * Constructs an event that can be published to registered subscribers on - * both this Autopsy node and other Autopsy nodes. + * Constructs the base class part of an application event that can be + * published to registered subscribers on both this Autopsy node and other + * Autopsy nodes. * * @param eventName The event name. * @param oldValue The "old" value to associate with the event. May be @@ -60,7 +71,7 @@ public class AutopsyEvent extends PropertyChangeEvent implements Serializable { } /** - * Gets the source type (local or remote). + * Gets the event source type (local or remote). * * @return SourceType The source type of the event, local or remote. */ @@ -69,12 +80,9 @@ public class AutopsyEvent extends PropertyChangeEvent implements Serializable { } /** - * Gets the source type (local or remote) as a string. This is for clients - * that do not have access to the AutopsyEvent type, and is necessary - * because the events package is not currently a public package within the - * Autopsy-Core NetBeans Module (NBM). + * Gets the event source type (local or remote) as a string. * - * @return A string, either "LOCAL" or "REMOTE", as an Object. + * @return A string, either "LOCAL" or "REMOTE." */ @Override public Object getSource() { @@ -82,10 +90,10 @@ public class AutopsyEvent extends PropertyChangeEvent implements Serializable { } /** - * Sets the source type (local or remote). This field is mutable in this way - * to allow an event to be published both locally and remotely without - * requiring the construction of two separate objects. It is for use by the - * event publishing classes within this package only. + * Sets the source type (local or remote). This field is mutable to allow an + * event to be published both locally and remotely without requiring the + * construction of two separate objects. It is for use by the event + * publishing classes within this package only. * * @param sourceType The source type of the event, local or remote. */