use of com.helger.en16931.cii2ubl.CIIToUBL23Converter in project en16931-cii2ubl by phax.
the class CIIToUBLConverter method call.
// doing the business
public Integer call() throws Exception {
m_sOutputDir = _normalizeOutputDirectory(m_sOutputDir);
m_aSourceFiles = _normalizeInputFiles(m_aSourceFiles);
final AbstractCIIToUBLConverter<?> aConverter;
if ("2.1".equals(m_sUBLVersion))
aConverter = new CIIToUBL21Converter();
else if ("2.2".equals(m_sUBLVersion))
aConverter = new CIIToUBL22Converter();
else if ("2.3".equals(m_sUBLVersion))
aConverter = new CIIToUBL23Converter();
else
throw new IllegalStateException("Unsupported UBL version '" + m_sUBLVersion + "' provided.");
aConverter.setUBLCreationMode(m_eMode).setVATScheme(m_sVATScheme).setCustomizationID(m_sCustomizationID).setProfileID(m_sProfileID).setCardAccountNetworkID(m_sCardAccountNetworkID);
final Locale aErrorLocale = Locale.US;
for (final File f : m_aSourceFiles) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Converting file=" + f.getAbsolutePath());
final File aDestFile = new File(m_sOutputDir, FilenameHelper.getBaseName(f) + "-ubl.xml");
// TODO switch between versions
final ErrorList aErrorList = new ErrorList();
final Serializable aUBL = aConverter.convertCIItoUBL(f, aErrorList);
if (aErrorList.containsAtLeastOneError() || aUBL == null) {
LOGGER.error("Failed to convert CII file '" + f.getAbsolutePath() + "' to UBL:");
for (final IError aError : aErrorList) LOGGER.error(aError.getAsString(aErrorLocale));
} else {
final boolean bFormattedOutput = true;
final ESuccess eSuccess;
if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType) {
eSuccess = UBL21Writer.invoice().setFormattedOutput(bFormattedOutput).write((oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType) aUBL, aDestFile);
} else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType) {
eSuccess = UBL21Writer.creditNote().setFormattedOutput(bFormattedOutput).write((oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType) aUBL, aDestFile);
} else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType) {
eSuccess = UBL22Writer.invoice().setFormattedOutput(bFormattedOutput).write((oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType) aUBL, aDestFile);
} else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) {
eSuccess = UBL22Writer.creditNote().setFormattedOutput(bFormattedOutput).write((oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) aUBL, aDestFile);
} else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_23.InvoiceType) {
eSuccess = UBL23Writer.invoice().setFormattedOutput(bFormattedOutput).write((oasis.names.specification.ubl.schema.xsd.invoice_23.InvoiceType) aUBL, aDestFile);
} else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.creditnote_23.CreditNoteType) {
eSuccess = UBL23Writer.creditNote().setFormattedOutput(bFormattedOutput).write((oasis.names.specification.ubl.schema.xsd.creditnote_23.CreditNoteType) aUBL, aDestFile);
} else
throw new IllegalStateException("Unsupported UBL version '" + m_sUBLVersion + "'");
if (eSuccess.isSuccess())
LOGGER.info("Successfully wrote UBL file " + aDestFile.getAbsolutePath());
else
LOGGER.error("Failed to write UBL file " + aDestFile.getAbsolutePath());
}
}
return Integer.valueOf(0);
}
Aggregations