Search in sources :

Example 16 with ApplicationException

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

the class Api method putLeasePostalAddress.

@ActionSemantics(Of.IDEMPOTENT)
public void putLeasePostalAddress(@Named("reference") final String partyReference, @Named("agreementRoleType") final String agreementRoleType, @Named("leaseReference") @Optional final String leaseReference, @Named("address1") @Optional final String address1, @Named("address2") @Optional final String address2, @Named("address3") @Optional final String address3, @Named("postalCode") @Optional final String postalCode, @Named("city") @Optional final String city, @Named("stateCode") @Optional final String stateCode, @Named("countryCode") @Optional final String countryCode, @Named("isInvoiceAddress") @Optional final BigInteger isInvoiceAddress) {
    if (address1 != null && partyReference != null && leaseReference != null) {
        final Lease lease = fetchLease(leaseReference);
        final Party party = fetchParty(partyReference);
        final AgreementRoleCommunicationChannelType agreementRoleCommunicationChannelType = agreementRoleCommunicationChannelTypes.findByTitle(isInvoiceAddress.compareTo(BigInteger.ZERO) == 0 ? LeaseConstants.AgreementRoleCommunicationChannelType.INVOICE_ADDRESS.getTitle() : LeaseConstants.AgreementRoleCommunicationChannelType.ADMINISTRATION_ADDRESS.getTitle());
        if (agreementRoleCommunicationChannelType == null)
            throw new ApplicationException(String.format("AgreementRoleCommunicationChannelType not found."));
        PostalAddress address = (PostalAddress) postalAddresses.findByAddress(party, address1, postalCode, city, fetchCountry(countryCode));
        if (address == null) {
            address = communicationChannels.newPostal(party, CommunicationChannelType.POSTAL_ADDRESS, address1, address2, null, postalCode, city, fetchState(stateCode, false), fetchCountry(countryCode, false));
        }
        final AgreementRoleType art = agreementRoleTypes.findByTitle(StringUtils.capitalize(agreementRoleType.toLowerCase()));
        if (art == null)
            throw new ApplicationException(String.format("AgreementRoleType %s not found.", agreementRoleType));
        final AgreementRole role = lease.findRole(party, art, clockService.now());
        if (role == null)
            throw new ApplicationException(String.format("Role for %s, %s not found.", partyReference, agreementRoleType));
        role.addCommunicationChannel(agreementRoleCommunicationChannelType, address);
    }
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException)

Example 17 with ApplicationException

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

the class ProjectImport method importData.

@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
    if (previousRow != null) {
    // TODO: support sparse sheets ?
    }
    Project parent = null;
    if (getParentReference() != null) {
        parent = projectRepository.findByReference(getParentReference());
        if (parent == null) {
            throw new ApplicationException(String.format("Parent with reference %s not found.", getParentReference()));
        }
        if (!parent.getAtPath().equals(getAtPath())) {
            throw new ApplicationException(String.format("AtPath parent %s does not match %s.", getParentReference(), getAtPath()));
        }
        if (!parent.getItems().isEmpty()) {
            // TODO: (ECP-438) until we find out more about the process, prevent a the choice of a project having items
            throw new ApplicationException(String.format("Parent with reference %s has items and cannot be a parent therefore.", getAtPath()));
        }
    }
    Project project = findOrCreateProjectAndUpdateParent(getReference(), getName(), getStartDate(), getEndDate(), getAtPath(), parent);
    if (getItemChargeReference() != null) {
        Charge charge = chargeRepository.findByReference(getItemChargeReference());
        Property property = propertyRepository.findPropertyByReference(getItemPropertyReference());
        Tax tax = taxRepository.findByReference(getItemTaxReference());
        wrapperFactory.wrap(project).addItem(charge, getItemDescription(), getItemBudgetedAmount(), getItemStartDate(), getItemEndDate(), property, tax);
    }
    return Lists.newArrayList(project);
}
Also used : Project(org.estatio.module.capex.dom.project.Project) ApplicationException(org.apache.isis.applib.ApplicationException) Charge(org.estatio.module.charge.dom.Charge) Tax(org.estatio.module.tax.dom.Tax) Property(org.estatio.module.asset.dom.Property) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 18 with ApplicationException

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

the class CommunicationChannelImport method importData.

@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
    List<Object> results = new ArrayList<>();
    // Party
    final Party party = fetchParty(partyReference);
    if (party == null)
        throw new ApplicationException(String.format("Party with reference [%s] not found", partyReference));
    // Address
    if (address1 != null || address2 != null || address3 != null) {
        final Country country = countryRepository.findCountry(countryCode);
        PostalAddress comm = (PostalAddress) postalAddressRepository.findByAddress(party, address1, address2, address3, postalCode, city, country);
        if (comm == null) {
            comm = communicationChannelRepository.newPostal(party, CommunicationChannelType.POSTAL_ADDRESS, address1, address2, address3, postalCode, city, stateRepository.findState(stateCode), countryRepository.findCountry(countryCode));
        }
        if (legal != null && legal) {
            comm.setLegal(true);
        }
        // attach to lease
        if (leaseReference != null) {
            Lease lease = fetchLease(leaseReference);
            if (lease != null && addressType != null) {
                final AgreementRoleType art = agreementRoleTypeRepository.find(LeaseAgreementRoleTypeEnum.TENANT);
                final AgreementRoleCommunicationChannelType arcct = agreementRoleCommunicationChannelTypeRepository.findByTitle(addressType);
                lease.findRoleWithType(art, lease.getStartDate()).addCommunicationChannel(arcct, comm, lease.getStartDate());
            }
        }
    }
    // Phone
    if (phoneNumber != null) {
        CommunicationChannel comm = phoneOrFaxNumberRepository.findByPhoneOrFaxNumber(party, phoneNumber);
        if (comm == null) {
            comm = communicationChannelRepository.newPhoneOrFax(party, CommunicationChannelType.PHONE_NUMBER, phoneNumber);
            comm.setReference(leaseReference);
        }
    }
    // Fax
    if (faxNumber != null) {
        CommunicationChannel comm = phoneOrFaxNumberRepository.findByPhoneOrFaxNumber(party, faxNumber);
        if (comm == null) {
            comm = communicationChannelRepository.newPhoneOrFax(party, CommunicationChannelType.FAX_NUMBER, faxNumber);
            comm.setReference(leaseReference);
        }
    }
    // Email
    if (emailAddress != null) {
        CommunicationChannel comm = emailAddressRepository.findByEmailAddress(party, emailAddress);
        if (comm == null) {
            comm = communicationChannelRepository.newEmail(party, CommunicationChannelType.EMAIL_ADDRESS, emailAddress);
            comm.setReference(leaseReference);
        }
    }
    return results;
}
Also used : PostalAddress(org.incode.module.communications.dom.impl.commchannel.PostalAddress) Party(org.estatio.module.party.dom.Party) ApplicationException(org.apache.isis.applib.ApplicationException) AgreementRoleCommunicationChannelType(org.estatio.module.agreement.dom.AgreementRoleCommunicationChannelType) Lease(org.estatio.module.lease.dom.Lease) AgreementRoleType(org.estatio.module.agreement.dom.role.AgreementRoleType) ArrayList(java.util.ArrayList) Country(org.incode.module.country.dom.impl.Country) DomainObject(org.apache.isis.applib.annotation.DomainObject) CommunicationChannel(org.incode.module.communications.dom.impl.commchannel.CommunicationChannel) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 19 with ApplicationException

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

the class LeaseItemImport 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 20 with ApplicationException

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

the class LeaseTermForIndexableRentImport 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)

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