use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class PartySubscriptionsForOrders method on.
@Programmatic
@com.google.common.eventbus.Subscribe
@org.axonframework.eventhandling.annotation.EventHandler
public void on(final Party.DeleteEvent ev) {
Party sourceParty = (Party) ev.getSource();
Party replacementParty = ev.getReplacement();
switch(ev.getEventPhase()) {
case VALIDATE:
if (replacementParty == null && orderRepository.findBySellerParty(sourceParty).size() > 0) {
ev.invalidate("Party is in use as seller in an order. Provide replacement");
}
break;
case EXECUTING:
if (replacementParty != null) {
for (Order order : orderRepository.findBySellerParty(sourceParty)) {
order.setSeller(replacementParty);
}
}
break;
default:
break;
}
}
use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class RunBackgroundCommandsService method runBackgroundCommands.
@Programmatic
public void runBackgroundCommands() throws InterruptedException {
List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
assertThat(commands).hasSize(1);
transactionService.nextTransaction();
BackgroundCommandExecutionFromBackgroundCommandServiceJdo backgroundExec = new BackgroundCommandExecutionFromBackgroundCommandServiceJdo();
final SimpleSession session = new SimpleSession("scheduler_user", new String[] { "admin_role" });
final Thread thread = new Thread(() -> backgroundExec.execute(session, null));
thread.start();
thread.join(5000L);
commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
assertThat(commands).isEmpty();
}
use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class IncomingDocAsInvoiceViewModel method init.
@Programmatic
public void init() {
IncomingInvoice incomingInvoice = getDomainObject();
setIncomingInvoiceType(incomingInvoice.getType());
setInvoiceNumber(incomingInvoice.getInvoiceNumber());
setBuyer(incomingInvoice.getBuyer());
setSeller(incomingInvoice.getSeller());
setInvoiceDate(incomingInvoice.getInvoiceDate());
setDueDate(incomingInvoice.getDueDate());
setPaymentMethod(incomingInvoice.getPaymentMethod());
setDateReceived(incomingInvoice.getDateReceived());
setBankAccount(incomingInvoice.getBankAccount());
setCurrency(incomingInvoice.getCurrency());
final Optional<IncomingInvoiceItem> firstItemIfAny = getFirstItemIfAny();
if (firstItemIfAny.isPresent()) {
IncomingInvoiceItem invoiceItem = firstItemIfAny.get();
setCharge(invoiceItem.getCharge());
setDescription(invoiceItem.getDescription());
setNetAmount(invoiceItem.getNetAmount());
setVatAmount(invoiceItem.getVatAmount());
setGrossAmount(invoiceItem.getGrossAmount());
setTax(invoiceItem.getTax());
setDueDate(invoiceItem.getDueDate());
setPeriod(periodFrom(invoiceItem.getStartDate(), invoiceItem.getEndDate()));
setProperty((org.estatio.module.asset.dom.Property) invoiceItem.getFixedAsset());
setProject(invoiceItem.getProject());
setBudgetItem(invoiceItem.getBudgetItem());
final Optional<OrderItemInvoiceItemLink> linkIfAny = orderItemInvoiceItemLinkRepository.findByInvoiceItem(invoiceItem);
linkIfAny.ifPresent(link -> {
final OrderItem linkOrderItem = link.getOrderItem();
IncomingDocAsInvoiceViewModel.this.setOrderItem(linkOrderItem);
});
} else {
// for the first time we edit there will be no first item,
// so we instead get the property from the header invoice
setProperty(incomingInvoice.getProperty());
}
}
use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class DebtorBankAccountService method uniqueDebtorAccountToPay.
@Programmatic
public BankAccount uniqueDebtorAccountToPay(final IncomingInvoice invoice) {
final Party buyer = invoice.getBuyer();
List<BankAccount> bankAccountsForBuyer = bankAccountRepository.findBankAccountsByOwner(buyer);
final Property propertyIfAny = invoice.getProperty();
if (propertyIfAny != null) {
List<FixedAssetFinancialAccount> fafrList = fixedAssetFinancialAccountRepository.findByFixedAsset(propertyIfAny);
List<FinancialAccount> bankAccountsForProperty = fafrList.stream().map(FixedAssetFinancialAccount::getFinancialAccount).filter(BankAccount.class::isInstance).map(BankAccount.class::cast).collect(Collectors.toList());
bankAccountsForBuyer.retainAll(bankAccountsForProperty);
}
// original implementation ... see if we already have a unique bank account
int numBankAccounts = bankAccountsForBuyer.size();
switch(numBankAccounts) {
case 0:
return null;
case 1:
return bankAccountsForBuyer.get(0);
default:
}
// see if removing non-preferred helps
bankAccountsForBuyer.removeIf(x -> (x.getPreferred() == null || !x.getPreferred()));
numBankAccounts = bankAccountsForBuyer.size();
switch(numBankAccounts) {
case 0:
return null;
case 1:
return bankAccountsForBuyer.get(0);
default:
// give up, still non-duplicate
return null;
}
}
use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class UpcomingPaymentService method getUpcomingPayments.
@Programmatic
public List<UpcomingPaymentTotal> getUpcomingPayments() {
List<IncomingInvoice> invoiceSelectionForUpcomingPayments = new ArrayList<>();
invoiceSelectionForUpcomingPayments.addAll(incomingInvoiceRepository.findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.COMPLETED, PaymentMethod.BANK_TRANSFER));
invoiceSelectionForUpcomingPayments.addAll(incomingInvoiceRepository.findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.APPROVED, PaymentMethod.BANK_TRANSFER));
invoiceSelectionForUpcomingPayments.addAll(incomingInvoiceRepository.findByApprovalStateAndPaymentMethod(IncomingInvoiceApprovalState.PENDING_BANK_ACCOUNT_CHECK, PaymentMethod.BANK_TRANSFER));
List<UpcomingPaymentTotal> upcomingPayments = new ArrayList<>();
for (IncomingInvoice invoice : invoiceSelectionForUpcomingPayments) {
UpcomingPaymentTotal upcomingPaymentTotal;
if (paymentTotalForBankAccount(upcomingPayments, invoice).isEmpty()) {
upcomingPaymentTotal = new UpcomingPaymentTotal(debtorBankAccountService.uniqueDebtorAccountToPay(invoice));
upcomingPaymentTotal.addValue(invoice);
upcomingPayments.add(upcomingPaymentTotal);
} else {
upcomingPaymentTotal = paymentTotalForBankAccount(upcomingPayments, invoice).get(0);
upcomingPaymentTotal.addValue(invoice);
}
}
return upcomingPayments;
}
Aggregations