Skip to content
Snippets Groups Projects
Commit 4c785d1b authored by apriestman's avatar apriestman
Browse files

Move get/set person methods.

parent 5313b36c
No related branches found
No related tags found
No related merge requests found
......@@ -469,70 +469,6 @@ public Host getHost(DataSource dataSource) throws TskCoreException {
db.releaseSingleUserCaseReadLock();
}
}
/**
* Get person for the given host or empty if no associated person.
*
* @param host The host.
*
* @return The parent person or empty if no parent person.
*
* @throws TskCoreException if error occurs.
*/
public Optional<Person> getPerson(Host host) throws TskCoreException {
String queryString = "SELECT p.id AS personId, p.name AS name FROM \n"
+ "tsk_persons p INNER JOIN tsk_hosts h\n"
+ "ON p.id = h.person_id \n"
+ "WHERE h.id = " + host.getHostId();
db.acquireSingleUserCaseReadLock();
try (CaseDbConnection connection = this.db.getConnection();
Statement s = connection.createStatement();
ResultSet rs = connection.executeQuery(s, queryString)) {
if (rs.next()) {
return Optional.of(new Person(rs.getLong("personId"), rs.getString("name")));
} else {
return Optional.empty();
}
} catch (SQLException ex) {
throw new TskCoreException(String.format("Error getting person for host with ID = %d", host.getHostId()), ex);
} finally {
db.releaseSingleUserCaseReadLock();
}
}
/**
* Set host's parent person.
*
* @param host The host whose parent will be set.
* @param person The person to be a parent or null to remove any parent
* person reference from this host.
*
* @throws TskCoreException
*/
public void setPerson(Host host, Person person) throws TskCoreException {
if (host == null) {
throw new TskCoreException("Illegal argument passed to setPerson: host must be non-null.");
}
String queryString = (person == null)
? String.format("UPDATE tsk_hosts SET person_id = NULL WHERE id = %d", host.getHostId())
: String.format("UPDATE tsk_hosts SET person_id = %d WHERE id = %d", person.getPersonId(), host.getHostId());
db.acquireSingleUserCaseWriteLock();
try (CaseDbConnection connection = this.db.getConnection();
Statement s = connection.createStatement();) {
s.executeUpdate(queryString);
} catch (SQLException ex) {
throw new TskCoreException(String.format("Error getting persons"), ex);
} finally {
db.releaseSingleUserCaseWriteLock();
}
db.getPersonManager().fireChangeEvent(person);
}
/**
* Merge source host into destination host.
......
......@@ -322,6 +322,70 @@ private Optional<Person> getPerson(String name, CaseDbConnection connection) thr
throw new TskCoreException(String.format("Error getting person with name = %s", name), ex);
}
}
/**
* Get person for the given host or empty if no associated person.
*
* @param host The host.
*
* @return The parent person or empty if no parent person.
*
* @throws TskCoreException if error occurs.
*/
public Optional<Person> getPerson(Host host) throws TskCoreException {
String queryString = "SELECT p.id AS personId, p.name AS name FROM \n"
+ "tsk_persons p INNER JOIN tsk_hosts h\n"
+ "ON p.id = h.person_id \n"
+ "WHERE h.id = " + host.getHostId();
db.acquireSingleUserCaseReadLock();
try (CaseDbConnection connection = this.db.getConnection();
Statement s = connection.createStatement();
ResultSet rs = connection.executeQuery(s, queryString)) {
if (rs.next()) {
return Optional.of(new Person(rs.getLong("personId"), rs.getString("name")));
} else {
return Optional.empty();
}
} catch (SQLException ex) {
throw new TskCoreException(String.format("Error getting person for host with ID = %d", host.getHostId()), ex);
} finally {
db.releaseSingleUserCaseReadLock();
}
}
/**
* Set host's parent person.
*
* @param host The host whose parent will be set.
* @param person The person to be a parent or null to remove any parent
* person reference from this host.
*
* @throws TskCoreException
*/
public void setPerson(Host host, Person person) throws TskCoreException {
if (host == null) {
throw new TskCoreException("Illegal argument passed to setPerson: host must be non-null.");
}
String queryString = (person == null)
? String.format("UPDATE tsk_hosts SET person_id = NULL WHERE id = %d", host.getHostId())
: String.format("UPDATE tsk_hosts SET person_id = %d WHERE id = %d", person.getPersonId(), host.getHostId());
db.acquireSingleUserCaseWriteLock();
try (CaseDbConnection connection = this.db.getConnection();
Statement s = connection.createStatement();) {
s.executeUpdate(queryString);
} catch (SQLException ex) {
throw new TskCoreException(String.format("Error getting persons"), ex);
} finally {
db.releaseSingleUserCaseWriteLock();
}
db.getPersonManager().fireChangeEvent(person);
}
/**
* Fires an event when a person is created.
......
......@@ -800,8 +800,7 @@ public void osAccountInstanceTests() throws TskCoreException, OsAccountManager.N
accountAttributes.add(attrib2);
// add attributes to account.
osAccount1.addAttributes(accountAttributes);
caseDB.getOsAccountManager().addOsAccountAttributes(osAccount1, accountAttributes);
// now get the account with same sid, and get its attribuites and verify.
Optional<OsAccount> existingAccount1 = caseDB.getOsAccountManager().getOsAccountByAddr(osAccount1.getAddr().get(), caseDB.getOsAccountRealmManager().getRealmById(osAccount1.getRealmId()));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment