From c64cbb351f023c844ebd779720a790a51bddc53e Mon Sep 17 00:00:00 2001 From: Raman Arora Date: Wed, 11 Mar 2020 12:07:29 -0400 Subject: [PATCH 1/2] 6111: CVT displays incorrect To phone number for Outgoing calls. --- .../relationships/CallLogNode.java | 60 ++++++++++++++++--- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/communications/relationships/CallLogNode.java b/Core/src/org/sleuthkit/autopsy/communications/relationships/CallLogNode.java index 288b3efa3f..055cddcc09 100755 --- a/Core/src/org/sleuthkit/autopsy/communications/relationships/CallLogNode.java +++ b/Core/src/org/sleuthkit/autopsy/communications/relationships/CallLogNode.java @@ -19,6 +19,7 @@ package org.sleuthkit.autopsy.communications.relationships; import java.util.logging.Level; +import org.apache.commons.lang.StringUtils; import org.openide.nodes.Sheet; import org.sleuthkit.autopsy.communications.Utils; import static org.sleuthkit.autopsy.communications.relationships.RelationshipsNodeUtilities.getAttributeDisplayString; @@ -67,14 +68,6 @@ final class CallLogNode extends BlackboardArtifactNode { return sheet; } - String phoneNumber = getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_FROM); - if(phoneNumber == null || phoneNumber.isEmpty()) { - phoneNumber = getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_TO); - } - if(phoneNumber == null || phoneNumber.isEmpty()) { - phoneNumber = getAttributeDisplayString(artifact, TSK_PHONE_NUMBER); - } - long duration = -1; try{ duration = getCallDuration(artifact); @@ -84,7 +77,7 @@ final class CallLogNode extends BlackboardArtifactNode { sheetSet.put(createNode(TSK_DATETIME_START, artifact)); sheetSet.put(createNode(TSK_DIRECTION, artifact)); - sheetSet.put(new NodeProperty<>(TSK_PHONE_NUMBER.getLabel(), TSK_PHONE_NUMBER.getDisplayName(), "", phoneNumber)); + sheetSet.put(new NodeProperty<>(TSK_PHONE_NUMBER.getLabel(), TSK_PHONE_NUMBER.getDisplayName(), "", getPhoneNumber(artifact))); if(duration != -1) { sheetSet.put(new NodeProperty<>("duration", "Duration", "", Long.toString(duration))); } @@ -107,6 +100,55 @@ final class CallLogNode extends BlackboardArtifactNode { return endAttribute.getValueLong() - startAttribute.getValueLong(); } + /** + * Returns the phone number to display in the To/From column. The number is + * picked from one the the 3 possible phone number attributes, based on the + * direction of the call. + * + * @param artifact Call log artifact. + * + * @return Phone number. + */ + private String getPhoneNumber(BlackboardArtifact artifact) { + String direction = getAttributeDisplayString(artifact, TSK_DIRECTION); + + String phoneNumberToReturn = ""; + String fromPhoneNumber = getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_FROM); + String toPhoneNumber = getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_TO); + String phoneNumber = getAttributeDisplayString(artifact, TSK_PHONE_NUMBER); + + switch (direction.toLowerCase()) { + case "incoming": // NON-NLS + + if (!StringUtils.isBlank(fromPhoneNumber)) { + phoneNumberToReturn = fromPhoneNumber; + } else if (!StringUtils.isBlank(phoneNumber)) { + phoneNumberToReturn = phoneNumber; + } else if (!StringUtils.isBlank(toPhoneNumber)) { + phoneNumberToReturn = toPhoneNumber; + } + break; + case "outgoing": // NON-NLS + if (!StringUtils.isBlank(toPhoneNumber)) { + phoneNumberToReturn = toPhoneNumber; + } else if (!StringUtils.isBlank(phoneNumber)) { + phoneNumberToReturn = phoneNumber; + } else if (!StringUtils.isBlank(fromPhoneNumber)) { + phoneNumberToReturn = fromPhoneNumber; + } + break; + default: + if (!StringUtils.isBlank(toPhoneNumber)) { + phoneNumberToReturn = toPhoneNumber; + } else if (!StringUtils.isBlank(fromPhoneNumber)) { + phoneNumberToReturn = fromPhoneNumber; + } else if (!StringUtils.isBlank(phoneNumber)) { + phoneNumberToReturn = phoneNumber; + } + } + + return phoneNumberToReturn; + } /** * Circumvent DataResultFilterNode's slightly odd delegation to * BlackboardArtifactNode.getSourceName(). From ad5106d7d431aaf4d1eba68aff3c737b83d65c7b Mon Sep 17 00:00:00 2001 From: Raman Arora Date: Wed, 11 Mar 2020 13:43:31 -0400 Subject: [PATCH 2/2] Addressed Codacy comments. --- .../relationships/CallLogNode.java | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/communications/relationships/CallLogNode.java b/Core/src/org/sleuthkit/autopsy/communications/relationships/CallLogNode.java index 055cddcc09..3151d75780 100755 --- a/Core/src/org/sleuthkit/autopsy/communications/relationships/CallLogNode.java +++ b/Core/src/org/sleuthkit/autopsy/communications/relationships/CallLogNode.java @@ -102,53 +102,57 @@ final class CallLogNode extends BlackboardArtifactNode { /** * Returns the phone number to display in the To/From column. The number is - * picked from one the the 3 possible phone number attributes, based on the + * picked from one of the 3 possible phone number attributes, based on the * direction of the call. * * @param artifact Call log artifact. * - * @return Phone number. + * @return Phone number to display. */ private String getPhoneNumber(BlackboardArtifact artifact) { String direction = getAttributeDisplayString(artifact, TSK_DIRECTION); - String phoneNumberToReturn = ""; + String phoneNumberToReturn; String fromPhoneNumber = getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_FROM); String toPhoneNumber = getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_TO); String phoneNumber = getAttributeDisplayString(artifact, TSK_PHONE_NUMBER); - switch (direction.toLowerCase()) { case "incoming": // NON-NLS - - if (!StringUtils.isBlank(fromPhoneNumber)) { - phoneNumberToReturn = fromPhoneNumber; - } else if (!StringUtils.isBlank(phoneNumber)) { - phoneNumberToReturn = phoneNumber; - } else if (!StringUtils.isBlank(toPhoneNumber)) { - phoneNumberToReturn = toPhoneNumber; - } + phoneNumberToReturn = getFirstNonBlank(fromPhoneNumber, phoneNumber, toPhoneNumber); break; case "outgoing": // NON-NLS - if (!StringUtils.isBlank(toPhoneNumber)) { - phoneNumberToReturn = toPhoneNumber; - } else if (!StringUtils.isBlank(phoneNumber)) { - phoneNumberToReturn = phoneNumber; - } else if (!StringUtils.isBlank(fromPhoneNumber)) { - phoneNumberToReturn = fromPhoneNumber; - } + phoneNumberToReturn = getFirstNonBlank(toPhoneNumber, phoneNumber, fromPhoneNumber); break; default: - if (!StringUtils.isBlank(toPhoneNumber)) { - phoneNumberToReturn = toPhoneNumber; - } else if (!StringUtils.isBlank(fromPhoneNumber)) { - phoneNumberToReturn = fromPhoneNumber; - } else if (!StringUtils.isBlank(phoneNumber)) { - phoneNumberToReturn = phoneNumber; - } + phoneNumberToReturn = getFirstNonBlank(toPhoneNumber, fromPhoneNumber, phoneNumber ); + break; } return phoneNumberToReturn; } + + /** + * Checks the given string arguments in order and returns the first non blank string. + * Returns a blank string if all the input strings are blank. + * + * @param string1 First string to check + * @param string2 Second string to check + * @param string3 Third string to check + * + * @retunr first non blank string if there is one, blank string otherwise. + * + */ + private String getFirstNonBlank(String string1, String string2, String string3 ) { + + if (!StringUtils.isBlank(string1)) { + return string1; + } else if (!StringUtils.isBlank(string2)) { + return string2; + } else if (!StringUtils.isBlank(string3)) { + return string3; + } + return ""; + } /** * Circumvent DataResultFilterNode's slightly odd delegation to * BlackboardArtifactNode.getSourceName().