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);
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations