Beispiel #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;
  }
Beispiel #2
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;
 }
Beispiel #3
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;
  }
Beispiel #4
0
 /**
  * Processes an invoice.
  *
  * @param document the document to process
  * @param supplier the supplier submitting the invoice
  * @param stockLocation the stock location
  * @param accountId the supplier account identifier
  */
 public void process(
     InboxDocument document, Party supplier, Party stockLocation, String accountId) {
   InvoiceType invoice = (InvoiceType) document.getContent();
   try {
     Delivery delivery = mapper.map(invoice, supplier, stockLocation, accountId);
     service.save(delivery.getActs());
     notifyListener(delivery.getDelivery());
   } catch (Throwable exception) {
     String invoiceId = (invoice.getID() != null) ? invoice.getID().getValue() : null;
     Message message =
         ESCIAdapterMessages.failedToProcessInvoice(
             invoiceId, supplier, stockLocation, exception.getMessage());
     throw new ESCIAdapterException(message, exception);
   }
 }