Esempio n. 1
0
  /**
   * Returns a <tt>CustomerPartyType</tt> corresponding to the passed
   * <em>party.organisationStockLocation</em>.
   *
   * <p>The contact details will be either those of the <em>party.organisationLocation</em> or the
   * parent </em>party.organisationPractice</em>. If the location has a <em>contact.location</em>,
   * then the location's details will be used, otherwise the practice's details will be used.
   *
   * <p>The customer identifier will be that of the stock location.
   *
   * <p>NOTE: the supplied <em>entityRelationship.supplierStockLocation*</em> relationship may have
   * an optional <em>accountId</em> node, used to populate the
   * <tt>SupplierAssignedAccountIDType</tt>
   *
   * @param contactName a contact name to supply with telephone, email and fax details, May be
   *     <tt>null</tt>
   * @param location the practice location
   * @param stockLocation the stock location
   * @param supplierStockLocation an <em>entityRelationship.supplierStockLocation*</em> relationship
   * @return the corresponding <tt>CustomerPartyType</tt>
   */
  private CustomerPartyType getCustomer(
      String contactName,
      Party location,
      Party stockLocation,
      EntityRelationship supplierStockLocation) {
    CustomerPartyType result = new CustomerPartyType();
    Party customer;

    Party practice = locationRules.getPractice(location);
    if (practice == null) {
      throw new IllegalStateException("No practice for location: " + location.getId());
    }

    Contact locationContact =
        partyRules.getContact(location, ContactArchetypes.LOCATION, "BILLING");
    if (locationContact == null) {
      locationContact = partyRules.getContact(practice, ContactArchetypes.LOCATION, "BILLING");
      if (locationContact == null) {
        throw new IllegalStateException("No contact.location for location: " + location.getId());
      }
      customer = practice;
    } else {
      customer = location;
    }
    Contact phoneContact =
        partyRules.getContact(customer, ContactArchetypes.PHONE, false, "FAX", "BILLING");
    Contact faxContact =
        partyRules.getContact(customer, ContactArchetypes.PHONE, true, null, "FAX", "BILLING");
    if (faxContact == null) {
      faxContact = partyRules.getContact(customer, ContactArchetypes.PHONE, true, null, "FAX");
    }
    Contact emailContact = partyRules.getContact(customer, ContactArchetypes.EMAIL, "BILLING");

    CustomerAssignedAccountIDType customerId =
        UBLHelper.initID(new CustomerAssignedAccountIDType(), stockLocation.getId());

    PartyType party = getParty(customer, locationContact);
    party.setContact(getContact(contactName, phoneContact, faxContact, emailContact));

    result.setCustomerAssignedAccountID(customerId);

    IMObjectBean bean = factory.createBean(supplierStockLocation);
    String accountId = bean.getString("accountId");
    if (!StringUtils.isEmpty(accountId)) {
      SupplierAssignedAccountIDType supplierId =
          UBLHelper.initID(new SupplierAssignedAccountIDType(), accountId);
      result.setSupplierAssignedAccountID(supplierId);
    }

    result.setParty(party);
    return result;
  }
Esempio n. 2
0
  /**
   * Returns a <tt>SupplierPartyType</tt> corresponding to the passed supplier.
   *
   * @param supplier the supplier
   * @return the corresponding <tt>SupplierPartyType</tt>
   */
  private SupplierPartyType getSupplier(Party supplier) {
    SupplierPartyType result = new SupplierPartyType();

    CustomerAssignedAccountIDType accountId =
        UBLHelper.initID(new CustomerAssignedAccountIDType(), supplier.getId());
    Contact contact = partyRules.getContact(supplier, ContactArchetypes.LOCATION, null);

    result.setCustomerAssignedAccountID(accountId);
    result.setParty(getParty(supplier, contact));
    return result;
  }