Skip to content

Commit

Permalink
[tr064] Merge duplicate phone book entries (openhab#9739)
Browse files Browse the repository at this point in the history
* [tr064] Merge duplicate phone book entries

Fixes openhab#9738

Signed-off-by: Stefan Triller <[email protected]>
  • Loading branch information
t2000 authored and thinkingstone committed Nov 7, 2021
1 parent 710dcbf commit 7aba980
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,25 @@ private void getPhonebook() {
phonebook = phonebooksType.getPhonebook().getContact().stream().map(contact -> {
String contactName = contact.getPerson().getRealName();
return contact.getTelephony().getNumber().stream()
.collect(Collectors.toMap(number -> normalizeNumber(number.getValue()), number -> contactName));
.collect(Collectors.toMap(number -> normalizeNumber(number.getValue()), number -> contactName,
this::mergeSameContactNames));
}).collect(HashMap::new, HashMap::putAll, HashMap::putAll);
logger.debug("Downloaded phonebook {}: {}", phonebookName, phonebook);
} catch (JAXBException | InterruptedException | ExecutionException | TimeoutException e) {
logger.warn("Failed to get phonebook with URL {}:", phonebookUrl, e);
}
}

// in case there are multiple phone entries with same number -> name mapping, i.e. in phonebooks exported from
// mobiles containing multiple accounts like: local, cloudprovider1, messenger1, messenger2,...
private String mergeSameContactNames(String nameA, String nameB) {
if (nameA != null && nameA.equals(nameB)) {
return nameA;
}
throw new IllegalStateException(
"Found different names for the same number: '" + nameA + "' and '" + nameB + "'");
}

@Override
public String getName() {
return phonebookName;
Expand Down

0 comments on commit 7aba980

Please sign in to comment.