Search in sources :

Example 6 with QuantityType

use of org.geotoolkit.swe.xml.v100.QuantityType in project arctic-sea by 52North.

the class SweCommonEncoderv20 method asPropertyType.

private XmlObject asPropertyType(AbstractDataComponentType type) throws NotYetSupportedEncodingException {
    if (type instanceof BooleanType) {
        BooleanPropertyType propertyType = BooleanPropertyType.Factory.newInstance();
        propertyType.setBoolean((BooleanType) type);
        return propertyType;
    } else if (type instanceof CountType) {
        CountPropertyType propertyType = CountPropertyType.Factory.newInstance();
        propertyType.setCount((CountType) type);
        return propertyType;
    } else if (type instanceof CountRangeType) {
        CountRangePropertyType propertyType = CountRangePropertyType.Factory.newInstance();
        propertyType.setCountRange((CountRangeType) type);
        return propertyType;
    } else if (type instanceof QuantityType) {
        QuantityPropertyType propertyType = QuantityPropertyType.Factory.newInstance();
        propertyType.setQuantity((QuantityType) type);
        return propertyType;
    } else if (type instanceof QuantityRangeType) {
        QuantityRangePropertyType propertyType = QuantityRangePropertyType.Factory.newInstance();
        propertyType.setQuantityRange((QuantityRangeType) type);
        return propertyType;
    } else if (type instanceof TimeType) {
        TimePropertyType propertyType = TimePropertyType.Factory.newInstance();
        propertyType.setTime((TimeType) type);
        return propertyType;
    } else if (type instanceof TimeRangeType) {
        TimeRangePropertyType propertyType = TimeRangePropertyType.Factory.newInstance();
        propertyType.setTimeRange((TimeRangeType) type);
        return propertyType;
    } else if (type instanceof CategoryType) {
        CategoryPropertyType propertyType = CategoryPropertyType.Factory.newInstance();
        propertyType.setCategory((CategoryType) type);
        return propertyType;
    } else if (type instanceof CategoryRangeType) {
        CategoryRangePropertyType propertyType = CategoryRangePropertyType.Factory.newInstance();
        propertyType.setCategoryRange((CategoryRangeType) type);
        return propertyType;
    } else if (type instanceof MatrixType) {
        MatrixPropertyType propertyType = MatrixPropertyType.Factory.newInstance();
        propertyType.setMatrix((MatrixType) type);
        return propertyType;
    } else if (type instanceof DataArrayType) {
        DataArrayPropertyType propertyType = DataArrayPropertyType.Factory.newInstance();
        propertyType.setDataArray1((DataArrayType) type);
        return propertyType;
    } else if (type instanceof DataChoiceType) {
        DataChoicePropertyType propertyType = DataChoicePropertyType.Factory.newInstance();
        propertyType.setDataChoice((DataChoiceType) type);
        return propertyType;
    } else if (type instanceof DataRecordType) {
        DataRecordPropertyType propertyType = DataRecordPropertyType.Factory.newInstance();
        propertyType.setDataRecord((DataRecordType) type);
        return propertyType;
    } else if (type instanceof TextType) {
        TextPropertyType propertyType = TextPropertyType.Factory.newInstance();
        propertyType.setText((TextType) type);
        return propertyType;
    } else if (type instanceof VectorType) {
        VectorPropertyType propertyType = VectorPropertyType.Factory.newInstance();
        propertyType.setVector((VectorType) type);
        return propertyType;
    } else {
        throw new NotYetSupportedEncodingException(type.getClass().getName(), type);
    }
}
Also used : DataRecordType(net.opengis.swe.x20.DataRecordType) CategoryRangeType(net.opengis.swe.x20.CategoryRangeType) MatrixPropertyType(net.opengis.swe.x20.MatrixPropertyType) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) CategoryType(net.opengis.swe.x20.CategoryType) DataArrayPropertyType(net.opengis.swe.x20.DataArrayPropertyType) TimeRangePropertyType(net.opengis.swe.x20.TimeRangePropertyType) CountType(net.opengis.swe.x20.CountType) TimeType(net.opengis.swe.x20.TimeType) VectorPropertyType(net.opengis.swe.x20.VectorPropertyType) CountPropertyType(net.opengis.swe.x20.CountPropertyType) CountRangeType(net.opengis.swe.x20.CountRangeType) DataChoiceType(net.opengis.swe.x20.DataChoiceType) VectorType(net.opengis.swe.x20.VectorType) QuantityPropertyType(net.opengis.swe.x20.QuantityPropertyType) TextPropertyType(net.opengis.swe.x20.TextPropertyType) CountRangePropertyType(net.opengis.swe.x20.CountRangePropertyType) BooleanPropertyType(net.opengis.swe.x20.BooleanPropertyType) DataChoicePropertyType(net.opengis.swe.x20.DataChoicePropertyType) DataArrayType(net.opengis.swe.x20.DataArrayType) QuantityRangePropertyType(net.opengis.swe.x20.QuantityRangePropertyType) CategoryRangePropertyType(net.opengis.swe.x20.CategoryRangePropertyType) BooleanType(net.opengis.swe.x20.BooleanType) DataRecordPropertyType(net.opengis.swe.x20.DataRecordPropertyType) TextType(net.opengis.swe.x20.TextType) TimeRangeType(net.opengis.swe.x20.TimeRangeType) QuantityType(net.opengis.swe.x20.QuantityType) MatrixType(net.opengis.swe.x20.MatrixType) TimePropertyType(net.opengis.swe.x20.TimePropertyType) QuantityRangeType(net.opengis.swe.x20.QuantityRangeType) CategoryPropertyType(net.opengis.swe.x20.CategoryPropertyType)

Example 7 with QuantityType

use of org.geotoolkit.swe.xml.v100.QuantityType in project en16931-cii2ubl by phax.

the class CIIToUBL22Converter method convertToInvoice.

@Nullable
public InvoiceType convertToInvoice(@Nonnull final CrossIndustryInvoiceType aCIIInvoice, @Nonnull final ErrorList aErrorList) {
    ValueEnforcer.notNull(aCIIInvoice, "CIIInvoice");
    ValueEnforcer.notNull(aErrorList, "ErrorList");
    final ExchangedDocumentType aED = aCIIInvoice.getExchangedDocument();
    final SupplyChainTradeTransactionType aSCTT = aCIIInvoice.getSupplyChainTradeTransaction();
    if (aSCTT == null) {
        // Mandatory element
        return null;
    }
    final HeaderTradeAgreementType aHeaderAgreement = aSCTT.getApplicableHeaderTradeAgreement();
    final HeaderTradeDeliveryType aHeaderDelivery = aSCTT.getApplicableHeaderTradeDelivery();
    final HeaderTradeSettlementType aHeaderSettlement = aSCTT.getApplicableHeaderTradeSettlement();
    if (aHeaderAgreement == null || aHeaderDelivery == null || aHeaderSettlement == null) {
        // All mandatory elements
        return null;
    }
    final InvoiceType aUBLInvoice = new InvoiceType();
    if (false)
        aUBLInvoice.setUBLVersionID(UBL_VERSION);
    if (StringHelper.hasText(getCustomizationID()))
        aUBLInvoice.setCustomizationID(getCustomizationID());
    if (StringHelper.hasText(getProfileID()))
        aUBLInvoice.setProfileID(getProfileID());
    if (aED != null)
        aUBLInvoice.setID(aED.getIDValue());
    // Mandatory supplier
    final SupplierPartyType aUBLSupplier = new SupplierPartyType();
    aUBLInvoice.setAccountingSupplierParty(aUBLSupplier);
    // Mandatory customer
    final CustomerPartyType aUBLCustomer = new CustomerPartyType();
    aUBLInvoice.setAccountingCustomerParty(aUBLCustomer);
    // IssueDate
    {
        LocalDate aIssueDate = null;
        if (aED != null && aED.getIssueDateTime() != null)
            aIssueDate = _parseDate(aED.getIssueDateTime().getDateTimeString(), aErrorList);
        if (aIssueDate != null)
            aUBLInvoice.setIssueDate(aIssueDate);
    }
    // DueDate
    {
        LocalDate aDueDate = null;
        for (final TradePaymentTermsType aPaymentTerms : aHeaderSettlement.getSpecifiedTradePaymentTerms()) if (aPaymentTerms.getDueDateDateTime() != null) {
            aDueDate = _parseDate(aPaymentTerms.getDueDateDateTime().getDateTimeString(), aErrorList);
            if (aDueDate != null)
                break;
        }
        if (aDueDate != null)
            aUBLInvoice.setDueDate(aDueDate);
    }
    // InvoiceTypeCode
    if (aED != null)
        aUBLInvoice.setInvoiceTypeCode(aED.getTypeCodeValue());
    // Note
    if (aED != null)
        for (final un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100.NoteType aEDNote : aED.getIncludedNote()) ifNotNull(aUBLInvoice::addNote, _copyNote(aEDNote));
    // TaxPointDate
    for (final TradeTaxType aTradeTax : aHeaderSettlement.getApplicableTradeTax()) {
        if (aTradeTax.getTaxPointDate() != null) {
            final LocalDate aTaxPointDate = _parseDate(aTradeTax.getTaxPointDate().getDateString(), aErrorList);
            if (aTaxPointDate != null) {
                // Use the first tax point date only
                aUBLInvoice.setTaxPointDate(aTaxPointDate);
                break;
            }
        }
    }
    // DocumentCurrencyCode
    final String sDefaultCurrencyCode = aHeaderSettlement.getInvoiceCurrencyCodeValue();
    aUBLInvoice.setDocumentCurrencyCode(sDefaultCurrencyCode);
    // TaxCurrencyCode
    if (aHeaderSettlement.getTaxCurrencyCodeValue() != null) {
        aUBLInvoice.setTaxCurrencyCode(aHeaderSettlement.getTaxCurrencyCodeValue());
    }
    // AccountingCost
    for (final TradeAccountingAccountType aAccount : aHeaderSettlement.getReceivableSpecifiedTradeAccountingAccount()) {
        final String sID = aAccount.getIDValue();
        if (StringHelper.hasText(sID)) {
            // Use the first ID
            aUBLInvoice.setAccountingCost(sID);
            break;
        }
    }
    // BuyerReferences
    if (aHeaderAgreement.getBuyerReferenceValue() != null) {
        aUBLInvoice.setBuyerReference(aHeaderAgreement.getBuyerReferenceValue());
    }
    // InvoicePeriod
    {
        final SpecifiedPeriodType aSPT = aHeaderSettlement.getBillingSpecifiedPeriod();
        if (aSPT != null) {
            final DateTimeType aStartDT = aSPT.getStartDateTime();
            final DateTimeType aEndDT = aSPT.getEndDateTime();
            if (aStartDT != null && aEndDT != null) {
                final PeriodType aUBLPeriod = new PeriodType();
                aUBLPeriod.setStartDate(_parseDate(aStartDT.getDateTimeString(), aErrorList));
                aUBLPeriod.setEndDate(_parseDate(aEndDT.getDateTimeString(), aErrorList));
                aUBLInvoice.addInvoicePeriod(aUBLPeriod);
            }
        }
    }
    // OrderReference
    {
        final OrderReferenceType aUBLOrderRef = _createUBLOrderRef(aHeaderAgreement.getBuyerOrderReferencedDocument(), aHeaderAgreement.getSellerOrderReferencedDocument());
        aUBLInvoice.setOrderReference(aUBLOrderRef);
    }
    // BillingReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderSettlement.getInvoiceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null) {
            final BillingReferenceType aUBLBillingRef = new BillingReferenceType();
            aUBLBillingRef.setInvoiceDocumentReference(aUBLDocRef);
            aUBLInvoice.addBillingReference(aUBLBillingRef);
        }
    }
    // DespatchDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderDelivery.getDespatchAdviceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLInvoice.addDespatchDocumentReference(aUBLDocRef);
    }
    // ReceiptDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderDelivery.getReceivingAdviceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLInvoice.addReceiptDocumentReference(aUBLDocRef);
    }
    // OriginatorDocumentReference
    {
        for (final ReferencedDocumentType aRD : aHeaderAgreement.getAdditionalReferencedDocument()) {
            // Use for "Tender or lot reference" with TypeCode "50"
            if (isOriginatorDocumentReferenceTypeCode(aRD.getTypeCodeValue())) {
                final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aRD, aErrorList);
                if (aUBLDocRef != null)
                    aUBLInvoice.addOriginatorDocumentReference(aUBLDocRef);
            }
        }
    }
    // ContractDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderAgreement.getContractReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLInvoice.addContractDocumentReference(aUBLDocRef);
    }
    // AdditionalDocumentReference
    {
        for (final ReferencedDocumentType aRD : aHeaderAgreement.getAdditionalReferencedDocument()) {
            // Except OriginatorDocumentReference
            if (!isOriginatorDocumentReferenceTypeCode(aRD.getTypeCodeValue())) {
                final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aRD, aErrorList);
                if (aUBLDocRef != null)
                    aUBLInvoice.addAdditionalDocumentReference(aUBLDocRef);
            }
        }
    }
    // ProjectReference
    {
        final ProcuringProjectType aSpecifiedProcuring = aHeaderAgreement.getSpecifiedProcuringProject();
        if (aSpecifiedProcuring != null) {
            final String sID = aSpecifiedProcuring.getIDValue();
            if (StringHelper.hasText(sID)) {
                final ProjectReferenceType aUBLProjectRef = new ProjectReferenceType();
                aUBLProjectRef.setID(sID);
                aUBLInvoice.addProjectReference(aUBLProjectRef);
            }
        }
    }
    // Supplier Party
    {
        final TradePartyType aSellerParty = aHeaderAgreement.getSellerTradeParty();
        if (aSellerParty != null) {
            final PartyType aUBLParty = _convertParty(aSellerParty, true);
            for (final TaxRegistrationType aTaxRegistration : aSellerParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aSellerParty);
            if (aUBLPartyLegalEntity != null)
                aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            final ContactType aUBLContact = _convertContact(aSellerParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLSupplier.setParty(aUBLParty);
        }
    }
    // Customer Party
    {
        final TradePartyType aBuyerParty = aHeaderAgreement.getBuyerTradeParty();
        if (aBuyerParty != null) {
            final PartyType aUBLParty = _convertParty(aBuyerParty, false);
            for (final TaxRegistrationType aTaxRegistration : aBuyerParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aBuyerParty);
            if (aUBLPartyLegalEntity != null)
                aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            final ContactType aUBLContact = _convertContact(aBuyerParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLCustomer.setParty(aUBLParty);
        }
    }
    // Payee Party
    {
        final TradePartyType aPayeeParty = aHeaderSettlement.getPayeeTradeParty();
        if (aPayeeParty != null) {
            final PartyType aUBLParty = _convertParty(aPayeeParty, false);
            for (final TaxRegistrationType aTaxRegistration : aPayeeParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            // validation rules warning
            if (false) {
                final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aPayeeParty);
                if (aUBLPartyLegalEntity != null)
                    aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            }
            final ContactType aUBLContact = _convertContact(aPayeeParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLInvoice.setPayeeParty(aUBLParty);
        }
    }
    // Tax Representative Party
    {
        final TradePartyType aTaxRepresentativeParty = aHeaderAgreement.getSellerTaxRepresentativeTradeParty();
        if (aTaxRepresentativeParty != null) {
            final PartyType aUBLParty = _convertParty(aTaxRepresentativeParty, false);
            for (final TaxRegistrationType aTaxRegistration : aTaxRepresentativeParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            // validation rules warning
            if (false) {
                final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aTaxRepresentativeParty);
                if (aUBLPartyLegalEntity != null)
                    aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            }
            final ContactType aUBLContact = _convertContact(aTaxRepresentativeParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLInvoice.setTaxRepresentativeParty(aUBLParty);
        }
    }
    // Delivery
    {
        final DeliveryType aUBLDelivery = new DeliveryType();
        boolean bUseDelivery = false;
        final SupplyChainEventType aSCE = aHeaderDelivery.getActualDeliverySupplyChainEvent();
        if (aSCE != null) {
            final DateTimeType aODT = aSCE.getOccurrenceDateTime();
            if (aODT != null) {
                aUBLDelivery.setActualDeliveryDate(_parseDate(aODT.getDateTimeString(), aErrorList));
                bUseDelivery = true;
            }
        }
        final TradePartyType aShipToParty = aHeaderDelivery.getShipToTradeParty();
        if (aShipToParty != null) {
            final oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_22.LocationType aUBLDeliveryLocation = new oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_22.LocationType();
            boolean bUseLocation = false;
            final oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_22.IDType aUBLID = _extractFirstPartyID(aShipToParty);
            if (aUBLID != null) {
                aUBLDeliveryLocation.setID(aUBLID);
                bUseLocation = true;
            }
            final TradeAddressType aPostalAddress = aShipToParty.getPostalTradeAddress();
            if (aPostalAddress != null) {
                aUBLDeliveryLocation.setAddress(_convertPostalAddress(aPostalAddress));
                bUseLocation = true;
            }
            if (bUseLocation) {
                aUBLDelivery.setDeliveryLocation(aUBLDeliveryLocation);
                bUseDelivery = true;
            }
            final TextType aName = aShipToParty.getName();
            if (aName != null) {
                final PartyType aUBLDeliveryParty = new PartyType();
                final PartyNameType aUBLPartyName = new PartyNameType();
                aUBLPartyName.setName(_copyName(aName, new NameType()));
                aUBLDeliveryParty.addPartyName(aUBLPartyName);
                aUBLDelivery.setDeliveryParty(aUBLDeliveryParty);
                bUseDelivery = true;
            }
        }
        if (bUseDelivery)
            aUBLInvoice.addDelivery(aUBLDelivery);
    }
    // Payment means
    {
        for (final TradeSettlementPaymentMeansType aPaymentMeans : aHeaderSettlement.getSpecifiedTradeSettlementPaymentMeans()) {
            _convertPaymentMeans(aHeaderSettlement, aPaymentMeans, x -> _addPartyID(x, aUBLInvoice.getAccountingSupplierParty().getParty()), aUBLInvoice::addPaymentMeans, aErrorList);
            // Allowed again in 1.2.1: exactly 2
            if (false)
                // Since v1.2.0 only one is allowed
                if (true)
                    break;
        }
    }
    // Payment Terms
    {
        for (final TradePaymentTermsType aPaymentTerms : aHeaderSettlement.getSpecifiedTradePaymentTerms()) {
            final PaymentTermsType aUBLPaymenTerms = new PaymentTermsType();
            for (final TextType aDesc : aPaymentTerms.getDescription()) ifNotNull(aUBLPaymenTerms::addNote, _copyNote(aDesc));
            if (aUBLPaymenTerms.hasNoteEntries())
                aUBLInvoice.addPaymentTerms(aUBLPaymenTerms);
        }
    }
    // Allowance Charge
    {
        for (final TradeAllowanceChargeType aAllowanceCharge : aHeaderSettlement.getSpecifiedTradeAllowanceCharge()) {
            ETriState eIsCharge = ETriState.UNDEFINED;
            if (aAllowanceCharge.getChargeIndicator() != null)
                eIsCharge = _parseIndicator(aAllowanceCharge.getChargeIndicator(), aErrorList);
            else
                aErrorList.add(_buildError(new String[] { "CrossIndustryInvoice", "SupplyChainTradeTransaction", "ApplicableHeaderTradeSettlement", "SpecifiedTradeAllowanceCharge" }, "Failed to determine if SpecifiedTradeAllowanceCharge is an Allowance or a Charge"));
            if (eIsCharge.isDefined()) {
                final AllowanceChargeType aUBLAllowanceCharge = new AllowanceChargeType();
                aUBLAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                _copyAllowanceCharge(aAllowanceCharge, aUBLAllowanceCharge, sDefaultCurrencyCode);
                aUBLInvoice.addAllowanceCharge(aUBLAllowanceCharge);
            }
        }
    }
    final TradeSettlementHeaderMonetarySummationType aSTSHMS = aHeaderSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation();
    // TaxTotal
    {
        TaxTotalType aUBLTaxTotal = null;
        if (aSTSHMS != null && aSTSHMS.hasTaxTotalAmountEntries()) {
            // For all currencies
            for (final AmountType aTaxTotalAmount : aSTSHMS.getTaxTotalAmount()) {
                final TaxTotalType aUBLCurTaxTotal = new TaxTotalType();
                aUBLCurTaxTotal.setTaxAmount(_copyAmount(aTaxTotalAmount, new TaxAmountType(), sDefaultCurrencyCode));
                aUBLInvoice.addTaxTotal(aUBLCurTaxTotal);
                if (aUBLTaxTotal == null) {
                    // Use the first one
                    aUBLTaxTotal = aUBLCurTaxTotal;
                }
            }
        } else {
            // Mandatory in UBL
            final TaxAmountType aUBLTaxAmount = new TaxAmountType();
            aUBLTaxAmount.setValue(BigDecimal.ZERO);
            aUBLTaxAmount.setCurrencyID(sDefaultCurrencyCode);
            aUBLTaxTotal = new TaxTotalType();
            aUBLTaxTotal.setTaxAmount(aUBLTaxAmount);
            aUBLInvoice.addTaxTotal(aUBLTaxTotal);
        }
        for (final TradeTaxType aTradeTax : aHeaderSettlement.getApplicableTradeTax()) {
            final TaxSubtotalType aUBLTaxSubtotal = new TaxSubtotalType();
            if (aTradeTax.hasBasisAmountEntries()) {
                aUBLTaxSubtotal.setTaxableAmount(_copyAmount(aTradeTax.getBasisAmountAtIndex(0), new TaxableAmountType(), sDefaultCurrencyCode));
            }
            if (aTradeTax.hasCalculatedAmountEntries()) {
                aUBLTaxSubtotal.setTaxAmount(_copyAmount(aTradeTax.getCalculatedAmountAtIndex(0), new TaxAmountType(), sDefaultCurrencyCode));
            }
            final TaxCategoryType aUBLTaxCategory = new TaxCategoryType();
            aUBLTaxCategory.setID(aTradeTax.getCategoryCodeValue());
            if (aTradeTax.getRateApplicablePercentValue() != null)
                aUBLTaxCategory.setPercent(MathHelper.getWithoutTrailingZeroes(aTradeTax.getRateApplicablePercentValue()));
            if (StringHelper.hasText(aTradeTax.getExemptionReasonCodeValue()))
                aUBLTaxCategory.setTaxExemptionReasonCode(aTradeTax.getExemptionReasonCodeValue());
            if (aTradeTax.getExemptionReason() != null) {
                final TaxExemptionReasonType aUBLTaxExemptionReason = new TaxExemptionReasonType();
                aUBLTaxExemptionReason.setValue(aTradeTax.getExemptionReason().getValue());
                aUBLTaxExemptionReason.setLanguageID(aTradeTax.getExemptionReason().getLanguageID());
                aUBLTaxExemptionReason.setLanguageLocaleID(aTradeTax.getExemptionReason().getLanguageLocaleID());
                aUBLTaxCategory.addTaxExemptionReason(aUBLTaxExemptionReason);
            }
            final TaxSchemeType aUBLTaxScheme = new TaxSchemeType();
            aUBLTaxScheme.setID(getVATScheme());
            aUBLTaxCategory.setTaxScheme(aUBLTaxScheme);
            aUBLTaxSubtotal.setTaxCategory(aUBLTaxCategory);
            aUBLTaxTotal.addTaxSubtotal(aUBLTaxSubtotal);
        }
    }
    // LegalMonetaryTotal
    {
        final MonetaryTotalType aUBLMonetaryTotal = new MonetaryTotalType();
        if (aSTSHMS != null) {
            if (aSTSHMS.hasLineTotalAmountEntries())
                aUBLMonetaryTotal.setLineExtensionAmount(_copyAmount(aSTSHMS.getLineTotalAmountAtIndex(0), new LineExtensionAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasTaxBasisTotalAmountEntries())
                aUBLMonetaryTotal.setTaxExclusiveAmount(_copyAmount(aSTSHMS.getTaxBasisTotalAmountAtIndex(0), new TaxExclusiveAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasGrandTotalAmountEntries())
                aUBLMonetaryTotal.setTaxInclusiveAmount(_copyAmount(aSTSHMS.getGrandTotalAmountAtIndex(0), new TaxInclusiveAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasAllowanceTotalAmountEntries())
                aUBLMonetaryTotal.setAllowanceTotalAmount(_copyAmount(aSTSHMS.getAllowanceTotalAmountAtIndex(0), new AllowanceTotalAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasChargeTotalAmountEntries())
                aUBLMonetaryTotal.setChargeTotalAmount(_copyAmount(aSTSHMS.getChargeTotalAmountAtIndex(0), new ChargeTotalAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasTotalPrepaidAmountEntries())
                aUBLMonetaryTotal.setPrepaidAmount(_copyAmount(aSTSHMS.getTotalPrepaidAmountAtIndex(0), new PrepaidAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasRoundingAmountEntries()) {
                // compatibility
                if (MathHelper.isNE0(aSTSHMS.getRoundingAmountAtIndex(0).getValue()))
                    aUBLMonetaryTotal.setPayableRoundingAmount(_copyAmount(aSTSHMS.getRoundingAmountAtIndex(0), new PayableRoundingAmountType(), sDefaultCurrencyCode));
            }
            if (aSTSHMS.hasDuePayableAmountEntries())
                aUBLMonetaryTotal.setPayableAmount(_copyAmount(aSTSHMS.getDuePayableAmountAtIndex(0), new PayableAmountType(), sDefaultCurrencyCode));
        }
        aUBLInvoice.setLegalMonetaryTotal(aUBLMonetaryTotal);
    }
    // All invoice lines
    for (final SupplyChainTradeLineItemType aLineItem : aSCTT.getIncludedSupplyChainTradeLineItem()) {
        final InvoiceLineType aUBLInvoiceLine = new InvoiceLineType();
        final DocumentLineDocumentType aDLD = aLineItem.getAssociatedDocumentLineDocument();
        aUBLInvoiceLine.setID(_copyID(aDLD.getLineID()));
        // Note
        for (final un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100.NoteType aLineNote : aDLD.getIncludedNote()) ifNotNull(aUBLInvoiceLine::addNote, _copyNote(aLineNote));
        // Line extension amount
        boolean bLineExtensionAmountIsNegative = false;
        final LineTradeSettlementType aLineSettlement = aLineItem.getSpecifiedLineTradeSettlement();
        final TradeSettlementLineMonetarySummationType aSTSLMS = aLineSettlement.getSpecifiedTradeSettlementLineMonetarySummation();
        if (aSTSLMS != null) {
            if (aSTSLMS.hasLineTotalAmountEntries()) {
                aUBLInvoiceLine.setLineExtensionAmount(_copyAmount(aSTSLMS.getLineTotalAmountAtIndex(0), new LineExtensionAmountType(), sDefaultCurrencyCode));
                if (isLT0Strict(aUBLInvoiceLine.getLineExtensionAmountValue()))
                    bLineExtensionAmountIsNegative = true;
            }
        }
        // Invoiced quantity
        final LineTradeDeliveryType aLineDelivery = aLineItem.getSpecifiedLineTradeDelivery();
        if (aLineDelivery != null) {
            final QuantityType aBilledQuantity = aLineDelivery.getBilledQuantity();
            if (aBilledQuantity != null) {
                aUBLInvoiceLine.setInvoicedQuantity(_copyQuantity(aBilledQuantity, new InvoicedQuantityType()));
            }
        }
        // Accounting cost
        if (aLineSettlement.hasReceivableSpecifiedTradeAccountingAccountEntries()) {
            final TradeAccountingAccountType aLineAA = aLineSettlement.getReceivableSpecifiedTradeAccountingAccountAtIndex(0);
            aUBLInvoiceLine.setAccountingCost(aLineAA.getIDValue());
        }
        // Invoice period
        final SpecifiedPeriodType aLineBillingPeriod = aLineSettlement.getBillingSpecifiedPeriod();
        if (aLineBillingPeriod != null) {
            final PeriodType aUBLLinePeriod = new PeriodType();
            if (aLineBillingPeriod.getStartDateTime() != null)
                aUBLLinePeriod.setStartDate(_parseDate(aLineBillingPeriod.getStartDateTime().getDateTimeString(), aErrorList));
            if (aLineBillingPeriod.getEndDateTime() != null)
                aUBLLinePeriod.setEndDate(_parseDate(aLineBillingPeriod.getEndDateTime().getDateTimeString(), aErrorList));
            aUBLInvoiceLine.addInvoicePeriod(aUBLLinePeriod);
        }
        // Order line reference
        final LineTradeAgreementType aLineAgreement = aLineItem.getSpecifiedLineTradeAgreement();
        if (aLineAgreement != null) {
            final ReferencedDocumentType aBuyerOrderReference = aLineAgreement.getBuyerOrderReferencedDocument();
            if (aBuyerOrderReference != null && StringHelper.hasText(aBuyerOrderReference.getLineIDValue())) {
                final OrderLineReferenceType aUBLOrderLineReference = new OrderLineReferenceType();
                aUBLOrderLineReference.setLineID(_copyID(aBuyerOrderReference.getLineID(), new LineIDType()));
                aUBLInvoiceLine.addOrderLineReference(aUBLOrderLineReference);
            }
        }
        // Document reference
        for (final ReferencedDocumentType aLineReferencedDocument : aLineSettlement.getAdditionalReferencedDocument()) {
            final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aLineReferencedDocument, aErrorList);
            if (aUBLDocRef != null)
                aUBLInvoiceLine.addDocumentReference(aUBLDocRef);
        }
        // Allowance charge
        for (final TradeAllowanceChargeType aLineAllowanceCharge : aLineSettlement.getSpecifiedTradeAllowanceCharge()) {
            ETriState eIsCharge = ETriState.UNDEFINED;
            if (aLineAllowanceCharge.getChargeIndicator() != null)
                eIsCharge = _parseIndicator(aLineAllowanceCharge.getChargeIndicator(), aErrorList);
            else
                aErrorList.add(_buildError(new String[] { "CrossIndustryInvoice", "SupplyChainTradeTransaction", "IncludedSupplyChainTradeLineItem", "SpecifiedLineTradeSettlement", "SpecifiedTradeAllowanceCharge" }, "Failed to determine if SpecifiedTradeAllowanceCharge is an Allowance or a Charge"));
            if (eIsCharge.isDefined()) {
                final AllowanceChargeType aUBLLineAllowanceCharge = new AllowanceChargeType();
                aUBLLineAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                _copyAllowanceCharge(aLineAllowanceCharge, aUBLLineAllowanceCharge, sDefaultCurrencyCode);
                aUBLInvoiceLine.addAllowanceCharge(aUBLLineAllowanceCharge);
            }
        }
        // Item
        final ItemType aUBLItem = new ItemType();
        final TradeProductType aLineProduct = aLineItem.getSpecifiedTradeProduct();
        if (aLineProduct != null) {
            final TextType aDescription = aLineProduct.getDescription();
            if (aDescription != null)
                ifNotNull(aUBLItem::addDescription, _copyName(aDescription, new DescriptionType()));
            if (aLineProduct.hasNameEntries())
                aUBLItem.setName(_copyName(aLineProduct.getNameAtIndex(0), new NameType()));
            final IDType aBuyerAssignedID = aLineProduct.getBuyerAssignedID();
            if (aBuyerAssignedID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aBuyerAssignedID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setBuyersItemIdentification(aUBLID);
            }
            final IDType aSellerAssignedID = aLineProduct.getSellerAssignedID();
            if (aSellerAssignedID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aSellerAssignedID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setSellersItemIdentification(aUBLID);
            }
            final IDType aGlobalID = aLineProduct.getGlobalID();
            if (aGlobalID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aGlobalID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setStandardItemIdentification(aUBLID);
            }
            final TradeCountryType aOriginCountry = aLineProduct.getOriginTradeCountry();
            if (aOriginCountry != null) {
                final CountryType aUBLCountry = new CountryType();
                aUBLCountry.setIdentificationCode(aOriginCountry.getIDValue());
                if (aOriginCountry.hasNameEntries())
                    aUBLCountry.setName(_copyName(aOriginCountry.getNameAtIndex(0), new NameType()));
                aUBLItem.setOriginCountry(aUBLCountry);
            }
            // Commodity Classification
            for (final ProductClassificationType aLineProductClassification : aLineProduct.getDesignatedProductClassification()) {
                final CodeType aClassCode = aLineProductClassification.getClassCode();
                if (aClassCode != null) {
                    final CommodityClassificationType aUBLCommodityClassification = new CommodityClassificationType();
                    aUBLCommodityClassification.setItemClassificationCode(_copyCode(aClassCode, new ItemClassificationCodeType()));
                    if (aUBLCommodityClassification.getItemClassificationCode() != null)
                        aUBLItem.addCommodityClassification(aUBLCommodityClassification);
                }
            }
        }
        for (final TradeTaxType aTradeTax : aLineSettlement.getApplicableTradeTax()) {
            final TaxCategoryType aUBLTaxCategory = new TaxCategoryType();
            aUBLTaxCategory.setID(aTradeTax.getCategoryCodeValue());
            if (aTradeTax.getRateApplicablePercentValue() != null)
                aUBLTaxCategory.setPercent(MathHelper.getWithoutTrailingZeroes(aTradeTax.getRateApplicablePercentValue()));
            final TaxSchemeType aUBLTaxScheme = new TaxSchemeType();
            aUBLTaxScheme.setID(getVATScheme());
            aUBLTaxCategory.setTaxScheme(aUBLTaxScheme);
            aUBLItem.addClassifiedTaxCategory(aUBLTaxCategory);
        }
        if (aLineProduct != null) {
            for (final ProductCharacteristicType aAPC : aLineProduct.getApplicableProductCharacteristic()) if (aAPC.hasDescriptionEntries()) {
                final ItemPropertyType aUBLAdditionalItem = new ItemPropertyType();
                aUBLAdditionalItem.setName(_copyName(aAPC.getDescriptionAtIndex(0), new NameType()));
                if (aAPC.hasValueEntries())
                    aUBLAdditionalItem.setValue(aAPC.getValueAtIndex(0).getValue());
                if (aUBLAdditionalItem.getName() != null)
                    aUBLItem.addAdditionalItemProperty(aUBLAdditionalItem);
            }
        }
        final PriceType aUBLPrice = new PriceType();
        boolean bUsePrice = false;
        if (aLineAgreement != null) {
            final TradePriceType aNPPTP = aLineAgreement.getNetPriceProductTradePrice();
            if (aNPPTP != null) {
                if (aNPPTP.hasChargeAmountEntries()) {
                    aUBLPrice.setPriceAmount(_copyAmount(aNPPTP.getChargeAmountAtIndex(0), new PriceAmountType(), sDefaultCurrencyCode));
                    bUsePrice = true;
                }
                if (aNPPTP.getBasisQuantity() != null) {
                    aUBLPrice.setBaseQuantity(_copyQuantity(aNPPTP.getBasisQuantity(), new BaseQuantityType()));
                    bUsePrice = true;
                }
            }
        }
        swapQuantityAndPriceIfNeeded(bLineExtensionAmountIsNegative, aUBLInvoiceLine.getInvoicedQuantityValue(), aUBLInvoiceLine::setInvoicedQuantity, bUsePrice ? aUBLPrice.getPriceAmountValue() : null, bUsePrice ? aUBLPrice::setPriceAmount : null);
        // Allowance charge
        final TradePriceType aTradePrice = aLineAgreement.getNetPriceProductTradePrice();
        if (aTradePrice != null)
            for (final TradeAllowanceChargeType aPriceAllowanceCharge : aTradePrice.getAppliedTradeAllowanceCharge()) {
                ETriState eIsCharge = ETriState.UNDEFINED;
                if (aPriceAllowanceCharge.getChargeIndicator() != null)
                    eIsCharge = _parseIndicator(aPriceAllowanceCharge.getChargeIndicator(), aErrorList);
                else
                    aErrorList.add(_buildError(new String[] { "CrossIndustryInvoice", "SupplyChainTradeTransaction", "IncludedSupplyChainTradeLineItem", "SpecifiedLineTradeAgreement", "NetPriceProductTradePrice", "AppliedTradeAllowanceCharge" }, "Failed to determine if AppliedTradeAllowanceCharge is an Allowance or a Charge"));
                if (eIsCharge.isDefined()) {
                    final AllowanceChargeType aUBLLineAllowanceCharge = new AllowanceChargeType();
                    aUBLLineAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                    _copyAllowanceCharge(aPriceAllowanceCharge, aUBLLineAllowanceCharge, sDefaultCurrencyCode);
                    aUBLPrice.addAllowanceCharge(aUBLLineAllowanceCharge);
                }
            }
        if (bUsePrice)
            aUBLInvoiceLine.setPrice(aUBLPrice);
        aUBLInvoiceLine.setItem(aUBLItem);
        aUBLInvoice.addInvoiceLine(aUBLInvoiceLine);
    }
    return aUBLInvoice;
}
Also used : DateTimeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.DateTimeType) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100) FormattedDateTimeType(un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType) CodeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.CodeType) ErrorList(com.helger.commons.error.list.ErrorList) ETriState(com.helger.commons.state.ETriState) CollectionHelper(com.helger.commons.collection.CollectionHelper) BigDecimal(java.math.BigDecimal) TextType(un.unece.uncefact.data.standard.unqualifieddatatype._100.TextType) CrossIndustryInvoiceType(un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) BinaryObjectType(un.unece.uncefact.data.standard.unqualifieddatatype._100.BinaryObjectType) MathHelper(com.helger.commons.math.MathHelper) oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_22(oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_22) CGlobal(com.helger.commons.CGlobal) StringHelper(com.helger.commons.string.StringHelper) AmountType(un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType) oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_22(oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_22) EqualsHelper(com.helger.commons.equals.EqualsHelper) Serializable(java.io.Serializable) ValueEnforcer(com.helger.commons.ValueEnforcer) QuantityType(un.unece.uncefact.data.standard.unqualifieddatatype._100.QuantityType) Consumer(java.util.function.Consumer) InvoiceType(oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType) LocalDate(java.time.LocalDate) IErrorList(com.helger.commons.error.list.IErrorList) IDType(un.unece.uncefact.data.standard.unqualifieddatatype._100.IDType) LocalDate(java.time.LocalDate) un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100) TextType(un.unece.uncefact.data.standard.unqualifieddatatype._100.TextType) AmountType(un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_22(oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_22) IDType(un.unece.uncefact.data.standard.unqualifieddatatype._100.IDType) DateTimeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.DateTimeType) FormattedDateTimeType(un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType) QuantityType(un.unece.uncefact.data.standard.unqualifieddatatype._100.QuantityType) ETriState(com.helger.commons.state.ETriState) CrossIndustryInvoiceType(un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType) InvoiceType(oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType) CodeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.CodeType) Nullable(javax.annotation.Nullable)

Example 8 with QuantityType

use of org.geotoolkit.swe.xml.v100.QuantityType in project en16931-cii2ubl by phax.

the class CIIToUBL23Converter method convertToInvoice.

@Nullable
public InvoiceType convertToInvoice(@Nonnull final CrossIndustryInvoiceType aCIIInvoice, @Nonnull final ErrorList aErrorList) {
    ValueEnforcer.notNull(aCIIInvoice, "CIIInvoice");
    ValueEnforcer.notNull(aErrorList, "ErrorList");
    final ExchangedDocumentType aED = aCIIInvoice.getExchangedDocument();
    final SupplyChainTradeTransactionType aSCTT = aCIIInvoice.getSupplyChainTradeTransaction();
    if (aSCTT == null) {
        // Mandatory element
        return null;
    }
    final HeaderTradeAgreementType aHeaderAgreement = aSCTT.getApplicableHeaderTradeAgreement();
    final HeaderTradeDeliveryType aHeaderDelivery = aSCTT.getApplicableHeaderTradeDelivery();
    final HeaderTradeSettlementType aHeaderSettlement = aSCTT.getApplicableHeaderTradeSettlement();
    if (aHeaderAgreement == null || aHeaderDelivery == null || aHeaderSettlement == null) {
        // All mandatory elements
        return null;
    }
    final InvoiceType aUBLInvoice = new InvoiceType();
    if (false)
        aUBLInvoice.setUBLVersionID(UBL_VERSION);
    if (StringHelper.hasText(getCustomizationID()))
        aUBLInvoice.setCustomizationID(getCustomizationID());
    if (StringHelper.hasText(getProfileID()))
        aUBLInvoice.setProfileID(getProfileID());
    if (aED != null)
        aUBLInvoice.setID(aED.getIDValue());
    // Mandatory supplier
    final SupplierPartyType aUBLSupplier = new SupplierPartyType();
    aUBLInvoice.setAccountingSupplierParty(aUBLSupplier);
    // Mandatory customer
    final CustomerPartyType aUBLCustomer = new CustomerPartyType();
    aUBLInvoice.setAccountingCustomerParty(aUBLCustomer);
    // IssueDate
    {
        LocalDate aIssueDate = null;
        if (aED != null && aED.getIssueDateTime() != null)
            aIssueDate = _parseDate(aED.getIssueDateTime().getDateTimeString(), aErrorList);
        if (aIssueDate != null)
            aUBLInvoice.setIssueDate(aIssueDate);
    }
    // DueDate
    {
        LocalDate aDueDate = null;
        for (final TradePaymentTermsType aPaymentTerms : aHeaderSettlement.getSpecifiedTradePaymentTerms()) if (aPaymentTerms.getDueDateDateTime() != null) {
            aDueDate = _parseDate(aPaymentTerms.getDueDateDateTime().getDateTimeString(), aErrorList);
            if (aDueDate != null)
                break;
        }
        if (aDueDate != null)
            aUBLInvoice.setDueDate(aDueDate);
    }
    // InvoiceTypeCode
    if (aED != null)
        aUBLInvoice.setInvoiceTypeCode(aED.getTypeCodeValue());
    // Note
    if (aED != null)
        for (final un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100.NoteType aEDNote : aED.getIncludedNote()) ifNotNull(aUBLInvoice::addNote, _copyNote(aEDNote));
    // TaxPointDate
    for (final TradeTaxType aTradeTax : aHeaderSettlement.getApplicableTradeTax()) {
        if (aTradeTax.getTaxPointDate() != null) {
            final LocalDate aTaxPointDate = _parseDate(aTradeTax.getTaxPointDate().getDateString(), aErrorList);
            if (aTaxPointDate != null) {
                // Use the first tax point date only
                aUBLInvoice.setTaxPointDate(aTaxPointDate);
                break;
            }
        }
    }
    // DocumentCurrencyCode
    final String sDefaultCurrencyCode = aHeaderSettlement.getInvoiceCurrencyCodeValue();
    aUBLInvoice.setDocumentCurrencyCode(sDefaultCurrencyCode);
    // TaxCurrencyCode
    if (aHeaderSettlement.getTaxCurrencyCodeValue() != null) {
        aUBLInvoice.setTaxCurrencyCode(aHeaderSettlement.getTaxCurrencyCodeValue());
    }
    // AccountingCost
    for (final TradeAccountingAccountType aAccount : aHeaderSettlement.getReceivableSpecifiedTradeAccountingAccount()) {
        final String sID = aAccount.getIDValue();
        if (StringHelper.hasText(sID)) {
            // Use the first ID
            aUBLInvoice.setAccountingCost(sID);
            break;
        }
    }
    // BuyerReferences
    if (aHeaderAgreement.getBuyerReferenceValue() != null) {
        aUBLInvoice.setBuyerReference(aHeaderAgreement.getBuyerReferenceValue());
    }
    // InvoicePeriod
    {
        final SpecifiedPeriodType aSPT = aHeaderSettlement.getBillingSpecifiedPeriod();
        if (aSPT != null) {
            final DateTimeType aStartDT = aSPT.getStartDateTime();
            final DateTimeType aEndDT = aSPT.getEndDateTime();
            if (aStartDT != null && aEndDT != null) {
                final PeriodType aUBLPeriod = new PeriodType();
                aUBLPeriod.setStartDate(_parseDate(aStartDT.getDateTimeString(), aErrorList));
                aUBLPeriod.setEndDate(_parseDate(aEndDT.getDateTimeString(), aErrorList));
                aUBLInvoice.addInvoicePeriod(aUBLPeriod);
            }
        }
    }
    // OrderReference
    {
        final OrderReferenceType aUBLOrderRef = _createUBLOrderRef(aHeaderAgreement.getBuyerOrderReferencedDocument(), aHeaderAgreement.getSellerOrderReferencedDocument());
        aUBLInvoice.setOrderReference(aUBLOrderRef);
    }
    // BillingReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderSettlement.getInvoiceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null) {
            final BillingReferenceType aUBLBillingRef = new BillingReferenceType();
            aUBLBillingRef.setInvoiceDocumentReference(aUBLDocRef);
            aUBLInvoice.addBillingReference(aUBLBillingRef);
        }
    }
    // DespatchDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderDelivery.getDespatchAdviceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLInvoice.addDespatchDocumentReference(aUBLDocRef);
    }
    // ReceiptDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderDelivery.getReceivingAdviceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLInvoice.addReceiptDocumentReference(aUBLDocRef);
    }
    // OriginatorDocumentReference
    {
        for (final ReferencedDocumentType aRD : aHeaderAgreement.getAdditionalReferencedDocument()) {
            // Use for "Tender or lot reference" with TypeCode "50"
            if (isOriginatorDocumentReferenceTypeCode(aRD.getTypeCodeValue())) {
                final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aRD, aErrorList);
                if (aUBLDocRef != null)
                    aUBLInvoice.addOriginatorDocumentReference(aUBLDocRef);
            }
        }
    }
    // ContractDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderAgreement.getContractReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLInvoice.addContractDocumentReference(aUBLDocRef);
    }
    // AdditionalDocumentReference
    {
        for (final ReferencedDocumentType aRD : aHeaderAgreement.getAdditionalReferencedDocument()) {
            // Except OriginatorDocumentReference
            if (!isOriginatorDocumentReferenceTypeCode(aRD.getTypeCodeValue())) {
                final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aRD, aErrorList);
                if (aUBLDocRef != null)
                    aUBLInvoice.addAdditionalDocumentReference(aUBLDocRef);
            }
        }
    }
    // ProjectReference
    {
        final ProcuringProjectType aSpecifiedProcuring = aHeaderAgreement.getSpecifiedProcuringProject();
        if (aSpecifiedProcuring != null) {
            final String sID = aSpecifiedProcuring.getIDValue();
            if (StringHelper.hasText(sID)) {
                final ProjectReferenceType aUBLProjectRef = new ProjectReferenceType();
                aUBLProjectRef.setID(sID);
                aUBLInvoice.addProjectReference(aUBLProjectRef);
            }
        }
    }
    // Supplier Party
    {
        final TradePartyType aSellerParty = aHeaderAgreement.getSellerTradeParty();
        if (aSellerParty != null) {
            final PartyType aUBLParty = _convertParty(aSellerParty, true);
            for (final TaxRegistrationType aTaxRegistration : aSellerParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aSellerParty);
            if (aUBLPartyLegalEntity != null)
                aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            final ContactType aUBLContact = _convertContact(aSellerParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLSupplier.setParty(aUBLParty);
        }
    }
    // Customer Party
    {
        final TradePartyType aBuyerParty = aHeaderAgreement.getBuyerTradeParty();
        if (aBuyerParty != null) {
            final PartyType aUBLParty = _convertParty(aBuyerParty, false);
            for (final TaxRegistrationType aTaxRegistration : aBuyerParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aBuyerParty);
            if (aUBLPartyLegalEntity != null)
                aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            final ContactType aUBLContact = _convertContact(aBuyerParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLCustomer.setParty(aUBLParty);
        }
    }
    // Payee Party
    {
        final TradePartyType aPayeeParty = aHeaderSettlement.getPayeeTradeParty();
        if (aPayeeParty != null) {
            final PartyType aUBLParty = _convertParty(aPayeeParty, false);
            for (final TaxRegistrationType aTaxRegistration : aPayeeParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            // validation rules warning
            if (false) {
                final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aPayeeParty);
                if (aUBLPartyLegalEntity != null)
                    aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            }
            final ContactType aUBLContact = _convertContact(aPayeeParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLInvoice.setPayeeParty(aUBLParty);
        }
    }
    // Tax Representative Party
    {
        final TradePartyType aTaxRepresentativeParty = aHeaderAgreement.getSellerTaxRepresentativeTradeParty();
        if (aTaxRepresentativeParty != null) {
            final PartyType aUBLParty = _convertParty(aTaxRepresentativeParty, false);
            for (final TaxRegistrationType aTaxRegistration : aTaxRepresentativeParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            // validation rules warning
            if (false) {
                final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aTaxRepresentativeParty);
                if (aUBLPartyLegalEntity != null)
                    aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            }
            final ContactType aUBLContact = _convertContact(aTaxRepresentativeParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLInvoice.setTaxRepresentativeParty(aUBLParty);
        }
    }
    // Delivery
    {
        final DeliveryType aUBLDelivery = new DeliveryType();
        boolean bUseDelivery = false;
        final SupplyChainEventType aSCE = aHeaderDelivery.getActualDeliverySupplyChainEvent();
        if (aSCE != null) {
            final DateTimeType aODT = aSCE.getOccurrenceDateTime();
            if (aODT != null) {
                aUBLDelivery.setActualDeliveryDate(_parseDate(aODT.getDateTimeString(), aErrorList));
                bUseDelivery = true;
            }
        }
        final TradePartyType aShipToParty = aHeaderDelivery.getShipToTradeParty();
        if (aShipToParty != null) {
            final oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_23.LocationType aUBLDeliveryLocation = new oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_23.LocationType();
            boolean bUseLocation = false;
            final oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_23.IDType aUBLID = _extractFirstPartyID(aShipToParty);
            if (aUBLID != null) {
                aUBLDeliveryLocation.setID(aUBLID);
                bUseLocation = true;
            }
            final TradeAddressType aPostalAddress = aShipToParty.getPostalTradeAddress();
            if (aPostalAddress != null) {
                aUBLDeliveryLocation.setAddress(_convertPostalAddress(aPostalAddress));
                bUseLocation = true;
            }
            if (bUseLocation) {
                aUBLDelivery.setDeliveryLocation(aUBLDeliveryLocation);
                bUseDelivery = true;
            }
            final TextType aName = aShipToParty.getName();
            if (aName != null) {
                final PartyType aUBLDeliveryParty = new PartyType();
                final PartyNameType aUBLPartyName = new PartyNameType();
                aUBLPartyName.setName(_copyName(aName, new NameType()));
                aUBLDeliveryParty.addPartyName(aUBLPartyName);
                aUBLDelivery.setDeliveryParty(aUBLDeliveryParty);
                bUseDelivery = true;
            }
        }
        if (bUseDelivery)
            aUBLInvoice.addDelivery(aUBLDelivery);
    }
    // Payment means
    {
        for (final TradeSettlementPaymentMeansType aPaymentMeans : aHeaderSettlement.getSpecifiedTradeSettlementPaymentMeans()) {
            _convertPaymentMeans(aHeaderSettlement, aPaymentMeans, x -> _addPartyID(x, aUBLInvoice.getAccountingSupplierParty().getParty()), aUBLInvoice::addPaymentMeans, aErrorList);
            // Allowed again in 1.2.1: exactly 2
            if (false)
                // Since v1.2.0 only one is allowed
                if (true)
                    break;
        }
    }
    // Payment Terms
    {
        for (final TradePaymentTermsType aPaymentTerms : aHeaderSettlement.getSpecifiedTradePaymentTerms()) {
            final PaymentTermsType aUBLPaymenTerms = new PaymentTermsType();
            for (final TextType aDesc : aPaymentTerms.getDescription()) ifNotNull(aUBLPaymenTerms::addNote, _copyNote(aDesc));
            if (aUBLPaymenTerms.hasNoteEntries())
                aUBLInvoice.addPaymentTerms(aUBLPaymenTerms);
        }
    }
    // Allowance Charge
    {
        for (final TradeAllowanceChargeType aAllowanceCharge : aHeaderSettlement.getSpecifiedTradeAllowanceCharge()) {
            ETriState eIsCharge = ETriState.UNDEFINED;
            if (aAllowanceCharge.getChargeIndicator() != null)
                eIsCharge = _parseIndicator(aAllowanceCharge.getChargeIndicator(), aErrorList);
            else
                aErrorList.add(_buildError(new String[] { "CrossIndustryInvoice", "SupplyChainTradeTransaction", "ApplicableHeaderTradeSettlement", "SpecifiedTradeAllowanceCharge" }, "Failed to determine if SpecifiedTradeAllowanceCharge is an Allowance or a Charge"));
            if (eIsCharge.isDefined()) {
                final AllowanceChargeType aUBLAllowanceCharge = new AllowanceChargeType();
                aUBLAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                _copyAllowanceCharge(aAllowanceCharge, aUBLAllowanceCharge, sDefaultCurrencyCode);
                aUBLInvoice.addAllowanceCharge(aUBLAllowanceCharge);
            }
        }
    }
    final TradeSettlementHeaderMonetarySummationType aSTSHMS = aHeaderSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation();
    // TaxTotal
    {
        TaxTotalType aUBLTaxTotal = null;
        if (aSTSHMS != null && aSTSHMS.hasTaxTotalAmountEntries()) {
            // For all currencies
            for (final AmountType aTaxTotalAmount : aSTSHMS.getTaxTotalAmount()) {
                final TaxTotalType aUBLCurTaxTotal = new TaxTotalType();
                aUBLCurTaxTotal.setTaxAmount(_copyAmount(aTaxTotalAmount, new TaxAmountType(), sDefaultCurrencyCode));
                aUBLInvoice.addTaxTotal(aUBLCurTaxTotal);
                if (aUBLTaxTotal == null) {
                    // Use the first one
                    aUBLTaxTotal = aUBLCurTaxTotal;
                }
            }
        } else {
            // Mandatory in UBL
            final TaxAmountType aUBLTaxAmount = new TaxAmountType();
            aUBLTaxAmount.setValue(BigDecimal.ZERO);
            aUBLTaxAmount.setCurrencyID(sDefaultCurrencyCode);
            aUBLTaxTotal = new TaxTotalType();
            aUBLTaxTotal.setTaxAmount(aUBLTaxAmount);
            aUBLInvoice.addTaxTotal(aUBLTaxTotal);
        }
        for (final TradeTaxType aTradeTax : aHeaderSettlement.getApplicableTradeTax()) {
            final TaxSubtotalType aUBLTaxSubtotal = new TaxSubtotalType();
            if (aTradeTax.hasBasisAmountEntries()) {
                aUBLTaxSubtotal.setTaxableAmount(_copyAmount(aTradeTax.getBasisAmountAtIndex(0), new TaxableAmountType(), sDefaultCurrencyCode));
            }
            if (aTradeTax.hasCalculatedAmountEntries()) {
                aUBLTaxSubtotal.setTaxAmount(_copyAmount(aTradeTax.getCalculatedAmountAtIndex(0), new TaxAmountType(), sDefaultCurrencyCode));
            }
            final TaxCategoryType aUBLTaxCategory = new TaxCategoryType();
            aUBLTaxCategory.setID(aTradeTax.getCategoryCodeValue());
            if (aTradeTax.getRateApplicablePercentValue() != null)
                aUBLTaxCategory.setPercent(MathHelper.getWithoutTrailingZeroes(aTradeTax.getRateApplicablePercentValue()));
            if (StringHelper.hasText(aTradeTax.getExemptionReasonCodeValue()))
                aUBLTaxCategory.setTaxExemptionReasonCode(aTradeTax.getExemptionReasonCodeValue());
            if (aTradeTax.getExemptionReason() != null) {
                final TaxExemptionReasonType aUBLTaxExemptionReason = new TaxExemptionReasonType();
                aUBLTaxExemptionReason.setValue(aTradeTax.getExemptionReason().getValue());
                aUBLTaxExemptionReason.setLanguageID(aTradeTax.getExemptionReason().getLanguageID());
                aUBLTaxExemptionReason.setLanguageLocaleID(aTradeTax.getExemptionReason().getLanguageLocaleID());
                aUBLTaxCategory.addTaxExemptionReason(aUBLTaxExemptionReason);
            }
            final TaxSchemeType aUBLTaxScheme = new TaxSchemeType();
            aUBLTaxScheme.setID(getVATScheme());
            aUBLTaxCategory.setTaxScheme(aUBLTaxScheme);
            aUBLTaxSubtotal.setTaxCategory(aUBLTaxCategory);
            aUBLTaxTotal.addTaxSubtotal(aUBLTaxSubtotal);
        }
    }
    // LegalMonetaryTotal
    {
        final MonetaryTotalType aUBLMonetaryTotal = new MonetaryTotalType();
        if (aSTSHMS != null) {
            if (aSTSHMS.hasLineTotalAmountEntries())
                aUBLMonetaryTotal.setLineExtensionAmount(_copyAmount(aSTSHMS.getLineTotalAmountAtIndex(0), new LineExtensionAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasTaxBasisTotalAmountEntries())
                aUBLMonetaryTotal.setTaxExclusiveAmount(_copyAmount(aSTSHMS.getTaxBasisTotalAmountAtIndex(0), new TaxExclusiveAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasGrandTotalAmountEntries())
                aUBLMonetaryTotal.setTaxInclusiveAmount(_copyAmount(aSTSHMS.getGrandTotalAmountAtIndex(0), new TaxInclusiveAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasAllowanceTotalAmountEntries())
                aUBLMonetaryTotal.setAllowanceTotalAmount(_copyAmount(aSTSHMS.getAllowanceTotalAmountAtIndex(0), new AllowanceTotalAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasChargeTotalAmountEntries())
                aUBLMonetaryTotal.setChargeTotalAmount(_copyAmount(aSTSHMS.getChargeTotalAmountAtIndex(0), new ChargeTotalAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasTotalPrepaidAmountEntries())
                aUBLMonetaryTotal.setPrepaidAmount(_copyAmount(aSTSHMS.getTotalPrepaidAmountAtIndex(0), new PrepaidAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasRoundingAmountEntries()) {
                // compatibility
                if (MathHelper.isNE0(aSTSHMS.getRoundingAmountAtIndex(0).getValue()))
                    aUBLMonetaryTotal.setPayableRoundingAmount(_copyAmount(aSTSHMS.getRoundingAmountAtIndex(0), new PayableRoundingAmountType(), sDefaultCurrencyCode));
            }
            if (aSTSHMS.hasDuePayableAmountEntries())
                aUBLMonetaryTotal.setPayableAmount(_copyAmount(aSTSHMS.getDuePayableAmountAtIndex(0), new PayableAmountType(), sDefaultCurrencyCode));
        }
        aUBLInvoice.setLegalMonetaryTotal(aUBLMonetaryTotal);
    }
    // All invoice lines
    for (final SupplyChainTradeLineItemType aLineItem : aSCTT.getIncludedSupplyChainTradeLineItem()) {
        final InvoiceLineType aUBLInvoiceLine = new InvoiceLineType();
        final DocumentLineDocumentType aDLD = aLineItem.getAssociatedDocumentLineDocument();
        aUBLInvoiceLine.setID(_copyID(aDLD.getLineID()));
        // Note
        for (final un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100.NoteType aLineNote : aDLD.getIncludedNote()) ifNotNull(aUBLInvoiceLine::addNote, _copyNote(aLineNote));
        // Line extension amount
        boolean bLineExtensionAmountIsNegative = false;
        final LineTradeSettlementType aLineSettlement = aLineItem.getSpecifiedLineTradeSettlement();
        final TradeSettlementLineMonetarySummationType aSTSLMS = aLineSettlement.getSpecifiedTradeSettlementLineMonetarySummation();
        if (aSTSLMS != null) {
            if (aSTSLMS.hasLineTotalAmountEntries()) {
                aUBLInvoiceLine.setLineExtensionAmount(_copyAmount(aSTSLMS.getLineTotalAmountAtIndex(0), new LineExtensionAmountType(), sDefaultCurrencyCode));
                if (isLT0Strict(aUBLInvoiceLine.getLineExtensionAmountValue()))
                    bLineExtensionAmountIsNegative = true;
            }
        }
        // Invoiced quantity
        final LineTradeDeliveryType aLineDelivery = aLineItem.getSpecifiedLineTradeDelivery();
        if (aLineDelivery != null) {
            final QuantityType aBilledQuantity = aLineDelivery.getBilledQuantity();
            if (aBilledQuantity != null) {
                aUBLInvoiceLine.setInvoicedQuantity(_copyQuantity(aBilledQuantity, new InvoicedQuantityType()));
            }
        }
        // Accounting cost
        if (aLineSettlement.hasReceivableSpecifiedTradeAccountingAccountEntries()) {
            final TradeAccountingAccountType aLineAA = aLineSettlement.getReceivableSpecifiedTradeAccountingAccountAtIndex(0);
            aUBLInvoiceLine.setAccountingCost(aLineAA.getIDValue());
        }
        // Invoice period
        final SpecifiedPeriodType aLineBillingPeriod = aLineSettlement.getBillingSpecifiedPeriod();
        if (aLineBillingPeriod != null) {
            final PeriodType aUBLLinePeriod = new PeriodType();
            if (aLineBillingPeriod.getStartDateTime() != null)
                aUBLLinePeriod.setStartDate(_parseDate(aLineBillingPeriod.getStartDateTime().getDateTimeString(), aErrorList));
            if (aLineBillingPeriod.getEndDateTime() != null)
                aUBLLinePeriod.setEndDate(_parseDate(aLineBillingPeriod.getEndDateTime().getDateTimeString(), aErrorList));
            aUBLInvoiceLine.addInvoicePeriod(aUBLLinePeriod);
        }
        // Order line reference
        final LineTradeAgreementType aLineAgreement = aLineItem.getSpecifiedLineTradeAgreement();
        if (aLineAgreement != null) {
            final ReferencedDocumentType aBuyerOrderReference = aLineAgreement.getBuyerOrderReferencedDocument();
            if (aBuyerOrderReference != null && StringHelper.hasText(aBuyerOrderReference.getLineIDValue())) {
                final OrderLineReferenceType aUBLOrderLineReference = new OrderLineReferenceType();
                aUBLOrderLineReference.setLineID(_copyID(aBuyerOrderReference.getLineID(), new LineIDType()));
                aUBLInvoiceLine.addOrderLineReference(aUBLOrderLineReference);
            }
        }
        // Document reference
        for (final ReferencedDocumentType aLineReferencedDocument : aLineSettlement.getAdditionalReferencedDocument()) {
            final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aLineReferencedDocument, aErrorList);
            if (aUBLDocRef != null)
                aUBLInvoiceLine.addDocumentReference(aUBLDocRef);
        }
        // Allowance charge
        for (final TradeAllowanceChargeType aLineAllowanceCharge : aLineSettlement.getSpecifiedTradeAllowanceCharge()) {
            ETriState eIsCharge = ETriState.UNDEFINED;
            if (aLineAllowanceCharge.getChargeIndicator() != null)
                eIsCharge = _parseIndicator(aLineAllowanceCharge.getChargeIndicator(), aErrorList);
            else
                aErrorList.add(_buildError(new String[] { "CrossIndustryInvoice", "SupplyChainTradeTransaction", "IncludedSupplyChainTradeLineItem", "SpecifiedLineTradeSettlement", "SpecifiedTradeAllowanceCharge" }, "Failed to determine if SpecifiedTradeAllowanceCharge is an Allowance or a Charge"));
            if (eIsCharge.isDefined()) {
                final AllowanceChargeType aUBLLineAllowanceCharge = new AllowanceChargeType();
                aUBLLineAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                _copyAllowanceCharge(aLineAllowanceCharge, aUBLLineAllowanceCharge, sDefaultCurrencyCode);
                aUBLInvoiceLine.addAllowanceCharge(aUBLLineAllowanceCharge);
            }
        }
        // Item
        final ItemType aUBLItem = new ItemType();
        final TradeProductType aLineProduct = aLineItem.getSpecifiedTradeProduct();
        if (aLineProduct != null) {
            final TextType aDescription = aLineProduct.getDescription();
            if (aDescription != null)
                ifNotNull(aUBLItem::addDescription, _copyName(aDescription, new DescriptionType()));
            if (aLineProduct.hasNameEntries())
                aUBLItem.setName(_copyName(aLineProduct.getNameAtIndex(0), new NameType()));
            final IDType aBuyerAssignedID = aLineProduct.getBuyerAssignedID();
            if (aBuyerAssignedID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aBuyerAssignedID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setBuyersItemIdentification(aUBLID);
            }
            final IDType aSellerAssignedID = aLineProduct.getSellerAssignedID();
            if (aSellerAssignedID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aSellerAssignedID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setSellersItemIdentification(aUBLID);
            }
            final IDType aGlobalID = aLineProduct.getGlobalID();
            if (aGlobalID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aGlobalID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setStandardItemIdentification(aUBLID);
            }
            final TradeCountryType aOriginCountry = aLineProduct.getOriginTradeCountry();
            if (aOriginCountry != null) {
                final CountryType aUBLCountry = new CountryType();
                aUBLCountry.setIdentificationCode(aOriginCountry.getIDValue());
                if (aOriginCountry.hasNameEntries())
                    aUBLCountry.setName(_copyName(aOriginCountry.getNameAtIndex(0), new NameType()));
                aUBLItem.setOriginCountry(aUBLCountry);
            }
            // Commodity Classification
            for (final ProductClassificationType aLineProductClassification : aLineProduct.getDesignatedProductClassification()) {
                final CodeType aClassCode = aLineProductClassification.getClassCode();
                if (aClassCode != null) {
                    final CommodityClassificationType aUBLCommodityClassification = new CommodityClassificationType();
                    aUBLCommodityClassification.setItemClassificationCode(_copyCode(aClassCode, new ItemClassificationCodeType()));
                    if (aUBLCommodityClassification.getItemClassificationCode() != null)
                        aUBLItem.addCommodityClassification(aUBLCommodityClassification);
                }
            }
        }
        for (final TradeTaxType aTradeTax : aLineSettlement.getApplicableTradeTax()) {
            final TaxCategoryType aUBLTaxCategory = new TaxCategoryType();
            aUBLTaxCategory.setID(aTradeTax.getCategoryCodeValue());
            if (aTradeTax.getRateApplicablePercentValue() != null)
                aUBLTaxCategory.setPercent(MathHelper.getWithoutTrailingZeroes(aTradeTax.getRateApplicablePercentValue()));
            final TaxSchemeType aUBLTaxScheme = new TaxSchemeType();
            aUBLTaxScheme.setID(getVATScheme());
            aUBLTaxCategory.setTaxScheme(aUBLTaxScheme);
            aUBLItem.addClassifiedTaxCategory(aUBLTaxCategory);
        }
        if (aLineProduct != null) {
            for (final ProductCharacteristicType aAPC : aLineProduct.getApplicableProductCharacteristic()) if (aAPC.hasDescriptionEntries()) {
                final ItemPropertyType aUBLAdditionalItem = new ItemPropertyType();
                aUBLAdditionalItem.setName(_copyName(aAPC.getDescriptionAtIndex(0), new NameType()));
                if (aAPC.hasValueEntries())
                    aUBLAdditionalItem.setValue(aAPC.getValueAtIndex(0).getValue());
                if (aUBLAdditionalItem.getName() != null)
                    aUBLItem.addAdditionalItemProperty(aUBLAdditionalItem);
            }
        }
        final PriceType aUBLPrice = new PriceType();
        boolean bUsePrice = false;
        if (aLineAgreement != null) {
            final TradePriceType aNPPTP = aLineAgreement.getNetPriceProductTradePrice();
            if (aNPPTP != null) {
                if (aNPPTP.hasChargeAmountEntries()) {
                    aUBLPrice.setPriceAmount(_copyAmount(aNPPTP.getChargeAmountAtIndex(0), new PriceAmountType(), sDefaultCurrencyCode));
                    bUsePrice = true;
                }
                if (aNPPTP.getBasisQuantity() != null) {
                    aUBLPrice.setBaseQuantity(_copyQuantity(aNPPTP.getBasisQuantity(), new BaseQuantityType()));
                    bUsePrice = true;
                }
            }
        }
        swapQuantityAndPriceIfNeeded(bLineExtensionAmountIsNegative, aUBLInvoiceLine.getInvoicedQuantityValue(), aUBLInvoiceLine::setInvoicedQuantity, bUsePrice ? aUBLPrice.getPriceAmountValue() : null, bUsePrice ? aUBLPrice::setPriceAmount : null);
        // Allowance charge
        final TradePriceType aTradePrice = aLineAgreement.getNetPriceProductTradePrice();
        if (aTradePrice != null)
            for (final TradeAllowanceChargeType aPriceAllowanceCharge : aTradePrice.getAppliedTradeAllowanceCharge()) {
                ETriState eIsCharge = ETriState.UNDEFINED;
                if (aPriceAllowanceCharge.getChargeIndicator() != null)
                    eIsCharge = _parseIndicator(aPriceAllowanceCharge.getChargeIndicator(), aErrorList);
                else
                    aErrorList.add(_buildError(new String[] { "CrossIndustryInvoice", "SupplyChainTradeTransaction", "IncludedSupplyChainTradeLineItem", "SpecifiedLineTradeAgreement", "NetPriceProductTradePrice", "AppliedTradeAllowanceCharge" }, "Failed to determine if AppliedTradeAllowanceCharge is an Allowance or a Charge"));
                if (eIsCharge.isDefined()) {
                    final AllowanceChargeType aUBLLineAllowanceCharge = new AllowanceChargeType();
                    aUBLLineAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                    _copyAllowanceCharge(aPriceAllowanceCharge, aUBLLineAllowanceCharge, sDefaultCurrencyCode);
                    aUBLPrice.addAllowanceCharge(aUBLLineAllowanceCharge);
                }
            }
        if (bUsePrice)
            aUBLInvoiceLine.setPrice(aUBLPrice);
        aUBLInvoiceLine.setItem(aUBLItem);
        aUBLInvoice.addInvoiceLine(aUBLInvoiceLine);
    }
    return aUBLInvoice;
}
Also used : DateTimeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.DateTimeType) un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100) FormattedDateTimeType(un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType) CodeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.CodeType) ErrorList(com.helger.commons.error.list.ErrorList) ETriState(com.helger.commons.state.ETriState) CollectionHelper(com.helger.commons.collection.CollectionHelper) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_23.CreditNoteType) BigDecimal(java.math.BigDecimal) TextType(un.unece.uncefact.data.standard.unqualifieddatatype._100.TextType) CrossIndustryInvoiceType(un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) BinaryObjectType(un.unece.uncefact.data.standard.unqualifieddatatype._100.BinaryObjectType) MathHelper(com.helger.commons.math.MathHelper) CGlobal(com.helger.commons.CGlobal) oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_23(oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_23) StringHelper(com.helger.commons.string.StringHelper) AmountType(un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType) oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_23(oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_23) InvoiceType(oasis.names.specification.ubl.schema.xsd.invoice_23.InvoiceType) EqualsHelper(com.helger.commons.equals.EqualsHelper) Serializable(java.io.Serializable) ValueEnforcer(com.helger.commons.ValueEnforcer) QuantityType(un.unece.uncefact.data.standard.unqualifieddatatype._100.QuantityType) Consumer(java.util.function.Consumer) LocalDate(java.time.LocalDate) IErrorList(com.helger.commons.error.list.IErrorList) IDType(un.unece.uncefact.data.standard.unqualifieddatatype._100.IDType) LocalDate(java.time.LocalDate) un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100) TextType(un.unece.uncefact.data.standard.unqualifieddatatype._100.TextType) AmountType(un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_23.CreditNoteType) oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_23(oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_23) IDType(un.unece.uncefact.data.standard.unqualifieddatatype._100.IDType) DateTimeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.DateTimeType) FormattedDateTimeType(un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType) QuantityType(un.unece.uncefact.data.standard.unqualifieddatatype._100.QuantityType) ETriState(com.helger.commons.state.ETriState) CrossIndustryInvoiceType(un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType) InvoiceType(oasis.names.specification.ubl.schema.xsd.invoice_23.InvoiceType) CodeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.CodeType) Nullable(javax.annotation.Nullable)

Example 9 with QuantityType

use of org.geotoolkit.swe.xml.v100.QuantityType in project en16931-cii2ubl by phax.

the class CIIToUBL21Converter method convertToInvoice.

@Nullable
public InvoiceType convertToInvoice(@Nonnull final CrossIndustryInvoiceType aCIIInvoice, @Nonnull final ErrorList aErrorList) {
    ValueEnforcer.notNull(aCIIInvoice, "CIIInvoice");
    ValueEnforcer.notNull(aErrorList, "ErrorList");
    final ExchangedDocumentType aED = aCIIInvoice.getExchangedDocument();
    final SupplyChainTradeTransactionType aSCTT = aCIIInvoice.getSupplyChainTradeTransaction();
    if (aSCTT == null) {
        // Mandatory element
        return null;
    }
    final HeaderTradeAgreementType aHeaderAgreement = aSCTT.getApplicableHeaderTradeAgreement();
    final HeaderTradeDeliveryType aHeaderDelivery = aSCTT.getApplicableHeaderTradeDelivery();
    final HeaderTradeSettlementType aHeaderSettlement = aSCTT.getApplicableHeaderTradeSettlement();
    if (aHeaderAgreement == null || aHeaderDelivery == null || aHeaderSettlement == null) {
        // All mandatory elements
        return null;
    }
    final InvoiceType aUBLInvoice = new InvoiceType();
    if (false)
        aUBLInvoice.setUBLVersionID(UBL_VERSION);
    if (StringHelper.hasText(getCustomizationID()))
        aUBLInvoice.setCustomizationID(getCustomizationID());
    if (StringHelper.hasText(getProfileID()))
        aUBLInvoice.setProfileID(getProfileID());
    if (aED != null)
        aUBLInvoice.setID(aED.getIDValue());
    // Mandatory supplier
    final SupplierPartyType aUBLSupplier = new SupplierPartyType();
    aUBLInvoice.setAccountingSupplierParty(aUBLSupplier);
    // Mandatory customer
    final CustomerPartyType aUBLCustomer = new CustomerPartyType();
    aUBLInvoice.setAccountingCustomerParty(aUBLCustomer);
    // IssueDate
    {
        LocalDate aIssueDate = null;
        if (aED != null && aED.getIssueDateTime() != null)
            aIssueDate = _parseDate(aED.getIssueDateTime().getDateTimeString(), aErrorList);
        if (aIssueDate != null)
            aUBLInvoice.setIssueDate(aIssueDate);
    }
    // DueDate
    {
        LocalDate aDueDate = null;
        for (final TradePaymentTermsType aPaymentTerms : aHeaderSettlement.getSpecifiedTradePaymentTerms()) if (aPaymentTerms.getDueDateDateTime() != null) {
            aDueDate = _parseDate(aPaymentTerms.getDueDateDateTime().getDateTimeString(), aErrorList);
            if (aDueDate != null)
                break;
        }
        if (aDueDate != null)
            aUBLInvoice.setDueDate(aDueDate);
    }
    // InvoiceTypeCode
    if (aED != null)
        aUBLInvoice.setInvoiceTypeCode(aED.getTypeCodeValue());
    // Note
    if (aED != null)
        for (final un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100.NoteType aEDNote : aED.getIncludedNote()) ifNotNull(aUBLInvoice::addNote, _copyNote(aEDNote));
    // TaxPointDate
    for (final TradeTaxType aTradeTax : aHeaderSettlement.getApplicableTradeTax()) {
        if (aTradeTax.getTaxPointDate() != null) {
            final LocalDate aTaxPointDate = _parseDate(aTradeTax.getTaxPointDate().getDateString(), aErrorList);
            if (aTaxPointDate != null) {
                // Use the first tax point date only
                aUBLInvoice.setTaxPointDate(aTaxPointDate);
                break;
            }
        }
    }
    // DocumentCurrencyCode
    final String sDefaultCurrencyCode = aHeaderSettlement.getInvoiceCurrencyCodeValue();
    aUBLInvoice.setDocumentCurrencyCode(sDefaultCurrencyCode);
    // TaxCurrencyCode
    if (aHeaderSettlement.getTaxCurrencyCodeValue() != null) {
        aUBLInvoice.setTaxCurrencyCode(aHeaderSettlement.getTaxCurrencyCodeValue());
    }
    // AccountingCost
    for (final TradeAccountingAccountType aAccount : aHeaderSettlement.getReceivableSpecifiedTradeAccountingAccount()) {
        final String sID = aAccount.getIDValue();
        if (StringHelper.hasText(sID)) {
            // Use the first ID
            aUBLInvoice.setAccountingCost(sID);
            break;
        }
    }
    // BuyerReferences
    if (aHeaderAgreement.getBuyerReferenceValue() != null) {
        aUBLInvoice.setBuyerReference(aHeaderAgreement.getBuyerReferenceValue());
    }
    // InvoicePeriod
    {
        final SpecifiedPeriodType aSPT = aHeaderSettlement.getBillingSpecifiedPeriod();
        if (aSPT != null) {
            final DateTimeType aStartDT = aSPT.getStartDateTime();
            final DateTimeType aEndDT = aSPT.getEndDateTime();
            if (aStartDT != null && aEndDT != null) {
                final PeriodType aUBLPeriod = new PeriodType();
                aUBLPeriod.setStartDate(_parseDate(aStartDT.getDateTimeString(), aErrorList));
                aUBLPeriod.setEndDate(_parseDate(aEndDT.getDateTimeString(), aErrorList));
                aUBLInvoice.addInvoicePeriod(aUBLPeriod);
            }
        }
    }
    // OrderReference
    {
        final OrderReferenceType aUBLOrderRef = _createUBLOrderRef(aHeaderAgreement.getBuyerOrderReferencedDocument(), aHeaderAgreement.getSellerOrderReferencedDocument());
        aUBLInvoice.setOrderReference(aUBLOrderRef);
    }
    // BillingReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderSettlement.getInvoiceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null) {
            final BillingReferenceType aUBLBillingRef = new BillingReferenceType();
            aUBLBillingRef.setInvoiceDocumentReference(aUBLDocRef);
            aUBLInvoice.addBillingReference(aUBLBillingRef);
        }
    }
    // DespatchDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderDelivery.getDespatchAdviceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLInvoice.addDespatchDocumentReference(aUBLDocRef);
    }
    // ReceiptDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderDelivery.getReceivingAdviceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLInvoice.addReceiptDocumentReference(aUBLDocRef);
    }
    // OriginatorDocumentReference
    {
        for (final ReferencedDocumentType aRD : aHeaderAgreement.getAdditionalReferencedDocument()) {
            // Use for "Tender or lot reference" with TypeCode "50"
            if (isOriginatorDocumentReferenceTypeCode(aRD.getTypeCodeValue())) {
                final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aRD, aErrorList);
                if (aUBLDocRef != null)
                    aUBLInvoice.addOriginatorDocumentReference(aUBLDocRef);
            }
        }
    }
    // ContractDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderAgreement.getContractReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLInvoice.addContractDocumentReference(aUBLDocRef);
    }
    // AdditionalDocumentReference
    {
        for (final ReferencedDocumentType aRD : aHeaderAgreement.getAdditionalReferencedDocument()) {
            // Except OriginatorDocumentReference
            if (!isOriginatorDocumentReferenceTypeCode(aRD.getTypeCodeValue())) {
                final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aRD, aErrorList);
                if (aUBLDocRef != null)
                    aUBLInvoice.addAdditionalDocumentReference(aUBLDocRef);
            }
        }
    }
    // ProjectReference
    {
        final ProcuringProjectType aSpecifiedProcuring = aHeaderAgreement.getSpecifiedProcuringProject();
        if (aSpecifiedProcuring != null) {
            final String sID = aSpecifiedProcuring.getIDValue();
            if (StringHelper.hasText(sID)) {
                final ProjectReferenceType aUBLProjectRef = new ProjectReferenceType();
                aUBLProjectRef.setID(sID);
                aUBLInvoice.addProjectReference(aUBLProjectRef);
            }
        }
    }
    // Supplier Party
    {
        final TradePartyType aSellerParty = aHeaderAgreement.getSellerTradeParty();
        if (aSellerParty != null) {
            final PartyType aUBLParty = _convertParty(aSellerParty, true);
            for (final TaxRegistrationType aTaxRegistration : aSellerParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aSellerParty);
            if (aUBLPartyLegalEntity != null)
                aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            final ContactType aUBLContact = _convertContact(aSellerParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLSupplier.setParty(aUBLParty);
        }
    }
    // Customer Party
    {
        final TradePartyType aBuyerParty = aHeaderAgreement.getBuyerTradeParty();
        if (aBuyerParty != null) {
            final PartyType aUBLParty = _convertParty(aBuyerParty, false);
            for (final TaxRegistrationType aTaxRegistration : aBuyerParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aBuyerParty);
            if (aUBLPartyLegalEntity != null)
                aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            final ContactType aUBLContact = _convertContact(aBuyerParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLCustomer.setParty(aUBLParty);
        }
    }
    // Payee Party
    {
        final TradePartyType aPayeeParty = aHeaderSettlement.getPayeeTradeParty();
        if (aPayeeParty != null) {
            final PartyType aUBLParty = _convertParty(aPayeeParty, false);
            for (final TaxRegistrationType aTaxRegistration : aPayeeParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            // validation rules warning
            if (false) {
                final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aPayeeParty);
                if (aUBLPartyLegalEntity != null)
                    aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            }
            final ContactType aUBLContact = _convertContact(aPayeeParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLInvoice.setPayeeParty(aUBLParty);
        }
    }
    // Tax Representative Party
    {
        final TradePartyType aTaxRepresentativeParty = aHeaderAgreement.getSellerTaxRepresentativeTradeParty();
        if (aTaxRepresentativeParty != null) {
            final PartyType aUBLParty = _convertParty(aTaxRepresentativeParty, false);
            for (final TaxRegistrationType aTaxRegistration : aTaxRepresentativeParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            // validation rules warning
            if (false) {
                final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aTaxRepresentativeParty);
                if (aUBLPartyLegalEntity != null)
                    aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            }
            final ContactType aUBLContact = _convertContact(aTaxRepresentativeParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLInvoice.setTaxRepresentativeParty(aUBLParty);
        }
    }
    // Delivery
    {
        final DeliveryType aUBLDelivery = new DeliveryType();
        boolean bUseDelivery = false;
        final SupplyChainEventType aSCE = aHeaderDelivery.getActualDeliverySupplyChainEvent();
        if (aSCE != null) {
            final DateTimeType aODT = aSCE.getOccurrenceDateTime();
            if (aODT != null) {
                aUBLDelivery.setActualDeliveryDate(_parseDate(aODT.getDateTimeString(), aErrorList));
                bUseDelivery = true;
            }
        }
        final TradePartyType aShipToParty = aHeaderDelivery.getShipToTradeParty();
        if (aShipToParty != null) {
            final oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21.LocationType aUBLDeliveryLocation = new oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21.LocationType();
            boolean bUseLocation = false;
            final oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_21.IDType aUBLID = _extractFirstPartyID(aShipToParty);
            if (aUBLID != null) {
                aUBLDeliveryLocation.setID(aUBLID);
                bUseLocation = true;
            }
            final TradeAddressType aPostalAddress = aShipToParty.getPostalTradeAddress();
            if (aPostalAddress != null) {
                aUBLDeliveryLocation.setAddress(_convertPostalAddress(aPostalAddress));
                bUseLocation = true;
            }
            if (bUseLocation) {
                aUBLDelivery.setDeliveryLocation(aUBLDeliveryLocation);
                bUseDelivery = true;
            }
            final TextType aName = aShipToParty.getName();
            if (aName != null) {
                final PartyType aUBLDeliveryParty = new PartyType();
                final PartyNameType aUBLPartyName = new PartyNameType();
                aUBLPartyName.setName(_copyName(aName, new NameType()));
                aUBLDeliveryParty.addPartyName(aUBLPartyName);
                aUBLDelivery.setDeliveryParty(aUBLDeliveryParty);
                bUseDelivery = true;
            }
        }
        if (bUseDelivery)
            aUBLInvoice.addDelivery(aUBLDelivery);
    }
    // Payment means
    {
        for (final TradeSettlementPaymentMeansType aPaymentMeans : aHeaderSettlement.getSpecifiedTradeSettlementPaymentMeans()) {
            _convertPaymentMeans(aHeaderSettlement, aPaymentMeans, x -> _addPartyID(x, aUBLInvoice.getAccountingSupplierParty().getParty()), aUBLInvoice::addPaymentMeans, aErrorList);
            // Allowed again in 1.2.1: exactly 2
            if (false)
                // Since v1.2.0 only one is allowed
                if (true)
                    break;
        }
    }
    // Payment Terms
    {
        for (final TradePaymentTermsType aPaymentTerms : aHeaderSettlement.getSpecifiedTradePaymentTerms()) {
            final PaymentTermsType aUBLPaymenTerms = new PaymentTermsType();
            for (final TextType aDesc : aPaymentTerms.getDescription()) ifNotNull(aUBLPaymenTerms::addNote, _copyNote(aDesc));
            if (aUBLPaymenTerms.hasNoteEntries())
                aUBLInvoice.addPaymentTerms(aUBLPaymenTerms);
        }
    }
    // Allowance Charge
    {
        for (final TradeAllowanceChargeType aAllowanceCharge : aHeaderSettlement.getSpecifiedTradeAllowanceCharge()) {
            ETriState eIsCharge = ETriState.UNDEFINED;
            if (aAllowanceCharge.getChargeIndicator() != null)
                eIsCharge = _parseIndicator(aAllowanceCharge.getChargeIndicator(), aErrorList);
            else
                aErrorList.add(_buildError(new String[] { "CrossIndustryInvoice", "SupplyChainTradeTransaction", "ApplicableHeaderTradeSettlement", "SpecifiedTradeAllowanceCharge" }, "Failed to determine if SpecifiedTradeAllowanceCharge is an Allowance or a Charge"));
            if (eIsCharge.isDefined()) {
                final AllowanceChargeType aUBLAllowanceCharge = new AllowanceChargeType();
                aUBLAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                _copyAllowanceCharge(aAllowanceCharge, aUBLAllowanceCharge, sDefaultCurrencyCode);
                aUBLInvoice.addAllowanceCharge(aUBLAllowanceCharge);
            }
        }
    }
    final TradeSettlementHeaderMonetarySummationType aSTSHMS = aHeaderSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation();
    // TaxTotal
    {
        TaxTotalType aUBLTaxTotal = null;
        if (aSTSHMS != null && aSTSHMS.hasTaxTotalAmountEntries()) {
            // For all currencies
            for (final AmountType aTaxTotalAmount : aSTSHMS.getTaxTotalAmount()) {
                final TaxTotalType aUBLCurTaxTotal = new TaxTotalType();
                aUBLCurTaxTotal.setTaxAmount(_copyAmount(aTaxTotalAmount, new TaxAmountType(), sDefaultCurrencyCode));
                aUBLInvoice.addTaxTotal(aUBLCurTaxTotal);
                if (aUBLTaxTotal == null) {
                    // Use the first one
                    aUBLTaxTotal = aUBLCurTaxTotal;
                }
            }
        } else {
            // Mandatory in UBL
            final TaxAmountType aUBLTaxAmount = new TaxAmountType();
            aUBLTaxAmount.setValue(BigDecimal.ZERO);
            aUBLTaxAmount.setCurrencyID(sDefaultCurrencyCode);
            aUBLTaxTotal = new TaxTotalType();
            aUBLTaxTotal.setTaxAmount(aUBLTaxAmount);
            aUBLInvoice.addTaxTotal(aUBLTaxTotal);
        }
        for (final TradeTaxType aTradeTax : aHeaderSettlement.getApplicableTradeTax()) {
            final TaxSubtotalType aUBLTaxSubtotal = new TaxSubtotalType();
            if (aTradeTax.hasBasisAmountEntries()) {
                aUBLTaxSubtotal.setTaxableAmount(_copyAmount(aTradeTax.getBasisAmountAtIndex(0), new TaxableAmountType(), sDefaultCurrencyCode));
            }
            if (aTradeTax.hasCalculatedAmountEntries()) {
                aUBLTaxSubtotal.setTaxAmount(_copyAmount(aTradeTax.getCalculatedAmountAtIndex(0), new TaxAmountType(), sDefaultCurrencyCode));
            }
            final TaxCategoryType aUBLTaxCategory = new TaxCategoryType();
            aUBLTaxCategory.setID(aTradeTax.getCategoryCodeValue());
            if (aTradeTax.getRateApplicablePercentValue() != null)
                aUBLTaxCategory.setPercent(MathHelper.getWithoutTrailingZeroes(aTradeTax.getRateApplicablePercentValue()));
            if (StringHelper.hasText(aTradeTax.getExemptionReasonCodeValue()))
                aUBLTaxCategory.setTaxExemptionReasonCode(aTradeTax.getExemptionReasonCodeValue());
            if (aTradeTax.getExemptionReason() != null) {
                final TaxExemptionReasonType aUBLTaxExemptionReason = new TaxExemptionReasonType();
                aUBLTaxExemptionReason.setValue(aTradeTax.getExemptionReason().getValue());
                aUBLTaxExemptionReason.setLanguageID(aTradeTax.getExemptionReason().getLanguageID());
                aUBLTaxExemptionReason.setLanguageLocaleID(aTradeTax.getExemptionReason().getLanguageLocaleID());
                aUBLTaxCategory.addTaxExemptionReason(aUBLTaxExemptionReason);
            }
            final TaxSchemeType aUBLTaxScheme = new TaxSchemeType();
            aUBLTaxScheme.setID(getVATScheme());
            aUBLTaxCategory.setTaxScheme(aUBLTaxScheme);
            aUBLTaxSubtotal.setTaxCategory(aUBLTaxCategory);
            aUBLTaxTotal.addTaxSubtotal(aUBLTaxSubtotal);
        }
    }
    // LegalMonetaryTotal
    {
        final MonetaryTotalType aUBLMonetaryTotal = new MonetaryTotalType();
        if (aSTSHMS != null) {
            if (aSTSHMS.hasLineTotalAmountEntries())
                aUBLMonetaryTotal.setLineExtensionAmount(_copyAmount(aSTSHMS.getLineTotalAmountAtIndex(0), new LineExtensionAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasTaxBasisTotalAmountEntries())
                aUBLMonetaryTotal.setTaxExclusiveAmount(_copyAmount(aSTSHMS.getTaxBasisTotalAmountAtIndex(0), new TaxExclusiveAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasGrandTotalAmountEntries())
                aUBLMonetaryTotal.setTaxInclusiveAmount(_copyAmount(aSTSHMS.getGrandTotalAmountAtIndex(0), new TaxInclusiveAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasAllowanceTotalAmountEntries())
                aUBLMonetaryTotal.setAllowanceTotalAmount(_copyAmount(aSTSHMS.getAllowanceTotalAmountAtIndex(0), new AllowanceTotalAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasChargeTotalAmountEntries())
                aUBLMonetaryTotal.setChargeTotalAmount(_copyAmount(aSTSHMS.getChargeTotalAmountAtIndex(0), new ChargeTotalAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasTotalPrepaidAmountEntries())
                aUBLMonetaryTotal.setPrepaidAmount(_copyAmount(aSTSHMS.getTotalPrepaidAmountAtIndex(0), new PrepaidAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasRoundingAmountEntries()) {
                // compatibility
                if (MathHelper.isNE0(aSTSHMS.getRoundingAmountAtIndex(0).getValue()))
                    aUBLMonetaryTotal.setPayableRoundingAmount(_copyAmount(aSTSHMS.getRoundingAmountAtIndex(0), new PayableRoundingAmountType(), sDefaultCurrencyCode));
            }
            if (aSTSHMS.hasDuePayableAmountEntries())
                aUBLMonetaryTotal.setPayableAmount(_copyAmount(aSTSHMS.getDuePayableAmountAtIndex(0), new PayableAmountType(), sDefaultCurrencyCode));
        }
        aUBLInvoice.setLegalMonetaryTotal(aUBLMonetaryTotal);
    }
    // All invoice lines
    for (final SupplyChainTradeLineItemType aLineItem : aSCTT.getIncludedSupplyChainTradeLineItem()) {
        final InvoiceLineType aUBLInvoiceLine = new InvoiceLineType();
        final DocumentLineDocumentType aDLD = aLineItem.getAssociatedDocumentLineDocument();
        aUBLInvoiceLine.setID(_copyID(aDLD.getLineID()));
        // Note
        for (final un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100.NoteType aLineNote : aDLD.getIncludedNote()) ifNotNull(aUBLInvoiceLine::addNote, _copyNote(aLineNote));
        // Line extension amount
        boolean bLineExtensionAmountIsNegative = false;
        final LineTradeSettlementType aLineSettlement = aLineItem.getSpecifiedLineTradeSettlement();
        final TradeSettlementLineMonetarySummationType aSTSLMS = aLineSettlement.getSpecifiedTradeSettlementLineMonetarySummation();
        if (aSTSLMS != null) {
            if (aSTSLMS.hasLineTotalAmountEntries()) {
                aUBLInvoiceLine.setLineExtensionAmount(_copyAmount(aSTSLMS.getLineTotalAmountAtIndex(0), new LineExtensionAmountType(), sDefaultCurrencyCode));
                if (isLT0Strict(aUBLInvoiceLine.getLineExtensionAmountValue()))
                    bLineExtensionAmountIsNegative = true;
            }
        }
        // Invoiced quantity
        final LineTradeDeliveryType aLineDelivery = aLineItem.getSpecifiedLineTradeDelivery();
        if (aLineDelivery != null) {
            final QuantityType aBilledQuantity = aLineDelivery.getBilledQuantity();
            if (aBilledQuantity != null) {
                aUBLInvoiceLine.setInvoicedQuantity(_copyQuantity(aBilledQuantity, new InvoicedQuantityType()));
            }
        }
        // Accounting cost
        if (aLineSettlement.hasReceivableSpecifiedTradeAccountingAccountEntries()) {
            final TradeAccountingAccountType aLineAA = aLineSettlement.getReceivableSpecifiedTradeAccountingAccountAtIndex(0);
            aUBLInvoiceLine.setAccountingCost(aLineAA.getIDValue());
        }
        // Invoice period
        final SpecifiedPeriodType aLineBillingPeriod = aLineSettlement.getBillingSpecifiedPeriod();
        if (aLineBillingPeriod != null) {
            final PeriodType aUBLLinePeriod = new PeriodType();
            if (aLineBillingPeriod.getStartDateTime() != null)
                aUBLLinePeriod.setStartDate(_parseDate(aLineBillingPeriod.getStartDateTime().getDateTimeString(), aErrorList));
            if (aLineBillingPeriod.getEndDateTime() != null)
                aUBLLinePeriod.setEndDate(_parseDate(aLineBillingPeriod.getEndDateTime().getDateTimeString(), aErrorList));
            aUBLInvoiceLine.addInvoicePeriod(aUBLLinePeriod);
        }
        // Order line reference
        final LineTradeAgreementType aLineAgreement = aLineItem.getSpecifiedLineTradeAgreement();
        if (aLineAgreement != null) {
            final ReferencedDocumentType aBuyerOrderReference = aLineAgreement.getBuyerOrderReferencedDocument();
            if (aBuyerOrderReference != null && StringHelper.hasText(aBuyerOrderReference.getLineIDValue())) {
                final OrderLineReferenceType aUBLOrderLineReference = new OrderLineReferenceType();
                aUBLOrderLineReference.setLineID(_copyID(aBuyerOrderReference.getLineID(), new LineIDType()));
                aUBLInvoiceLine.addOrderLineReference(aUBLOrderLineReference);
            }
        }
        // Document reference
        for (final ReferencedDocumentType aLineReferencedDocument : aLineSettlement.getAdditionalReferencedDocument()) {
            final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aLineReferencedDocument, aErrorList);
            if (aUBLDocRef != null)
                aUBLInvoiceLine.addDocumentReference(aUBLDocRef);
        }
        // Allowance charge
        for (final TradeAllowanceChargeType aLineAllowanceCharge : aLineSettlement.getSpecifiedTradeAllowanceCharge()) {
            ETriState eIsCharge = ETriState.UNDEFINED;
            if (aLineAllowanceCharge.getChargeIndicator() != null)
                eIsCharge = _parseIndicator(aLineAllowanceCharge.getChargeIndicator(), aErrorList);
            else
                aErrorList.add(_buildError(new String[] { "CrossIndustryInvoice", "SupplyChainTradeTransaction", "IncludedSupplyChainTradeLineItem", "SpecifiedLineTradeSettlement", "SpecifiedTradeAllowanceCharge" }, "Failed to determine if SpecifiedTradeAllowanceCharge is an Allowance or a Charge"));
            if (eIsCharge.isDefined()) {
                final AllowanceChargeType aUBLLineAllowanceCharge = new AllowanceChargeType();
                aUBLLineAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                _copyAllowanceCharge(aLineAllowanceCharge, aUBLLineAllowanceCharge, sDefaultCurrencyCode);
                aUBLInvoiceLine.addAllowanceCharge(aUBLLineAllowanceCharge);
            }
        }
        // Item
        final ItemType aUBLItem = new ItemType();
        final TradeProductType aLineProduct = aLineItem.getSpecifiedTradeProduct();
        if (aLineProduct != null) {
            final TextType aDescription = aLineProduct.getDescription();
            if (aDescription != null)
                ifNotNull(aUBLItem::addDescription, _copyName(aDescription, new DescriptionType()));
            if (aLineProduct.hasNameEntries())
                aUBLItem.setName(_copyName(aLineProduct.getNameAtIndex(0), new NameType()));
            final IDType aBuyerAssignedID = aLineProduct.getBuyerAssignedID();
            if (aBuyerAssignedID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aBuyerAssignedID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setBuyersItemIdentification(aUBLID);
            }
            final IDType aSellerAssignedID = aLineProduct.getSellerAssignedID();
            if (aSellerAssignedID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aSellerAssignedID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setSellersItemIdentification(aUBLID);
            }
            final IDType aGlobalID = aLineProduct.getGlobalID();
            if (aGlobalID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aGlobalID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setStandardItemIdentification(aUBLID);
            }
            final TradeCountryType aOriginCountry = aLineProduct.getOriginTradeCountry();
            if (aOriginCountry != null) {
                final CountryType aUBLCountry = new CountryType();
                aUBLCountry.setIdentificationCode(aOriginCountry.getIDValue());
                if (aOriginCountry.hasNameEntries())
                    aUBLCountry.setName(_copyName(aOriginCountry.getNameAtIndex(0), new NameType()));
                aUBLItem.setOriginCountry(aUBLCountry);
            }
            // Commodity Classification
            for (final ProductClassificationType aLineProductClassification : aLineProduct.getDesignatedProductClassification()) {
                final CodeType aClassCode = aLineProductClassification.getClassCode();
                if (aClassCode != null) {
                    final CommodityClassificationType aUBLCommodityClassification = new CommodityClassificationType();
                    aUBLCommodityClassification.setItemClassificationCode(_copyCode(aClassCode, new ItemClassificationCodeType()));
                    if (aUBLCommodityClassification.getItemClassificationCode() != null)
                        aUBLItem.addCommodityClassification(aUBLCommodityClassification);
                }
            }
        }
        for (final TradeTaxType aTradeTax : aLineSettlement.getApplicableTradeTax()) {
            final TaxCategoryType aUBLTaxCategory = new TaxCategoryType();
            aUBLTaxCategory.setID(aTradeTax.getCategoryCodeValue());
            if (aTradeTax.getRateApplicablePercentValue() != null)
                aUBLTaxCategory.setPercent(MathHelper.getWithoutTrailingZeroes(aTradeTax.getRateApplicablePercentValue()));
            final TaxSchemeType aUBLTaxScheme = new TaxSchemeType();
            aUBLTaxScheme.setID(getVATScheme());
            aUBLTaxCategory.setTaxScheme(aUBLTaxScheme);
            aUBLItem.addClassifiedTaxCategory(aUBLTaxCategory);
        }
        if (aLineProduct != null) {
            for (final ProductCharacteristicType aAPC : aLineProduct.getApplicableProductCharacteristic()) if (aAPC.hasDescriptionEntries()) {
                final ItemPropertyType aUBLAdditionalItem = new ItemPropertyType();
                aUBLAdditionalItem.setName(_copyName(aAPC.getDescriptionAtIndex(0), new NameType()));
                if (aAPC.hasValueEntries())
                    aUBLAdditionalItem.setValue(aAPC.getValueAtIndex(0).getValue());
                if (aUBLAdditionalItem.getName() != null)
                    aUBLItem.addAdditionalItemProperty(aUBLAdditionalItem);
            }
        }
        final PriceType aUBLPrice = new PriceType();
        boolean bUsePrice = false;
        if (aLineAgreement != null) {
            final TradePriceType aNPPTP = aLineAgreement.getNetPriceProductTradePrice();
            if (aNPPTP != null) {
                if (aNPPTP.hasChargeAmountEntries()) {
                    aUBLPrice.setPriceAmount(_copyAmount(aNPPTP.getChargeAmountAtIndex(0), new PriceAmountType(), sDefaultCurrencyCode));
                    bUsePrice = true;
                }
                if (aNPPTP.getBasisQuantity() != null) {
                    aUBLPrice.setBaseQuantity(_copyQuantity(aNPPTP.getBasisQuantity(), new BaseQuantityType()));
                    bUsePrice = true;
                }
            }
        }
        swapQuantityAndPriceIfNeeded(bLineExtensionAmountIsNegative, aUBLInvoiceLine.getInvoicedQuantityValue(), aUBLInvoiceLine::setInvoicedQuantity, bUsePrice ? aUBLPrice.getPriceAmountValue() : null, bUsePrice ? aUBLPrice::setPriceAmount : null);
        // Allowance charge
        final TradePriceType aTradePrice = aLineAgreement.getNetPriceProductTradePrice();
        if (aTradePrice != null)
            for (final TradeAllowanceChargeType aPriceAllowanceCharge : aTradePrice.getAppliedTradeAllowanceCharge()) {
                ETriState eIsCharge = ETriState.UNDEFINED;
                if (aPriceAllowanceCharge.getChargeIndicator() != null)
                    eIsCharge = _parseIndicator(aPriceAllowanceCharge.getChargeIndicator(), aErrorList);
                else
                    aErrorList.add(_buildError(new String[] { "CrossIndustryInvoice", "SupplyChainTradeTransaction", "IncludedSupplyChainTradeLineItem", "SpecifiedLineTradeAgreement", "NetPriceProductTradePrice", "AppliedTradeAllowanceCharge" }, "Failed to determine if AppliedTradeAllowanceCharge is an Allowance or a Charge"));
                if (eIsCharge.isDefined()) {
                    final AllowanceChargeType aUBLLineAllowanceCharge = new AllowanceChargeType();
                    aUBLLineAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                    _copyAllowanceCharge(aPriceAllowanceCharge, aUBLLineAllowanceCharge, sDefaultCurrencyCode);
                    aUBLPrice.addAllowanceCharge(aUBLLineAllowanceCharge);
                }
            }
        if (bUsePrice)
            aUBLInvoiceLine.setPrice(aUBLPrice);
        aUBLInvoiceLine.setItem(aUBLItem);
        aUBLInvoice.addInvoiceLine(aUBLInvoiceLine);
    }
    return aUBLInvoice;
}
Also used : DateTimeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.DateTimeType) un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100) FormattedDateTimeType(un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType) CodeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.CodeType) ErrorList(com.helger.commons.error.list.ErrorList) ETriState(com.helger.commons.state.ETriState) CollectionHelper(com.helger.commons.collection.CollectionHelper) BigDecimal(java.math.BigDecimal) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType) TextType(un.unece.uncefact.data.standard.unqualifieddatatype._100.TextType) CrossIndustryInvoiceType(un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) BinaryObjectType(un.unece.uncefact.data.standard.unqualifieddatatype._100.BinaryObjectType) MathHelper(com.helger.commons.math.MathHelper) oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_21(oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_21) CGlobal(com.helger.commons.CGlobal) StringHelper(com.helger.commons.string.StringHelper) AmountType(un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType) EqualsHelper(com.helger.commons.equals.EqualsHelper) Serializable(java.io.Serializable) ValueEnforcer(com.helger.commons.ValueEnforcer) oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21(oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21) QuantityType(un.unece.uncefact.data.standard.unqualifieddatatype._100.QuantityType) Consumer(java.util.function.Consumer) InvoiceType(oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType) LocalDate(java.time.LocalDate) IErrorList(com.helger.commons.error.list.IErrorList) IDType(un.unece.uncefact.data.standard.unqualifieddatatype._100.IDType) LocalDate(java.time.LocalDate) un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100) TextType(un.unece.uncefact.data.standard.unqualifieddatatype._100.TextType) AmountType(un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType) oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21(oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21) IDType(un.unece.uncefact.data.standard.unqualifieddatatype._100.IDType) DateTimeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.DateTimeType) FormattedDateTimeType(un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType) QuantityType(un.unece.uncefact.data.standard.unqualifieddatatype._100.QuantityType) ETriState(com.helger.commons.state.ETriState) CrossIndustryInvoiceType(un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType) InvoiceType(oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType) CodeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.CodeType) Nullable(javax.annotation.Nullable)

Example 10 with QuantityType

use of org.geotoolkit.swe.xml.v100.QuantityType in project geotoolkit by Geomatys.

the class SmlXMLBindingTest method ComponentUnmarshallMarshalingTest.

/**
 * Test simple Record Marshalling.
 *
 * @throws java.lang.Exception
 */
@Test
public void ComponentUnmarshallMarshalingTest() throws Exception {
    Unmarshaller unmarshaller = SensorMLMarshallerPool.getInstance().acquireUnmarshaller();
    InputStream is = SmlXMLBindingTest.class.getResourceAsStream("/org/geotoolkit/sml/component.xml");
    Object unmarshalled = unmarshaller.unmarshal(is);
    if (unmarshalled instanceof JAXBElement) {
        unmarshalled = ((JAXBElement) unmarshalled).getValue();
    }
    assertTrue(unmarshalled instanceof SensorML);
    SensorML result = (SensorML) unmarshalled;
    Member member = new Member();
    member.setRole("urn:x-ogx:def:sensor:OGC:detector");
    ComponentType component = new ComponentType();
    List<JAXBElement<String>> kw = new ArrayList<JAXBElement<String>>();
    kw.add(sml100Factory.createKeywordsKeywordListKeyword("piezometer"));
    kw.add(sml100Factory.createKeywordsKeywordListKeyword("geosciences"));
    kw.add(sml100Factory.createKeywordsKeywordListKeyword("point d'eau"));
    Keywords keywords = new Keywords(new KeywordList(URI.create("urn:x-brgm:def:gcmd:keywords"), kw));
    component.setKeywords(keywords);
    Classifier cl1 = new Classifier("intendedApplication", new Term("eaux souterraines", URI.create("urn:x-ogc:def:classifier:OGC:application")));
    CodeSpacePropertyType cs = new CodeSpacePropertyType("urn:x-brgm:def:GeoPoint:bss");
    Classifier cl2 = new Classifier("sensorType", new Term(cs, "Profondeur", URI.create("urn:sensor:classifier:sensorType")));
    List<Classifier> cls = new ArrayList<Classifier>();
    cls.add(cl1);
    cls.add(cl2);
    ClassifierList claList = new ClassifierList(null, cls);
    Classification classification = new Classification(claList);
    component.setClassification(classification);
    List<Identifier> identifiers = new ArrayList<Identifier>();
    cs = new CodeSpacePropertyType("urn:x-brgm:def:sensorSystem:hydras");
    Identifier id1 = new Identifier("supervisorCode", new Term(cs, "00ARGLELES_2000", URI.create("urn:x-ogc:def:identifier:OGC:modelNumber")));
    Identifier id2 = new Identifier("longName", new Term("Madofil II", URI.create("urn:x-ogc:def:identifier:OGC:longname")));
    identifiers.add(id1);
    identifiers.add(id2);
    IdentifierList identifierList = new IdentifierList(null, identifiers);
    Identification identification = new Identification(identifierList);
    component.setIdentification(identification);
    TimePeriodType period = new TimePeriodType(new TimePositionType("2004-06-01"));
    ValidTime vTime = new ValidTime(period);
    component.setValidTime(vTime);
    Capabilities capabilities = new Capabilities();
    TimeRange timeRange = new TimeRange(Arrays.asList("1987-04-23", "now"));
    DataComponentPropertyType field = new DataComponentPropertyType("periodOfData", "urn:x-brgm:def:property:periodOfData", timeRange);
    DataRecordType record = new DataRecordType("urn:x-brgm:def:property:periodOfData", Arrays.asList(field));
    JAXBElement<? extends AbstractDataRecordType> jbRecord = swe100Factory.createDataRecord(record);
    capabilities.setAbstractDataRecord(jbRecord);
    component.setCapabilities(capabilities);
    Contact contact = new Contact("urn:x-ogc:def:role:manufacturer", new ResponsibleParty("IRIS"));
    component.setContact(contact);
    Position position = new Position("conductivitePosition", "piezometer#piezoPosition");
    component.setPosition(position);
    IoComponentPropertyType io = new IoComponentPropertyType("level", new ObservableProperty("urn:x-ogc:def:phenomenon:OGC:level"));
    InputList inputList = new InputList(Arrays.asList(io));
    Inputs inputs = new Inputs(inputList);
    component.setInputs(inputs);
    IoComponentPropertyType io2 = new IoComponentPropertyType("depth", new ObservableProperty("urn:x-ogc:def:phenomenon:OGC:depth"));
    OutputList outputList = new OutputList(Arrays.asList(io2));
    Outputs outputs = new Outputs(outputList);
    component.setOutputs(outputs);
    List<DataComponentPropertyType> params = new ArrayList<DataComponentPropertyType>();
    UomPropertyType uom = new UomPropertyType(null, "urn:ogc:unit:minuts");
    QuantityType quantity1 = new QuantityType("urn:x-ogc:def:property:frequency", uom, 60.0);
    DataComponentPropertyType p1 = new DataComponentPropertyType("frequency", "urn:x-ogc:def:property:frequency", quantity1);
    params.add(p1);
    UomPropertyType uom2 = new UomPropertyType("m", null);
    QuantityType quantity2 = new QuantityType("urn:x-ogc:def:property:precision", uom2, 0.05);
    DataComponentPropertyType p2 = new DataComponentPropertyType("precision", "urn:x-ogc:def:property:precision", quantity2);
    params.add(p2);
    QuantityRange quantityRange = new QuantityRange(uom2, Arrays.asList(0.0, 10.0));
    DataComponentPropertyType p3 = new DataComponentPropertyType("validity", "urn:x-ogc:def:property:validity", quantityRange);
    params.add(p3);
    ParameterList paramList = new ParameterList(params);
    Parameters parameters = new Parameters(paramList);
    component.setParameters(parameters);
    component.setPosition(new Position("conductivitePosition", "piezometer#piezoPosition"));
    component.setName(new DefaultIdentifier("Capteur Profondeur de ARGELES"));
    member.setProcess(sml100Factory.createComponent(component));
    SensorML expectedResult = new SensorML("1.0", Arrays.asList(member));
    assertEquals(result.getMember().size(), 1);
    assertTrue(result.getMember().get(0).getProcess() != null);
    assertTrue(result.getMember().get(0).getProcess().getValue() instanceof ComponentType);
    ComponentType resultProcess = (ComponentType) result.getMember().get(0).getProcess().getValue();
    assertEquals(resultProcess.getCapabilities(), component.getCapabilities());
    assertTrue(resultProcess.getContact().size() == 1);
    assertEquals(resultProcess.getContact().get(0).getContactList(), component.getContact().get(0).getContactList());
    assertEquals(resultProcess.getContact().get(0).getResponsibleParty().getContactInfo(), component.getContact().get(0).getResponsibleParty().getContactInfo());
    assertEquals(resultProcess.getContact().get(0).getResponsibleParty().getOrganizationName(), component.getContact().get(0).getResponsibleParty().getOrganizationName());
    assertEquals(resultProcess.getContact().get(0).getResponsibleParty(), component.getContact().get(0).getResponsibleParty());
    assertEquals(resultProcess.getContact().get(0), component.getContact().get(0));
    assertEquals(resultProcess.getContact(), component.getContact());
    assertTrue(resultProcess.getClassification().size() == 1);
    assertTrue(resultProcess.getClassification().get(0).getClassifierList().getClassifier().size() == 2);
    assertEquals(resultProcess.getClassification().get(0).getClassifierList().getClassifier().get(0).getTerm(), component.getClassification().get(0).getClassifierList().getClassifier().get(0).getTerm());
    assertEquals(resultProcess.getClassification().get(0).getClassifierList().getClassifier().get(0), component.getClassification().get(0).getClassifierList().getClassifier().get(0));
    assertEquals(resultProcess.getClassification().get(0).getClassifierList().getClassifier(), component.getClassification().get(0).getClassifierList().getClassifier());
    assertEquals(resultProcess.getClassification().get(0).getClassifierList(), component.getClassification().get(0).getClassifierList());
    assertEquals(resultProcess.getClassification().get(0), component.getClassification().get(0));
    assertEquals(resultProcess.getClassification(), component.getClassification());
    assertEquals(resultProcess.getIdentification(), component.getIdentification());
    assertEquals(resultProcess.getValidTime(), component.getValidTime());
    assertEquals(resultProcess.getParameters(), component.getParameters());
    assertEquals(resultProcess.getInputs().getInputList().getInput(), component.getInputs().getInputList().getInput());
    assertEquals(resultProcess.getInputs().getInputList(), component.getInputs().getInputList());
    assertEquals(resultProcess.getInputs(), component.getInputs());
    assertEquals(resultProcess.getOutputs(), component.getOutputs());
    assertEquals(resultProcess.getSMLLocation(), component.getSMLLocation());
    assertEquals(resultProcess.getPosition(), component.getPosition());
    assertEquals(resultProcess.getSpatialReferenceFrame(), component.getSpatialReferenceFrame());
    assertEquals(resultProcess.getDocumentation(), component.getDocumentation());
    assertEquals(resultProcess.getCharacteristics(), component.getCharacteristics());
    assertEquals(resultProcess.getKeywords(), component.getKeywords());
    assertEquals(resultProcess.getParameters(), component.getParameters());
    assertEquals(resultProcess.getName(), component.getName());
    assertEquals(resultProcess, component);
    assertEquals(expectedResult.getMember().get(0), result.getMember().get(0));
    assertEquals(expectedResult.getMember(), result.getMember());
    assertEquals(expectedResult, result);
    SensorMLMarshallerPool.getInstance().recycle(unmarshaller);
}
Also used : DataRecordType(org.geotoolkit.swe.xml.v100.DataRecordType) AbstractDataRecordType(org.geotoolkit.swe.xml.v100.AbstractDataRecordType) Keywords(org.geotoolkit.sml.xml.v100.Keywords) InputList(org.geotoolkit.sml.xml.v100.InputList) ArrayList(java.util.ArrayList) Identification(org.geotoolkit.sml.xml.v100.Identification) Classifier(org.geotoolkit.sml.xml.v100.Classifier) IdentifierList(org.geotoolkit.sml.xml.v100.IdentifierList) ValidTime(org.geotoolkit.sml.xml.v100.ValidTime) UomPropertyType(org.geotoolkit.swe.xml.v100.UomPropertyType) Identifier(org.geotoolkit.sml.xml.v100.Identifier) DefaultIdentifier(org.apache.sis.metadata.iso.DefaultIdentifier) ObservableProperty(org.geotoolkit.swe.xml.v100.ObservableProperty) Classification(org.geotoolkit.sml.xml.v100.Classification) CodeSpacePropertyType(org.geotoolkit.swe.xml.v100.CodeSpacePropertyType) DataComponentPropertyType(org.geotoolkit.swe.xml.v100.DataComponentPropertyType) DefaultIdentifier(org.apache.sis.metadata.iso.DefaultIdentifier) Unmarshaller(javax.xml.bind.Unmarshaller) Member(org.geotoolkit.sml.xml.v100.Member) Inputs(org.geotoolkit.sml.xml.v100.Inputs) TimePositionType(org.geotoolkit.gml.xml.v311.TimePositionType) ComponentType(org.geotoolkit.sml.xml.v100.ComponentType) Parameters(org.geotoolkit.sml.xml.v100.Parameters) Position(org.geotoolkit.sml.xml.v100.Position) InputStream(java.io.InputStream) ClassifierList(org.geotoolkit.sml.xml.v100.ClassifierList) QuantityRange(org.geotoolkit.swe.xml.v100.QuantityRange) JAXBElement(javax.xml.bind.JAXBElement) Term(org.geotoolkit.sml.xml.v100.Term) ResponsibleParty(org.geotoolkit.sml.xml.v100.ResponsibleParty) SensorML(org.geotoolkit.sml.xml.v100.SensorML) IoComponentPropertyType(org.geotoolkit.sml.xml.v100.IoComponentPropertyType) Contact(org.geotoolkit.sml.xml.v100.Contact) TimeRange(org.geotoolkit.swe.xml.v100.TimeRange) TimePeriodType(org.geotoolkit.gml.xml.v311.TimePeriodType) QuantityType(org.geotoolkit.swe.xml.v100.QuantityType) Capabilities(org.geotoolkit.sml.xml.v100.Capabilities) KeywordList(org.geotoolkit.sml.xml.v100.KeywordList) Outputs(org.geotoolkit.sml.xml.v100.Outputs) ParameterList(org.geotoolkit.sml.xml.v100.ParameterList) OutputList(org.geotoolkit.sml.xml.v100.OutputList)

Aggregations

BigDecimal (java.math.BigDecimal)9 QuantityType (un.unece.uncefact.data.standard.unqualifieddatatype._20.QuantityType)9 CGlobal (com.helger.commons.CGlobal)6 ValueEnforcer (com.helger.commons.ValueEnforcer)6 CollectionHelper (com.helger.commons.collection.CollectionHelper)6 EqualsHelper (com.helger.commons.equals.EqualsHelper)6 ErrorList (com.helger.commons.error.list.ErrorList)6 IErrorList (com.helger.commons.error.list.IErrorList)6 MathHelper (com.helger.commons.math.MathHelper)6 ETriState (com.helger.commons.state.ETriState)6 StringHelper (com.helger.commons.string.StringHelper)6 Serializable (java.io.Serializable)6 LocalDate (java.time.LocalDate)6 Consumer (java.util.function.Consumer)6 Nonnull (javax.annotation.Nonnull)6 Nullable (javax.annotation.Nullable)6 CrossIndustryInvoiceType (un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType)6 FormattedDateTimeType (un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType)6 un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100 (un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100)6 AmountType (un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType)6