use of org.isisaddons.module.security.dom.tenancy.ApplicationTenancy in project estatio by estatio.
the class EstatioApplicationTenancyRepositoryForProperty method findOrCreateTenancyFor.
public ApplicationTenancy findOrCreateTenancyFor(final Property property) {
ApplicationTenancy propertyTenancy = applicationTenancies.findByPath(pathFor(property));
if (propertyTenancy != null) {
return propertyTenancy;
}
final ApplicationTenancy countryApplicationTenancy = estatioApplicationTenancyRepositoryForCountry.findOrCreateTenancyFor(property.getCountry());
final String tenancyName = String.format("%s/%s ", countryApplicationTenancy.getPath(), property.getReference());
return applicationTenancies.newTenancy(tenancyName, pathFor(property), countryApplicationTenancy);
}
use of org.isisaddons.module.security.dom.tenancy.ApplicationTenancy in project estatio by estatio.
the class ChargeImport method importData.
@Override
@Programmatic
public List<Object> importData(Object previousRow) {
ChargeGroup chargeGroup = null;
if (getChargeGroupReference() != null) {
chargeGroup = findOrCreateChargeGroup(chargeGroupReference, chargeGroupName);
}
final ApplicationTenancy applicationTenancy = securityApplicationTenancyRepository.findByPath(atPath);
final Applicability applicability = this.applicability != null ? Applicability.valueOf(this.applicability) : Applicability.IN_AND_OUT;
Tax tax = null;
if (getTaxReference() != null) {
tax = taxRepository.findOrCreate(taxReference, taxReference, applicationTenancy);
}
if (getReference() == null) {
setReference(getName());
}
final Charge charge = chargeRepository.upsert(getReference(), getName(), getDescription(), applicationTenancy, applicability, tax, chargeGroup);
if (getParent() != null) {
Charge parentCharge = chargeRepository.findByReference(getParent());
if (parentCharge != null) {
charge.setParent(parentCharge);
}
}
if (externalReference != null) {
charge.setExternalReference(externalReference);
}
if (sortOrder != null) {
charge.setSortOrder(sortOrder);
}
return Lists.newArrayList(charge);
}
use of org.isisaddons.module.security.dom.tenancy.ApplicationTenancy in project estatio by estatio.
the class IndexImport method importData.
@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
final ApplicationTenancy applicationTenancy = applicationTenancyRepository.findByPath(getAtPath());
// Creator and implement IndexCreator, IndexBaseCreator, IndexValueCreator
final IndexValue indexValue = indexRepository.findOrCreateIndex(applicationTenancy, indexReference, indexName).findOrCreateBase(indexBaseStartDate, indexBaseFactor).newIndexValue(startDate, value);
return Lists.newArrayList(indexValue);
}
use of org.isisaddons.module.security.dom.tenancy.ApplicationTenancy in project estatio by estatio.
the class IndexValuesMaintenanceMenu method uploadIndexValues.
// //////////////////////////////////////
@Action(publishing = Publishing.DISABLED, semantics = SemanticsOf.IDEMPOTENT)
@MemberOrder(sequence = "2")
public List<IndexValueMaintLineItem> uploadIndexValues(@Parameter(fileAccept = ".xlsx") @ParameterLayout(named = "Excel spreadsheet") final Blob spreadsheet, final Country country) {
final ApplicationTenancy applicationTenancy = estatioApplicationTenancyRepository.findOrCreateTenancyFor(country);
List<IndexValueMaintLineItem> lineItems = excelService.fromExcel(spreadsheet, IndexValueMaintLineItem.class, IndexValueMaintLineItem.class.getSimpleName());
for (IndexValueMaintLineItem lineItem : lineItems) {
lineItem.setAtPath(applicationTenancy.getPath());
}
return lineItems;
}
use of org.isisaddons.module.security.dom.tenancy.ApplicationTenancy in project estatio by estatio.
the class IndexValueMaintLineItem method apply.
// //////////////////////////////////////
@MemberOrder(sequence = "2")
@ActionSemantics(Of.IDEMPOTENT)
@Bulk
public void apply() {
if (bulkInteractionContext.isFirst()) {
String error = check();
if (error != null) {
getContainer().raiseError(error);
return;
}
}
// only null on first pass, then populated
ApplicationTenancy applicationTenancy = (ApplicationTenancy) scratchpad.get("applicationTenancy");
if (applicationTenancy == null) {
final String atPath = getAtPath();
applicationTenancy = applicationTenancies.findTenancyByPath(atPath);
scratchpad.put("applicationTenancy", applicationTenancy);
}
// only null on first pass, then populated
Index index = (Index) scratchpad.get("index");
if (index == null) {
final String reference = getReference();
index = indexRepository.newIndex(reference, reference, applicationTenancy);
scratchpad.put("index", index);
setIndex(index);
}
// only null on first pass, then populated, and only if !existingIndex
IndexBase previousBase = (IndexBase) scratchpad.get("previousBase");
final LocalDate baseStartDate = getBaseStartDate();
final BigDecimal baseFactor = getBaseFactor();
IndexBase indexBase = indexBaseRepository.findByIndexAndDate(index, baseStartDate);
if (indexBase == null) {
indexBase = indexBaseRepository.newIndexBase(index, previousBase, baseStartDate, baseFactor);
}
setIndexBase(indexBase);
// for next time need to create
scratchpad.put("previousBase", indexBase);
final LocalDate valueStartDate = getValueStartDate();
final BigDecimal value = getValue();
IndexValue indexValue = indexValueRepository.findByIndexAndStartDate(index, valueStartDate);
if (indexValue == null) {
indexValue = indexValueRepository.findOrCreate(index, valueStartDate, value);
} else {
indexValue.setValue(value);
}
setIndexValue(indexValue);
// belt-n-braces so that subsequent queries succeed...
getContainer().flush();
}
Aggregations