7553 data model event changes

This commit is contained in:
Richard Cordovano 2021-05-04 14:05:49 -04:00
parent 856eced424
commit bb2e65a770
28 changed files with 588 additions and 293 deletions

View File

@ -432,7 +432,7 @@ public class Case {
* OSAccount associated with the current case added. Call getOsAccount * OSAccount associated with the current case added. Call getOsAccount
* to get the added account; * to get the added account;
*/ */
OS_ACCOUNT_ADDED, OS_ACCOUNTS_ADDED,
/** /**
* OSAccount associated with the current case has changed. Call * OSAccount associated with the current case has changed. Call
* getOsAccount to get the changed account; * getOsAccount to get the changed account;
@ -441,7 +441,7 @@ public class Case {
/** /**
* OSAccount associated with the current case has been deleted. * OSAccount associated with the current case has been deleted.
*/ */
OS_ACCOUNT_REMOVED, OS_ACCOUNTS_DELETED,
/** /**
* Hosts associated with the current case added. * Hosts associated with the current case added.
*/ */
@ -449,7 +449,7 @@ public class Case {
/** /**
* Hosts associated with the current case has changed. * Hosts associated with the current case has changed.
*/ */
HOSTS_CHANGED, HOSTS_UPDATED,
/** /**
* Hosts associated with the current case has been deleted. * 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 associated with the current case has changed.
*/ */
PERSONS_CHANGED, PERSONS_UPDATED,
/** /**
* Persons associated with the current case has been deleted. * 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 @Subscribe
public void publishOsAccountsDeletedEvent(TskEvent.OsAccountsDeletedTskEvent event) { 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 @Subscribe
public void publishHostsDeletedEvent(TskEvent.HostsDeletedTskEvent event) { 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 @Subscribe
public void publishPersonsDeletedEvent(TskEvent.PersonsDeletedTskEvent event) { public void publishPersonsDeletedEvent(TskEvent.PersonsDeletedTskEvent event) {
eventPublisher.publish(new PersonsDeletedEvent(event.getObjectIds())); eventPublisher.publish(new PersonsDeletedEvent(event.getPersonIds()));
} }
} }

View File

@ -23,17 +23,21 @@ import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.datamodel.Host; 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; private static final long serialVersionUID = 1L;
/** /**
* Main constructor. * Constructs an application event published when hosts have been added to
* @param dataModelObjects The hosts that have been added. * the Sleuth Kit data model for a case.
*
* @param persons The hosts that have been added.
*/ */
public HostsAddedEvent(List<Host> dataModelObjects) { public HostsAddedEvent(List<Host> hosts) {
super(Case.Events.HOSTS_ADDED.name(), dataModelObjects); super(Case.Events.HOSTS_ADDED.name(), hosts);
} }
} }

View File

@ -0,0 +1,39 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2021 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> 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<Host> hosts) {
super(Case.Events.HOSTS_ADDED_TO_PERSON.toString(), person, hosts);
}
}

View File

@ -18,34 +18,34 @@
*/ */
package org.sleuthkit.autopsy.casemodule.events; package org.sleuthkit.autopsy.casemodule.events;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.sleuthkit.autopsy.casemodule.Case; 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<Host> { public final class HostsDeletedEvent extends TskDataModelObjectsDeletedEvent {
private static final long serialVersionUID = 1L; 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 * @param hostIds The host IDs of the deleted hosts.
* database row IDs, etc.) of the Hosts that have
* been deleted.
*/ */
public HostsDeletedEvent(List<Long> dataModelObjectIds) { public HostsDeletedEvent(List<Long> hostIds) {
super(Case.Events.HOSTS_DELETED.name(), dataModelObjectIds); super(Case.Events.HOSTS_DELETED.name(), hostIds);
} }
@Override /**
protected List<Host> getDataModelObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException { * Gets the host IDs of the hosts that have been deleted.
return Collections.emptyList(); *
* @return The host IDs.
*/
public List<Long> getHostIds() {
return getOldValue();
} }
} }

View File

@ -22,44 +22,48 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import org.sleuthkit.datamodel.Host; import org.sleuthkit.datamodel.Host;
import org.sleuthkit.datamodel.HostManager;
import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException; 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<Host> { public class HostsEvent extends TskDataModelChangedEvent<Host, Host> {
private static final long serialVersionUID = 1L; 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 * @param eventName The name of the Case.Events enum value for the event
* type. * type.
* @param dataModelObjects The list of hosts for the event. * @param hosts The hosts.
*/ */
protected HostsEvent(String eventName, List<Host> dataModelObjects) { protected HostsEvent(String eventName, List<Host> hosts) {
super(eventName, dataModelObjects, Host::getHostId); super(eventName, null, null, hosts, Host::getHostId);
}
/**
* Gets the hosts that have been added or updated.
*
* @return The hosts.
*/
public List<Host> getHosts() {
return getNewValue();
} }
@Override @Override
protected List<Host> getDataModelObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException { protected List<Host> getNewValueObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException {
HostManager hostManager = caseDb.getHostManager(); List<Host> hosts = new ArrayList<>();
List<Host> toRet = new ArrayList<>(); for (Long id : ids) {
if (ids != null) { Optional<Host> host = caseDb.getHostManager().getHostById(id);
for (Long id : ids) { if (host.isPresent()) {
if (id == null) { hosts.add(host.get());
continue;
}
Optional<Host> thisHostOpt = hostManager.getHostById(id);
thisHostOpt.ifPresent((h) -> toRet.add(h));
} }
} }
return hosts;
return toRet;
} }
} }

View File

@ -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<Host> hosts) {
super(Case.Events.HOSTS_REMOVED_FROM_PERSON.toString(), person, hosts);
}
}

View File

@ -23,19 +23,21 @@ import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.datamodel.Host; 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 { public class HostsUpdatedEvent extends HostsEvent {
private static final long serialVersionUID = 1L; 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 * @param hosts The updated persons.
* changed.
*/ */
public HostsUpdatedEvent(List<Host> dataModelObjects) { public HostsUpdatedEvent(List<Host> hosts) {
super(Case.Events.HOSTS_CHANGED.name(), dataModelObjects); super(Case.Events.HOSTS_UPDATED.name(), hosts);
} }
} }

View File

@ -19,22 +19,25 @@
package org.sleuthkit.autopsy.casemodule.events; package org.sleuthkit.autopsy.casemodule.events;
import java.util.List; 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; 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 { public final class OsAccountsAddedEvent extends OsAccountsEvent {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* Constructs an event published when OS accounts are added to a case. * Constructs an application event published when OS accounts are added to
* @param accounts * the Sleuth Kit data model for a case.
*
* @param osAccounts The OS accounts that were added.
*/ */
public OsAccountsAddedEvent(List<OsAccount> accounts) { public OsAccountsAddedEvent(List<OsAccount> osAccounts) {
super(Case.Events.OS_ACCOUNT_ADDED.toString(), accounts); super(OS_ACCOUNTS_ADDED.toString(), osAccounts);
} }
} }

View File

@ -18,32 +18,34 @@
*/ */
package org.sleuthkit.autopsy.casemodule.events; package org.sleuthkit.autopsy.casemodule.events;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.sleuthkit.autopsy.casemodule.Case; 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<OsAccount> { public final class OsAccountsDeletedEvent extends TskDataModelObjectsDeletedEvent {
private static final long serialVersionUID = 1L; 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<Long> osAccountObjectIds) { public OsAccountsDeletedEvent(List<Long> osAccountObjectIds) {
super(Case.Events.OS_ACCOUNT_REMOVED.toString(), osAccountObjectIds); super(Case.Events.OS_ACCOUNTS_DELETED.toString(), osAccountObjectIds);
} }
@Override /**
protected List<OsAccount> getDataModelObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException { * Gets the Sleuth Kit object IDs of the deleted OS accounts.
return Collections.emptyList(); *
* @return The object IDs.
*/
List<Long> getOsAccountObjectIds() {
return getOldValue();
} }
} }

View File

@ -20,45 +20,47 @@ package org.sleuthkit.autopsy.casemodule.events;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.sleuthkit.datamodel.OsAccount; import org.sleuthkit.datamodel.OsAccount;
import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException; 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<OsAccount> { class OsAccountsEvent extends TskDataModelChangedEvent<OsAccount, OsAccount> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* Construct a new OsAccountEvent. * 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 event. * @param eventName The name of the Case.Events enum value for the event
* @param account The OsAccount the event applies to. * type.
* @param account The OS accounts.
*/ */
OsAccountsEvent(String eventName, List<OsAccount> accounts) { OsAccountsEvent(String eventName, List<OsAccount> osAccounts) {
super(eventName, accounts, OsAccount::getId); super(eventName, null, null, osAccounts, OsAccount::getId);
} }
/** /**
* Returns the OsAccount that changed. * Gets the OS accounts that have been added or updated.
* *
* @return The OsAccount that was changed. * @return The OS accounts.
*/ */
public OsAccount getOsAccount() { public List<OsAccount> getOsAccounts() {
List<OsAccount> accounts = getNewValue(); return getNewValue();
return accounts.get(0);
} }
@Override @Override
protected List<OsAccount> getDataModelObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException { protected List<OsAccount> getNewValueObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException {
Long id = ids.get(0); List<OsAccount> osAccounts = new ArrayList<>();
OsAccount account = caseDb.getOsAccountManager().getOsAccountByObjectId(id); for (Long id : ids) {
List<OsAccount> accounts = new ArrayList<>(); osAccounts.add(caseDb.getOsAccountManager().getOsAccountByObjectId(id));
accounts.add(account); }
return accounts; return osAccounts;
} }
} }

View File

@ -23,19 +23,21 @@ import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.datamodel.OsAccount; 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 { public final class OsAccountsUpdatedEvent extends OsAccountsEvent {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* Constructs an event published when OS accounts in the case have been * Constructs an application event published when OS accounts in the Sleuth
* updated. * Kit data model for a case have been updated.
* *
* @param accounts The accounts. * @param osAccounts The OS accounts that were updated.
*/ */
public OsAccountsUpdatedEvent(List<OsAccount> accounts) { public OsAccountsUpdatedEvent(List<OsAccount> osAccounts) {
super(Case.Events.OS_ACCOUNT_CHANGED.toString(), accounts); super(Case.Events.OS_ACCOUNT_CHANGED.toString(), osAccounts);
} }
} }

View File

@ -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<Person, Host> {
private static final long serialVersionUID = 1L;
/**
*
* @param eventName
* @param person
* @param hosts
*/
PersonHostsEvent(String eventName, Person person, List<Host> hosts) {
super(eventName, Collections.singletonList(person), Person::getPersonId, hosts, Host::getHostId);
}
/**
*
* @return
*/
Person getPerson() {
return getOldValue().get(0);
}
/**
*
* @return
*/
List<Host> getHosts() {
return getNewValue();
}
@Override
protected List<Person> getOldValueObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException {
List<Person> persons = new ArrayList<>();
for (Long id : ids) {
Optional<Person> person = caseDb.getPersonManager().getPerson(id);
if (person.isPresent()) {
persons.add(person.get());
}
}
return persons;
}
@Override
protected List<Host> getNewValueObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException {
List<Host> hosts = new ArrayList<>();
for (Long id : ids) {
Optional<Host> host = caseDb.getHostManager().getHostById(id);
if (host.isPresent()) {
hosts.add(host.get());
}
}
return hosts;
}
}

View File

@ -23,14 +23,16 @@ import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.datamodel.Person; 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 { public class PersonsAddedEvent extends PersonsEvent {
private static final long serialVersionUID = 1L; 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. * @param persons The persons that have been added.
*/ */

View File

@ -18,33 +18,34 @@
*/ */
package org.sleuthkit.autopsy.casemodule.events; package org.sleuthkit.autopsy.casemodule.events;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.sleuthkit.autopsy.casemodule.Case; 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<Person> { public class PersonsDeletedEvent extends TskDataModelObjectsDeletedEvent {
private static final long serialVersionUID = 1L; 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) * @param personIds The IDs of the persons that have been deleted.
* of the persons that have been deleted.
*/ */
public PersonsDeletedEvent(List<Long> dataModelObjectIds) { public PersonsDeletedEvent(List<Long> personIds) {
super(Case.Events.PERSONS_DELETED.name(), dataModelObjectIds); super(Case.Events.PERSONS_DELETED.name(), personIds);
} }
@Override /**
protected List<Person> getDataModelObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException { * Gets the person IDs of the persons that have been deleted.
return Collections.emptyList(); *
* @return The person IDs.
*/
List<Long> getPersonIds() {
return getOldValue();
} }
} }

View File

@ -22,44 +22,49 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import org.sleuthkit.datamodel.Person; import org.sleuthkit.datamodel.Person;
import org.sleuthkit.datamodel.PersonManager;
import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException; 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<Person> { public class PersonsEvent extends TskDataModelChangedEvent<Person, Person> {
private static final long serialVersionUID = 1L; 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 * @param eventName The name of the Case.Events enum value for the event
* type. * type.
* @param dataModelObjects The list of persons for the event. * @param persons The persons.
*/ */
PersonsEvent(String eventName, List<Person> dataModelObjects) { PersonsEvent(String eventName, List<Person> persons) {
super(eventName, dataModelObjects, Person::getPersonId); super(eventName, null, null, persons, Person::getPersonId);
}
/**
* Gets the persons that have been added or updated.
*
* @return The persons.
*/
public List<Person> getPersons() {
return getNewValue();
} }
@Override @Override
protected List<Person> getDataModelObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException { protected List<Person> getNewValueObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException {
PersonManager personManager = caseDb.getPersonManager(); List<Person> persons = new ArrayList<>();
List<Person> toRet = new ArrayList<>(); for (Long id : ids) {
if (ids != null) { Optional<Person> person = caseDb.getPersonManager().getPerson(id);
for (Long id : ids) { if (person.isPresent()) {
if (id == null) { persons.add(person.get());
continue;
}
Optional<Person> thisPersonOpt = personManager.getPerson(id);
thisPersonOpt.ifPresent((h) -> toRet.add(h));
} }
} }
return persons;
return toRet;
} }
} }

View File

@ -23,19 +23,21 @@ import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.datamodel.Person; 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 { public class PersonsUpdatedEvent extends PersonsEvent {
private static final long serialVersionUID = 1L; 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. * @param persons The updated persons.
*/ */
public PersonsUpdatedEvent(List<Person> persons) { public PersonsUpdatedEvent(List<Person> persons) {
super(Case.Events.PERSONS_CHANGED.name(), persons); super(Case.Events.PERSONS_UPDATED.name(), persons);
} }
} }

View File

@ -28,32 +28,37 @@ import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException; 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<Report> { public final class ReportAddedEvent extends TskDataModelChangedEvent<Report, Report> {
private static final long serialVersionUID = 1L; 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) { 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() { public Report getReport() {
List<Report> reports = getNewValue(); List<Report> reports = getNewValue();
return reports.get(0); return reports.get(0);
} }
@Override @Override
protected List<Report> getDataModelObjects(SleuthkitCase caseD, List<Long> ids) throws TskCoreException { protected List<Report> getNewValueObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException {
Long id = ids.get(0); Long id = ids.get(0);
Report report = caseD.getReportById(id);
List<Report> reports = new ArrayList<>(); List<Report> reports = new ArrayList<>();
reports.add(report); reports.add(caseDb.getReportById(id));
return reports; return reports;
} }

View File

@ -32,123 +32,142 @@ import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskCoreException;
/** /**
* An abstract base class for application events published when Sleuth Kit Data * An abstract base class for application events published when one or more
* Model objects for a case are added, updated, or deleted. * Sleuth Kit Data Model objects for a case change in some way.
* *
* @param <T> 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 <T> The Sleuth Kit Data Model object type of the "old" data model
* objects.
* @param <U> The Sleuth Kit Data Model object type of the "new" data model
* objects.
*/ */
public abstract class TskDataModelChangedEvent<T> extends AutopsyEvent { public abstract class TskDataModelChangedEvent<T, U> extends AutopsyEvent {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(TskDataModelChangedEvent.class.getName()); private static final Logger logger = Logger.getLogger(TskDataModelChangedEvent.class.getName());
private final boolean isDeletionEvent; private final boolean hasOldValue;
private final List<Long> dataModelObjectIds; private final List<Long> oldValueIds;
private transient List<T> dataModelObjects; private transient List<T> oldValueObjects;
private final boolean hasNewValue;
private final List<Long> newValueIds;
private transient List<U> newValueObjects;
/** /**
* Constructs an instance of an abstract base class for application events * Constructs the base class part for application events published when one
* published when Sleuth Kit Data Model objects for a case are added or * or more Sleuth Kit Data Model objects for a case change in some way.
* 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 eventName The event name.
* @param dataModelObjects The Sleuth Kit Data Model objects that have been * @param oldValueObjects A list of he Data Model objects that have been
* added or updated. * designated as the "old" objects in the event.
* @param getIdMethod A method that can be applied to the data model * May be null.
* objects to get their unique numeric IDs (TSK * @param oldValueGetIdMethod A method that can be applied to the "old" data
* object IDs, case database row IDs, etc.). * 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<T> dataModelObjects, Function<T, Long> getIdMethod) { protected TskDataModelChangedEvent(String eventName, List<T> oldValueObjects, Function<T, Long> oldValueGetIdMethod, List<U> newValueObjects, Function<U, Long> newValueGetIdMethod) {
super(eventName, null, null); super(eventName, null, null);
isDeletionEvent = false; oldValueIds = new ArrayList<>();
this.dataModelObjectIds = new ArrayList<>(); this.oldValueObjects = new ArrayList<>();
this.dataModelObjectIds.addAll(dataModelObjects.stream().map(o -> getIdMethod.apply(o)).collect(Collectors.toList())); if (oldValueObjects != null) {
this.dataModelObjects = new ArrayList<>(); hasOldValue = true;
this.dataModelObjects.addAll(dataModelObjects); oldValueIds.addAll(oldValueObjects.stream()
} .map(o -> oldValueGetIdMethod.apply(o))
.collect(Collectors.toList()));
/** this.oldValueObjects.addAll(oldValueObjects);
* 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<Long> 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<Long> getOldValue() {
if (isDeletionEvent) {
return getDataModelObjectIds();
} else { } 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 * Gets a list of the Data Model objects that have been designated as the
* this event came from another host collaborating on a multi-user case, the * "old" objects in the event.
* Sleuth Kit Data Model objects will be reconstructed on the current host.
* *
* @return The objects. * @return The list of the "old" data model objects. May be empty.
*/ */
@Override @Override
public List<T> getNewValue() { public List<T> getOldValue() {
if (!isDeletionEvent) { if (hasOldValue) {
if (dataModelObjects == null) { if (oldValueObjects == null) {
try { try {
Case currentCase = Case.getCurrentCaseThrows(); Case currentCase = Case.getCurrentCaseThrows();
SleuthkitCase caseDb = currentCase.getSleuthkitCase(); SleuthkitCase caseDb = currentCase.getSleuthkitCase();
dataModelObjects = getDataModelObjects(caseDb, dataModelObjectIds); oldValueObjects = getOldValueObjects(caseDb, oldValueIds);
} catch (NoCurrentCaseException | TskCoreException ex) { } 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.emptyList();
} }
} }
return Collections.unmodifiableList(dataModelObjects); return Collections.unmodifiableList(oldValueObjects);
} else { } else {
return Collections.emptyList(); return Collections.emptyList();
} }
} }
/** /**
* Gets the unique numeric IDs (TSK object IDs, case database row IDs, etc.) * Gets a list of the Data Model objects that have been designated as the
* of the Sleuth Kit Data Model objects associated with this application * "new" objects in the event.
* event.
* *
* This method is provided as an optimization that allows handling of an * @return The list of the "new" data model objects. May be empty.
* 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<Long> getDataModelObjectIds() { @Override
return Collections.unmodifiableList(dataModelObjectIds); public List<U> 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 Sleuth Kit Data Model objects associated with this application * Reconstructs the "old" Sleuth Kit Data Model objects associated with this
* event. If this event came from another host collaborating on a multi-user * application event, if any, using the given unique numeric IDs (TSK object
* case, the Sleuth Kit Data Model objects, this method will be called to * IDs, case database row IDs, etc.) to query the given case database.
* 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 caseDb The case database.
* @param ids The unique, numeric IDs (TSK object IDs, case database row * @param ids The unique, numeric IDs (TSK object IDs, case database row
@ -160,6 +179,27 @@ public abstract class TskDataModelChangedEvent<T> extends AutopsyEvent {
* getting the Sleuth Kit * getting the Sleuth Kit
* Data Model objects. * Data Model objects.
*/ */
abstract protected List<T> getDataModelObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException; protected List<T> getOldValueObjects(SleuthkitCase caseDb, List<Long> 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<U> getNewValueObjects(SleuthkitCase caseDb, List<Long> ids) throws TskCoreException {
return Collections.emptyList();
}
} }

View File

@ -0,0 +1,60 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2021 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> 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<Long> deletedObjectIds;
protected TskDataModelObjectsDeletedEvent(String eventName, List<Long> deletedObjectIds) {
super(eventName, null, null);
this.deletedObjectIds = new ArrayList<>();
this.deletedObjectIds.addAll(deletedObjectIds);
}
@Override
public List<Long> getOldValue() {
return Collections.unmodifiableList(deletedObjectIds);
}
}

View File

@ -47,13 +47,12 @@ import org.sleuthkit.datamodel.TskCoreException;
*/ */
public final class AutopsyTreeChildFactory extends ChildFactory.Detachable<Object> { public final class AutopsyTreeChildFactory extends ChildFactory.Detachable<Object> {
private static final Set<Case.Events> LISTENING_EVENTS = EnumSet.of( private static final Set<Case.Events> LISTENING_EVENTS = EnumSet.of(Case.Events.DATA_SOURCE_ADDED,
Case.Events.DATA_SOURCE_ADDED,
Case.Events.HOSTS_ADDED, Case.Events.HOSTS_ADDED,
Case.Events.HOSTS_DELETED, Case.Events.HOSTS_DELETED,
Case.Events.PERSONS_ADDED, Case.Events.PERSONS_ADDED,
Case.Events.PERSONS_DELETED, Case.Events.PERSONS_DELETED,
Case.Events.PERSONS_CHANGED Case.Events.PERSONS_UPDATED
); );
private static final Set<String> LISTENING_EVENT_NAMES = LISTENING_EVENTS.stream() private static final Set<String> LISTENING_EVENT_NAMES = LISTENING_EVENTS.stream()

View File

@ -50,11 +50,10 @@ public class DataSourcesByTypeNode extends DisplayableItemNode {
*/ */
public static class DataSourcesByTypeChildren extends ChildFactory.Detachable<HostDataSources> { public static class DataSourcesByTypeChildren extends ChildFactory.Detachable<HostDataSources> {
private static final Set<Case.Events> UPDATE_EVTS = EnumSet.of( private static final Set<Case.Events> UPDATE_EVTS = EnumSet.of(Case.Events.DATA_SOURCE_ADDED,
Case.Events.DATA_SOURCE_ADDED,
Case.Events.HOSTS_ADDED, Case.Events.HOSTS_ADDED,
Case.Events.HOSTS_DELETED, Case.Events.HOSTS_DELETED,
Case.Events.HOSTS_CHANGED); Case.Events.HOSTS_UPDATED);
private static final Set<String> UPDATE_EVT_STRS = UPDATE_EVTS.stream() private static final Set<String> UPDATE_EVT_STRS = UPDATE_EVTS.stream()
.map(evt -> evt.name()) .map(evt -> evt.name())

View File

@ -177,7 +177,7 @@ public class HostNode extends DisplayableItemNode {
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
String eventType = evt.getPropertyName(); 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() ((HostsUpdatedEvent) evt).getNewValue().stream()
.filter(h -> h != null && h.getHostId() == hostId) .filter(h -> h != null && h.getHostId() == hostId)
.findFirst() .findFirst()
@ -246,7 +246,7 @@ public class HostNode extends DisplayableItemNode {
host == null ? Lookups.fixed(displayName) : Lookups.fixed(host, displayName)); host == null ? Lookups.fixed(displayName) : Lookups.fixed(host, displayName));
hostId = host == null ? null : host.getHostId(); 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)); WeakListeners.propertyChange(hostChangePcl, this));
super.setName(displayName); super.setName(displayName);
super.setDisplayName(displayName); super.setDisplayName(displayName);

View File

@ -124,8 +124,8 @@ public final class OsAccounts implements AutopsyVisitableItem {
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
String eventType = evt.getPropertyName(); String eventType = evt.getPropertyName();
if (eventType.equals(Case.Events.OS_ACCOUNT_ADDED.toString()) if (eventType.equals(Case.Events.OS_ACCOUNTS_ADDED.toString())
|| eventType.equals(Case.Events.OS_ACCOUNT_REMOVED.toString())) { || eventType.equals(Case.Events.OS_ACCOUNTS_DELETED.toString())) {
refresh(true); refresh(true);
} else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) { } 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 // 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 @Override
protected void addNotify() { 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); Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), listener);
} }
@Override @Override
protected void removeNotify() { 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); Case.removeEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), listener);
} }
@ -184,10 +184,13 @@ public final class OsAccounts implements AutopsyVisitableItem {
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(Case.Events.OS_ACCOUNT_CHANGED.name())) { if (evt.getPropertyName().equals(Case.Events.OS_ACCOUNT_CHANGED.name())) {
if (((OsAccountsUpdatedEvent) evt).getOsAccount().getId() == account.getId()) { OsAccountsUpdatedEvent updateEvent = (OsAccountsUpdatedEvent) evt;
// Update the account node to the new one for (OsAccount acct : updateEvent.getOsAccounts()) {
account = ((OsAccountsUpdatedEvent) evt).getOsAccount(); if (acct.getId() == account.getId()) {
updateSheet(); account = acct;
updateSheet();
break;
}
} }
} else if (evt.getPropertyName().equals(REALM_DATA_AVAILABLE_EVENT)) { } else if (evt.getPropertyName().equals(REALM_DATA_AVAILABLE_EVENT)) {
OsAccountRealm realm = (OsAccountRealm) evt.getNewValue(); OsAccountRealm realm = (OsAccountRealm) evt.getNewValue();

View File

@ -68,10 +68,9 @@ public class PersonGroupingNode extends DisplayableItemNode {
private static final Logger logger = Logger.getLogger(PersonChildren.class.getName()); private static final Logger logger = Logger.getLogger(PersonChildren.class.getName());
private static final Set<Case.Events> CHILD_EVENTS = EnumSet.of( private static final Set<Case.Events> CHILD_EVENTS = EnumSet.of(Case.Events.HOSTS_ADDED,
Case.Events.HOSTS_ADDED,
Case.Events.HOSTS_DELETED, Case.Events.HOSTS_DELETED,
Case.Events.PERSONS_CHANGED); Case.Events.PERSONS_UPDATED);
private static final Set<String> CHILD_EVENTS_STR = CHILD_EVENTS.stream() private static final Set<String> CHILD_EVENTS_STR = CHILD_EVENTS.stream()
.map(ev -> ev.name()) .map(ev -> ev.name())
@ -145,7 +144,7 @@ public class PersonGroupingNode extends DisplayableItemNode {
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
String eventType = evt.getPropertyName(); 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() ((PersonsUpdatedEvent) evt).getNewValue().stream()
.filter(p -> p != null && p.getPersonId() == personId) .filter(p -> p != null && p.getPersonId() == personId)
.findFirst() .findFirst()
@ -192,7 +191,7 @@ public class PersonGroupingNode extends DisplayableItemNode {
this.setIconBaseWithExtension(ICON_PATH); this.setIconBaseWithExtension(ICON_PATH);
this.person = person; this.person = person;
this.personId = person == null ? null : person.getPersonId(); 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)); WeakListeners.propertyChange(personChangePcl, this));
} }

View File

@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.datamodel.hosts;
import java.awt.Frame; import java.awt.Frame;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.util.Collections;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
@ -66,7 +67,7 @@ public class AssociateNewPersonAction extends AbstractAction {
newPersonName = getAddDialogName(); newPersonName = getAddDialogName();
if (StringUtils.isNotBlank(newPersonName)) { if (StringUtils.isNotBlank(newPersonName)) {
Person person = Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().newPerson(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) { } catch (NoCurrentCaseException | TskCoreException ex) {
String hostName = this.host == null || this.host.getName() == null ? "" : this.host.getName(); String hostName = this.host == null || this.host.getName() == null ? "" : this.host.getName();

View File

@ -19,6 +19,7 @@
package org.sleuthkit.autopsy.datamodel.hosts; package org.sleuthkit.autopsy.datamodel.hosts;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.util.Collections;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
@ -65,7 +66,7 @@ public class AssociatePersonAction extends AbstractAction {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try { try {
Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().setPerson(host, person); Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().addHostsToPerson(person, Collections.singletonList(host));
} catch (NoCurrentCaseException | TskCoreException ex) { } catch (NoCurrentCaseException | TskCoreException ex) {
String hostName = this.host == null || this.host.getName() == null ? "" : this.host.getName(); String hostName = this.host == null || this.host.getName() == null ? "" : this.host.getName();
String personName = this.person == null || this.person.getName() == null ? "" : this.person.getName(); String personName = this.person == null || this.person.getName() == null ? "" : this.person.getName();

View File

@ -19,6 +19,7 @@
package org.sleuthkit.autopsy.datamodel.hosts; package org.sleuthkit.autopsy.datamodel.hosts;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.util.Collections;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
@ -46,6 +47,7 @@ public class RemoveParentPersonAction extends AbstractAction {
private static final Logger logger = Logger.getLogger(RemoveParentPersonAction.class.getName()); private static final Logger logger = Logger.getLogger(RemoveParentPersonAction.class.getName());
private final Person person;
private final Host host; private final Host host;
/** /**
@ -59,12 +61,13 @@ public class RemoveParentPersonAction extends AbstractAction {
person == null || person.getName() == null person == null || person.getName() == null
? Bundle.RemoveParentPersonAction_unknownPerson() : person.getName())); ? Bundle.RemoveParentPersonAction_unknownPerson() : person.getName()));
this.host = host; this.host = host;
this.person = person;
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try { try {
Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().setPerson(host, null); Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().removeHostsFromPerson(person, Collections.singletonList(host));
} catch (NoCurrentCaseException | TskCoreException ex) { } catch (NoCurrentCaseException | TskCoreException ex) {
String hostName = this.host == null || this.host.getName() == null ? "" : this.host.getName(); 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); logger.log(Level.WARNING, String.format("Unable to remove parent from host: %s", hostName), ex);

View File

@ -1,7 +1,7 @@
/* /*
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2015 Basis Technology Corp. * Copyright 2015-2021 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org * Contact: carrier <at> sleuthkit <dot> org
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -22,12 +22,18 @@ import java.beans.PropertyChangeEvent;
import java.io.Serializable; import java.io.Serializable;
/** /**
* A base class for events to be published to registered subscribers on both * A base class for application events that can be published to registered
* this Autopsy node and other Autopsy nodes. The class extends * subscribers on both this Autopsy node and other Autopsy nodes.
* PropertyChangeEvent to integrate with legacy use of JavaBeans *
* PropertyChangeEvents and PropertyChangeListeners as an application event * The class extends PropertyChangeEvent to integrate with legacy use of
* system, and implements Serializable to allow it to be published over a * JavaBeans PropertyChangeEvents and PropertyChangeListeners as an application
* network in serialized form. * 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 { 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 * 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 { public enum SourceType {
LOCAL, LOCAL,
REMOTE REMOTE
}; };
/** /**
* Constructs an event that can be published to registered subscribers on * Constructs the base class part of an application event that can be
* both this Autopsy node and other Autopsy nodes. * published to registered subscribers on both this Autopsy node and other
* Autopsy nodes.
* *
* @param eventName The event name. * @param eventName The event name.
* @param oldValue The "old" value to associate with the event. May be * @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. * @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 * Gets the event source type (local or remote) as a string.
* 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).
* *
* @return A string, either "LOCAL" or "REMOTE", as an Object. * @return A string, either "LOCAL" or "REMOTE."
*/ */
@Override @Override
public Object getSource() { 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 * Sets the source type (local or remote). This field is mutable to allow an
* to allow an event to be published both locally and remotely without * event to be published both locally and remotely without requiring the
* requiring the construction of two separate objects. It is for use by the * construction of two separate objects. It is for use by the event
* event publishing classes within this package only. * publishing classes within this package only.
* *
* @param sourceType The source type of the event, local or remote. * @param sourceType The source type of the event, local or remote.
*/ */