From bb5049d184afed7e64fe0007c0ca52246f0e7189 Mon Sep 17 00:00:00 2001 From: Stefan Triller Date: Thu, 7 Jan 2021 21:47:05 +0100 Subject: [PATCH 1/2] [tr064] Merge duplicate phone book entries Fixes #9738 Signed-off-by: Stefan Triller --- .../internal/phonebook/Tr064PhonebookImpl.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/Tr064PhonebookImpl.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/Tr064PhonebookImpl.java index b9e1dc650c9a6..c4b5c1ba3a876 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/Tr064PhonebookImpl.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/Tr064PhonebookImpl.java @@ -72,7 +72,8 @@ 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, + (nameA, nameB) -> mergeSameContactNames(nameA, nameB))); }).collect(HashMap::new, HashMap::putAll, HashMap::putAll); logger.debug("Downloaded phonebook {}: {}", phonebookName, phonebook); } catch (JAXBException | InterruptedException | ExecutionException | TimeoutException e) { @@ -80,6 +81,16 @@ private void getPhonebook() { } } + // 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; From a3798b74f0ced132b435dacf108a07b8b8460bb3 Mon Sep 17 00:00:00 2001 From: Stefan Triller Date: Fri, 8 Jan 2021 08:25:17 +0100 Subject: [PATCH 2/2] Integrate review comments Signed-off-by: Stefan Triller --- .../binding/tr064/internal/phonebook/Tr064PhonebookImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/Tr064PhonebookImpl.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/Tr064PhonebookImpl.java index c4b5c1ba3a876..8e7782b763685 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/Tr064PhonebookImpl.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/Tr064PhonebookImpl.java @@ -73,7 +73,7 @@ private void getPhonebook() { String contactName = contact.getPerson().getRealName(); return contact.getTelephony().getNumber().stream() .collect(Collectors.toMap(number -> normalizeNumber(number.getValue()), number -> contactName, - (nameA, nameB) -> mergeSameContactNames(nameA, nameB))); + this::mergeSameContactNames)); }).collect(HashMap::new, HashMap::putAll, HashMap::putAll); logger.debug("Downloaded phonebook {}: {}", phonebookName, phonebook); } catch (JAXBException | InterruptedException | ExecutionException | TimeoutException e) {