use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.
the class LeaseBuilder method execute.
@Override
protected void execute(final ExecutionContext executionContext) {
checkParam("reference", executionContext, String.class);
checkParam("name", executionContext, String.class);
checkParam("property", executionContext, Unit.class);
checkParam("landlord", executionContext, Party.class);
checkParam("tenant", executionContext, Party.class);
checkParam("startDate", executionContext, LocalDate.class);
checkParam("endDate", executionContext, LocalDate.class);
defaultParam("invoiceAddressCreationPolicy", executionContext, InvoiceAddressCreationPolicy.DONT_CREATE);
defaultParam("addressesCreationPolicy", executionContext, AddressesCreationPolicy.DONT_CREATE);
landlord.addRole(LeaseRoleTypeEnum.LANDLORD);
tenant.addRole(LeaseRoleTypeEnum.TENANT);
final ApplicationTenancy atPath = ApplicationTenancy_enum.Global.findUsing(serviceRegistry);
final LeaseType leaseType = leaseTypeRepository.findOrCreate("STD", "Standard", atPath);
Lease lease = leaseRepository.newLease(property.getApplicationTenancy(), reference, name, leaseType, startDate, null, endDate, landlord, tenant);
executionContext.addResult(this, lease.getReference(), lease);
if (manager != null) {
final AgreementRole role = lease.createRole(agreementRoleTypeRepository.find(LeaseAgreementRoleTypeEnum.MANAGER), manager, null, null);
executionContext.addResult(this, role);
}
for (final OccupancySpec spec : occupancySpecs) {
Occupancy occupancy = occupancyRepository.newOccupancy(lease, spec.unit, spec.startDate);
occupancy.setEndDate(spec.endDate);
occupancy.setBrandName(spec.brand, spec.brandCoverage, spec.countryOfOrigin);
occupancy.setSectorName(spec.sector);
occupancy.setActivityName(spec.activity);
executionContext.addResult(this, occupancy);
}
if (invoiceAddressCreationPolicy == InvoiceAddressCreationPolicy.CREATE) {
addInvoiceAddressForTenant(lease, tenant, CommunicationChannelType.EMAIL_ADDRESS);
}
if (addressesCreationPolicy == AddressesCreationPolicy.CREATE) {
createAddress(lease, AgreementRoleCommunicationChannelTypeEnum.ADMINISTRATION_ADDRESS);
createAddress(lease, AgreementRoleCommunicationChannelTypeEnum.INVOICE_ADDRESS);
}
if (leaseRepository.findLeaseByReference(reference) == null) {
throw new RuntimeException("could not find lease reference='" + reference + "'");
}
object = lease;
}
use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.
the class ClassificationForOccImport method importData.
@Override
public List<Object> importData(final Object previousRow) {
final Lease lease = leaseRepository.findLeaseByReference(getLeaseReference());
if (lease == null) {
throw new IllegalArgumentException(String.format("No lease found for '%s'", getLeaseReference()));
}
final Unit unit = unitRepository.findUnitByReference(getUnitReference());
if (unit == null) {
throw new IllegalArgumentException(String.format("No unit found for '%s'", getUnitReference()));
}
final Occupancy occupancy = occupancyRepository.findByLease(lease).stream().filter(x -> x.getUnit().equals(unit)).findFirst().get();
if (occupancy == null) {
throw new IllegalArgumentException(String.format("No occupancy found for lease '%s' and unit '%s'", getLeaseReference(), getUnitReference()));
}
final Taxonomy taxonomy = (Taxonomy) categoryRepository.findByReference(getTaxonomyReference());
if (taxonomy == null) {
throw new IllegalArgumentException(String.format("No taxonomy found for '%s'", getTaxonomyReference()));
}
final Category category = categoryRepository.findByTaxonomyAndReference(taxonomy, getCategoryReference());
if (category == null) {
throw new IllegalArgumentException(String.format("No category found for '%s'", getCategoryReference()));
}
final Classification classification = classificationRepository.create(category, occupancy);
return Lists.newArrayList(classification);
}
use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.
the class OccupancyImport method importData.
@Override
@Programmatic
public List<Object> importData(Object previousRow) {
final Lease lease = fetchLease(leaseReference);
final Unit unit = unitRepository.findUnitByReference(unitReference);
if (unitReference != null && unit == null) {
throw new ApplicationException(String.format("Unit with reference %s not found.", unitReference));
}
Occupancy occupancy = occupancyRepository.findByLeaseAndUnitAndStartDate(lease, unit, startDate);
if (occupancy == null) {
occupancy = occupancyRepository.newOccupancy(lease, unit, startDate);
}
occupancy.setEndDate(endDate);
occupancy.setUnitSizeName(size);
occupancy.setBrandName(brand != null ? brand.replaceAll("\\p{C}", "").trim() : null, null, null);
occupancy.setSectorName(sector);
occupancy.setActivityName(activity);
occupancy.setReportTurnover(reportTurnover != null ? Occupancy.OccupancyReportingType.valueOf(reportTurnover) : Occupancy.OccupancyReportingType.NO);
occupancy.setReportRent(reportRent != null ? Occupancy.OccupancyReportingType.valueOf(reportRent) : Occupancy.OccupancyReportingType.NO);
occupancy.setReportOCR(reportOCR != null ? Occupancy.OccupancyReportingType.valueOf(reportOCR) : Occupancy.OccupancyReportingType.NO);
return Lists.newArrayList(occupancy);
}
use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.
the class InvoiceForLease method getCurrentOccupancy.
@Programmatic
public Occupancy getCurrentOccupancy() {
final InvoiceForLease invoice = this;
final Lease leaseIfAny = invoice.getLease();
if (leaseIfAny == null) {
return null;
}
final SortedSet<Occupancy> occupancies = leaseIfAny.getOccupancies();
if (occupancies.isEmpty()) {
return null;
}
return occupancies.first();
}
use of org.estatio.module.lease.dom.occupancy.Occupancy in project estatio by estatio.
the class InvoiceAttributesVM method getCurrentOccupancyBrandName.
@Programmatic
public String getCurrentOccupancyBrandName() {
final Occupancy currentOccupancy = invoice.getCurrentOccupancy();
if (currentOccupancy == null) {
return null;
}
final Brand brand = currentOccupancy.getBrand();
if (brand == null) {
return null;
}
return brand.getName();
}
Aggregations