Skip to content

Commit

Permalink
Improved identifier value check API to be scheme dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Nov 22, 2023
1 parent 002b6e5 commit 9c03379
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 108 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,9 @@ They depend on several other libraries so I suggest you are going for the Maven
* v9.1.1 - 2023-11-22
* Added the "peppol-directory-businesscard" to the known submodules in the BOM part of pom.xml
* Updated to OpenPeppol eDEC Code Lists v8.7
* Improved the Peppol Document Type Identifier value syntax checks
* Improved the Peppol Process Identifier value syntax checks
* Improved the Peppol Document Type Identifier value syntax checks - for `busdox-docid-qns` and for `peppol-doctype-wildcard`
* Improved the Peppol Process Identifier value syntax checks
* Identifier value checks can now be different per identifier scheme
* v9.1.0 - 2023-11-09
* Added new submodule `peppol-directory-businesscard`. It is meant to replace the `phoss-directory-businesscard` one.
* v9.0.8 - 2023-08-22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,20 @@ public boolean isDocumentTypeIdentifierSchemeValid (@Nullable final String sSche
}

@Override
public boolean isDocumentTypeIdentifierValueValid (@Nullable final String sValue)
public boolean isDocumentTypeIdentifierValueValid (@Nullable final String sScheme, @Nullable final String sValue)
{
return BDXR1IdentifierHelper.isValidIdentifierValue (sValue);
}

@Nullable
public BDXR1DocumentTypeIdentifier createDocumentTypeIdentifier (@Nullable final String sScheme, @Nullable final String sValue)
public BDXR1DocumentTypeIdentifier createDocumentTypeIdentifier (@Nullable final String sScheme,
@Nullable final String sValue)
{
final String sRealScheme = nullNotEmpty (sScheme);
final String sRealValue = nullNotEmpty (isDocumentTypeIdentifierCaseInsensitive (sRealScheme) ? getUnifiedValue (sValue) : sValue);
if (isDocumentTypeIdentifierSchemeValid (sRealScheme) && isDocumentTypeIdentifierValueValid (sRealValue))
final String sRealValue = nullNotEmpty (isDocumentTypeIdentifierCaseInsensitive (sRealScheme) ? getUnifiedValue (sValue)
: sValue);
if (isDocumentTypeIdentifierSchemeValid (sRealScheme) &&
isDocumentTypeIdentifierValueValid (sRealScheme, sRealValue))
return new BDXR1DocumentTypeIdentifier (sRealScheme, sRealValue);
return null;
}
Expand All @@ -91,17 +94,19 @@ public boolean isParticipantIdentifierSchemeValid (@Nullable final String sSchem
}

@Override
public boolean isParticipantIdentifierValueValid (@Nullable final String sValue)
public boolean isParticipantIdentifierValueValid (@Nullable final String sScheme, @Nullable final String sValue)
{
return BDXR1IdentifierHelper.isValidIdentifierValue (sValue);
}

@Nullable
public BDXR1ParticipantIdentifier createParticipantIdentifier (@Nullable final String sScheme, @Nullable final String sValue)
public BDXR1ParticipantIdentifier createParticipantIdentifier (@Nullable final String sScheme,
@Nullable final String sValue)
{
final String sRealScheme = nullNotEmpty (sScheme);
final String sRealValue = nullNotEmpty (isParticipantIdentifierCaseInsensitive (sRealScheme) ? getUnifiedValue (sValue) : sValue);
if (isParticipantIdentifierSchemeValid (sRealScheme) && isParticipantIdentifierValueValid (sRealValue))
final String sRealValue = nullNotEmpty (isParticipantIdentifierCaseInsensitive (sRealScheme) ? getUnifiedValue (sValue)
: sValue);
if (isParticipantIdentifierSchemeValid (sRealScheme) && isParticipantIdentifierValueValid (sRealScheme, sRealValue))
return new BDXR1ParticipantIdentifier (sRealScheme, sRealValue);
return null;
}
Expand All @@ -120,7 +125,7 @@ public boolean isProcessIdentifierCaseInsensitive (@Nullable final String sSchem
}

@Override
public boolean isProcessIdentifierValueValid (final String sValue)
public boolean isProcessIdentifierValueValid (@Nullable final String sScheme, @Nullable final String sValue)
{
return BDXR1IdentifierHelper.isValidIdentifierValue (sValue);
}
Expand All @@ -129,9 +134,10 @@ public boolean isProcessIdentifierValueValid (final String sValue)
public BDXR1ProcessIdentifier createProcessIdentifier (@Nullable final String sScheme, @Nullable final String sValue)
{
final String sRealScheme = nullNotEmpty (sScheme);
final String sRealValue = nullNotEmpty (isProcessIdentifierCaseInsensitive (sRealScheme) ? getUnifiedValue (sValue) : sValue);
final String sRealValue = nullNotEmpty (isProcessIdentifierCaseInsensitive (sRealScheme) ? getUnifiedValue (sValue)
: sValue);

if (isProcessIdentifierSchemeValid (sRealScheme) && isProcessIdentifierValueValid (sRealValue))
if (isProcessIdentifierSchemeValid (sRealScheme) && isProcessIdentifierValueValid (sRealScheme, sRealValue))
return new BDXR1ProcessIdentifier (sRealScheme, sRealValue);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,20 @@ public boolean isDocumentTypeIdentifierSchemeValid (@Nullable final String sSche
}

@Override
public boolean isDocumentTypeIdentifierValueValid (@Nullable final String sValue)
public boolean isDocumentTypeIdentifierValueValid (@Nullable final String sScheme, @Nullable final String sValue)
{
return BDXR2IdentifierHelper.isValidIdentifierValue (sValue);
}

@Nullable
public BDXR2DocumentTypeIdentifier createDocumentTypeIdentifier (@Nullable final String sScheme, @Nullable final String sValue)
public BDXR2DocumentTypeIdentifier createDocumentTypeIdentifier (@Nullable final String sScheme,
@Nullable final String sValue)
{
final String sRealScheme = nullNotEmpty (sScheme);
final String sRealValue = nullNotEmpty (isDocumentTypeIdentifierCaseInsensitive (sRealScheme) ? getUnifiedValue (sValue) : sValue);
if (isDocumentTypeIdentifierSchemeValid (sRealScheme) && isDocumentTypeIdentifierValueValid (sRealValue))
final String sRealValue = nullNotEmpty (isDocumentTypeIdentifierCaseInsensitive (sRealScheme) ? getUnifiedValue (sValue)
: sValue);
if (isDocumentTypeIdentifierSchemeValid (sRealScheme) &&
isDocumentTypeIdentifierValueValid (sRealScheme, sRealValue))
return new BDXR2DocumentTypeIdentifier (sRealScheme, sRealValue);
return null;
}
Expand All @@ -91,17 +94,19 @@ public boolean isParticipantIdentifierSchemeValid (@Nullable final String sSchem
}

@Override
public boolean isParticipantIdentifierValueValid (@Nullable final String sValue)
public boolean isParticipantIdentifierValueValid (@Nullable final String sScheme, @Nullable final String sValue)
{
return BDXR2IdentifierHelper.isValidIdentifierValue (sValue);
}

@Nullable
public BDXR2ParticipantIdentifier createParticipantIdentifier (@Nullable final String sScheme, @Nullable final String sValue)
public BDXR2ParticipantIdentifier createParticipantIdentifier (@Nullable final String sScheme,
@Nullable final String sValue)
{
final String sRealScheme = nullNotEmpty (sScheme);
final String sRealValue = nullNotEmpty (isParticipantIdentifierCaseInsensitive (sRealScheme) ? getUnifiedValue (sValue) : sValue);
if (isParticipantIdentifierSchemeValid (sRealScheme) && isParticipantIdentifierValueValid (sRealValue))
final String sRealValue = nullNotEmpty (isParticipantIdentifierCaseInsensitive (sRealScheme) ? getUnifiedValue (sValue)
: sValue);
if (isParticipantIdentifierSchemeValid (sRealScheme) && isParticipantIdentifierValueValid (sRealScheme, sRealValue))
return new BDXR2ParticipantIdentifier (sRealScheme, sRealValue);
return null;
}
Expand All @@ -120,7 +125,7 @@ public boolean isProcessIdentifierCaseInsensitive (@Nullable final String sSchem
}

@Override
public boolean isProcessIdentifierValueValid (final String sValue)
public boolean isProcessIdentifierValueValid (@Nullable final String sScheme, @Nullable final String sValue)
{
return BDXR2IdentifierHelper.isValidIdentifierValue (sValue);
}
Expand All @@ -129,9 +134,10 @@ public boolean isProcessIdentifierValueValid (final String sValue)
public BDXR2ProcessIdentifier createProcessIdentifier (@Nullable final String sScheme, @Nullable final String sValue)
{
final String sRealScheme = nullNotEmpty (sScheme);
final String sRealValue = nullNotEmpty (isProcessIdentifierCaseInsensitive (sRealScheme) ? getUnifiedValue (sValue) : sValue);
final String sRealValue = nullNotEmpty (isProcessIdentifierCaseInsensitive (sRealScheme) ? getUnifiedValue (sValue)
: sValue);

if (isProcessIdentifierSchemeValid (sRealScheme) && isProcessIdentifierValueValid (sRealValue))
if (isProcessIdentifierSchemeValid (sRealScheme) && isProcessIdentifierValueValid (sRealScheme, sRealValue))
return new BDXR2ProcessIdentifier (sRealScheme, sRealValue);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,26 @@ default boolean isDocumentTypeIdentifierSchemeValid (@Nullable final String sSch
* @return <code>true</code> if the document type identifier value is valid,
* <code>false</code> otherwise
*/
@Deprecated (forRemoval = true, since = "9.1.1")
default boolean isDocumentTypeIdentifierValueValid (@Nullable final String sValue)
{
return isDocumentTypeIdentifierValueValid (null, sValue);
}

/**
* Check if the passed document type identifier value is valid for the
* provided scheme.
*
* @param sScheme
* The document type identifier scheme of the value to be checked.
* @param sValue
* The document type identifier value to be checked (without the
* scheme). May be <code>null</code>.
* @return <code>true</code> if the document type identifier value is valid
* for the provided scheme, <code>false</code> otherwise
* @since 9.1.1
*/
default boolean isDocumentTypeIdentifierValueValid (@Nullable final String sScheme, @Nullable final String sValue)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,26 @@ default boolean isParticipantIdentifierSchemeValid (@Nullable final String sSche
* @return <code>true</code> if the participant identifier value is valid,
* <code>false</code> otherwise.
*/
@Deprecated (forRemoval = true, since = "9.1.1")
default boolean isParticipantIdentifierValueValid (@Nullable final String sValue)
{
return isParticipantIdentifierValueValid (null, sValue);
}

/**
* Check if the passed participant identifier value is valid.
*
* @param sScheme
* The scheme of the participant identifier value to be checked. May be
* <code>null</code>.
* @param sValue
* The participant identifier value to be checked (without the scheme).
* May be <code>null</code>.
* @return <code>true</code> if the participant identifier value is valid,
* <code>false</code> otherwise.
* @since 9.1.1
*/
default boolean isParticipantIdentifierValueValid (@Nullable final String sScheme, @Nullable final String sValue)
{
return true;
}
Expand Down Expand Up @@ -158,6 +177,7 @@ default IParticipantIdentifier parseParticipantIdentifier (@Nullable final Strin
@Nullable
default IParticipantIdentifier getClone (@Nullable final IParticipantIdentifier aParticipantID)
{
return aParticipantID == null ? null : createParticipantIdentifier (aParticipantID.getScheme (), aParticipantID.getValue ());
return aParticipantID == null ? null : createParticipantIdentifier (aParticipantID.getScheme (),
aParticipantID.getValue ());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,31 @@ default boolean isProcessIdentifierSchemeValid (@Nullable final String sScheme)
* Check if the passed process identifier value is valid.
*
* @param sValue
* The document type identifier value to be checked (without the
* scheme). May be <code>null</code>.
* @return <code>true</code> if the document type identifier value is valid,
* The process identifier value to be checked (without the scheme). May
* be <code>null</code>.
* @return <code>true</code> if the process identifier value is valid,
* <code>false</code> otherwise
*/
@Deprecated (forRemoval = true, since = "9.1.1")
default boolean isProcessIdentifierValueValid (@Nullable final String sValue)
{
return isProcessIdentifierValueValid (null, sValue);
}

/**
* Check if the passed process identifier value is valid.
*
* @param sScheme
* The process identifier scheme of the value to be checked. May be
* <code>null</code>.
* @param sValue
* The process identifier value to be checked (without the scheme). May
* be <code>null</code>.
* @return <code>true</code> if the process identifier value is valid,
* <code>false</code> otherwise
* @since 9.1.1
*/
default boolean isProcessIdentifierValueValid (@Nullable final String sScheme, @Nullable final String sValue)
{
return true;
}
Expand Down
Loading

0 comments on commit 9c03379

Please sign in to comment.