diff --git a/bindings/java/src/org/sleuthkit/datamodel/Host.java b/bindings/java/src/org/sleuthkit/datamodel/Host.java index 22a785e7c0a182683b5e808c2ed8138bfca0c244..3be378369c1ca93f77c4c12f4101ed19960e5a60 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/Host.java +++ b/bindings/java/src/org/sleuthkit/datamodel/Host.java @@ -27,8 +27,8 @@ public final class Host { private final long id; - private String name; - private HostDbStatus status; + private final String name; + private final HostDbStatus status; Host(long id, String name) { this(id, name, HostDbStatus.ACTIVE); @@ -57,33 +57,15 @@ public long getHostId() { public String getName() { return name; } - - /** - * Sets the name for the host. - * @param newName The new name. - */ - public void setName(String newName) { - this.name = newName; - } - /** * Gets the status for the host. * * @return Host status. */ - public HostDbStatus getStatus() { + HostDbStatus getStatus() { return status; } - - /** - * Sets the status for the host. - * - * @param status Host status. - */ - public void setStatus(HostDbStatus status) { - this.status = status; - } @Override public int hashCode() { diff --git a/bindings/java/src/org/sleuthkit/datamodel/HostManager.java b/bindings/java/src/org/sleuthkit/datamodel/HostManager.java index 4ec15da4cd64bb0107b8434b3de40d48c6e5d906..40ad7529bc9269dfdc917e8ab1cf7f7c2650e023 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/HostManager.java +++ b/bindings/java/src/org/sleuthkit/datamodel/HostManager.java @@ -151,21 +151,23 @@ Host newHost(String name, CaseDbTransaction trans) throws TskCoreException { } /** - * Updates host in database based on the host object provided. + * Updates the name of the provided host. * - * @param newHost The host to be updated. + * @param host The host to be updated. + * @param newName The new name of the host. * - * @return The newly returned host. + * @return The updated host. * * @throws TskCoreException */ - public Host updateHost(Host newHost) throws TskCoreException { - if (newHost == null) { + public Host updateHostName(Host host, String newName) throws TskCoreException { + if (host == null) { throw new TskCoreException("Illegal argument passed to updateHost: No host argument provided."); - } else if (newHost.getName() == null) { - throw new TskCoreException(String.format("Illegal argument passed to updateHost: Host with id %d has no name", newHost.getHostId())); + } else if (newName == null) { + throw new TskCoreException(String.format("Illegal argument passed to updateHost: Host with id %d has no name", host.getHostId())); } + long hostId = host.getHostId(); Host updatedHost = null; db.acquireSingleUserCaseWriteLock(); try (CaseDbConnection connection = db.getConnection()) { @@ -178,16 +180,16 @@ public Host updateHost(Host newHost) throws TskCoreException { PreparedStatement preparedStatement = connection.getPreparedStatement(hostInsertSQL, Statement.RETURN_GENERATED_KEYS); preparedStatement.clearParameters(); - preparedStatement.setString(1, newHost.getName()); - preparedStatement.setLong(2, newHost.getHostId()); + preparedStatement.setString(1, newName); + preparedStatement.setLong(2, hostId); connection.executeUpdate(preparedStatement); - updatedHost = getHostById(newHost.getHostId(), connection).orElseThrow(() + updatedHost = getHostById(hostId, connection).orElseThrow(() -> new TskCoreException((String.format("Error while fetching newly updated host with id: %d, ")))); } catch (SQLException ex) { - throw new TskCoreException(String.format("Error updating host with name = %s", newHost.getName()), ex); + throw new TskCoreException(String.format("Error updating host with name = %s", newName), ex); } finally { db.releaseSingleUserCaseWriteLock(); }