Skip to content

Commit

Permalink
Taking over TypeCode for additional references; #18
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Dec 15, 2022
1 parent 4f4334c commit 42a952e
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ protected static IError _buildError (@Nullable final String [] aPath, final Stri
* @return <code>null</code> if the format is unknown.
*/
@Nullable
protected static String _getDatePattern (@Nonnull @Nonempty final String sFormat, @Nonnull final IErrorList aErrorList)
protected static String _getDatePattern (@Nonnull @Nonempty final String sFormat,
@Nonnull final IErrorList aErrorList)
{
ValueEnforcer.notEmpty (sFormat, "Format");
ValueEnforcer.notNull (aErrorList, "ErrorList");
Expand Down Expand Up @@ -270,7 +271,9 @@ protected static String _getDatePattern (@Nonnull @Nonempty final String sFormat
}

@Nullable
protected static LocalDate parseDate (@Nullable final String sDate, @Nullable final String sFormat, @Nonnull final IErrorList aErrorList)
protected static LocalDate parseDate (@Nullable final String sDate,
@Nullable final String sFormat,
@Nonnull final IErrorList aErrorList)
{
if (StringHelper.hasNoText (sDate))
return null;
Expand All @@ -284,7 +287,8 @@ protected static LocalDate parseDate (@Nullable final String sDate, @Nullable fi
// Try to parse it
final LocalDate aDate = PDTFromString.getLocalDateFromString (sDate, sPattern);
if (aDate == null)
aErrorList.add (_buildError (null, "Failed to parse the date '" + sDate + "' using format '" + sRealFormat + "'"));
aErrorList.add (_buildError (null,
"Failed to parse the date '" + sDate + "' using format '" + sRealFormat + "'"));

return aDate;
}
Expand Down Expand Up @@ -320,7 +324,8 @@ protected static LocalDate _parseDate (@Nullable final un.unece.uncefact.data.st
}

@Nonnull
protected static ETriState _parseIndicator (@Nullable final IndicatorType aIndicator, @Nonnull final IErrorList aErrorList)
protected static ETriState _parseIndicator (@Nullable final IndicatorType aIndicator,
@Nonnull final IErrorList aErrorList)
{
if (aIndicator == null)
return ETriState.UNDEFINED;
Expand All @@ -340,7 +345,8 @@ protected static ETriState _parseIndicator (@Nullable final IndicatorType aIndic
if ("false".equals (sIndicator))
return ETriState.FALSE;

aErrorList.add (_buildError (null, "Failed to parse the indicator value '" + aIndicator + "' to a boolean value."));
aErrorList.add (_buildError (null,
"Failed to parse the indicator value '" + aIndicator + "' to a boolean value."));
return ETriState.UNDEFINED;
}

Expand Down Expand Up @@ -492,9 +498,16 @@ protected static boolean isPaymentMeansCodeOtherKnown (@Nullable final String s)

protected static boolean isOriginatorDocumentReferenceTypeCode (@Nullable final String s)
{
// BT-17
return "50".equals (s);
}

protected static boolean isValidDocumentReferenceTypeCode (@Nullable final String s)
{
// BT-17 or BT-18
return isOriginatorDocumentReferenceTypeCode (s) || "130".equals (s);
}

protected static boolean isLT0Strict (@Nullable final BigDecimal aBD)
{
return aBD != null && MathHelper.isLT0 (aBD);
Expand All @@ -515,7 +528,8 @@ protected static boolean canUseGlobalID (@Nonnull final TradePartyType aParty)
protected static ICommonsList <IDType> getAllUsableGlobalIDs (@Nonnull final TradePartyType aParty)
{
return CommonsArrayList.createFiltered (aParty.getGlobalID (),
x -> StringHelper.hasText (x.getValue ()) && StringHelper.hasText (x.getSchemeID ()));
x -> StringHelper.hasText (x.getValue ()) &&
StringHelper.hasText (x.getSchemeID ()));
}

/**
Expand Down Expand Up @@ -663,10 +677,13 @@ protected static ETriState isInvoiceType (@Nonnull final CrossIndustryInvoiceTyp

// Check total
final SupplyChainTradeTransactionType aTransaction = aCIIInvoice.getSupplyChainTradeTransaction ();
final HeaderTradeSettlementType aSettlement = aTransaction == null ? null : aTransaction.getApplicableHeaderTradeSettlement ();
final HeaderTradeSettlementType aSettlement = aTransaction == null ? null
: aTransaction.getApplicableHeaderTradeSettlement ();
final TradeSettlementHeaderMonetarySummationType aTotal = aSettlement == null ? null
: aSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation ();
final AmountType aDuePayable = aTotal == null || aTotal.hasNoDuePayableAmountEntries () ? null : aTotal.getDuePayableAmount ().get (0);
final AmountType aDuePayable = aTotal == null ||
aTotal.hasNoDuePayableAmountEntries () ? null
: aTotal.getDuePayableAmount ().get (0);

if (eIsInvoice.isUndefined () && aDuePayable != null)
{
Expand All @@ -682,7 +699,8 @@ protected static ETriState isInvoiceType (@Nonnull final CrossIndustryInvoiceTyp
}
else
if (LOGGER.isDebugEnabled ())
LOGGER.debug ("Determined the provided CII document to be " + (eIsInvoice.isTrue () ? "an Invoice" : "a CreditNote"));
LOGGER.debug ("Determined the provided CII document to be " +
(eIsInvoice.isTrue () ? "an Invoice" : "a CreditNote"));

return eIsInvoice;
}
Expand Down Expand Up @@ -723,5 +741,6 @@ public Serializable convertCIItoUBL (@Nonnull final File aFile, @Nonnull final E
* <code>null</code> in case of error.
*/
@Nullable
public abstract Serializable convertCIItoUBL (@Nonnull CrossIndustryInvoiceType aCIIInvoice, @Nonnull ErrorList aErrorList);
public abstract Serializable convertCIItoUBL (@Nonnull CrossIndustryInvoiceType aCIIInvoice,
@Nonnull ErrorList aErrorList);
}
Loading

0 comments on commit 42a952e

Please sign in to comment.