Skip to content

Commit

Permalink
Merge pull request sleuthkit#6946 from rcordovano/7553-rcordovano-dat…
Browse files Browse the repository at this point in the history
…a-model-event-changes

7553 data model event changes
  • Loading branch information
rcordovano authored Jun 2, 2021
2 parents 2f3393f + 3635925 commit 0685c99
Show file tree
Hide file tree
Showing 37 changed files with 1,232 additions and 868 deletions.
172 changes: 57 additions & 115 deletions Core/src/org/sleuthkit/autopsy/casemodule/Case.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@
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.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;
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;
Expand Down Expand Up @@ -429,43 +431,50 @@ public enum Events {
*/
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_ACCOUNT_ADDED,
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_ACCOUNT_REMOVED,
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_CHANGED,
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_CHANGED,
PERSONS_UPDATED,
/**
* Persons associated with the current case has been deleted.
* One or more persons been deleted from the case.
*/
PERSONS_DELETED;
PERSONS_DELETED,
/**
* One or more hosts have been added to a person.
*/
HOSTS_ADDED_TO_PERSON,
/**
* One or more hosts have been removed from a person.
*/
HOSTS_REMOVED_FROM_PERSON;

};

/**
Expand Down Expand Up @@ -500,24 +509,18 @@ public void publishArtifactsPostedEvent(Blackboard.ArtifactsPostedEvent event) {
}

@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.getOsAccountObjectIds()));
}

/**
Expand All @@ -528,8 +531,7 @@ public void publishOsAccountDeletedEvent(TskEvent.OsAccountsDeletedTskEvent even
*/
@Subscribe
public void publishHostsAddedEvent(TskEvent.HostsAddedTskEvent event) {
eventPublisher.publish(new HostsAddedEvent(
event == null ? Collections.emptyList() : event.getHosts()));
eventPublisher.publish(new HostsAddedEvent(event.getHosts()));
}

/**
Expand All @@ -539,9 +541,8 @@ public void publishHostsAddedEvent(TskEvent.HostsAddedTskEvent event) {
* @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()));
}

/**
Expand All @@ -552,8 +553,7 @@ public void publishHostsChangedEvent(TskEvent.HostsChangedTskEvent event) {
*/
@Subscribe
public void publishHostsDeletedEvent(TskEvent.HostsDeletedTskEvent event) {
eventPublisher.publish(new HostsRemovedEvent(
event == null ? Collections.emptyList() : event.getHosts()));
eventPublisher.publish(new HostsDeletedEvent(event.getHostIds()));
}

/**
Expand All @@ -564,8 +564,7 @@ public void publishHostsDeletedEvent(TskEvent.HostsDeletedTskEvent event) {
*/
@Subscribe
public void publishPersonsAddedEvent(TskEvent.PersonsAddedTskEvent event) {
eventPublisher.publish(new PersonsAddedEvent(
event == null ? Collections.emptyList() : event.getPersons()));
eventPublisher.publish(new PersonsAddedEvent(event.getPersons()));
}

/**
Expand All @@ -575,9 +574,8 @@ public void publishPersonsAddedEvent(TskEvent.PersonsAddedTskEvent event) {
* @param event The sleuthkit event for the updating of persons.
*/
@Subscribe
public void publishPersonsChangedEvent(TskEvent.PersonsChangedTskEvent event) {
eventPublisher.publish(new PersonsChangedEvent(
event == null ? Collections.emptyList() : event.getPersons()));
public void publishPersonsUpdatedEvent(TskEvent.PersonsUpdatedTskEvent event) {
eventPublisher.publish(new PersonsUpdatedEvent(event.getPersons()));
}

/**
Expand All @@ -588,9 +586,19 @@ public void publishPersonsChangedEvent(TskEvent.PersonsChangedTskEvent event) {
*/
@Subscribe
public void publishPersonsDeletedEvent(TskEvent.PersonsDeletedTskEvent event) {
eventPublisher.publish(new PersonsDeletedEvent(
event == null ? Collections.emptyList() : event.getPersons()));
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.getHostIds()));
}

}

/**
Expand Down Expand Up @@ -1826,72 +1834,6 @@ public void notifyBlackBoardArtifactTagDeleted(BlackboardArtifactTag deletedTag)
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@
import org.sleuthkit.datamodel.Host;

/**
* Event fired when new hosts are added.
* Application events 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 hosts The hosts that have been added.
*/
public HostsAddedEvent(List<Host> dataModelObjects) {
super(Case.Events.HOSTS_ADDED.name(), dataModelObjects);
public HostsAddedEvent(List<Host> hosts) {
super(Case.Events.HOSTS_ADDED.name(), hosts);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* 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 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 TskDataModelChangedEvent<Person, Host> {

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.
*/
public HostsAddedToPersonEvent(Person person, List<Host> 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<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;
}

}
Loading

0 comments on commit 0685c99

Please sign in to comment.