Example #1
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 #2
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 #3
0
 /**
  * Helper to return the location associated with a stock location.
  *
  * @param stockLocation the stock location
  * @return the corresponding location
  * @throws ESCIAdapterException if the stock location isn't associated with a practice location
  */
 private Party getLocation(Party stockLocation) {
   EntityBean bean = factory.createEntityBean(stockLocation);
   // TODO - there could be more than one location which refers to different
   // party.organisationLocation
   Party result = (Party) bean.getNodeSourceEntity("locations");
   if (result == null) {
     throw new ESCIAdapterException(
         ESCIAdapterMessages.noPracticeLocationForStockLocation(stockLocation));
   }
   return result;
 }
Example #4
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 #5
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 #6
0
 /**
  * Helper to format a phone/fax number.
  *
  * @param contact the phone/fax contact. May be <tt>null</tt>
  * @param areaCodeNode the area code node.
  * @param numberNode the phone number node
  * @return a formatted number, or <tt>null</tt> if <tt>number</tt> is null
  */
 private String formatPhone(Contact contact, String areaCodeNode, String numberNode) {
   String result = null;
   if (contact != null) {
     IMObjectBean bean = factory.createBean(contact);
     String number = bean.getString(numberNode);
     if (!StringUtils.isEmpty(number)) {
       String areaCode = bean.getString(areaCodeNode);
       if (!StringUtils.isEmpty(areaCode)) {
         result = "(" + areaCode + ") " + number; // todo - localise
       } else {
         result = number;
       }
     }
   }
   return result;
 }
Example #7
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 #8
0
 /**
  * Returns the UN/CEFACT unit code for the given package units code from an <em>lookup.uom</em>.
  *
  * <p>If no package is specified, defaults to {@link #DEFAULT_PACKAGE_UNITS}.
  *
  * @param packageUnits the package units code
  * @return the corresponding unit code
  */
 private String getUnitCode(String packageUnits) {
   String result = null;
   if (!StringUtils.isEmpty("packageUnits")) {
     Lookup lookup = lookupService.getLookup("lookup.uom", packageUnits);
     if (lookup != null) {
       IMObjectBean lookupBean = factory.createBean(lookup);
       String unitCode = lookupBean.getString("unitCode");
       if (!StringUtils.isEmpty(unitCode)) {
         result = unitCode;
       }
     }
     if (result == null) {
       log.warn(
           "No unit code for package units="
               + packageUnits
               + ". Defaulting to "
               + DEFAULT_PACKAGE_UNITS);
     }
   }
   if (result == null) {
     result = DEFAULT_PACKAGE_UNITS;
   }
   return result;
 }