コード例 #1
0
ファイル: OrderMapperImpl.java プロジェクト: VitalPet/OPEN
  /**
   * 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;
  }
コード例 #2
0
ファイル: OrderMapperImpl.java プロジェクト: VitalPet/OPEN
  /**
   * 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;
  }
コード例 #3
0
ファイル: OrderMapperImpl.java プロジェクト: VitalPet/OPEN
  /**
   * 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;
  }