Search in sources :

Example 1 with IndexBase

use of org.estatio.module.index.dom.IndexBase in project estatio by estatio.

the class IndexBuilder method execute.

@Override
protected void execute(final ExecutionContext executionContext) {
    checkParam("reference", executionContext, String.class);
    checkParam("name", executionContext, String.class);
    final Index index = createIndex(applicationTenancy, reference, name, executionContext);
    for (final Base base : bases) {
        final IndexBase indexBase = createIndexBase(index, base.year, base.factor, executionContext);
        for (final Value value : base.values) {
            createIndexValues(indexBase, value.year, value.values, executionContext);
        }
    }
    object = index;
}
Also used : IndexValue(org.estatio.module.index.dom.IndexValue) Index(org.estatio.module.index.dom.Index) IndexBase(org.estatio.module.index.dom.IndexBase) IndexBase(org.estatio.module.index.dom.IndexBase)

Example 2 with IndexBase

use of org.estatio.module.index.dom.IndexBase 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();
}
Also used : Index(org.estatio.module.index.dom.Index) IndexBase(org.estatio.module.index.dom.IndexBase) IndexValue(org.estatio.module.index.dom.IndexValue) LocalDate(org.joda.time.LocalDate) ApplicationTenancy(org.isisaddons.module.security.dom.tenancy.ApplicationTenancy) BigDecimal(java.math.BigDecimal) ActionSemantics(org.apache.isis.applib.annotation.ActionSemantics) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) Bulk(org.apache.isis.applib.annotation.Bulk)

Aggregations

Index (org.estatio.module.index.dom.Index)2 IndexBase (org.estatio.module.index.dom.IndexBase)2 IndexValue (org.estatio.module.index.dom.IndexValue)2 BigDecimal (java.math.BigDecimal)1 ActionSemantics (org.apache.isis.applib.annotation.ActionSemantics)1 Bulk (org.apache.isis.applib.annotation.Bulk)1 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)1 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)1 LocalDate (org.joda.time.LocalDate)1