diff --git a/peppol-mlr/pom.xml b/peppol-mlr/pom.xml
index 9d817d02..5192519a 100644
--- a/peppol-mlr/pom.xml
+++ b/peppol-mlr/pom.xml
@@ -71,6 +71,11 @@
peppol-id
+
+ com.helger.phive
+ phive-api
+
+
org.slf4j
slf4j-simple
diff --git a/peppol-mlr/src/main/java/com/helger/peppol/mlr/PeppolMLRBuilder.java b/peppol-mlr/src/main/java/com/helger/peppol/mlr/PeppolMLRBuilder.java
index f8884d81..595cba9d 100644
--- a/peppol-mlr/src/main/java/com/helger/peppol/mlr/PeppolMLRBuilder.java
+++ b/peppol-mlr/src/main/java/com/helger/peppol/mlr/PeppolMLRBuilder.java
@@ -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;
@@ -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;
@@ -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
+ * null
.
+ * @return A new {@link PeppolMLRBuilder} and never null
.
+ */
+ @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;
+ }
}
diff --git a/peppol-mlr/src/test/java/com/helger/peppol/mlr/PeppolMLRBuilderTest.java b/peppol-mlr/src/test/java/com/helger/peppol/mlr/PeppolMLRBuilderTest.java
index eb087c22..ee30a658 100644
--- a/peppol-mlr/src/test/java/com/helger/peppol/mlr/PeppolMLRBuilderTest.java
+++ b/peppol-mlr/src/test/java/com/helger/peppol/mlr/PeppolMLRBuilderTest.java
@@ -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
@@ -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"));
}
}
diff --git a/pom.xml b/pom.xml
index 71d2bf08..c8f5b88b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -124,6 +124,13 @@
pom
import
+
+ com.helger.phive
+ phive-parent-pom
+ 9.0.0
+ pom
+ import
+
dnsjava