DefaultIBizCustomerImporter.java

  1. /*
  2.  * *************************************************************************************************************************************************************
  3.  *
  4.  * blueHour: open source accounting
  5.  * http://tidalwave.it/projects/bluehour
  6.  *
  7.  * Copyright (C) 2013 - 2024 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *************************************************************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
  12.  * You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  17.  * CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and limitations under the License.
  18.  *
  19.  * *************************************************************************************************************************************************************
  20.  *
  21.  * git clone https://bitbucket.org/tidalwave/bluehour-src
  22.  * git clone https://github.com/tidalwave-it/bluehour-src
  23.  *
  24.  * *************************************************************************************************************************************************************
  25.  */
  26. package it.tidalwave.accounting.importer.ibiz.impl;

  27. import javax.annotation.CheckForNull;
  28. import javax.annotation.Nonnull;
  29. import java.io.IOException;
  30. import java.nio.file.Path;
  31. import it.tidalwave.accounting.importer.ibiz.spi.IBizCustomerImporter;
  32. import it.tidalwave.accounting.model.CustomerRegistry;
  33. import lombok.RequiredArgsConstructor;
  34. import lombok.extern.slf4j.Slf4j;

  35. /***************************************************************************************************************************************************************
  36.  *
  37.  * @author  Fabrizio Giudici
  38.  *
  39.  **************************************************************************************************************************************************************/
  40. @RequiredArgsConstructor @Slf4j
  41. public class DefaultIBizCustomerImporter implements IBizCustomerImporter
  42.   {
  43.     @Nonnull
  44.     private final CustomerRegistry customerRegistry;

  45.     @Nonnull
  46.     private final Path path;

  47.     /***********************************************************************************************************************************************************
  48.      * {@inheritDoc}
  49.      **********************************************************************************************************************************************************/
  50.     @Override
  51.     public void importCustomers()
  52.       throws IOException
  53.       {
  54.         log.debug("importCustomers()");
  55. /*        final NativeAddressBook addressBook = NativeAddressBook.instance();
  56.         IBizUtils.loadConfiguration(path.resolve("clients")).getStream("clients").forEach(customerConfig ->
  57.           {
  58.             final String firstName = trim(customerConfig.getString("firstName"));
  59.             final String clientCompany = customerConfig.getString("clientCompany");
  60.             final Contact contact = getContact(addressBook, firstName, clientCompany);

  61.             customerRegistry.addCustomer().withId(customerConfig.getId("addressBookId"))
  62.                                           .withName(firstName)
  63.                                           .withBillingAddress(getAddress(contact))
  64.                                           .withVatNumber(getVatNumber(contact))
  65.                                           .create();
  66.           });*/
  67.       }

  68. //    @Nonnull
  69. //    private String getVatNumber (final @Nonnull Contact contact)
  70. //      {
  71. //        final MultiValue<String> phone = contact.getPhone();
  72. //        final MultiValue<String> email = contact.getEmail();
  73. //        String vat = "";
  74. //
  75. //        if (email != null)
  76. //          {
  77. //            vat = email.getFirstHomeValue(); // VAT is also there in my address book...
  78. //          }
  79. //
  80. //        if (((vat == null) || vat.equals("")) && (phone != null))
  81. //          {
  82. //            vat = phone.getFirstHomeValue(); // VAT is also there in my address book...
  83. //          }
  84. //
  85. //        return vat;
  86. //      }

  87. //    @Nonnull
  88. //    private Address getAddress (final @Nonnull Contact contact)
  89. //      {
  90. //        Address.Builder addressBuilder = Address.builder();
  91. //
  92. //        if (contact.getAddress() != null)
  93. //          {
  94. //            final corny.addressbook.data.Address addr = contact.getAddress().getFirstHomeValue();
  95. //            addressBuilder = addressBuilder.withCity(addr.getCity())
  96. //                                           .withState(addr.getCountry())
  97. //                                           .withStreet(addr.getStreet())
  98. //                                           .withZip("" + addr.getZip());
  99. //          }
  100. //
  101. //        return addressBuilder.create();
  102. //    }

  103.     /***********************************************************************************************************************************************************
  104.      *
  105.      **********************************************************************************************************************************************************/
  106. //    @Nonnull
  107. //    private Contact getContact (final @Nonnull NativeAddressBook addressBook,
  108. //                                final @Nonnull String firstName,
  109. //                                final @Nonnull String clientCompany)
  110. //      {
  111. //        List<Contact> contacts = addressBook.getContactsWithFirstName(firstName);
  112. //
  113. //        if (contacts.isEmpty())
  114. //          {
  115. //            contacts = addressBook.getContactsWithSomeAttribute(clientCompany);
  116. //          }
  117. //
  118. //        return contacts.get(0);
  119. //      }
  120.    
  121.     @Nonnull
  122.     private static String trim (@CheckForNull final String string)
  123.       {
  124.         return (string == null) ? "" : string.trim();
  125.       }
  126.   }