Search in sources :

Example 11 with ApplicationException

use of org.apache.isis.applib.ApplicationException in project estatio by estatio.

the class GuaranteeImport method fetchLease.

private Lease fetchLease(final String leaseReference) {
    final Lease lease;
    lease = leaseRepository.findLeaseByReference(leaseReference.trim().replaceAll("~", "+"));
    if (lease == null) {
        throw new ApplicationException(String.format("Lease with reference %s not found.", leaseReference));
    }
    return lease;
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) Lease(org.estatio.module.lease.dom.Lease)

Example 12 with ApplicationException

use of org.apache.isis.applib.ApplicationException in project estatio by estatio.

the class Communication method sendByEmail.

// so can invoke via BackgroundService
@Action(hidden = Where.EVERYWHERE)
public Communication sendByEmail() {
    // body...
    final Document coverNoteDoc = findDocument(DocumentConstants.PAPERCLIP_ROLE_COVER);
    final String emailBody = coverNoteDoc.asChars();
    // (email) attachments..
    // this corresponds to the primary document and any attachments
    final List<DataSource> attachments = Lists.newArrayList();
    final Document primaryDocument = getPrimaryDocument();
    if (primaryDocument != null) {
        // should be the case
        attachments.add(primaryDocument.asDataSource());
    }
    attachments.addAll(findDocumentsInRoleAsStream(DocumentConstants.PAPERCLIP_ROLE_ATTACHMENT).map(DocumentAbstract::asDataSource).collect(Collectors.toList()));
    // cc..
    final List<String> toList = findCorrespondents(CommChannelRoleType.TO);
    final List<String> ccList = findCorrespondents(CommChannelRoleType.CC);
    final List<String> bccList = findCorrespondents(CommChannelRoleType.BCC);
    // subject ...
    final String subject = getSubject();
    // finally, we send
    final boolean send = emailService.send(toList, ccList, bccList, subject, emailBody, attachments.toArray(new DataSource[] {}));
    if (!send) {
        throw new ApplicationException("Failed to send email; see system logs for details.");
    }
    // mark this comm as having been sent.
    sent();
    return this;
}
Also used : DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) ApplicationException(org.apache.isis.applib.ApplicationException) Document(org.incode.module.document.dom.impl.docs.Document) DataSource(javax.activation.DataSource) Action(org.apache.isis.applib.annotation.Action)

Example 13 with ApplicationException

use of org.apache.isis.applib.ApplicationException in project estatio by estatio.

the class PartitionItemImport method importData.

@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
    Property property = propertyRepository.findPropertyByReference(propertyReference);
    if (property == null)
        throw new ApplicationException(String.format("Property with reference [%s] not found.", propertyReference));
    final Budget budget = budgetRepository.findOrCreateBudget(property, startDate, endDate);
    final KeyTable keyTable = keyTableRepository.findOrCreateBudgetKeyTable(budget, keyTableName, FoundationValueType.MANUAL, KeyValueMethod.PERCENT, 6);
    findOrCreateBudgetKeyItem(keyTable, unitRepository.findUnitByReference(unitReference), keyValue, sourceValue);
    final Charge charge = fetchCharge(budgetChargeReference);
    final BudgetItem butgetItem = findOrCreateBudgetItem(budget, charge, budgetValue);
    final Charge scheduleCharge = fetchCharge(invoiceChargeReference);
    final Partitioning partitioning = findOrCreatePartitioning(budget);
    findOrCreatePartitionItem(partitioning, scheduleCharge, butgetItem, keyTable, percentage);
    return Lists.newArrayList();
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) BudgetItem(org.estatio.module.budget.dom.budgetitem.BudgetItem) Partitioning(org.estatio.module.budget.dom.partioning.Partitioning) Charge(org.estatio.module.charge.dom.Charge) Budget(org.estatio.module.budget.dom.budget.Budget) KeyTable(org.estatio.module.budget.dom.keytable.KeyTable) Property(org.estatio.module.asset.dom.Property) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 14 with ApplicationException

use of org.apache.isis.applib.ApplicationException in project estatio by estatio.

the class Api method putPartyCommunicationChannels.

// //////////////////////////////////////
@ActionSemantics(Of.IDEMPOTENT)
public void putPartyCommunicationChannels(@Named("reference") final String partyReference, @Named("reference") @Optional final String reference, @Named("address1") @Optional final String address1, @Named("address2") @Optional final String address2, @Named("address3") @Optional final String address3, @Named("city") @Optional final String city, @Named("postalCode") @Optional final String postalCode, @Named("stateCode") @Optional final String stateCode, @Named("countryCode") @Optional final String countryCode, @Named("phoneNumber") @Optional final String phoneNumber, @Named("faxNumber") @Optional final String faxNumber, @Named("emailAddress") @Optional final String emailAddress, @Named("legal") @Optional final Boolean legal) {
    final Party party = fetchParty(partyReference);
    if (party == null)
        throw new ApplicationException(String.format("Party with reference [%s] not found", partyReference));
    // Address
    if (address1 != null) {
        final Country country = fetchCountry(countryCode);
        PostalAddress comm = (PostalAddress) postalAddresses.findByAddress(party, address1, postalCode, city, country);
        if (comm == null) {
            comm = communicationChannels.newPostal(party, CommunicationChannelType.POSTAL_ADDRESS, address1, address2, null, postalCode, city, states.findState(stateCode), countries.findCountry(countryCode));
            comm.setReference(reference);
        }
        if (legal) {
            comm.setLegal(true);
        }
    }
    // Phone
    if (phoneNumber != null) {
        CommunicationChannel comm = phoneOrFaxNumbers.findByPhoneOrFaxNumber(party, phoneNumber);
        if (comm == null) {
            comm = communicationChannels.newPhoneOrFax(party, CommunicationChannelType.PHONE_NUMBER, phoneNumber);
            comm.setReference(reference);
        }
    }
    // Fax
    if (faxNumber != null) {
        CommunicationChannel comm = phoneOrFaxNumbers.findByPhoneOrFaxNumber(party, faxNumber);
        if (comm == null) {
            comm = communicationChannels.newPhoneOrFax(party, CommunicationChannelType.FAX_NUMBER, faxNumber);
            comm.setReference(reference);
        }
    }
    // Email
    if (emailAddress != null) {
        CommunicationChannel comm = emailAddresses.findByEmailAddress(party, emailAddress);
        if (comm == null) {
            comm = communicationChannels.newEmail(party, CommunicationChannelType.EMAIL_ADDRESS, emailAddress);
            comm.setReference(reference);
        }
    }
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) Country(org.estatio.dom.geography.Country)

Example 15 with ApplicationException

use of org.apache.isis.applib.ApplicationException in project estatio by estatio.

the class Api method putBankMandate.

@ActionSemantics(Of.IDEMPOTENT)
public void putBankMandate(@Named("reference") final String reference, @Named("sepaMandateIdentifier") @Optional final String sepaMandateIdentifier, @Named("name") @Optional final String name, @Named("leaseReference") final String leaseReference, @Named("debtorReference") final String debtorReference, @Named("creditorReference") final String creditorReference, @Named("bankAccountReference") final String bankAccountReference, @Named("startDate") final LocalDate startDate, @Named("endDate") @Optional final LocalDate endDate) {
    BankMandate bankMandate = (BankMandate) agreements.findAgreementByReference(reference);
    final BankAccount bankAccount = (BankAccount) financialAccounts.findAccountByReference(bankAccountReference);
    if (bankAccount == null)
        throw new ApplicationException(String.format("BankAccount with reference %1$s not found", bankAccountReference));
    final Lease lease = fetchLease(leaseReference);
    final Party debtor = fetchParty(debtorReference);
    final Party creditor = fetchParty(creditorReference);
    if (bankMandate == null) {
        lease.newMandate(bankAccount, reference, startDate, endDate);
        bankMandate = lease.getPaidBy();
        bankMandate.setName(name);
    // EST-467, previously was:
    // bankMandate = bankMandates.newBankMandate(reference, name,
    // startDate, endDate, debtor, creditor, bankAccount);
    }
    // upsert
    bankMandate.setBankAccount(bankAccount);
    bankMandate.setName(name);
    bankMandate.setStartDate(startDate);
    bankMandate.setEndDate(endDate);
    bankMandate.setSepaMandateIdentifier(sepaMandateIdentifier);
    lease.paidBy(bankMandate);
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) BankAccount(org.estatio.dom.financial.bankaccount.BankAccount) BankMandate(org.estatio.dom.bankmandate.BankMandate)

Aggregations

ApplicationException (org.apache.isis.applib.ApplicationException)23 Lease (org.estatio.module.lease.dom.Lease)11 Programmatic (org.apache.isis.applib.annotation.Programmatic)6 Charge (org.estatio.module.charge.dom.Charge)4 Property (org.estatio.module.asset.dom.Property)3 IOException (java.io.IOException)2 Budget (org.estatio.module.budget.dom.budget.Budget)2 BudgetCalculationType (org.estatio.module.budget.dom.budgetcalculation.BudgetCalculationType)2 BudgetItem (org.estatio.module.budget.dom.budgetitem.BudgetItem)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 DataSource (javax.activation.DataSource)1 HttpHost (org.apache.http.HttpHost)1 StatusLine (org.apache.http.StatusLine)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)1 Action (org.apache.isis.applib.annotation.Action)1