UBL22InvoiceHelper { public static void cloneInvoiceToCreditNote (@Nonnull final InvoiceType aSrc, @Nonnull final CreditNoteType aDst) { aDst.setAccountingCost (aSrc.getAccountingCost () == null ? null : aSrc.getAccountingCost ().clone ()); aDst.setAccountingCostCode (aSrc.getAccountingCostCode () == null ? null : aSrc.getAccountingCostCode ().clone ()); aDst.setAccountingCustomerParty (aSrc.getAccountingCustomerParty () == null ? null : aSrc.getAccountingCustomerParty ().clone ()); aDst.setAccountingSupplierParty (aSrc.getAccountingSupplierParty () == null ? null : aSrc.getAccountingSupplierParty ().clone ()); { final List <DocumentReferenceType> retAdditionalDocumentReference = new ArrayList <> (); for (final DocumentReferenceType aItem : aSrc.getAdditionalDocumentReference ()) retAdditionalDocumentReference.add (aItem == null ? null : aItem.clone ()); aDst.setAdditionalDocumentReference (retAdditionalDocumentReference); } { final List <AllowanceChargeType> retAllowanceCharge = new ArrayList <> (); for (final AllowanceChargeType aItem : aSrc.getAllowanceCharge ()) retAllowanceCharge.add (aItem == null ? null : aItem.clone ()); aDst.setAllowanceCharge (retAllowanceCharge); } { final List <BillingReferenceType> retBillingReference = new ArrayList <> (); for (final BillingReferenceType aItem : aSrc.getBillingReference ()) retBillingReference.add (aItem == null ? null : aItem.clone ()); aDst.setBillingReference (retBillingReference); } aDst.setBuyerCustomerParty (aSrc.getBuyerCustomerParty () == null ? null : aSrc.getBuyerCustomerParty ().clone ()); aDst.setBuyerReference (aSrc.getBuyerReference () == null ? null : aSrc.getBuyerReference ().clone ()); { final List <DocumentReferenceType> retContractDocumentReference = new ArrayList <> (); for (final DocumentReferenceType aItem : aSrc.getContractDocumentReference ()) retContractDocumentReference.add (aItem == null ? null : aItem.clone ()); aDst.setContractDocumentReference (retContractDocumentReference); } aDst.setCopyIndicator (aSrc.getCopyIndicator () == null ? null : aSrc.getCopyIndicator ().clone ()); aDst.setCustomizationID (aSrc.getCustomizationID () == null ? null : aSrc.getCustomizationID ().clone ()); { final List <DeliveryType> retDelivery = new ArrayList <> (); for (final DeliveryType aItem : aSrc.getDelivery ()) retDelivery.add (aItem == null ? null : aItem.clone ()); aDst.setDelivery (retDelivery); } aDst.setDeliveryTerms (aSrc.getDeliveryTerms () == null ? null : new CommonsArrayList <> (aSrc.getDeliveryTerms ().clone ())); { final List <DocumentReferenceType> retDespatchDocumentReference = new ArrayList <> (); for (final DocumentReferenceType aItem : aSrc.getDespatchDocumentReference ()) retDespatchDocumentReference.add (aItem == null ? null : aItem.clone ()); aDst.setDespatchDocumentReference (retDespatchDocumentReference); } aDst.setDocumentCurrencyCode (aSrc.getDocumentCurrencyCode () == null ? null : aSrc.getDocumentCurrencyCode ().clone ()); aDst.setDueDate (aSrc.getDueDate () == null ? null : aSrc.getDueDate ().clone ()); aDst.setID (aSrc.getID () == null ? null : aSrc.getID ().clone ()); { final List <CreditNoteLineType> retInvoiceLine = new ArrayList <> (); for (final InvoiceLineType aItem : aSrc.getInvoiceLine ()) if (aItem == null) retInvoiceLine.add (null); else { final CreditNoteLineType aNewLine = new CreditNoteLineType (); cloneToCreditNoteLine (aItem, aNewLine); retInvoiceLine.add (aNewLine); } aDst.setCreditNoteLine (retInvoiceLine); } { final List <PeriodType> retInvoicePeriod = new ArrayList <> (); for (final PeriodType aItem : aSrc.getInvoicePeriod ()) retInvoicePeriod.add (aItem == null ? null : aItem.clone ()); aDst.setInvoicePeriod (retInvoicePeriod); } aDst.setCreditNoteTypeCode (cloneToCreditNoteTypeCode (aSrc.getInvoiceTypeCode ())); aDst.setIssueDate (aSrc.getIssueDate () == null ? null : aSrc.getIssueDate ().clone ()); aDst.setIssueTime (aSrc.getIssueTime () == null ? null : aSrc.getIssueTime ().clone ()); aDst.setLegalMonetaryTotal (aSrc.getLegalMonetaryTotal () == null ? null : aSrc.getLegalMonetaryTotal ().clone ()); aDst.setLineCountNumeric (aSrc.getLineCountNumeric () == null ? null : aSrc.getLineCountNumeric ().clone ()); { final List <NoteType> retNote = new ArrayList <> (); for (final NoteType aItem : aSrc.getNote ()) retNote.add (aItem == null ? null : aItem.clone ()); aDst.setNote (retNote); } aDst.setOrderReference (aSrc.getOrderReference () == null ? null : aSrc.getOrderReference ().clone ()); { final List <DocumentReferenceType> retOriginatorDocumentReference = new ArrayList <> (); for (final DocumentReferenceType aItem : aSrc.getOriginatorDocumentReference ()) retOriginatorDocumentReference.add (aItem == null ? null : aItem.clone ()); aDst.setOriginatorDocumentReference (retOriginatorDocumentReference); } aDst.setPayeeParty (aSrc.getPayeeParty () == null ? null : aSrc.getPayeeParty ().clone ()); aDst.setPaymentAlternativeCurrencyCode (aSrc.getPaymentAlternativeCurrencyCode () == null ? null : aSrc.getPaymentAlternativeCurrencyCode () .clone ()); aDst.setPaymentAlternativeExchangeRate (aSrc.getPaymentAlternativeExchangeRate () == null ? null : aSrc.getPaymentAlternativeExchangeRate () .clone ()); aDst.setPaymentCurrencyCode (aSrc.getPaymentCurrencyCode () == null ? null : aSrc.getPaymentCurrencyCode ().clone ()); aDst.setPaymentExchangeRate (aSrc.getPaymentExchangeRate () == null ? null : aSrc.getPaymentExchangeRate ().clone ()); { final List <PaymentMeansType> retPaymentMeans = new ArrayList <> (); for (final PaymentMeansType aItem : aSrc.getPaymentMeans ()) retPaymentMeans.add (aItem == null ? null : aItem.clone ()); aDst.setPaymentMeans (retPaymentMeans); } { final List <PaymentTermsType> retPaymentTerms = new ArrayList <> (); for (final PaymentTermsType aItem : aSrc.getPaymentTerms ()) retPaymentTerms.add (aItem == null ? null : aItem.clone ()); aDst.setPaymentTerms (retPaymentTerms); } aDst.setPricingCurrencyCode (aSrc.getPricingCurrencyCode () == null ? null : aSrc.getPricingCurrencyCode ().clone ()); aDst.setPricingExchangeRate (aSrc.getPricingExchangeRate () == null ? null : aSrc.getPricingExchangeRate ().clone ()); aDst.setProfileExecutionID (aSrc.getProfileExecutionID () == null ? null : aSrc.getProfileExecutionID ().clone ()); aDst.setProfileID (aSrc.getProfileID () == null ? null : aSrc.getProfileID ().clone ()); { final List <ProjectReferenceType> retProjectReference = new ArrayList <> (); for (final ProjectReferenceType aItem : aSrc.getProjectReference ()) retProjectReference.add (aItem == null ? null : aItem.clone ()); aDst.setProjectReference (retProjectReference); } { final List <DocumentReferenceType> retReceiptDocumentReference = new ArrayList <> (); for (final DocumentReferenceType aItem : aSrc.getReceiptDocumentReference ()) retReceiptDocumentReference.add (aItem == null ? null : aItem.clone ()); aDst.setReceiptDocumentReference (retReceiptDocumentReference); } aDst.setSellerSupplierParty (aSrc.getSellerSupplierParty () == null ? null : aSrc.getSellerSupplierParty ().clone ()); { final List <SignatureType> retSignature = new ArrayList <> (); for (final SignatureType aItem : aSrc.getSignature ()) retSignature.add (aItem == null ? null : aItem.clone ()); aDst.setSignature (retSignature); } { final List <DocumentReferenceType> retStatementDocument = new ArrayList <> (); for (final DocumentReferenceType aItem : aSrc.getStatementDocumentReference ()) retStatementDocument.add (aItem == null ? null : aItem.clone ()); aDst.setStatementDocumentReference (retStatementDocument); } aDst.setTaxCurrencyCode (aSrc.getTaxCurrencyCode () == null ? null : aSrc.getTaxCurrencyCode ().clone ()); aDst.setTaxExchangeRate (aSrc.getTaxExchangeRate () == null ? null : aSrc.getTaxExchangeRate ().clone ()); aDst.setTaxPointDate (aSrc.getTaxPointDate () == null ? null : aSrc.getTaxPointDate ().clone ()); aDst.setTaxRepresentativeParty (aSrc.getTaxRepresentativeParty () == null ? null : aSrc.getTaxRepresentativeParty ().clone ()); { final List <TaxTotalType> retTaxTotal = new ArrayList <> (); for (final TaxTotalType aItem : aSrc.getTaxTotal ()) retTaxTotal.add (aItem == null ? null : aItem.clone ()); aDst.setTaxTotal (retTaxTotal); } aDst.setUBLExtensions (aSrc.getUBLExtensions () == null ? null : aSrc.getUBLExtensions ().clone ()); aDst.setUBLVersionID (aSrc.getUBLVersionID () == null ? null : aSrc.getUBLVersionID ().clone ()); aDst.setUUID (aSrc.getUUID () == null ? null : aSrc.getUUID ().clone ()); { final List <TaxTotalType> retWithholdingTaxTotal = new ArrayList <> (); for (final TaxTotalType aItem : aSrc.getWithholdingTaxTotal ()) retWithholdingTaxTotal.add (aItem == null ? null : aItem.clone ()); aDst.setWithholdingTaxTotal (retWithholdingTaxTotal); } } private  UBL22InvoiceHelper(); @Nonnull static CreditedQuantityType cloneToCreditedQuantity(@Nonnull final InvoicedQuantityType aSrc); @Nullable static CreditNoteTypeCodeType cloneToCreditNoteTypeCode(@Nullable final InvoiceTypeCodeType aSrc); static void cloneToCreditNoteLine(@Nonnull final InvoiceLineType aSrc, @Nonnull final CreditNoteLineType aDst); static void cloneInvoiceToCreditNote(@Nonnull final InvoiceType aSrc, @Nonnull final CreditNoteType aDst);  }
@Test public void testComvertBackAndForth () { for (final String sFilename : MockUBL22TestDocuments.getUBL22TestDocuments (EUBL22DocumentType.INVOICE)) { LOGGER.info (sFilename); final Document aDoc = DOMReader.readXMLDOM (new ClassPathResource (sFilename), new DOMReaderSettings ().setSchema (EUBL22DocumentType.INVOICE.getSchema ())); assertNotNull (sFilename, aDoc); final InvoiceType aUBLObject = UBL22Reader.invoice ().read (aDoc); assertNotNull (sFilename, aUBLObject); final CreditNoteType aCreditNote = new CreditNoteType (); UBL22InvoiceHelper.cloneInvoiceToCreditNote (aUBLObject, aCreditNote); IErrorList aErrors = UBL22Validator.creditNote ().validate (aCreditNote); assertNotNull (sFilename, aErrors); assertFalse (sFilename, aErrors.containsAtLeastOneError ()); final InvoiceType aInvoice2 = new InvoiceType (); UBL22CreditNoteHelper.cloneCreditNoteToInvoice (aCreditNote, aInvoice2); aErrors = UBL22Validator.invoice ().validate (aInvoice2); assertNotNull (sFilename, aErrors); assertFalse (sFilename, aErrors.containsAtLeastOneError ()); } }