Example #1
0
  /**
   * Returns a <tt>ItemType</tt> for a supplier, order item, and product.
   *
   * @param bean the order item
   * @param supplier the supplier
   * @param product the product
   * @param packageUnits the package size unit code. May be <tt>null</tt>
   * @return an <tt>ItemType</tt> corresponding to the supplier and product
   */
  private ItemType getItem(ActBean bean, Party supplier, Product product, String packageUnits) {
    ItemType result = new ItemType();
    ItemIdentificationType buyersId = getItemIdentification(product.getId());
    String reorderCode = bean.getString("reorderCode");
    String reorderDescription = bean.getString("reorderDescription");
    if (!StringUtils.isEmpty(reorderCode)) {
      ItemIdentificationType sellersId = getItemIdentification(reorderCode);
      result.setSellersItemIdentification(sellersId);
    } else {
      throw new ESCIAdapterException(ESCIAdapterMessages.noSupplierOrderCode(supplier, product));
    }
    if (!StringUtils.isEmpty(reorderDescription)) {
      DescriptionType description = UBLHelper.initText(new DescriptionType(), reorderDescription);
      result.getDescription().add(description);
    }
    NameType name = UBLHelper.initName(new NameType(), product.getName());

    result.setBuyersItemIdentification(buyersId);
    result.setName(name);

    BigDecimal packageSize = bean.getBigDecimal("packageSize");
    if (packageSize != null && packageUnits != null) {
      PackQuantityType quantity =
          UBLHelper.initQuantity(new PackQuantityType(), BigDecimal.ONE, packageUnits);
      PackSizeNumericType size = UBLHelper.createPackSizeNumeric(packageSize);
      result.setPackQuantity(quantity);
      result.setPackSizeNumeric(size);
    }

    return result;
  }
Example #2
0
  /**
   * Returns an <tt>OrderLineType</tt> for an <em>act.supplierOrderItem</em>.
   *
   * @param act the order item to map
   * @param supplier the supplier
   * @param currency the currency that amounts are expressed in
   * @return a new <tt>OrderLineType</tt> corresponding to the act
   */
  private OrderLineType getOrderLine(Act act, Party supplier, Currency currency) {
    ActBean bean = factory.createActBean(act);
    Product product = (Product) bean.getNodeParticipant("product");

    OrderLineType orderLine = new OrderLineType();
    LineItemType lineItem = new LineItemType();

    String packageUnits = bean.getString("packageUnits");
    String unitCode = getUnitCode(packageUnits);

    ItemType item = getItem(bean, supplier, product, unitCode);
    lineItem.setItem(item);
    orderLine.setLineItem(lineItem);

    IDType id = UBLHelper.createID(act.getId());
    QuantityType quantity =
        UBLHelper.initQuantity(new QuantityType(), bean.getBigDecimal("quantity"), unitCode);
    LineExtensionAmountType lineAmount =
        UBLHelper.initAmount(new LineExtensionAmountType(), bean.getBigDecimal("total"), currency);
    TotalTaxAmountType taxAmount =
        UBLHelper.initAmount(new TotalTaxAmountType(), bean.getBigDecimal("tax"), currency);
    PriceType price = getPrice(bean.getBigDecimal("unitPrice"), unitCode, currency);

    lineItem.setID(id);
    lineItem.setQuantity(quantity);
    lineItem.setLineExtensionAmount(lineAmount);
    lineItem.setTotalTaxAmount(taxAmount);
    lineItem.setPrice(price);

    return orderLine;
  }
Example #3
0
 /**
  * Returns a <tt>PriceType</tt> for the specified price and unit code.
  *
  * @param price the price
  * @param unitCode the quantity unit code (UN/CEFACT). May be <tt>null</tt>
  * @param currency the currency
  * @return the corresponding <tt>PriceType</tt> for price and unitCode
  */
 private PriceType getPrice(BigDecimal price, String unitCode, Currency currency) {
   PriceType result = new PriceType();
   PriceAmountType priceAmount = UBLHelper.initAmount(new PriceAmountType(), price, currency);
   result.setPriceAmount(priceAmount);
   result.setBaseQuantity(
       UBLHelper.initQuantity(new BaseQuantityType(), BigDecimal.ONE, unitCode));
   return result;
 }
Example #4
0
  /**
   * Returns a <tt>MonetaryTotalType</tt> for an order.
   *
   * @param order the order
   * @param currency the currency
   * @return the corresponding <tt>MonetaryTotalType</tt>
   */
  private MonetaryTotalType getMonetaryTotal(FinancialAct order, Currency currency) {
    BigDecimal payableAmount = order.getTotal();
    BigDecimal lineExtensionAmount = payableAmount.subtract(order.getTaxAmount());

    MonetaryTotalType result = new MonetaryTotalType();
    result.setLineExtensionAmount(
        UBLHelper.initAmount(new LineExtensionAmountType(), lineExtensionAmount, currency));
    result.setPayableAmount(UBLHelper.initAmount(new PayableAmountType(), payableAmount, currency));
    return result;
  }
Example #5
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;
  }
Example #6
0
  /**
   * Maps an <em>act.supplierOrder</em> to an UBL order.
   *
   * @param order the <em>act.supplierOrder</em> to map
   * @return the corresponding UBL order
   * @throws ESCIAdapterException for mapping errors
   * @throws ArchetypeServiceException for any archetype service error
   */
  public Order map(FinancialAct order) {
    Order result = new Order();
    Currency currency = getCurrency();

    UBLVersionIDType version = UBLHelper.initID(new UBLVersionIDType(), "2.0");
    IDType id = UBLHelper.createID(order.getId());
    CopyIndicatorType copyIndicator = getCopyIndicatorType(false);

    GregorianCalendar startTime = new GregorianCalendar();
    startTime.setTime(order.getActivityStartTime());
    IssueDateType issueDate = UBLHelper.createIssueDate(startTime, datatypeFactory);
    IssueTimeType issueTime = UBLHelper.createIssueTime(startTime, datatypeFactory);

    ActBean bean = factory.createActBean(order);
    Entity author = bean.getNodeParticipant("author");
    Party stockLocation = (Party) bean.getNodeParticipant("stockLocation");
    Party location = getLocation(stockLocation);

    Party supplier = (Party) bean.getNodeParticipant("supplier");
    EntityRelationship supplierStockLocation =
        supplierRules.getSupplierStockLocation(supplier, stockLocation);
    if (supplierStockLocation == null) {
      throw new ESCIAdapterException(
          ESCIAdapterMessages.ESCINotConfigured(supplier, stockLocation));
    }
    String contactName = (author != null) ? author.getName() : null;
    CustomerPartyType customerParty =
        getCustomer(contactName, location, stockLocation, supplierStockLocation);
    SupplierPartyType supplierParty = getSupplier(supplier);

    TaxTotalType taxTotal = getTaxTotal(order, currency);
    MonetaryTotalType total = getMonetaryTotal(order, currency);

    result.setUBLVersionID(version);
    result.setID(id);
    result.setCopyIndicator(copyIndicator);
    result.setIssueDate(issueDate);
    result.setIssueTime(issueTime);
    result.setBuyerCustomerParty(customerParty);
    result.setSellerSupplierParty(supplierParty);
    result.getTaxTotal().add(taxTotal);
    result.setAnticipatedMonetaryTotal(total);

    for (Act item : bean.getNodeActs("items")) {
      OrderLineType line = getOrderLine(item, supplier, currency);
      result.getOrderLine().add(line);
    }
    return result;
  }
Example #7
0
 /**
  * Returns an <tt>ElectronicMailType</tt> for a <em>contact.email</em>.
  *
  * @param contact the email contact. May be <tt>null</tt>
  * @return a new <tt>ElectronicMailType</tt> or <tt>null</tt> if <tt>contact</tt> is null or
  *     unpopulated
  */
 private ElectronicMailType getEmail(Contact contact) {
   String email = null;
   if (contact != null) {
     IMObjectBean bean = factory.createBean(contact);
     email = StringUtils.trimToNull(bean.getString("emailAddress"));
   }
   return (email != null) ? UBLHelper.initText(new ElectronicMailType(), email) : null;
 }
Example #8
0
 /**
  * Returns a <tt>ContactType</tt> for the supplied contacts.
  *
  * @param name a contact name
  * @param phone the phone contact. May be <tt>null</tt>
  * @param fax the fax contact. May be <tt>null</tt>
  * @param email the email contact. May be <tt>null</tt>
  * @return the corresponding <tt>ContactType</tt>
  */
 private ContactType getContact(String name, Contact phone, Contact fax, Contact email) {
   ContactType contact = new ContactType();
   if (!StringUtils.isEmpty(name)) {
     contact.setName(UBLHelper.initName(new NameType(), name));
   }
   contact.setTelephone(getPhone(phone));
   contact.setTelefax(getFax(fax));
   contact.setElectronicMail(getEmail(email));
   return contact;
 }
Example #9
0
  /**
   * Returns a <tt>PartyType</tt> for the supplied party and contact.
   *
   * @param party the party
   * @param location the location contact. May be <tt>null</tt>
   * @return the corresponding <tt>PartyType</tt>
   */
  private PartyType getParty(Party party, Contact location) {
    PartyType result = new PartyType();

    PartyNameType partyName = new PartyNameType();
    partyName.setName(UBLHelper.createName(party.getName()));
    result.getPartyName().add(partyName);
    if (location != null) {
      result.setPostalAddress(getAddress(location));
    }
    return result;
  }
Example #10
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;
  }
Example #11
0
  /**
   * Returns an <tt>AddressType</tt> for the supplied <em>contact.location</em>.
   *
   * @param contact the location contact
   * @return the corresponding <tt>AddressType</tt>
   */
  private AddressType getAddress(Contact contact) {
    IMObjectBean bean = factory.createBean(contact);

    AddressType result = new AddressType();
    AddressLineType addressLineType = new AddressLineType();
    LineType line = UBLHelper.initText(new LineType(), bean.getString("address"));
    addressLineType.setLine(line);

    String city = lookupService.getName(contact, "suburb");
    CityNameType cityName = UBLHelper.initName(new CityNameType(), city);

    String state = lookupService.getName(contact, "state");
    CountrySubentityType stateName = UBLHelper.initText(new CountrySubentityType(), state);

    PostalZoneType postCode = UBLHelper.initText(new PostalZoneType(), bean.getString("postcode"));

    result.getAddressLine().add(addressLineType);
    result.setCityName(cityName);
    result.setCountrySubentity(stateName);
    result.setPostalZone(postCode);
    return result;
  }
Example #12
0
 /**
  * Returns the currency associated with the practice.
  *
  * @return the currency code
  */
 private Currency getCurrency() {
   return UBLHelper.getCurrency(practiceRules, currencies, factory);
 }
Example #13
0
 /**
  * Returns an <tt>ItemIdentificationType</tt> for the given identifier.
  *
  * @param id the identifier
  * @return a new <tt>ItemIdentificationType</tt>
  */
 private ItemIdentificationType getItemIdentification(String id) {
   ItemIdentificationType result = new ItemIdentificationType();
   result.setID(UBLHelper.createID(id));
   return result;
 }
Example #14
0
 /**
  * Returns an <tt>TelefaxType</tt> for a fax contact.
  *
  * @param contact the fax contact. May be <tt>null</tt>
  * @return a new <tt>TelefaxType</tt> or <tt>null</tt> if <tt>contact</tt> is null or unpopulated
  */
 private TelefaxType getFax(Contact contact) {
   String fax = formatPhone(contact, "areaCode", "telephoneNumber");
   return (fax != null) ? UBLHelper.initText(new TelefaxType(), fax) : null;
 }
Example #15
0
 /**
  * Returns an <tt>TelephoneType</tt> for a <em>contact.phoneNumber</em>.
  *
  * @param contact the phone contact. May be <tt>null</tt>
  * @return a new <tt>TelephoneType</tt> or <tt>null</tt> if <tt>contact</tt> is null or
  *     unpopulated
  */
 private TelephoneType getPhone(Contact contact) {
   String phone = formatPhone(contact, "areaCode", "telephoneNumber");
   return (phone != null) ? UBLHelper.initText(new TelephoneType(), phone) : null;
 }
Example #16
0
 /**
  * Returns a <tt>TaxTotalType</tt> for an order.
  *
  * @param order the order
  * @param currency the currency
  * @return the corresponding <tt>TaxTotalType</tt>
  */
 private TaxTotalType getTaxTotal(FinancialAct order, Currency currency) {
   TaxTotalType result = new TaxTotalType();
   result.setTaxAmount(UBLHelper.initAmount(new TaxAmountType(), order.getTaxAmount(), currency));
   return result;
 }