DefaultIBizCustomerImporter.java

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

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

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

  46.     @Nonnull
  47.     private final Path path;

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

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

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

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

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