use of org.incode.module.document.dom.impl.docs.DocumentAbstract in project estatio by estatio.
the class Smoke_IntegTest method can_create_postal_address.
@Test
public void can_create_postal_address() throws Exception {
// given
fixtureScripts.runFixtureScript(new DemoObjectWithNotes_and_DemoInvoice_and_docs_and_comms_recreate(), null);
transactionService.nextTransaction();
// and so given customer with an email
final DemoObjectWithNotes mary = customerMenu.findDemoObjectsWithNotesByName(DemoObjectWithNote_and_DemoInvoice_create3.MARY_HAS_PHONE_AND_POST).get(0);
final PostalAddress maryPost = (PostalAddress) linkRepository.findByOwnerAndCommunicationChannelType(mary, CommunicationChannelType.POSTAL_ADDRESS).get(0).getCommunicationChannel();
// and with an invoice
final DemoInvoice fredInvoice = invoiceRepository.findByCustomer(mary).get(0);
// that has an attached document
final Paperclip paperclip = paperclipRepository.findByAttachedTo(fredInvoice).get(0);
final DocumentAbstract document = paperclip.getDocument();
// when
final Document_sendByPost documentPrint = mixin(Document_sendByPost.class, document);
final Set<PostalAddress> postalAddresses = documentPrint.choices0Act();
// then
assertThat(postalAddresses).contains(maryPost);
// and when
final Communication comm = wrap(documentPrint).act(maryPost);
// then
assertThat(comm).isNotNull();
assertThat(comm.getState()).isEqualTo(CommunicationState.PENDING);
// same as emails
assertThat(comm.getCreatedAt()).isNotNull();
assertThat(comm.getType()).isEqualTo(CommunicationChannelType.POSTAL_ADDRESS);
assertThat(comm.getSubject()).isNotNull();
assertThat(comm.getSentAt()).isNull();
final List<CommunicationChannel> correspondentChannels = Lists.newArrayList(comm.getCorrespondents()).stream().map(CommChannelRole::getChannel).filter(Objects::nonNull).collect(Collectors.toList());
assertThat(correspondentChannels).contains(maryPost);
// when
final Communication_downloadPdfForPosting mixin = mixin(Communication_downloadPdfForPosting.class, comm);
wrap(mixin).act(mixin.default0Act());
// then
assertThat(comm.getState()).isEqualTo(CommunicationState.SENT);
assertThat(comm.getSentAt()).isNotNull();
}
use of org.incode.module.document.dom.impl.docs.DocumentAbstract in project estatio by estatio.
the class ForPrimaryDocOfInvoiceAttachToInvoiceAndAnyRelevantSupportingDocuments method doAdvise.
@Override
protected List<AttachmentAdvisor.PaperclipSpec> doAdvise(final DocumentTemplate documentTemplate, final Invoice invoice, final Document createdDocument) {
final List<PaperclipSpec> paperclipSpecs = Lists.newArrayList();
paperclipSpecs.add(new PaperclipSpec(null, invoice, createdDocument));
// not every supporting doc type supports each type of primary document
// for example, TAX_REGISTER supports invoices (but not PLs), whereas CALCULATION is other way around.
// we therefore need to filter the supporting documents that we find attached to the invoice.
//
// to start with, we get hold of the set of doc type (data)s that _do_ support the primary doc just created
DocumentTypeData primaryDocTypeData = DocumentTypeData.docTypeDataFor(createdDocument);
List<DocumentTypeData> supportingDocTypeDatasForThisPrimaryDoc = DocumentTypeData.supports(primaryDocTypeData);
// copy over all relevant supporting attached to this primary document (invoice or prelim letter)
final List<Paperclip> paperclips = paperclipRepository.findByAttachedTo(invoice);
for (Paperclip paperclip : paperclips) {
if (PaperclipRoleNames.SUPPORTING_DOCUMENT.equals(paperclip.getRoleName())) {
final DocumentAbstract supportingDocAbs = paperclip.getDocument();
if (supportingDocAbs instanceof Document) {
final Document supportingDoc = (Document) supportingDocAbs;
final DocumentTypeData supportingDocTypeData = DocumentTypeData.docTypeDataFor(supportingDoc);
// (and here is where filter out to only attach those that are relevant)
if (supportingDocTypeDatasForThisPrimaryDoc.contains(supportingDocTypeData)) {
// note that the supporting documents point to the primary doc, rather than the other way around
paperclipSpecs.add(new PaperclipSpec(PaperclipRoleNames.INVOICE_DOCUMENT_SUPPORTED_BY, createdDocument, supportingDoc));
}
}
}
}
return paperclipSpecs;
}
use of org.incode.module.document.dom.impl.docs.DocumentAbstract in project estatio by estatio.
the class InvoiceForLease_attachSupportingDocument method $$.
@Action(semantics = SemanticsOf.NON_IDEMPOTENT, commandDtoProcessor = DeriveBlobFromDummyPdfArg1.class)
@ActionLayout(contributed = Contributed.AS_ACTION, cssClassFa = "paperclip")
public Invoice $$(final DocumentType supportingDocumentType, @Parameter(fileAccept = "application/pdf") @ParameterLayout(named = "Receipt (PDF)") final Blob blob, @Parameter(optionality = Optionality.OPTIONAL) final String fileName, final String roleName) throws IOException {
//
// if appropriate, we will automatically attach the supporting doc (once created)
// to any unsent documents for this Invoice
// before we do anything, therefore, we get hold of those invoice documents.
//
DocumentTypeData supportedBy = DocumentTypeData.supportedBy(supportingDocumentType);
final List<DocumentAbstract> unsentDocuments = findUnsentDocumentsFor(invoiceForLease, supportedBy);
//
// now we create the receiptDoc, and attach to the invoice
//
String documentName = determineName(blob, fileName);
// unlike documents that are generated from a template (where we call documentTemplate#render), in this case
// we have the actual bytes; so we just set up the remaining state of the document manually.
final Document supportingDoc = documentService.createAndAttachDocumentForBlob(supportingDocumentType, this.invoiceForLease.getAtPath(), documentName, blob, PaperclipRoleNames.SUPPORTING_DOCUMENT, this.invoiceForLease);
//
for (DocumentAbstract unsentDocument : unsentDocuments) {
paperclipRepository.attach(supportingDoc, roleName, unsentDocument);
}
return this.invoiceForLease;
}
use of org.incode.module.document.dom.impl.docs.DocumentAbstract in project estatio by estatio.
the class InvoiceForLease_attachSupportingDocument method findUnsentDocumentsFor.
private List<DocumentAbstract> findUnsentDocumentsFor(final InvoiceForLease invoice, final DocumentTypeData docTypeData) {
final DocumentType documentType = docTypeData.findUsing(documentTypeRepository, queryResultsCache);
final List<DocumentAbstract> unsentDocuments = Lists.newArrayList();
final List<Paperclip> existingInvoicePaperclips = paperclipRepository.findByAttachedTo(invoice);
for (Paperclip paperclip : existingInvoicePaperclips) {
final DocumentAbstract document = paperclip.getDocument();
if (document.getType() == documentType) {
boolean sent = whetherSent(document);
if (!sent) {
unsentDocuments.add(document);
}
}
}
return unsentDocuments;
}
use of org.incode.module.document.dom.impl.docs.DocumentAbstract in project estatio by estatio.
the class InvoiceForLease_sendByPost method choices0$$.
public List<Document> choices0$$() {
final List<Paperclip> paperclips = paperclipRepository.findByAttachedTo(invoice);
final List<Document> documents = Lists.newArrayList();
for (Paperclip paperclip : paperclips) {
final DocumentAbstract documentAbs = paperclip.getDocument();
if (!(documentAbs instanceof Document)) {
continue;
}
final Document document = (Document) documentAbs;
if (document.getState() != DocumentState.RENDERED) {
continue;
}
if (!DocumentTypeData.isPrimaryType(document)) {
continue;
}
final Document_sendByPost document_sendByPost = document_sendByPost(document);
if (document_sendByPost.disableAct() != null) {
continue;
}
documents.add(document);
}
return documents;
}
Aggregations