![JAR search and dependency download from the Maven repository](/logo.png)
org.openfact.ubl.ubl21.creditnote.DefaultUBLCreditNoteCustomizator Maven / Gradle / Ivy
package org.openfact.ubl.ubl21.creditnote;
import oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType;
import org.openfact.models.DocumentModel;
import org.openfact.models.DocumentProvider;
import org.openfact.models.OrganizationModel;
import org.openfact.models.types.DocumentRequiredAction;
import org.openfact.models.types.DocumentType;
import org.openfact.models.utils.TypeToModel;
import org.openfact.provider.ProviderType;
import org.openfact.ubl.ubl21.qualifiers.UBLDocumentType;
import javax.ejb.Stateless;
import javax.inject.Inject;
@Stateless
@ProviderType("default")
@UBLDocumentType("CREDIT_NOTE")
public class DefaultUBLCreditNoteCustomizator implements UBLCreditNoteCustomizator {
@Inject
private TypeToModel typeToModel;
@Inject
private DocumentProvider documentProvider;
@Override
public void config(OrganizationModel organization, DocumentModel document, Object o) {
CreditNoteType creditNoteType;
if (o instanceof CreditNoteType) {
creditNoteType = (CreditNoteType) o;
} else {
throw new IllegalStateException("Object class " + o.getClass().getName() + " should be a children of " + CreditNoteType.class.getName());
}
typeToModel.importCreditNote(organization, document, creditNoteType);
// attach file
if (creditNoteType.getBillingReference() != null && !creditNoteType.getBillingReference().isEmpty()) {
creditNoteType.getBillingReference().stream()
.filter(p -> p.getInvoiceDocumentReference() != null)
.forEach(c -> {
String invoiceDocumentId = c.getInvoiceDocumentReference().getIDValue();
DocumentModel attachedDocument = documentProvider.getDocumentByTypeAndDocumentId(DocumentType.INVOICE, invoiceDocumentId, organization);
if (attachedDocument != null) {
document.addAttachedDocument(attachedDocument);
}
});
}
}
@Override
public DocumentRequiredAction[] getRequiredActions() {
return new DocumentRequiredAction[]{DocumentRequiredAction.SEND_TO_CUSTOMER, DocumentRequiredAction.SEND_TO_THIRD_PARTY};
}
@Override
public String[] getExtraRequiredActions() {
return new String[0];
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy