use of org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition in project estatio by estatio.
the class TaskIncomingDocumentPdfService method doLookupPdfFor.
private Blob doLookupPdfFor(final Task task) {
StateTransition<?, ?, ?, ?> stateTransition = stateTransitionService.findFor(task);
if (stateTransition == null) {
return null;
}
if (stateTransition instanceof IncomingDocumentCategorisationStateTransition) {
IncomingDocumentCategorisationStateTransition idcst = (IncomingDocumentCategorisationStateTransition) stateTransition;
final Document document = idcst.getDocument();
if (document == null) {
return null;
}
if (!Objects.equals(document.getMimeType(), "application/pdf")) {
return null;
}
return document.getBlob();
}
if (stateTransition instanceof OrderApprovalStateTransition) {
final OrderApprovalStateTransition oast = (OrderApprovalStateTransition) stateTransition;
final Order order = oast.getOrdr();
final Optional<Document> documentIfAny = lookupAttachedPdfService.lookupOrderPdfFrom(order);
return documentIfAny.map(DocumentAbstract::getBlob).orElse(null);
}
if (stateTransition instanceof IncomingInvoiceApprovalStateTransition) {
final IncomingInvoiceApprovalStateTransition iiast = (IncomingInvoiceApprovalStateTransition) stateTransition;
final IncomingInvoice invoice = iiast.getInvoice();
final Optional<Document> documentIfAny = lookupAttachedPdfService.lookupIncomingInvoicePdfFrom(invoice);
return documentIfAny.map(DocumentAbstract::getBlob).orElse(null);
}
if (stateTransition instanceof BankAccountVerificationStateTransition) {
final BankAccountVerificationStateTransition bavst = (BankAccountVerificationStateTransition) stateTransition;
final BankAccount bankAccount = bavst.getBankAccount();
final Optional<Document> documentIfAny = lookupAttachedPdfService.lookupIbanProofPdfFrom(bankAccount);
return documentIfAny.map(DocumentAbstract::getBlob).orElse(null);
}
return null;
}
use of org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition in project estatio by estatio.
the class IncomingDocViewModel_viewTask method pendingTask.
private Object pendingTask() {
final Document document = viewModel.getDocument();
final IncomingDocumentCategorisationStateTransition pendingTransition = repository.findByDomainObjectAndCompleted(document, false);
return pendingTransition != null ? pendingTransition.getTask() : null;
}
use of org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition in project estatio by estatio.
the class Order_2_IntegTest method orderFixtureLoadedProperly.
@Test
public void orderFixtureLoadedProperly() throws Exception {
assertThat(orderRepository.listAll().size()).isEqualTo(1);
List<Document> unclassifiedIncomingOrders = incomingDocumentRepository.findUnclassifiedIncomingOrders();
assertThat(unclassifiedIncomingOrders.size()).isEqualTo(0);
final String documentName = Order_enum.fakeOrder2Pdf.getDocument_d().findUsing(serviceRegistry).getName();
Document document = incomingDocumentRepository.findAllIncomingDocumentsByName(documentName).get(0);
List<IncomingDocumentCategorisationStateTransition> transitions = mixin(Document_categorisationTransitions.class, document).coll();
assertThat(transitions.size()).isEqualTo(2);
}
use of org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition in project estatio by estatio.
the class DocumentMenu_Upload_IntegTest method happy_case.
@Test
public void happy_case() throws Exception {
// given
List<Document> incomingDocumentsBefore = repository.findIncomingDocuments();
assertThat(incomingDocumentsBefore).isEmpty();
// when
final String fileName = "1020100123.pdf";
final byte[] pdfBytes = Resources.toByteArray(Resources.getResource(DocumentMenu_Upload_IntegTest.class, fileName));
final Blob blob = new Blob(fileName, "application/pdf", pdfBytes);
wrap(documentMenu).upload(blob);
transactionService.nextTransaction();
// then
List<Document> incomingDocumentsAfter = repository.findAllIncomingDocuments();
assertThat(incomingDocumentsAfter).hasSize(1);
final Document document = incomingDocumentsAfter.get(0);
final Blob documentBlob = document.getBlob();
assertThat(documentBlob.getName()).isEqualTo(blob.getName());
assertThat(documentBlob.getMimeType().getBaseType()).isEqualTo(blob.getMimeType().getBaseType());
assertThat(documentBlob.getBytes()).isEqualTo(blob.getBytes());
assertThat(JDOHelper.getVersion(document)).isEqualTo(1L);
assertThat(paperclipRepository.findByDocument(document).size()).isEqualTo(0);
// and then also
final List<IncomingDocumentCategorisationStateTransition> transitions = stateTransitionRepository.findByDomainObject(document);
assertThat(transitions).hasSize(2);
assertTransition(transitions.get(0), NEW, CATEGORISE, null);
assertTransition(transitions.get(1), null, INSTANTIATE, NEW);
// and when
final String fileName2 = "1020100123-altered.pdf";
final byte[] pdfBytes2 = Resources.toByteArray(Resources.getResource(DocumentMenu_Upload_IntegTest.class, fileName2));
final Blob similarNamedBlob = new Blob(fileName, "application/pdf", pdfBytes2);
wrap(documentMenu).upload(similarNamedBlob);
transactionService.nextTransaction();
// then
incomingDocumentsAfter = repository.findAllIncomingDocuments();
assertThat(incomingDocumentsAfter).hasSize(2);
assertThat(incomingDocumentsAfter.get(0).getName()).isEqualTo(fileName);
assertThat(incomingDocumentsAfter.get(0).getBlobBytes()).isEqualTo(similarNamedBlob.getBytes());
assertThat(JDOHelper.getVersion(incomingDocumentsAfter.get(0))).isEqualTo(2L);
assertThat(paperclipRepository.findByDocument(incomingDocumentsAfter.get(0)).size()).isEqualTo(1);
// has prefix arch-[date time indication]-
assertThat(incomingDocumentsAfter.get(1).getName()).contains(fileName);
assertThat(incomingDocumentsAfter.get(1).getBlobBytes()).isEqualTo(documentBlob.getBytes());
assertThat(JDOHelper.getVersion(incomingDocumentsAfter.get(1))).isEqualTo(1L);
assertThat(paperclipRepository.findByDocument(incomingDocumentsAfter.get(1)).size()).isEqualTo(0);
}
Aggregations