Skip to content

Commit

Permalink
Added support to create MLR from ValidationResultList; #45
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Dec 6, 2023
1 parent 37374bd commit e6278dc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
5 changes: 5 additions & 0 deletions peppol-mlr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
<artifactId>peppol-id</artifactId>
</dependency>

<dependency>
<groupId>com.helger.phive</groupId>
<artifactId>phive-api</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Locale;
import java.util.UUID;

import javax.annotation.Nonnull;
Expand All @@ -34,6 +35,7 @@
import com.helger.commons.datetime.PDTFactory;
import com.helger.commons.string.StringHelper;
import com.helger.peppolid.IParticipantIdentifier;
import com.helger.phive.api.result.ValidationResultList;

import oasis.names.specification.ubl.schema.xsd.applicationresponse_21.ApplicationResponseType;
import oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21.DocumentReferenceType;
Expand Down Expand Up @@ -361,4 +363,39 @@ public static PeppolMLRBuilder rejection ()
_init (ret);
return ret;
}

/**
* Create a predefined Peppol MLR builder based on the validation result list.
* If the list contains no error, {@link #acceptance()} is returned else
* {@link #rejection()} with the pre-filled lines is returned. Sender,
* Receiver and Reference ID need to be set manually anyway.
*
* @param aVRL
* The Validation result list to evaluate. May not be
* <code>null</code>.
* @return A new {@link PeppolMLRBuilder} and never <code>null</code>.
*/
@Nonnull
public static PeppolMLRBuilder createForValidationResultList (@Nonnull final ValidationResultList aVRL)
{
ValueEnforcer.notNull (aVRL, "ValidationResultList");

// Overall status
final PeppolMLRBuilder aMLRBuilder = aVRL.containsNoError () ? acceptance () : rejection ();

// Add each warning/error
final Locale aDisplayLocale = Locale.US;
aVRL.forEachFlattened (aError -> {
// Single error or warning?
final PeppolMLRLineResponseBuilder aLineBuilder = aError.isError () ? PeppolMLRLineResponseBuilder.rejection ()
.statusReasonCodeBusinessRuleViolationFatal ()
: PeppolMLRLineResponseBuilder.acknowledging ()
.statusReasonCodeBusinessRuleViolationWarning ();
aMLRBuilder.addLineResponse (aLineBuilder.errorField (aError.getErrorFieldName ())
.description (StringHelper.getConcatenatedOnDemand (aError.getErrorID (),
" - ",
aError.getErrorText (aDisplayLocale))));
});
return aMLRBuilder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void testMinimalNoLine ()

if (false)
LOGGER.info (new PeppolMLRMarshaller ().setFormattedOutput (true).getAsString (aMLR));
new PeppolMLRMarshaller ().setFormattedOutput (true).write (aMLR, new File ("generated/mlr1.xml"));
if (false)
new PeppolMLRMarshaller ().setFormattedOutput (true).write (aMLR, new File ("generated/mlr1.xml"));
}

@Test
Expand All @@ -72,6 +73,7 @@ public void testMinimalWithOneLine ()

if (false)
LOGGER.info (new PeppolMLRMarshaller ().setFormattedOutput (true).getAsString (aMLR));
new PeppolMLRMarshaller ().setFormattedOutput (true).write (aMLR, new File ("generated/mlr2.xml"));
if (false)
new PeppolMLRMarshaller ().setFormattedOutput (true).write (aMLR, new File ("generated/mlr2.xml"));
}
}
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.helger.phive</groupId>
<artifactId>phive-parent-pom</artifactId>
<version>9.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>dnsjava</groupId>
Expand Down

0 comments on commit e6278dc

Please sign in to comment.