From 73b2030d83a598b2114c749103b4ee115c5bd3dc Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 29 Apr 2021 10:15:27 -0400 Subject: [PATCH 01/14] 7553 data model event changes --- .../sleuthkit/autopsy/casemodule/Case.java | 114 +++------------- .../casemodule/events/HostsChangedEvent.java | 41 ------ .../autopsy/casemodule/events/HostsEvent.java | 28 +--- .../casemodule/events/HostsRemovedEvent.java | 39 ------ .../events/OsAccountAddedEvent.java | 35 ----- .../events/OsAccountChangedEvent.java | 34 ----- .../events/OsAccountDeletedEvent.java | 37 ------ .../casemodule/events/OsAccountEvent.java | 64 --------- .../casemodule/events/PersonsAddedEvent.java | 16 ++- .../events/PersonsChangedEvent.java | 41 ------ .../events/PersonsDeletedEvent.java | 27 ++-- .../casemodule/events/PersonsEvent.java | 34 +---- .../casemodule/events/ReportAddedEvent.java | 4 +- .../events/TskDataModelChangeEvent.java | 124 ------------------ .../sleuthkit/autopsy/datamodel/HostNode.java | 6 +- .../autopsy/datamodel/OsAccounts.java | 6 +- .../autopsy/datamodel/PersonGroupingNode.java | 6 +- 17 files changed, 66 insertions(+), 590 deletions(-) delete mode 100644 Core/src/org/sleuthkit/autopsy/casemodule/events/HostsChangedEvent.java delete mode 100644 Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedEvent.java delete mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountAddedEvent.java delete mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountChangedEvent.java delete mode 100644 Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountDeletedEvent.java delete mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountEvent.java delete mode 100644 Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsChangedEvent.java delete mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangeEvent.java diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index ddf8cc22b9..f77859d407 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -84,13 +84,13 @@ import org.sleuthkit.autopsy.casemodule.events.DataSourceAddedEvent; import org.sleuthkit.autopsy.casemodule.events.DataSourceDeletedEvent; import org.sleuthkit.autopsy.casemodule.events.DataSourceNameChangedEvent; import org.sleuthkit.autopsy.casemodule.events.HostsAddedEvent; -import org.sleuthkit.autopsy.casemodule.events.HostsChangedEvent; -import org.sleuthkit.autopsy.casemodule.events.HostsRemovedEvent; -import org.sleuthkit.autopsy.casemodule.events.OsAccountAddedEvent; -import org.sleuthkit.autopsy.casemodule.events.OsAccountChangedEvent; -import org.sleuthkit.autopsy.casemodule.events.OsAccountDeletedEvent; +import org.sleuthkit.autopsy.casemodule.events.HostsUpdatedEvent; +import org.sleuthkit.autopsy.casemodule.events.HostsDeletedEvent; +import org.sleuthkit.autopsy.casemodule.events.OsAccountsAddedEvent; +import org.sleuthkit.autopsy.casemodule.events.OsAccountsUpdatedEvent; +import org.sleuthkit.autopsy.casemodule.events.OsAccountsDeletedEvent; import org.sleuthkit.autopsy.casemodule.events.PersonsAddedEvent; -import org.sleuthkit.autopsy.casemodule.events.PersonsChangedEvent; +import org.sleuthkit.autopsy.casemodule.events.PersonsUpdatedEvent; import org.sleuthkit.autopsy.casemodule.events.PersonsDeletedEvent; import org.sleuthkit.autopsy.casemodule.events.ReportAddedEvent; import org.sleuthkit.autopsy.casemodule.multiusercases.CaseNodeData.CaseNodeDataException; @@ -500,24 +500,18 @@ public class Case { } @Subscribe - public void publishOsAccountAddedEvent(TskEvent.OsAccountsAddedTskEvent event) { - for (OsAccount account : event.getOsAcounts()) { - eventPublisher.publish(new OsAccountAddedEvent(account)); - } + public void publishOsAccountsAddedEvent(TskEvent.OsAccountsAddedTskEvent event) { + eventPublisher.publish(new OsAccountsAddedEvent(event.getOsAcounts())); } @Subscribe - public void publishOsAccountChangedEvent(TskEvent.OsAccountsChangedTskEvent event) { - for (OsAccount account : event.getOsAcounts()) { - eventPublisher.publish(new OsAccountChangedEvent(account)); - } + public void publishOsAccountsUpdatedEvent(TskEvent.OsAccountsUpdatedTskEvent event) { + eventPublisher.publish(new OsAccountsUpdatedEvent(event.getOsAcounts())); } @Subscribe - public void publishOsAccountDeletedEvent(TskEvent.OsAccountsDeletedTskEvent event) { - for (Long accountId : event.getOsAcountObjectIds()) { - eventPublisher.publish(new OsAccountDeletedEvent(accountId)); - } + public void publishOsAccountsDeletedEvent(TskEvent.OsAccountsDeletedTskEvent event) { + eventPublisher.publish(new OsAccountsDeletedEvent(event.getObjectIds())); } /** @@ -528,8 +522,7 @@ public class Case { */ @Subscribe public void publishHostsAddedEvent(TskEvent.HostsAddedTskEvent event) { - eventPublisher.publish(new HostsAddedEvent( - event == null ? Collections.emptyList() : event.getHosts())); + eventPublisher.publish(new HostsAddedEvent(event.getHosts())); } /** @@ -539,9 +532,8 @@ public class Case { * @param event The sleuthkit event for the updating of hosts. */ @Subscribe - public void publishHostsChangedEvent(TskEvent.HostsChangedTskEvent event) { - eventPublisher.publish(new HostsChangedEvent( - event == null ? Collections.emptyList() : event.getHosts())); + public void publishHostsUpdatedEvent(TskEvent.HostsUpdatedTskEvent event) { + eventPublisher.publish(new HostsUpdatedEvent(event.getHosts())); } /** @@ -552,8 +544,7 @@ public class Case { */ @Subscribe public void publishHostsDeletedEvent(TskEvent.HostsDeletedTskEvent event) { - eventPublisher.publish(new HostsRemovedEvent( - event == null ? Collections.emptyList() : event.getHosts())); + eventPublisher.publish(new HostsDeletedEvent(event.getObjectIds())); } /** @@ -575,8 +566,8 @@ public class Case { * @param event The sleuthkit event for the updating of persons. */ @Subscribe - public void publishPersonsChangedEvent(TskEvent.PersonsChangedTskEvent event) { - eventPublisher.publish(new PersonsChangedEvent( + public void publishPersonsUpdatedEvent(TskEvent.PersonsUpdatedTskEvent event) { + eventPublisher.publish(new PersonsUpdatedEvent( event == null ? Collections.emptyList() : event.getPersons())); } @@ -588,8 +579,7 @@ public class Case { */ @Subscribe public void publishPersonsDeletedEvent(TskEvent.PersonsDeletedTskEvent event) { - eventPublisher.publish(new PersonsDeletedEvent( - event == null ? Collections.emptyList() : event.getPersons())); + eventPublisher.publish(new PersonsDeletedEvent(event.getObjectIds())); } } @@ -1826,72 +1816,6 @@ public class Case { eventPublisher.publish(new BlackBoardArtifactTagDeletedEvent(deletedTag)); } - public void notifyOsAccountAdded(OsAccount account) { - eventPublisher.publish(new OsAccountAddedEvent(account)); - } - - public void notifyOsAccountChanged(OsAccount account) { - eventPublisher.publish(new OsAccountChangedEvent(account)); - } - - public void notifyOsAccountRemoved(Long osAccountObjectId) { - eventPublisher.publish(new OsAccountDeletedEvent(osAccountObjectId)); - } - - /** - * Notify via an autopsy event that a host has been added. - * - * @param host The host that has been added. - */ - public void notifyHostAdded(Host host) { - eventPublisher.publish(new HostsAddedEvent(Collections.singletonList(host))); - } - - /** - * Notify via an autopsy event that a host has been changed. - * - * @param newValue The host that has been updated. - */ - public void notifyHostChanged(Host newValue) { - eventPublisher.publish(new HostsChangedEvent(Collections.singletonList(newValue))); - } - - /** - * Notify via an autopsy event that a host has been deleted. - * - * @param host The host that has been deleted. - */ - public void notifyHostDeleted(Host host) { - eventPublisher.publish(new HostsRemovedEvent(Collections.singletonList(host))); - } - - /** - * Notify via an autopsy event that a person has been added. - * - * @param person The person that has been added. - */ - public void notifyPersonAdded(Person person) { - eventPublisher.publish(new PersonsAddedEvent(Collections.singletonList(person))); - } - - /** - * Notify via an autopsy event that a person has been changed. - * - * @param newValue The person that has been updated. - */ - public void notifyPersonChanged(Person newValue) { - eventPublisher.publish(new PersonsChangedEvent(Collections.singletonList(newValue))); - } - - /** - * Notify via an autopsy event that a person has been deleted. - * - * @param person The person that has been deleted. - */ - public void notifyPersonDeleted(Person person) { - eventPublisher.publish(new PersonsDeletedEvent(Collections.singletonList(person))); - } - /** * Adds a report to the case. * diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsChangedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsChangedEvent.java deleted file mode 100644 index a5b8692c03..0000000000 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsChangedEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.List; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.datamodel.Host; - -/** - * Event fired when hosts are changed. - */ -public class HostsChangedEvent extends HostsEvent { - - private static final long serialVersionUID = 1L; - - /** - * Main constructor. - * - * @param dataModelObjects The new values for the hosts that have been - * changed. - */ - public HostsChangedEvent(List dataModelObjects) { - super(Case.Events.HOSTS_CHANGED.name(), dataModelObjects); - } -} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsEvent.java index 7c9a31f01e..69f68c0b4e 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsEvent.java @@ -19,10 +19,8 @@ package org.sleuthkit.autopsy.casemodule.events; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import org.sleuthkit.datamodel.Host; import org.sleuthkit.datamodel.HostManager; import org.sleuthkit.datamodel.SleuthkitCase; @@ -31,32 +29,10 @@ import org.sleuthkit.datamodel.TskCoreException; /** * Base event class for when something pertaining to hosts changes. */ -public class HostsEvent extends TskDataModelChangeEvent { +public class HostsEvent extends TskDataModelChangedEvent { private static final long serialVersionUID = 1L; - /** - * Retrieves a list of ids from a list of hosts. - * - * @param hosts The hosts. - * @return The list of ids. - */ - private static List getIds(List hosts) { - return getSafeList(hosts).stream() - .filter(h -> h != null) - .map(h -> h.getHostId()).collect(Collectors.toList()); - } - - /** - * Returns the hosts or an empty list. - * - * @param hosts The host list. - * @return The host list or an empty list if the parameter is null. - */ - private static List getSafeList(List hosts) { - return hosts == null ? Collections.emptyList() : hosts; - } - /** * Main constructor. * @@ -65,7 +41,7 @@ public class HostsEvent extends TskDataModelChangeEvent { * @param dataModelObjects The list of hosts for the event. */ protected HostsEvent(String eventName, List dataModelObjects) { - super(eventName, getIds(dataModelObjects), new ArrayList<>(getSafeList(dataModelObjects))); + super(eventName, dataModelObjects, Host::getHostId); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedEvent.java deleted file mode 100644 index 407b83c32a..0000000000 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.List; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.datamodel.Host; - -/** - * Event fired when hosts are removed. - */ -public class HostsRemovedEvent extends HostsEvent { - - private static final long serialVersionUID = 1L; - - /** - * Main constructor. - * @param dataModelObjects The list of hosts that have been deleted. - */ - public HostsRemovedEvent(List dataModelObjects) { - super(Case.Events.HOSTS_DELETED.name(), dataModelObjects); - } -} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountAddedEvent.java deleted file mode 100755 index c9f89903f4..0000000000 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountAddedEvent.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.datamodel.OsAccount; - -/** - * Event published when an OsAccount is added to a case. - */ -public final class OsAccountAddedEvent extends OsAccountEvent { - - private static final long serialVersionUID = 1L; - - public OsAccountAddedEvent(OsAccount account) { - super(Case.Events.OS_ACCOUNT_ADDED.toString(), account); - } - -} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountChangedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountChangedEvent.java deleted file mode 100755 index 237373a8b9..0000000000 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountChangedEvent.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.datamodel.OsAccount; - -/** - * Event published when an OsAccount is updated. - */ -public final class OsAccountChangedEvent extends OsAccountEvent { - - private static final long serialVersionUID = 1L; - - public OsAccountChangedEvent(OsAccount account) { - super(Case.Events.OS_ACCOUNT_CHANGED.toString(), account); - } -} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountDeletedEvent.java deleted file mode 100644 index adc726fca8..0000000000 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountDeletedEvent.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.events.AutopsyEvent; - -/** - * Event published when an OsAccount is deleted. - * - * oldValue will contain the objectId of the account that was removed. newValue - * will be null. - */ -public final class OsAccountDeletedEvent extends AutopsyEvent { - - private static final long serialVersionUID = 1L; - - public OsAccountDeletedEvent(Long osAccountObjectId) { - super(Case.Events.OS_ACCOUNT_REMOVED.toString(), osAccountObjectId, null); - } -} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountEvent.java deleted file mode 100755 index d34da7822d..0000000000 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountEvent.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.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. - */ -class OsAccountEvent extends TskDataModelChangeEvent { - - 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. - */ - OsAccountEvent(String eventName, OsAccount account) { - super(eventName, Stream.of(account.getId()).collect(Collectors.toList()), Stream.of(account).collect(Collectors.toList())); - } - - /** - * Returns the OsAccount that changed. - * - * @return The OsAccount that was changed. - */ - public OsAccount getOsAccount() { - List accounts = getNewValue(); - return accounts.get(0); - } - - @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; - } -} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsAddedEvent.java index e2a8a7aabd..c61bc177f3 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsAddedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsAddedEvent.java @@ -23,17 +23,19 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.datamodel.Person; /** - * Event fired when new persons are added. + * Event fired when new persons are added to a case. */ public class PersonsAddedEvent extends PersonsEvent { - + private static final long serialVersionUID = 1L; - + /** - * Main constructor. - * @param dataModelObjects The persons that have been added. + * Constructs an event fired when new persons are added to a case. + * + * @param persons The persons that have been added. */ - public PersonsAddedEvent(List dataModelObjects) { - super(Case.Events.PERSONS_ADDED.name(), dataModelObjects); + public PersonsAddedEvent(List persons) { + super(Case.Events.PERSONS_ADDED.name(), persons); } + } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsChangedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsChangedEvent.java deleted file mode 100644 index f375a125bb..0000000000 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsChangedEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.List; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.datamodel.Person; - -/** - * Event fired when persons are changed. - */ -public class PersonsChangedEvent extends PersonsEvent { - - private static final long serialVersionUID = 1L; - - /** - * Main constructor. - * - * @param dataModelObjects The new values for the persons that have been - * changed. - */ - public PersonsChangedEvent(List dataModelObjects) { - super(Case.Events.PERSONS_CHANGED.name(), dataModelObjects); - } -} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsDeletedEvent.java index a63fef32cb..db80759214 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsDeletedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsDeletedEvent.java @@ -18,22 +18,33 @@ */ 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; /** - * Event fired when persons are removed. + * An event fired when persons are deleted from the case. */ -public class PersonsDeletedEvent extends PersonsEvent { - +public class PersonsDeletedEvent extends TskDataModelChangedEvent { + private static final long serialVersionUID = 1L; - + /** - * Main constructor. - * @param dataModelObjects The list of persons that have been deleted. + * Constructs an event fired when persons are deleted from the case. + * + * @param dataModelObjectIds The unique numeric IDs (case database row IDs) + * of the persons that have been deleted. */ - public PersonsDeletedEvent(List dataModelObjects) { - super(Case.Events.PERSONS_DELETED.name(), dataModelObjects); + public PersonsDeletedEvent(List dataModelObjectIds) { + super(Case.Events.PERSONS_DELETED.name(), dataModelObjectIds); } + + @Override + protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { + return Collections.emptyList(); + } + } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsEvent.java index e3f584d58a..5380ee4874 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsEvent.java @@ -19,10 +19,8 @@ package org.sleuthkit.autopsy.casemodule.events; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import org.sleuthkit.datamodel.Person; import org.sleuthkit.datamodel.PersonManager; import org.sleuthkit.datamodel.SleuthkitCase; @@ -31,30 +29,10 @@ import org.sleuthkit.datamodel.TskCoreException; /** * Base event class for when something pertaining to persons changes. */ -public class PersonsEvent extends TskDataModelChangeEvent { - - /** - * Retrieves a list of ids from a list of persons. - * - * @param persons The persons. - * @return The list of ids. - */ - private static List getIds(List persons) { - return getSafeList(persons).stream() - .filter(h -> h != null) - .map(h -> h.getPersonId()).collect(Collectors.toList()); - } - - /** - * Returns the persons or an empty list. - * - * @param persons The person list. - * @return The person list or an empty list if the parameter is null. - */ - private static List getSafeList(List persons) { - return persons == null ? Collections.emptyList() : persons; - } +public class PersonsEvent extends TskDataModelChangedEvent { + private static final long serialVersionUID = 1L; + /** * Main constructor. * @@ -62,10 +40,10 @@ public class PersonsEvent extends TskDataModelChangeEvent { * type. * @param dataModelObjects The list of persons for the event. */ - protected PersonsEvent(String eventName, List dataModelObjects) { - super(eventName, getIds(dataModelObjects), new ArrayList<>(getSafeList(dataModelObjects))); + PersonsEvent(String eventName, List dataModelObjects) { + super(eventName, dataModelObjects, Person::getPersonId); } - + @Override protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { PersonManager personManager = caseDb.getPersonManager(); diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/ReportAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/ReportAddedEvent.java index bb4145c804..47c5a30d5d 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/ReportAddedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/ReportAddedEvent.java @@ -30,7 +30,7 @@ import org.sleuthkit.datamodel.TskCoreException; /** * Event published when a report is added to a case. */ -public final class ReportAddedEvent extends TskDataModelChangeEvent { +public final class ReportAddedEvent extends TskDataModelChangedEvent { private static final long serialVersionUID = 1L; @@ -40,7 +40,7 @@ public final class ReportAddedEvent extends TskDataModelChangeEvent { * @param report The data source that was added. */ public ReportAddedEvent(Report report) { - super(Case.Events.REPORT_ADDED.toString(), Stream.of(report.getId()).collect(Collectors.toList()), Stream.of(report).collect(Collectors.toList())); + super(Case.Events.REPORT_ADDED.toString(), Stream.of(report).collect(Collectors.toList()), Report::getId); } public Report getReport() { diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangeEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangeEvent.java deleted file mode 100755 index 1bd9fd81ac..0000000000 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangeEvent.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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 java.util.logging.Level; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.events.AutopsyEvent; -import org.sleuthkit.datamodel.SleuthkitCase; -import org.sleuthkit.datamodel.TskCoreException; - -/** - * An application event generic used as a superclass for events published when - * something changes in the Sleuth Kit Data Model for a case. - * - * @param A Sleuth Kit Data Model object type. - */ -public abstract class TskDataModelChangeEvent extends AutopsyEvent { - - private static final long serialVersionUID = 1L; - private static final Logger logger = Logger.getLogger(TskDataModelChangeEvent.class.getName()); - private final List dataModelObjectIds; - private transient List dataModelObjects; - - /** - * Constructs an application event generic used as a superclass for events - * published when something changes in the Sleuth Kit Data Model for a case. - * - * @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 associated with this application - * event. - * @param dataModelObjects The Sleuth Kit Data Model objects associated - * with this application event - */ - protected TskDataModelChangeEvent(String eventName, List dataModelObjectIds, List dataModelObjects) { - super(eventName, null, null); - this.dataModelObjectIds = dataModelObjectIds; - this.dataModelObjects = dataModelObjects; - if (eventName == null) { - throw new IllegalArgumentException("eventName is null"); - } - if (dataModelObjectIds == null) { - throw new IllegalArgumentException("dataModelObjectIds is null"); - } - if (dataModelObjects == null) { - throw new IllegalArgumentException("dataModelObjects is null"); - } - } - - /** - * 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. - * - * @return The unique IDs. - */ - public final List getDataModelObjectIds() { - return Collections.unmodifiableList(dataModelObjectIds); - } - - /** - * Gets the Sleuth Kit Data Model objects associated with this application - * event. - * - * @return The objects. - */ - @Override - public List getNewValue() { - /* - * If this event came from another host collaborating on a multi-user - * case, the transient list of Sleuth Kit Data Model objects will be - * null and will need to be reconstructed on the current host. - */ - if (dataModelObjects == null) { - try { - Case currentCase = Case.getCurrentCaseThrows(); - SleuthkitCase caseDb = currentCase.getSleuthkitCase(); - dataModelObjects = getDataModelObjects(caseDb, dataModelObjectIds); - } catch (NoCurrentCaseException | TskCoreException ex) { - logger.log(Level.SEVERE, String.format("Error geting TSK Data Model objects for %s event (%s)", getPropertyName(), getSourceType()), ex); - return Collections.emptyList(); - } - } - return Collections.unmodifiableList(dataModelObjects); - } - - /** - * Gets the Sleuth Kit Data Model objects associated with this application - * event. - * - * @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. - */ - abstract protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException; - -} diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java index a98bdb61dd..57253ef60e 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java @@ -38,7 +38,7 @@ import org.openide.util.WeakListeners; import org.openide.util.lookup.Lookups; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; -import org.sleuthkit.autopsy.casemodule.events.HostsChangedEvent; +import org.sleuthkit.autopsy.casemodule.events.HostsUpdatedEvent; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.datamodel.hosts.AssociatePersonsMenuAction; import org.sleuthkit.autopsy.datamodel.hosts.MergeHostMenuAction; @@ -177,8 +177,8 @@ 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 HostsChangedEvent) { - ((HostsChangedEvent) evt).getNewValue().stream() + if (hostId != null && eventType.equals(Case.Events.HOSTS_CHANGED.toString()) && evt instanceof HostsUpdatedEvent) { + ((HostsUpdatedEvent) evt).getNewValue().stream() .filter(h -> h != null && h.getHostId() == hostId) .findFirst() .ifPresent((newHost) -> { diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java b/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java index 170251bd13..42a69caa99 100755 --- a/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java @@ -39,7 +39,7 @@ import org.openide.util.Exceptions; import org.openide.util.NbBundle.Messages; import org.openide.util.WeakListeners; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.casemodule.events.OsAccountChangedEvent; +import org.sleuthkit.autopsy.casemodule.events.OsAccountsUpdatedEvent; import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance; import org.sleuthkit.autopsy.corecomponents.DataResultViewerTable; import org.sleuthkit.autopsy.coreutils.Logger; @@ -184,9 +184,9 @@ public final class OsAccounts implements AutopsyVisitableItem { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(Case.Events.OS_ACCOUNT_CHANGED.name())) { - if (((OsAccountChangedEvent) evt).getOsAccount().getId() == account.getId()) { + if (((OsAccountsUpdatedEvent) evt).getOsAccount().getId() == account.getId()) { // Update the account node to the new one - account = ((OsAccountChangedEvent) evt).getOsAccount(); + account = ((OsAccountsUpdatedEvent) evt).getOsAccount(); updateSheet(); } } else if (evt.getPropertyName().equals(REALM_DATA_AVAILABLE_EVENT)) { diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java index 4f12779ee8..3934ffa06c 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java @@ -36,7 +36,7 @@ import org.openide.util.WeakListeners; import org.openide.util.lookup.Lookups; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; -import org.sleuthkit.autopsy.casemodule.events.PersonsChangedEvent; +import org.sleuthkit.autopsy.casemodule.events.PersonsUpdatedEvent; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.datamodel.persons.DeletePersonAction; import org.sleuthkit.autopsy.datamodel.persons.EditPersonAction; @@ -145,8 +145,8 @@ 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 PersonsChangedEvent) { - ((PersonsChangedEvent) evt).getNewValue().stream() + if (personId != null && eventType.equals(Case.Events.PERSONS_CHANGED.toString()) && evt instanceof PersonsUpdatedEvent) { + ((PersonsUpdatedEvent) evt).getNewValue().stream() .filter(p -> p != null && p.getPersonId() == personId) .findFirst() .ifPresent((newPerson) -> { From 34c72cdc3469adfcad1a19defc7d18a322548d09 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 29 Apr 2021 10:17:34 -0400 Subject: [PATCH 02/14] 7553 data model event changes --- .../casemodule/events/HostsDeletedEvent.java | 51 ++++++ .../casemodule/events/HostsUpdatedEvent.java | 41 +++++ .../events/OsAccountsAddedEvent.java | 40 +++++ .../events/OsAccountsDeletedEvent.java | 49 ++++++ .../casemodule/events/OsAccountsEvent.java | 64 +++++++ .../events/OsAccountsUpdatedEvent.java | 41 +++++ .../events/PersonsUpdatedEvent.java | 41 +++++ .../events/TskDataModelChangedEvent.java | 165 ++++++++++++++++++ 8 files changed, 492 insertions(+) create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/HostsDeletedEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/HostsUpdatedEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsAddedEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsDeletedEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsUpdatedEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsDeletedEvent.java new file mode 100755 index 0000000000..3d62b78405 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsDeletedEvent.java @@ -0,0 +1,51 @@ +/* + * 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.SleuthkitCase; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * Event fired when hosts are deleted. + */ +public class HostsDeletedEvent extends TskDataModelChangedEvent { + + private static final long serialVersionUID = 1L; + + /** + * Main constructor. + * + * @param dataModelObjectIds The unique numeric IDs (TSK object IDs, case + * database row IDs, etc.) of the Hosts that have + * been deleted. + */ + public HostsDeletedEvent(List dataModelObjectIds) { + super(Case.Events.HOSTS_DELETED.name(), dataModelObjectIds); + } + + @Override + protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { + return Collections.emptyList(); + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsUpdatedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsUpdatedEvent.java new file mode 100755 index 0000000000..6b06382c0a --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsUpdatedEvent.java @@ -0,0 +1,41 @@ +/* + * 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.List; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.Host; + +/** + * Event fired when hosts are changed. + */ +public class HostsUpdatedEvent extends HostsEvent { + + private static final long serialVersionUID = 1L; + + /** + * Main constructor. + * + * @param dataModelObjects The new values for the hosts that have been + * changed. + */ + public HostsUpdatedEvent(List dataModelObjects) { + super(Case.Events.HOSTS_CHANGED.name(), dataModelObjects); + } +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsAddedEvent.java new file mode 100755 index 0000000000..49a722062b --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsAddedEvent.java @@ -0,0 +1,40 @@ +/* + * 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.List; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.OsAccount; + +/** + * Event published when OS accounts are added to 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 + */ + public OsAccountsAddedEvent(List accounts) { + super(Case.Events.OS_ACCOUNT_ADDED.toString(), accounts); + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsDeletedEvent.java new file mode 100755 index 0000000000..52fe8d49a8 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsDeletedEvent.java @@ -0,0 +1,49 @@ +/* + * 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.OsAccount; +import org.sleuthkit.datamodel.SleuthkitCase; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * An event published when OS accounts are deleted from a case. + */ +public final class OsAccountsDeletedEvent extends TskDataModelChangedEvent { + + private static final long serialVersionUID = 1L; + + /** + * Constructs an event published when OS accounts are deleted from a case. + * + * @param osAccountObjectIds The object IDs of the deleted accounts. + */ + public OsAccountsDeletedEvent(List osAccountObjectIds) { + super(Case.Events.OS_ACCOUNT_REMOVED.toString(), osAccountObjectIds); + } + + @Override + protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { + return Collections.emptyList(); + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsEvent.java new file mode 100755 index 0000000000..af214776a8 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsEvent.java @@ -0,0 +1,64 @@ +/* + * 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.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. + */ +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. + */ + OsAccountsEvent(String eventName, List accounts) { + super(eventName, accounts, OsAccount::getId); + } + + /** + * Returns the OsAccount that changed. + * + * @return The OsAccount that was changed. + */ + public OsAccount getOsAccount() { + List accounts = getNewValue(); + return accounts.get(0); + } + + @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; + } +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java new file mode 100755 index 0000000000..22ef19584b --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java @@ -0,0 +1,41 @@ +/* + * 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.List; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.OsAccount; + +/** + * Event published when OS accounts in the 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. + * + * @param accounts The accounts. + */ + public OsAccountsUpdatedEvent(List accounts) { + super(Case.Events.OS_ACCOUNT_CHANGED.toString(), accounts); + } +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsUpdatedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsUpdatedEvent.java new file mode 100755 index 0000000000..cb5308d7ce --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonsUpdatedEvent.java @@ -0,0 +1,41 @@ +/* + * 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.List; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.datamodel.Person; + +/** + * An event fired when persons in a case are updated. + */ +public class PersonsUpdatedEvent extends PersonsEvent { + + private static final long serialVersionUID = 1L; + + /** + * Constructs an event fired when persons in a case are updated. + * + * @param persons The updated persons. + */ + public PersonsUpdatedEvent(List persons) { + super(Case.Events.PERSONS_CHANGED.name(), persons); + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java new file mode 100755 index 0000000000..68a47c35c1 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java @@ -0,0 +1,165 @@ +/* + * 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 java.util.function.Function; +import java.util.logging.Level; +import java.util.stream.Collectors; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.events.AutopsyEvent; +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. + * + * @param A Sleuth Kit Data Model object type. + */ +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; + + /** + * 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. + * + * @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.). + */ + protected TskDataModelChangedEvent(String eventName, List dataModelObjects, Function getIdMethod) { + 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(); + } else { + return Collections.emptyList(); + } + } + + /** + * 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. + * + * @return The objects. + */ + @Override + public List getNewValue() { + if (!isDeletionEvent) { + if (dataModelObjects == null) { + try { + Case currentCase = Case.getCurrentCaseThrows(); + SleuthkitCase caseDb = currentCase.getSleuthkitCase(); + dataModelObjects = getDataModelObjects(caseDb, dataModelObjectIds); + } catch (NoCurrentCaseException | TskCoreException ex) { + logger.log(Level.SEVERE, String.format("Error geting TSK Data Model objects for %s event (%s)", getPropertyName(), getSourceType()), ex); + return Collections.emptyList(); + } + } + return Collections.unmodifiableList(dataModelObjects); + } 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 current host. + * + * @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. + */ + abstract protected List getDataModelObjects(SleuthkitCase caseDb, List ids) throws TskCoreException; + +} From 856eced424d77879b4bd62693e2b29ccafc69946 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 29 Apr 2021 11:55:59 -0400 Subject: [PATCH 03/14] 7553 data model event changes --- Core/src/org/sleuthkit/autopsy/casemodule/Case.java | 6 ++---- .../autopsy/casemodule/events/TskDataModelChangedEvent.java | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index f77859d407..b2790bd8ec 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -555,8 +555,7 @@ public class Case { */ @Subscribe public void publishPersonsAddedEvent(TskEvent.PersonsAddedTskEvent event) { - eventPublisher.publish(new PersonsAddedEvent( - event == null ? Collections.emptyList() : event.getPersons())); + eventPublisher.publish(new PersonsAddedEvent(event.getPersons())); } /** @@ -567,8 +566,7 @@ public class Case { */ @Subscribe public void publishPersonsUpdatedEvent(TskEvent.PersonsUpdatedTskEvent event) { - eventPublisher.publish(new PersonsUpdatedEvent( - event == null ? Collections.emptyList() : event.getPersons())); + eventPublisher.publish(new PersonsUpdatedEvent(event.getPersons())); } /** diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java index 68a47c35c1..d0d8953e92 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java @@ -148,7 +148,7 @@ public abstract class TskDataModelChangedEvent extends AutopsyEvent { * 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 current host. + * reconstruct the objects on the curartifactExists(), I think we should continue to use what we have and suppress the deprecation warnings.Bent host. * * @param caseDb The case database. * @param ids The unique, numeric IDs (TSK object IDs, case database row From bb2e65a770febdbb36e651cfff42b384e5e21ce5 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Tue, 4 May 2021 14:05:49 -0400 Subject: [PATCH 04/14] 7553 data model event changes --- .../sleuthkit/autopsy/casemodule/Case.java | 25 ++- .../casemodule/events/HostsAddedEvent.java | 20 +- .../events/HostsAddedToPersonEvent.java | 39 ++++ .../casemodule/events/HostsDeletedEvent.java | 30 +-- .../autopsy/casemodule/events/HostsEvent.java | 46 ++-- .../events/HostsRemovedFromPersonEvent.java | 25 +++ .../casemodule/events/HostsUpdatedEvent.java | 14 +- .../events/OsAccountsAddedEvent.java | 17 +- .../events/OsAccountsDeletedEvent.java | 26 ++- .../casemodule/events/OsAccountsEvent.java | 52 ++--- .../events/OsAccountsUpdatedEvent.java | 14 +- .../casemodule/events/PersonHostsEvent.java | 75 +++++++ .../casemodule/events/PersonsAddedEvent.java | 8 +- .../events/PersonsDeletedEvent.java | 29 +-- .../casemodule/events/PersonsEvent.java | 51 +++-- .../events/PersonsUpdatedEvent.java | 10 +- .../casemodule/events/ReportAddedEvent.java | 25 ++- .../events/TskDataModelChangedEvent.java | 212 +++++++++++------- .../TskDataModelObjectsDeletedEvent.java | 60 +++++ .../datamodel/AutopsyTreeChildFactory.java | 5 +- .../datamodel/DataSourcesByTypeNode.java | 5 +- .../sleuthkit/autopsy/datamodel/HostNode.java | 4 +- .../autopsy/datamodel/OsAccounts.java | 19 +- .../autopsy/datamodel/PersonGroupingNode.java | 9 +- .../hosts/AssociateNewPersonAction.java | 3 +- .../hosts/AssociatePersonAction.java | 3 +- .../hosts/RemoveParentPersonAction.java | 5 +- .../autopsy/events/AutopsyEvent.java | 50 +++-- 28 files changed, 588 insertions(+), 293 deletions(-) create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedFromPersonEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/PersonHostsEvent.java create mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelObjectsDeletedEvent.java 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. */ From 0ee586196f5fd7de832f7a2df0322d05d629d550 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Tue, 4 May 2021 14:24:24 -0400 Subject: [PATCH 05/14] 7553 data model event changes --- .../sleuthkit/autopsy/casemodule/Case.java | 26 +++++++++---------- .../events/OsAccountsUpdatedEvent.java | 2 +- .../autopsy/datamodel/OsAccounts.java | 4 +-- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index 06809bffa8..f18c600942 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -429,49 +429,47 @@ public class Case { */ CR_COMMENT_CHANGED, /** - * OSAccount associated with the current case added. Call getOsAccount - * to get the added account; + * One or more OS accounts have been added to the case. */ OS_ACCOUNTS_ADDED, /** - * OSAccount associated with the current case has changed. Call - * getOsAccount to get the changed account; + * One or more OS accounts in the case have been updated. */ - OS_ACCOUNT_CHANGED, + OS_ACCOUNTS_UPDATED, /** - * OSAccount associated with the current case has been deleted. + * One or more OS accounts have been deleted from the case. */ OS_ACCOUNTS_DELETED, /** - * Hosts associated with the current case added. + * One or more hosts have been added to the case. */ HOSTS_ADDED, /** - * Hosts associated with the current case has changed. + * One or more hosts in the case have been updated. */ HOSTS_UPDATED, /** - * Hosts associated with the current case has been deleted. + * One or more hosts have been deleted from the case. */ HOSTS_DELETED, /** - * Persons associated with the current case added. + * One or more persons have been added to the case. */ PERSONS_ADDED, /** - * Persons associated with the current case has changed. + * One or more persons in the case have been updated. */ PERSONS_UPDATED, /** - * Persons associated with the current case has been deleted. + * One or more hosts persons been deleted from the case. */ PERSONS_DELETED, /** - * Hosts have been added to a person. + * One or more hosts have been added to a person. */ HOSTS_ADDED_TO_PERSON, /** - * Hosts have been removed from a person. + * One or more hosts have been removed from a person. */ HOSTS_REMOVED_FROM_PERSON; diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java index 9795f055d6..65767ccdfc 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/OsAccountsUpdatedEvent.java @@ -37,7 +37,7 @@ public final class OsAccountsUpdatedEvent extends OsAccountsEvent { * @param osAccounts The OS accounts that were updated. */ public OsAccountsUpdatedEvent(List osAccounts) { - super(Case.Events.OS_ACCOUNT_CHANGED.toString(), osAccounts); + super(Case.Events.OS_ACCOUNTS_UPDATED.toString(), osAccounts); } } diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java b/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java index 9472a65616..322ac8cddb 100755 --- a/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/OsAccounts.java @@ -183,7 +183,7 @@ public final class OsAccounts implements AutopsyVisitableItem { private final PropertyChangeListener listener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals(Case.Events.OS_ACCOUNT_CHANGED.name())) { + if (evt.getPropertyName().equals(Case.Events.OS_ACCOUNTS_UPDATED.name())) { OsAccountsUpdatedEvent updateEvent = (OsAccountsUpdatedEvent) evt; for (OsAccount acct : updateEvent.getOsAccounts()) { if (acct.getId() == account.getId()) { @@ -224,7 +224,7 @@ public final class OsAccounts implements AutopsyVisitableItem { setDisplayName(account.getName()); setIconBaseWithExtension(ICON_PATH); - Case.addEventTypeSubscriber(Collections.singleton(Case.Events.OS_ACCOUNT_CHANGED), weakListener); + Case.addEventTypeSubscriber(Collections.singleton(Case.Events.OS_ACCOUNTS_UPDATED), weakListener); } @Override From 92cba46d6d0ed26d2f40498ea79c93a6bdb3b8da Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Tue, 4 May 2021 15:07:51 -0400 Subject: [PATCH 06/14] 7553 data model event changes --- .../sleuthkit/autopsy/casemodule/Case.java | 13 ++++++ .../events/HostsAddedToPersonEvent.java | 18 +++++--- .../events/HostsRemovedFromPersonEvent.java | 40 ++++++++++++---- .../casemodule/events/PersonHostsEvent.java | 46 ++++++++++--------- 4 files changed, 80 insertions(+), 37 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index f18c600942..0274dd7c23 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -84,8 +84,10 @@ import org.sleuthkit.autopsy.casemodule.events.DataSourceAddedEvent; import org.sleuthkit.autopsy.casemodule.events.DataSourceDeletedEvent; import org.sleuthkit.autopsy.casemodule.events.DataSourceNameChangedEvent; import org.sleuthkit.autopsy.casemodule.events.HostsAddedEvent; +import org.sleuthkit.autopsy.casemodule.events.HostsAddedToPersonEvent; import org.sleuthkit.autopsy.casemodule.events.HostsUpdatedEvent; import org.sleuthkit.autopsy.casemodule.events.HostsDeletedEvent; +import org.sleuthkit.autopsy.casemodule.events.HostsRemovedFromPersonEvent; import org.sleuthkit.autopsy.casemodule.events.OsAccountsAddedEvent; import org.sleuthkit.autopsy.casemodule.events.OsAccountsUpdatedEvent; import org.sleuthkit.autopsy.casemodule.events.OsAccountsDeletedEvent; @@ -586,6 +588,17 @@ public class Case { public void publishPersonsDeletedEvent(TskEvent.PersonsDeletedTskEvent event) { eventPublisher.publish(new PersonsDeletedEvent(event.getPersonIds())); } + + @Subscribe + public void publishHostsAddedToPersonEvent(TskEvent.HostsAddedToPersonTskEvent event) { + eventPublisher.publish(new HostsAddedToPersonEvent(event.getPerson(), event.getHosts())); + } + + @Subscribe + public void publisHostsRemovedFromPersonEvent(TskEvent.HostsRemovedFromPersonTskEvent event) { + eventPublisher.publish(new HostsRemovedFromPersonEvent(event.getPerson(), event.getHosts())); + } + } /** diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java index 8b1b9da8a3..a7937330d2 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java @@ -18,22 +18,28 @@ */ 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 + * Application events published when one or more hosts have been added to a + * person. */ public final class HostsAddedToPersonEvent extends PersonHostsEvent { - + private static final long serialVersionUID = 1L; - + + /** + * Constructs an application event published when one or more hosts have + * been added to a person. + * + * @param person The person. + * @param hosts The hosts. + */ 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/HostsRemovedFromPersonEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedFromPersonEvent.java index eaf200368d..df84e0bbaa 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedFromPersonEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedFromPersonEvent.java @@ -1,7 +1,20 @@ /* - * 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. + * 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; @@ -11,15 +24,22 @@ import org.sleuthkit.datamodel.Host; import org.sleuthkit.datamodel.Person; /** - * - * @author rcordovano + * Application events published when one or more hosts have been removed from a + * person. */ -public class HostsRemovedFromPersonEvent extends PersonHostsEvent { - +public class HostsRemovedFromPersonEvent extends PersonHostsEvent { + private static final long serialVersionUID = 1L; - + + /** + * Constructs an application event published when one or more hosts have + * been removed from a person. + * + * @param person The person. + * @param hosts The hosts. + */ 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/PersonHostsEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonHostsEvent.java index f1426e38e4..edf0f8b65d 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonHostsEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonHostsEvent.java @@ -15,37 +15,41 @@ import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; /** - * - * @author rcordovano + * An abstract super class for person and host association change events. */ public abstract class PersonHostsEvent extends TskDataModelChangedEvent { - + private static final long serialVersionUID = 1L; - + /** - * - * @param eventName - * @param person - * @param hosts + * Constructs the abstract super class part of a person and host association + * change event. + * + * @param eventName The name of the Case.Events enum value for the event + * type. + * @param person The person that is the subject of the event. + * @param hosts The hosts that are the subject of the event. */ PersonHostsEvent(String eventName, Person person, List hosts) { super(eventName, Collections.singletonList(person), Person::getPersonId, hosts, Host::getHostId); } - + /** - * - * @return + * Gets the person. + * + * @return The person. */ - Person getPerson() { + public Person getPerson() { return getOldValue().get(0); } - + /** - * - * @return + * Gets the hosts. + * + * @return The hosts. */ - List getHosts() { - return getNewValue(); + public List getHosts() { + return getNewValue(); } @Override @@ -58,8 +62,8 @@ public abstract class PersonHostsEvent extends TskDataModelChangedEvent getNewValueObjects(SleuthkitCase caseDb, List ids) throws TskCoreException { List hosts = new ArrayList<>(); @@ -70,6 +74,6 @@ public abstract class PersonHostsEvent extends TskDataModelChangedEvent Date: Tue, 4 May 2021 15:21:57 -0400 Subject: [PATCH 07/14] 7553 data model event changes --- .../autopsy/casemodule/events/HostsAddedToPersonEvent.java | 2 +- .../autopsy/casemodule/events/HostsRemovedFromPersonEvent.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java index a7937330d2..7bee69fd24 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java @@ -38,7 +38,7 @@ public final class HostsAddedToPersonEvent extends PersonHostsEvent { * @param person The person. * @param hosts The hosts. */ - HostsAddedToPersonEvent(Person person, List hosts) { + public 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/HostsRemovedFromPersonEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedFromPersonEvent.java index df84e0bbaa..2d51cbba5b 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedFromPersonEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedFromPersonEvent.java @@ -38,7 +38,7 @@ public class HostsRemovedFromPersonEvent extends PersonHostsEvent { * @param person The person. * @param hosts The hosts. */ - HostsRemovedFromPersonEvent(Person person, List hosts) { + public HostsRemovedFromPersonEvent(Person person, List hosts) { super(Case.Events.HOSTS_REMOVED_FROM_PERSON.toString(), person, hosts); } From 98ea5d2bc967aa0efd12f49018e85e5f0d64c4f2 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Fri, 7 May 2021 12:06:27 -0400 Subject: [PATCH 08/14] 7553 data model event changes --- Core/src/org/sleuthkit/autopsy/casemodule/Case.java | 2 +- .../sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java | 4 ++-- .../org/sleuthkit/autopsy/casemodule/events/HostsEvent.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index 0274dd7c23..b477b11ea4 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -463,7 +463,7 @@ public class Case { */ PERSONS_UPDATED, /** - * One or more hosts persons been deleted from the case. + * One or more persons been deleted from the case. */ PERSONS_DELETED, /** diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java index bf355b66b7..b598c375d6 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java @@ -23,7 +23,7 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.datamodel.Host; /** - * An application event published when hosts have been added to the Sleuth Kit + * Application events published when hosts have been added to the Sleuth Kit * data model for a case. */ public final class HostsAddedEvent extends HostsEvent { @@ -39,5 +39,5 @@ public final class HostsAddedEvent extends HostsEvent { public HostsAddedEvent(List hosts) { super(Case.Events.HOSTS_ADDED.name(), hosts); } - + } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsEvent.java index 1ac350c272..465d265083 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsEvent.java @@ -41,7 +41,7 @@ public class HostsEvent extends TskDataModelChangedEvent { * type. * @param hosts The hosts. */ - protected HostsEvent(String eventName, List hosts) { + HostsEvent(String eventName, List hosts) { super(eventName, null, null, hosts, Host::getHostId); } From 90fc3c7153f0d15321bb5cb73aa9af5a552e83f8 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Mon, 10 May 2021 10:29:35 -0400 Subject: [PATCH 09/14] 7553 data model event changes --- .../sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java | 2 +- .../autopsy/casemodule/events/TskDataModelChangedEvent.java | 2 +- Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java index b598c375d6..f188c7d5a3 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedEvent.java @@ -34,7 +34,7 @@ public final class HostsAddedEvent extends HostsEvent { * 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. + * @param hosts The hosts that have been added. */ public HostsAddedEvent(List hosts) { super(Case.Events.HOSTS_ADDED.name(), hosts); diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java index 07ed7166d7..83ced035fc 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/TskDataModelChangedEvent.java @@ -103,7 +103,7 @@ public abstract class TskDataModelChangedEvent extends AutopsyEvent { } newValueIds = new ArrayList<>(); this.newValueObjects = new ArrayList<>(); - if (oldValueObjects != null) { + if (newValueObjects != null) { hasNewValue = true; newValueIds.addAll(newValueObjects.stream() .map(o -> newValueGetIdMethod.apply(o)) diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java index 644e2b6b80..99b0461112 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java @@ -178,7 +178,7 @@ public class HostNode extends DisplayableItemNode { public void propertyChange(PropertyChangeEvent evt) { String eventType = evt.getPropertyName(); if (hostId != null && eventType.equals(Case.Events.HOSTS_UPDATED.toString()) && evt instanceof HostsUpdatedEvent) { - ((HostsUpdatedEvent) evt).getNewValue().stream() + ((HostsUpdatedEvent) evt).getHosts().stream() .filter(h -> h != null && h.getHostId() == hostId) .findFirst() .ifPresent((newHost) -> { From 2e1cd9d4b1913b664443066a3a658e59891e6367 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Tue, 11 May 2021 09:38:18 -0400 Subject: [PATCH 10/14] 7553 data model event changes --- .../org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java index 736cab3028..eccf0eb18a 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java @@ -69,8 +69,11 @@ 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, + Case.Events.HOSTS_ADDED, Case.Events.HOSTS_DELETED, - Case.Events.PERSONS_UPDATED); + Case.Events.PERSONS_UPDATED, + Case.Events.HOSTS_ADDED_TO_PERSON, + Case.Events.HOSTS_REMOVED_FROM_PERSON); private static final Set CHILD_EVENTS_STR = CHILD_EVENTS.stream() .map(ev -> ev.name()) From 6955b075e10cee9bbf7e83ab2c2c752101a4c54f Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Wed, 12 May 2021 09:40:00 -0400 Subject: [PATCH 11/14] 7553 data model event changes --- .../sleuthkit/autopsy/casemodule/Case.java | 2 +- .../events/HostsAddedToPersonEvent.java | 51 ++++++++- .../events/HostsRemovedFromPersonEvent.java | 48 ++++++++- .../casemodule/events/PersonHostsEvent.java | 79 -------------- .../datamodel/AutopsyTreeChildFactory.java | 102 +++++++++++------- .../autopsy/datamodel/DataSourcesNode.java | 2 +- .../datamodel/DisplayableItemNodeVisitor.java | 4 +- ...ersonGroupingNode.java => PersonNode.java} | 57 ++++++---- .../datamodel/RootContentChildren.java | 2 +- .../DirectoryTreeTopComponent.java | 6 +- .../directorytree/ViewContextAction.java | 4 +- 11 files changed, 201 insertions(+), 156 deletions(-) delete mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/events/PersonHostsEvent.java rename Core/src/org/sleuthkit/autopsy/datamodel/{PersonGroupingNode.java => PersonNode.java} (81%) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index b477b11ea4..1d0e0dd833 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -596,7 +596,7 @@ public class Case { @Subscribe public void publisHostsRemovedFromPersonEvent(TskEvent.HostsRemovedFromPersonTskEvent event) { - eventPublisher.publish(new HostsRemovedFromPersonEvent(event.getPerson(), event.getHosts())); + eventPublisher.publish(new HostsRemovedFromPersonEvent(event.getPerson(), event.getHostIds())); } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java index 7bee69fd24..fffb39d82c 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsAddedToPersonEvent.java @@ -18,16 +18,21 @@ */ 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.autopsy.casemodule.Case; import org.sleuthkit.datamodel.Host; import org.sleuthkit.datamodel.Person; +import org.sleuthkit.datamodel.SleuthkitCase; +import org.sleuthkit.datamodel.TskCoreException; /** * Application events published when one or more hosts have been added to a * person. */ -public final class HostsAddedToPersonEvent extends PersonHostsEvent { +public final class HostsAddedToPersonEvent extends TskDataModelChangedEvent { private static final long serialVersionUID = 1L; @@ -39,7 +44,49 @@ public final class HostsAddedToPersonEvent extends PersonHostsEvent { * @param hosts The hosts. */ public HostsAddedToPersonEvent(Person person, List hosts) { - super(Case.Events.HOSTS_ADDED_TO_PERSON.toString(), person, hosts); + super(Case.Events.HOSTS_ADDED_TO_PERSON.toString(), Collections.singletonList(person), Person::getPersonId, hosts, Host::getHostId); } + /** + * Gets the person. + * + * @return The person. + */ + public Person getPerson() { + return getOldValue().get(0); + } + + /** + * Gets the hosts. + * + * @return The hosts. + */ + public 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/HostsRemovedFromPersonEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedFromPersonEvent.java index 2d51cbba5b..e23ef786ee 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedFromPersonEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/HostsRemovedFromPersonEvent.java @@ -18,16 +18,21 @@ */ 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.autopsy.casemodule.Case; import org.sleuthkit.datamodel.Host; import org.sleuthkit.datamodel.Person; +import org.sleuthkit.datamodel.SleuthkitCase; +import org.sleuthkit.datamodel.TskCoreException; /** * Application events published when one or more hosts have been removed from a * person. */ -public class HostsRemovedFromPersonEvent extends PersonHostsEvent { +public class HostsRemovedFromPersonEvent extends TskDataModelChangedEvent { private static final long serialVersionUID = 1L; @@ -36,10 +41,45 @@ public class HostsRemovedFromPersonEvent extends PersonHostsEvent { * been removed from a person. * * @param person The person. - * @param hosts The hosts. + * @param hostIds The host IDs of the removed hosts. */ - public HostsRemovedFromPersonEvent(Person person, List hosts) { - super(Case.Events.HOSTS_REMOVED_FROM_PERSON.toString(), person, hosts); + public HostsRemovedFromPersonEvent(Person person, List hostIds) { + super(Case.Events.HOSTS_REMOVED_FROM_PERSON.toString(), Collections.singletonList(person), Person::getPersonId, hostIds, (id -> id)); + } + + /** + * Gets the person. + * + * @return The person. + */ + public Person getPerson() { + return getOldValue().get(0); + } + + /** + * Gets the host IDs of the removed hosts. + * + * @return The host IDs. + */ + public List getHostIds() { + 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 { + return ids; } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonHostsEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonHostsEvent.java deleted file mode 100755 index edf0f8b65d..0000000000 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/PersonHostsEvent.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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; - -/** - * An abstract super class for person and host association change events. - */ -public abstract class PersonHostsEvent extends TskDataModelChangedEvent { - - private static final long serialVersionUID = 1L; - - /** - * Constructs the abstract super class part of a person and host association - * change event. - * - * @param eventName The name of the Case.Events enum value for the event - * type. - * @param person The person that is the subject of the event. - * @param hosts The hosts that are the subject of the event. - */ - PersonHostsEvent(String eventName, Person person, List hosts) { - super(eventName, Collections.singletonList(person), Person::getPersonId, hosts, Host::getHostId); - } - - /** - * Gets the person. - * - * @return The person. - */ - public Person getPerson() { - return getOldValue().get(0); - } - - /** - * Gets the hosts. - * - * @return The hosts. - */ - public 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/datamodel/AutopsyTreeChildFactory.java b/Core/src/org/sleuthkit/autopsy/datamodel/AutopsyTreeChildFactory.java index ca4368e1e4..387b7d24e1 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/AutopsyTreeChildFactory.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/AutopsyTreeChildFactory.java @@ -1,15 +1,15 @@ /* * Autopsy Forensic Browser - * - * Copyright 2018 Basis Technology Corp. + * + * Copyright 2018-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. @@ -42,33 +42,40 @@ import org.sleuthkit.datamodel.SleuthkitVisitableItem; import org.sleuthkit.datamodel.TskCoreException; /** - * Child factory to create the top level children of the autopsy tree - * + * A child factory to create the top level nodes in the main tree view. These + * nodes are the child nodes of the invisible root node of the tree. The child + * nodes that are created vary with the view option selected by the user: group + * by data type or group by person/host. */ public final class AutopsyTreeChildFactory extends ChildFactory.Detachable { - private static final Set LISTENING_EVENTS = EnumSet.of(Case.Events.DATA_SOURCE_ADDED, + private static final Set EVENTS_OF_INTEREST = 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_UPDATED + Case.Events.HOSTS_ADDED_TO_PERSON, + Case.Events.HOSTS_REMOVED_FROM_PERSON ); - private static final Set LISTENING_EVENT_NAMES = LISTENING_EVENTS.stream() + private static final Set EVENTS_OF_INTEREST_NAMES = EVENTS_OF_INTEREST.stream() .map(evt -> evt.name()) .collect(Collectors.toSet()); private static final Logger logger = Logger.getLogger(AutopsyTreeChildFactory.class.getName()); /** - * Listener for handling DATA_SOURCE_ADDED events. + * Listener for application events published when persons and/or hosts are + * added to or deleted from the data model for the current case. If the user + * has selected the group by person/host option for the tree, these events + * mean that the top-level person/host nodes in the tree need to be + * refreshed to reflect the changes. */ private final PropertyChangeListener pcl = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { String eventType = evt.getPropertyName(); - if (LISTENING_EVENT_NAMES.contains(eventType) + if (EVENTS_OF_INTEREST_NAMES.contains(eventType) && Objects.equals(CasePreferences.getGroupItemsInTreeByDataSource(), true)) { refreshChildren(); } @@ -78,26 +85,38 @@ public final class AutopsyTreeChildFactory extends ChildFactory.Detachable list) { + protected boolean createKeys(List keys) { try { SleuthkitCase tskCase = Case.getCurrentCaseThrows().getSleuthkitCase(); if (Objects.equals(CasePreferences.getGroupItemsInTreeByDataSource(), true)) { + /* + * The user has selected the group by person/host tree view + * option. + */ PersonManager personManager = tskCase.getPersonManager(); List persons = personManager.getPersons(); // show persons level if there are persons to be shown @@ -105,10 +124,10 @@ public final class AutopsyTreeChildFactory extends ChildFactory.Detachable keys = new ArrayList<>(Arrays.asList( + /* + * The user has selected the group by data type tree view + * option. + */ + List groupByDataTypeKeys = new ArrayList<>(Arrays.asList( new DataSourcesByType(), new Views(tskCase), new Results(tskCase), new Tags(), new Reports())); - - list.addAll(keys); + keys.addAll(groupByDataTypeKeys); } } catch (NoCurrentCaseException ex) { - logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS + logger.log(Level.SEVERE, "Failed to create tree because there is no current case", ex); //NON-NLS } catch (TskCoreException ex) { - logger.log(Level.SEVERE, "Exception while getting data from case.", ex); //NON-NLS + logger.log(Level.SEVERE, "Failed to create tree because of an error querying the case database", ex); //NON-NLS } return true; } /** - * Creates nodes for the top level Key + * Creates a node for a given key for the top level nodes in the main tree + * view. * - * @param key + * @param key The key. * - * @return Node for the key, null if key is unknown. + * @return A node for the key. */ @Override protected Node createNodeForKey(Object key) { - if (key instanceof SleuthkitVisitableItem) { - return ((SleuthkitVisitableItem) key).accept(new CreateSleuthkitNodeVisitor()); - } else if (key instanceof AutopsyVisitableItem) { - return ((AutopsyVisitableItem) key).accept(new RootContentChildren.CreateAutopsyNodeVisitor()); - } else { - logger.log(Level.SEVERE, "Unknown key type ", key.getClass().getName()); - return null; + Node node = null; + if (key != null) { + if (key instanceof SleuthkitVisitableItem) { + node = ((SleuthkitVisitableItem) key).accept(new CreateSleuthkitNodeVisitor()); + } else if (key instanceof AutopsyVisitableItem) { + node = ((AutopsyVisitableItem) key).accept(new RootContentChildren.CreateAutopsyNodeVisitor()); + } else { + logger.log(Level.SEVERE, "Unknown key type: ", key.getClass().getName()); + } } + return node; } /** - * Refresh the children + * Refreshes the top level nodes in the main tree view. */ public void refreshChildren() { refresh(true); } + } diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesNode.java index 033f14fc04..c8be68d164 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesNode.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2018 Basis Technology Corp. + * Copyright 2011-2021 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/DisplayableItemNodeVisitor.java b/Core/src/org/sleuthkit/autopsy/datamodel/DisplayableItemNodeVisitor.java index 61bc401ee5..ac3cd703c7 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/DisplayableItemNodeVisitor.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/DisplayableItemNodeVisitor.java @@ -197,7 +197,7 @@ public interface DisplayableItemNodeVisitor { T visit(OsAccounts.OsAccountListNode node); - T visit(PersonGroupingNode node); + T visit(PersonNode node); T visit(HostNode node); @@ -576,7 +576,7 @@ public interface DisplayableItemNodeVisitor { } @Override - public T visit(PersonGroupingNode node) { + public T visit(PersonNode node) { return defaultVisit(node); } diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/PersonNode.java similarity index 81% rename from Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java rename to Core/src/org/sleuthkit/autopsy/datamodel/PersonNode.java index eccf0eb18a..c67758c056 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/PersonGroupingNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/PersonNode.java @@ -1,15 +1,15 @@ /* * 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. @@ -45,16 +45,21 @@ import org.sleuthkit.datamodel.Person; import org.sleuthkit.datamodel.TskCoreException; /** - * A node to be displayed in the UI tree for a person and persons grouped in - * this host. + * A main tree view node that represents a person in a case. Its child nodes, if + * any, represent hosts in the case. There must be at least one person in a case + * for the person nodes layer to appear. If the persons layer is present, any + * hosts that are not associated with a person are grouped under an "Unknown + * Persons" person node. */ @NbBundle.Messages(value = {"PersonNode_unknownPersonNode_title=Unknown Persons"}) -public class PersonGroupingNode extends DisplayableItemNode { +public class PersonNode extends DisplayableItemNode { private static final String ICON_PATH = "org/sleuthkit/autopsy/images/person.png"; - + /** - * Returns the id of an unknown persons node. This can be used with a node lookup. + * Returns the id of an unknown persons node. This can be used with a node + * lookup. + * * @return The id of an unknown persons node. */ public static String getUnknownPersonId() { @@ -68,14 +73,13 @@ 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, - Case.Events.HOSTS_ADDED, - Case.Events.HOSTS_DELETED, - Case.Events.PERSONS_UPDATED, + private static final Set HOST_EVENTS_OF_INTEREST = EnumSet.of(Case.Events.HOSTS_ADDED, + Case.Events.HOSTS_ADDED, + Case.Events.HOSTS_DELETED, Case.Events.HOSTS_ADDED_TO_PERSON, Case.Events.HOSTS_REMOVED_FROM_PERSON); - - private static final Set CHILD_EVENTS_STR = CHILD_EVENTS.stream() + + private static final Set HOST_EVENTS_OF_INTEREST_NAMES = HOST_EVENTS_OF_INTEREST.stream() .map(ev -> ev.name()) .collect(Collectors.toSet()); @@ -91,13 +95,18 @@ public class PersonGroupingNode extends DisplayableItemNode { } /** - * Listener for handling adding and removing host events. + * Listener for application events that are published when hosts are + * added to or deleted from a case, and for events published when the + * associations between persons and hosts change. If the user has + * selected the group by person/host option for the main tree view, + * these events mean that person nodes in the tree need to be refreshed + * to reflect the structural changes. */ private final PropertyChangeListener hostAddedDeletedPcl = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { String eventType = evt.getPropertyName(); - if (eventType != null && CHILD_EVENTS_STR.contains(eventType)) { + if (eventType != null && HOST_EVENTS_OF_INTEREST_NAMES.contains(eventType)) { refresh(true); } } @@ -105,12 +114,12 @@ public class PersonGroupingNode extends DisplayableItemNode { @Override protected void addNotify() { - Case.addEventTypeSubscriber(CHILD_EVENTS, hostAddedDeletedPcl); + Case.addEventTypeSubscriber(HOST_EVENTS_OF_INTEREST, hostAddedDeletedPcl); } @Override protected void removeNotify() { - Case.removeEventTypeSubscriber(CHILD_EVENTS, hostAddedDeletedPcl); + Case.removeEventTypeSubscriber(HOST_EVENTS_OF_INTEREST, hostAddedDeletedPcl); } @Override @@ -141,7 +150,8 @@ public class PersonGroupingNode extends DisplayableItemNode { private final Long personId; /** - * Listener for handling person change events. + * Listener for application events that are published when the properties of + * persons in the case change. */ private final PropertyChangeListener personChangePcl = new PropertyChangeListener() { @Override @@ -163,6 +173,7 @@ public class PersonGroupingNode extends DisplayableItemNode { * Gets the display name for this person or "Unknown Persons". * * @param person The person. + * * @return The non-empty string for the display name. */ private static String getDisplayName(Person person) { @@ -176,17 +187,17 @@ public class PersonGroupingNode extends DisplayableItemNode { * * @param person The person record to be represented. */ - PersonGroupingNode(Person person) { + PersonNode(Person person) { this(person, getDisplayName(person)); } /** * Constructor. * - * @param person The person. + * @param person The person. * @param displayName The display name for the person. */ - private PersonGroupingNode(Person person, String displayName) { + private PersonNode(Person person, String displayName) { super(Children.create(new PersonChildren(person), false), person == null ? Lookups.fixed(displayName) : Lookups.fixed(person, displayName)); super.setName(displayName); diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/RootContentChildren.java b/Core/src/org/sleuthkit/autopsy/datamodel/RootContentChildren.java index 07ea924d82..4e489312c8 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/RootContentChildren.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/RootContentChildren.java @@ -187,7 +187,7 @@ public class RootContentChildren extends Children.Keys { @Override public AbstractNode visit(PersonGrouping personGrouping) { - return new PersonGroupingNode(personGrouping.getPerson()); + return new PersonNode(personGrouping.getPerson()); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java b/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java index d2cd291de0..e7db0d4803 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java @@ -84,7 +84,7 @@ import org.sleuthkit.autopsy.datamodel.InterestingHits; import org.sleuthkit.autopsy.datamodel.KeywordHits; import org.sleuthkit.autopsy.datamodel.ResultsNode; import org.sleuthkit.autopsy.datamodel.AutopsyTreeChildFactory; -import org.sleuthkit.autopsy.datamodel.PersonGroupingNode; +import org.sleuthkit.autopsy.datamodel.PersonNode; import org.sleuthkit.autopsy.datamodel.Tags; import org.sleuthkit.autopsy.datamodel.ViewsNode; import org.sleuthkit.autopsy.datamodel.accounts.Accounts; @@ -234,7 +234,7 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat if (node == null) { return Collections.emptyList(); } else if (node.getLookup().lookup(Person.class) != null - || PersonGroupingNode.getUnknownPersonId().equals(node.getLookup().lookup(String.class))) { + || PersonNode.getUnknownPersonId().equals(node.getLookup().lookup(String.class))) { Children children = node.getChildren(); Node[] childNodes = children == null ? null : children.getNodes(); if (childNodes != null) { @@ -1124,7 +1124,7 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat return null; } else if (node.getLookup().lookup(Host.class) != null || node.getLookup().lookup(Person.class) != null - || PersonGroupingNode.getUnknownPersonId().equals(node.getLookup().lookup(String.class))) { + || PersonNode.getUnknownPersonId().equals(node.getLookup().lookup(String.class))) { Children children = node.getChildren(); Node[] childNodes = children == null ? null : children.getNodes(); if (childNodes != null) { diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java b/Core/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java index 6fb134ceec..ee95a8ec80 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java @@ -49,7 +49,7 @@ import org.sleuthkit.autopsy.datamodel.ContentNodeSelectionInfo; import org.sleuthkit.autopsy.datamodel.DataSourcesByTypeNode; import org.sleuthkit.autopsy.datamodel.DataSourcesNode; import org.sleuthkit.autopsy.datamodel.DisplayableItemNode; -import org.sleuthkit.autopsy.datamodel.PersonGroupingNode; +import org.sleuthkit.autopsy.datamodel.PersonNode; import org.sleuthkit.autopsy.datamodel.RootContentChildren; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; @@ -330,7 +330,7 @@ public class ViewContextAction extends AbstractAction { } else if (node.getLookup().lookup(Host.class) != null || node.getLookup().lookup(Person.class) != null || DataSourcesByTypeNode.getNameIdentifier().equals(node.getLookup().lookup(String.class)) || - PersonGroupingNode.getUnknownPersonId().equals(node.getLookup().lookup(String.class))) { + PersonNode.getUnknownPersonId().equals(node.getLookup().lookup(String.class))) { Children children = node.getChildren(); Node[] childNodes = children == null ? null : children.getNodes(); if (childNodes == null) { From 358d9fef4a7bd3a1f6bf3ebc1c50618eb0207bfc Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Wed, 12 May 2021 10:13:38 -0400 Subject: [PATCH 12/14] 7553 data model event changes --- .../datamodel/DataSourceFilesNode.java | 182 ++++++++++++++++++ .../autopsy/datamodel/DataSources.java | 4 +- .../datamodel/DataSourcesByTypeNode.java | 155 --------------- .../autopsy/datamodel/DataSourcesNode.java | 166 +++++++--------- .../datamodel/DisplayableItemNodeVisitor.java | 8 +- .../datamodel/RootContentChildren.java | 4 +- .../directorytree/ViewContextAction.java | 10 +- 7 files changed, 269 insertions(+), 260 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/datamodel/DataSourceFilesNode.java delete mode 100644 Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesByTypeNode.java diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/DataSourceFilesNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/DataSourceFilesNode.java new file mode 100644 index 0000000000..fd45f69bf0 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/datamodel/DataSourceFilesNode.java @@ -0,0 +1,182 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2012-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.datamodel; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.EnumSet; +import java.util.List; +import java.util.logging.Level; +import org.openide.nodes.Children; +import org.openide.nodes.Sheet; +import org.openide.util.NbBundle; +import org.openide.util.lookup.Lookups; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.datamodel.TskDataException; + +/** + * A structural node in the main tree view when the user has selected the group + * by persons/hosts option. Instances of this node appear as children of a node + * representing a data source association with a host, and as a parent of a data + * source node. For example: "Host X" -> "Data Source Y" -> "Data Source Files" + * -> "Data Source Y", where "Data Source Files" is an instance of this node. + */ +public class DataSourceFilesNode extends DisplayableItemNode { + + private static final String NAME = NbBundle.getMessage(DataSourceFilesNode.class, "DataSourcesNode.name"); + + /** + * @return The name used to identify the node of this type with a lookup. + */ + public static String getNameIdentifier() { + return NAME; + } + + private final String displayName; + + // NOTE: The images passed in via argument will be ignored. + @Deprecated + public DataSourceFilesNode(List images) { + this(0); + } + + public DataSourceFilesNode() { + this(0); + } + + public DataSourceFilesNode(long dsObjId) { + super(Children.create(new DataSourcesNodeChildren(dsObjId), false), Lookups.singleton(NAME)); + displayName = (dsObjId > 0) ? NbBundle.getMessage(DataSourceFilesNode.class, "DataSourcesNode.group_by_datasource.name") : NAME; + init(); + } + + private void init() { + setName(NAME); + setDisplayName(displayName); + this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/image.png"); //NON-NLS + } + + @Override + public String getItemType() { + return getClass().getName(); + } + + /* + * Custom Keys implementation that listens for new data sources being added. + */ + public static class DataSourcesNodeChildren extends AbstractContentChildren { + + private static final Logger logger = Logger.getLogger(DataSourcesNodeChildren.class.getName()); + private final long datasourceObjId; + + List currentKeys; + + public DataSourcesNodeChildren() { + this(0); + } + + public DataSourcesNodeChildren(long dsObjId) { + super("ds_" + Long.toString(dsObjId)); + this.currentKeys = new ArrayList<>(); + this.datasourceObjId = dsObjId; + } + + private final PropertyChangeListener pcl = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + String eventType = evt.getPropertyName(); + if (eventType.equals(Case.Events.DATA_SOURCE_ADDED.toString())) { + refresh(true); + } + } + }; + + @Override + protected void onAdd() { + Case.addEventTypeSubscriber(EnumSet.of(Case.Events.DATA_SOURCE_ADDED), pcl); + } + + @Override + protected void onRemove() { + Case.removeEventTypeSubscriber(EnumSet.of(Case.Events.DATA_SOURCE_ADDED), pcl); + currentKeys.clear(); + } + + @Override + protected List makeKeys() { + try { + if (datasourceObjId == 0) { + currentKeys = Case.getCurrentCaseThrows().getDataSources(); + } else { + Content content = Case.getCurrentCaseThrows().getSleuthkitCase().getDataSource(datasourceObjId); + currentKeys = new ArrayList<>(Arrays.asList(content)); + } + + Collections.sort(currentKeys, new Comparator() { + @Override + public int compare(Content content1, Content content2) { + String content1Name = content1.getName().toLowerCase(); + String content2Name = content2.getName().toLowerCase(); + return content1Name.compareTo(content2Name); + } + + }); + + } catch (TskCoreException | NoCurrentCaseException | TskDataException ex) { + logger.log(Level.SEVERE, "Error getting data sources: {0}", ex.getMessage()); // NON-NLS + } + + return currentKeys; + } + } + + @Override + public boolean isLeafTypeNode() { + return false; + } + + @Override + public T accept(DisplayableItemNodeVisitor visitor) { + return visitor.visit(this); + } + + @Override + protected Sheet createSheet() { + Sheet sheet = super.createSheet(); + Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES); + if (sheetSet == null) { + sheetSet = Sheet.createPropertiesSet(); + sheet.put(sheetSet); + } + + sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.name"), + NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.displayName"), + NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.desc"), + NAME)); + return sheet; + } +} diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/DataSources.java b/Core/src/org/sleuthkit/autopsy/datamodel/DataSources.java index 52ca52e89f..4f23327401 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/DataSources.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/DataSources.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011 Basis Technology Corp. + * Copyright 2011-2021 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package org.sleuthkit.autopsy.datamodel; /** - * Root node to store the data sources in a case + * An "Autopsy visitable item" that supplies a */ public class DataSources implements AutopsyVisitableItem { diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesByTypeNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesByTypeNode.java deleted file mode 100644 index 700875d161..0000000000 --- a/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesByTypeNode.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * 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.datamodel; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; -import java.util.logging.Level; -import java.util.stream.Collectors; -import org.openide.nodes.ChildFactory; -import org.openide.nodes.Children; -import org.openide.nodes.Node; -import org.openide.nodes.Sheet; -import org.openide.util.NbBundle; -import org.openide.util.NbBundle.Messages; -import org.openide.util.lookup.Lookups; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.datamodel.TskCoreException; - -/** - * Root node for hosts displaying only data sources (no results, reports, etc.). - */ -@Messages({ - "DataSourcesHostsNode_name=Data Sources" -}) -public class DataSourcesByTypeNode extends DisplayableItemNode { - - /* - * Custom Keys implementation that listens for new data sources being added. - */ - public static class DataSourcesByTypeChildren extends ChildFactory.Detachable { - - private static final Set UPDATE_EVTS = EnumSet.of(Case.Events.DATA_SOURCE_ADDED, - Case.Events.HOSTS_ADDED, - Case.Events.HOSTS_DELETED, - Case.Events.HOSTS_UPDATED); - - private static final Set UPDATE_EVT_STRS = UPDATE_EVTS.stream() - .map(evt -> evt.name()) - .collect(Collectors.toSet()); - - private static final Logger logger = Logger.getLogger(DataSourcesByTypeChildren.class.getName()); - - private final PropertyChangeListener pcl = new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - String eventType = evt.getPropertyName(); - if (UPDATE_EVT_STRS.contains(eventType)) { - refresh(true); - } - } - }; - - @Override - protected void addNotify() { - Case.addEventTypeSubscriber(UPDATE_EVTS, pcl); - } - - @Override - protected void removeNotify() { - Case.removeEventTypeSubscriber(UPDATE_EVTS, pcl); - } - - @Override - protected boolean createKeys(List toPopulate) { - try { - Case.getCurrentCaseThrows().getSleuthkitCase().getHostManager().getAllHosts().stream() - .map(HostDataSources::new) - .sorted() - .forEach(toPopulate::add); - - } catch (TskCoreException | NoCurrentCaseException ex) { - logger.log(Level.SEVERE, "Error getting data sources: {0}", ex.getMessage()); // NON-NLS - } - - return true; - } - - @Override - protected Node createNodeForKey(HostDataSources key) { - return new HostNode(key); - } - - } - - private static final String NAME = Bundle.DataSourcesHostsNode_name(); - - /** - * @return The name used to identify the node of this type with a lookup. - */ - public static String getNameIdentifier() { - return NAME; - } - - /** - * Main constructor. - */ - DataSourcesByTypeNode() { - super(Children.create(new DataSourcesByTypeChildren(), false), Lookups.singleton(NAME)); - setName(NAME); - setDisplayName(NAME); - this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/image.png"); - } - - @Override - public String getItemType() { - return getClass().getName(); - } - - @Override - public boolean isLeafTypeNode() { - return false; - } - - @Override - public T accept(DisplayableItemNodeVisitor visitor) { - return visitor.visit(this); - } - - @Override - protected Sheet createSheet() { - Sheet sheet = super.createSheet(); - Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES); - if (sheetSet == null) { - sheetSet = Sheet.createPropertiesSet(); - sheet.put(sheetSet); - } - - sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.name"), - NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.displayName"), - NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.desc"), - NAME)); - return sheet; - } -} diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesNode.java index c8be68d164..c5fae53c03 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/DataSourcesNode.java @@ -1,15 +1,15 @@ /* * Autopsy Forensic Browser - * - * Copyright 2011-2021 Basis Technology Corp. + * + * 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. @@ -20,135 +20,117 @@ package org.sleuthkit.autopsy.datamodel; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; import java.util.EnumSet; import java.util.List; +import java.util.Set; import java.util.logging.Level; +import java.util.stream.Collectors; +import org.openide.nodes.ChildFactory; import org.openide.nodes.Children; +import org.openide.nodes.Node; import org.openide.nodes.Sheet; import org.openide.util.NbBundle; +import org.openide.util.NbBundle.Messages; import org.openide.util.lookup.Lookups; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.TskCoreException; -import org.sleuthkit.datamodel.TskDataException; /** - * Nodes for the images + * A top-level structural node (child of the invisible root node) in the main + * tree view when the user has selected the group by data type option. It + * appears as the parent node of the "directory tree" nodes that are the roots + * of the file trees for the individual data sources in a case. For example: + * "Data Sources" -> "Data Source X", "Data Source Y", where "Data Sources" is + * an instance of this node. The siblings of this node are the "Views, "Analysis + * Results," "Os Accounts," "Tags," and "Reports" nodes. */ +@Messages({ + "DataSourcesHostsNode_name=Data Sources" +}) public class DataSourcesNode extends DisplayableItemNode { - private static final String NAME = NbBundle.getMessage(DataSourcesNode.class, "DataSourcesNode.name"); - - /** - * @return The name used to identify the node of this type with a lookup. - */ - public static String getNameIdentifier() { - return NAME; - } - - private final String displayName; - - // NOTE: The images passed in via argument will be ignored. - @Deprecated - public DataSourcesNode(List images) { - this(0); - } - - public DataSourcesNode() { - this(0); - } - - public DataSourcesNode(long dsObjId) { - super(Children.create(new DataSourcesNodeChildren(dsObjId), false), Lookups.singleton(NAME)); - displayName = (dsObjId > 0) ? NbBundle.getMessage(DataSourcesNode.class, "DataSourcesNode.group_by_datasource.name") : NAME; - init(); - } - - private void init() { - setName(NAME); - setDisplayName(displayName); - this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/image.png"); //NON-NLS - } - - @Override - public String getItemType() { - return getClass().getName(); - } - /* * Custom Keys implementation that listens for new data sources being added. */ - public static class DataSourcesNodeChildren extends AbstractContentChildren { + public static class DataSourcesByTypeChildren extends ChildFactory.Detachable { - private static final Logger logger = Logger.getLogger(DataSourcesNodeChildren.class.getName()); - private final long datasourceObjId; - - List currentKeys; + private static final Set UPDATE_EVTS = EnumSet.of(Case.Events.DATA_SOURCE_ADDED, + Case.Events.HOSTS_ADDED, + Case.Events.HOSTS_DELETED, + Case.Events.HOSTS_UPDATED); - public DataSourcesNodeChildren() { - this(0); - } + private static final Set UPDATE_EVT_STRS = UPDATE_EVTS.stream() + .map(evt -> evt.name()) + .collect(Collectors.toSet()); + + private static final Logger logger = Logger.getLogger(DataSourcesByTypeChildren.class.getName()); - public DataSourcesNodeChildren(long dsObjId) { - super("ds_" + Long.toString(dsObjId)); - this.currentKeys = new ArrayList<>(); - this.datasourceObjId = dsObjId; - } - private final PropertyChangeListener pcl = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { String eventType = evt.getPropertyName(); - if (eventType.equals(Case.Events.DATA_SOURCE_ADDED.toString())) { + if (UPDATE_EVT_STRS.contains(eventType)) { refresh(true); } } }; @Override - protected void onAdd() { - Case.addEventTypeSubscriber(EnumSet.of(Case.Events.DATA_SOURCE_ADDED), pcl); + protected void addNotify() { + Case.addEventTypeSubscriber(UPDATE_EVTS, pcl); } @Override - protected void onRemove() { - Case.removeEventTypeSubscriber(EnumSet.of(Case.Events.DATA_SOURCE_ADDED), pcl); - currentKeys.clear(); + protected void removeNotify() { + Case.removeEventTypeSubscriber(UPDATE_EVTS, pcl); } @Override - protected List makeKeys() { + protected boolean createKeys(List toPopulate) { try { - if (datasourceObjId == 0) { - currentKeys = Case.getCurrentCaseThrows().getDataSources(); - } - else { - Content content = Case.getCurrentCaseThrows().getSleuthkitCase().getDataSource(datasourceObjId); - currentKeys = new ArrayList<>(Arrays.asList(content)); - } - - Collections.sort(currentKeys, new Comparator() { - @Override - public int compare(Content content1, Content content2) { - String content1Name = content1.getName().toLowerCase(); - String content2Name = content2.getName().toLowerCase(); - return content1Name.compareTo(content2Name); - } + Case.getCurrentCaseThrows().getSleuthkitCase().getHostManager().getAllHosts().stream() + .map(HostDataSources::new) + .sorted() + .forEach(toPopulate::add); - }); - - } catch (TskCoreException | NoCurrentCaseException | TskDataException ex) { + } catch (TskCoreException | NoCurrentCaseException ex) { logger.log(Level.SEVERE, "Error getting data sources: {0}", ex.getMessage()); // NON-NLS } - - return currentKeys; + + return true; } + + @Override + protected Node createNodeForKey(HostDataSources key) { + return new HostNode(key); + } + + } + + private static final String NAME = Bundle.DataSourcesHostsNode_name(); + + /** + * @return The name used to identify the node of this type with a lookup. + */ + public static String getNameIdentifier() { + return NAME; + } + + /** + * Main constructor. + */ + DataSourcesNode() { + super(Children.create(new DataSourcesByTypeChildren(), false), Lookups.singleton(NAME)); + setName(NAME); + setDisplayName(NAME); + this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/image.png"); + } + + @Override + public String getItemType() { + return getClass().getName(); } @Override @@ -176,4 +158,4 @@ public class DataSourcesNode extends DisplayableItemNode { NAME)); return sheet; } -} \ No newline at end of file +} diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/DisplayableItemNodeVisitor.java b/Core/src/org/sleuthkit/autopsy/datamodel/DisplayableItemNodeVisitor.java index ac3cd703c7..9d5f6334f3 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/DisplayableItemNodeVisitor.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/DisplayableItemNodeVisitor.java @@ -42,7 +42,7 @@ public interface DisplayableItemNodeVisitor { /* * Data Sources Area */ - T visit(DataSourcesNode in); + T visit(DataSourceFilesNode in); T visit(LayoutFileNode lfn); @@ -201,7 +201,7 @@ public interface DisplayableItemNodeVisitor { T visit(HostNode node); - T visit(DataSourcesByTypeNode node); + T visit(DataSourcesNode node); /* * Unsupported node @@ -416,7 +416,7 @@ public interface DisplayableItemNodeVisitor { } @Override - public T visit(DataSourcesNode in) { + public T visit(DataSourceFilesNode in) { return defaultVisit(in); } @@ -571,7 +571,7 @@ public interface DisplayableItemNodeVisitor { } @Override - public T visit(DataSourcesByTypeNode node) { + public T visit(DataSourcesNode node) { return defaultVisit(node); } diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/RootContentChildren.java b/Core/src/org/sleuthkit/autopsy/datamodel/RootContentChildren.java index 4e489312c8..2db14ad2d4 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/RootContentChildren.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/RootContentChildren.java @@ -135,7 +135,7 @@ public class RootContentChildren extends Children.Keys { @Override public AbstractNode visit(DataSources i) { - return new DataSourcesNode(i.filteringDataSourceObjId()); + return new DataSourceFilesNode(i.filteringDataSourceObjId()); } @Override @@ -202,7 +202,7 @@ public class RootContentChildren extends Children.Keys { @Override public AbstractNode visit(DataSourcesByType dataSourceHosts) { - return new DataSourcesByTypeNode(); + return new DataSourcesNode(); } } } diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java b/Core/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java index ee95a8ec80..c8f5848243 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java @@ -46,8 +46,8 @@ import org.sleuthkit.autopsy.datamodel.AbstractAbstractFileNode; import org.sleuthkit.autopsy.datamodel.AbstractFsContentNode; import org.sleuthkit.autopsy.datamodel.BlackboardArtifactNode; import org.sleuthkit.autopsy.datamodel.ContentNodeSelectionInfo; -import org.sleuthkit.autopsy.datamodel.DataSourcesByTypeNode; import org.sleuthkit.autopsy.datamodel.DataSourcesNode; +import org.sleuthkit.autopsy.datamodel.DataSourceFilesNode; import org.sleuthkit.autopsy.datamodel.DisplayableItemNode; import org.sleuthkit.autopsy.datamodel.PersonNode; import org.sleuthkit.autopsy.datamodel.RootContentChildren; @@ -227,7 +227,7 @@ public class ViewContextAction extends AbstractAction { } // for this data source, get the "Data Sources" child node - Node datasourceGroupingNode = treeNode.getChildren().findChild(DataSourcesNode.getNameIdentifier()); + Node datasourceGroupingNode = treeNode.getChildren().findChild(DataSourceFilesNode.getNameIdentifier()); // check whether this is the data source we are looking for parentTreeViewNode = findParentNodeInTree(parentContent, datasourceGroupingNode); @@ -243,7 +243,7 @@ public class ViewContextAction extends AbstractAction { Node datasourceGroupingNode = rootChildren.findChild(dsname); if (!Objects.isNull(datasourceGroupingNode)) { Children dsChildren = datasourceGroupingNode.getChildren(); - parentTreeViewNode = dsChildren.findChild(DataSourcesNode.getNameIdentifier()); + parentTreeViewNode = dsChildren.findChild(DataSourceFilesNode.getNameIdentifier()); } } @@ -260,7 +260,7 @@ public class ViewContextAction extends AbstractAction { } else { // Classic view // Start the search at the DataSourcesNode Children rootChildren = treeViewExplorerMgr.getRootContext().getChildren(); - Node rootDsNode = rootChildren == null ? null : rootChildren.findChild(DataSourcesByTypeNode.getNameIdentifier()); + Node rootDsNode = rootChildren == null ? null : rootChildren.findChild(DataSourcesNode.getNameIdentifier()); if (rootDsNode != null) { for (Node dataSourceLevelNode : getDataSourceLevelNodes(rootDsNode)) { DataSource dataSource = dataSourceLevelNode.getLookup().lookup(DataSource.class); @@ -329,7 +329,7 @@ public class ViewContextAction extends AbstractAction { return Collections.emptyList(); } else if (node.getLookup().lookup(Host.class) != null || node.getLookup().lookup(Person.class) != null || - DataSourcesByTypeNode.getNameIdentifier().equals(node.getLookup().lookup(String.class)) || + DataSourcesNode.getNameIdentifier().equals(node.getLookup().lookup(String.class)) || PersonNode.getUnknownPersonId().equals(node.getLookup().lookup(String.class))) { Children children = node.getChildren(); Node[] childNodes = children == null ? null : children.getNodes(); From 7733aa79460a23013460d523263d3c558ed68d6e Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 13 May 2021 11:34:16 -0400 Subject: [PATCH 13/14] 7553 data model event changes --- .../sleuthkit/autopsy/datamodel/AutopsyTreeChildFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/AutopsyTreeChildFactory.java b/Core/src/org/sleuthkit/autopsy/datamodel/AutopsyTreeChildFactory.java index 387b7d24e1..e1fb63a57b 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/AutopsyTreeChildFactory.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/AutopsyTreeChildFactory.java @@ -126,7 +126,7 @@ public final class AutopsyTreeChildFactory extends ChildFactory.Detachable Date: Thu, 13 May 2021 14:47:59 -0400 Subject: [PATCH 14/14] 7553 data model event changes --- Core/src/org/sleuthkit/autopsy/datamodel/PersonNode.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/PersonNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/PersonNode.java index c67758c056..3f01290353 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/PersonNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/PersonNode.java @@ -131,7 +131,12 @@ public class PersonNode extends DisplayableItemNode { protected boolean createKeys(List toPopulate) { List hosts = Collections.emptyList(); try { - hosts = Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().getHostsForPerson(this.person); + if (person != null) { + hosts = Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().getHostsForPerson(person); + } else { + // This is the "Unknown Persons" node, get the hosts that are not associated with a person. + hosts = Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().getHostsWithoutPersons(); + } } catch (NoCurrentCaseException | TskCoreException ex) { String personName = person == null || person.getName() == null ? "" : person.getName(); logger.log(Level.WARNING, String.format("Unable to get data sources for host: %s", personName), ex);