Search in sources :

Example 6 with CurrencyDao

use of org.openlca.core.database.CurrencyDao in project olca-modules by GreenDelta.

the class TestData method currency.

public static Currency currency(String name) {
    String currencyId = KeyGen.get("currency", name);
    CurrencyDao dao = new CurrencyDao(Tests.getDb());
    Currency currency = dao.getForRefId(currencyId);
    if (currency != null)
        return currency;
    currency = new Currency();
    currency.refId = currencyId;
    currency.name = name;
    currency.conversionFactor = 1;
    Currency ref = dao.getReferenceCurrency();
    if (ref != null)
        currency.referenceCurrency = ref;
    else
        currency.referenceCurrency = currency;
    return dao.insert(currency);
}
Also used : CurrencyDao(org.openlca.core.database.CurrencyDao) Currency(org.openlca.core.model.Currency)

Example 7 with CurrencyDao

use of org.openlca.core.database.CurrencyDao in project olca-modules by GreenDelta.

the class ConversionTableTest method testGetCurrencyFactor.

@Test
public void testGetCurrencyFactor() {
    CurrencyDao dao = new CurrencyDao(database);
    Currency eur = make("EUR", 1.0);
    Currency usd = make("USD", 0.88);
    usd.referenceCurrency = eur;
    dao.update(usd);
    ConversionTable table = ConversionTable.create(Tests.getDb());
    Assert.assertEquals(1.0, table.getCurrencyFactor(eur.id), 1e-10);
    Assert.assertEquals(0.88, table.getCurrencyFactor(usd.id), 1e-10);
    // the default factor should be 1.0
    Assert.assertEquals(1.0, table.getCurrencyFactor(-42L), 1e-10);
    dao.delete(usd);
    dao.delete(eur);
}
Also used : CurrencyDao(org.openlca.core.database.CurrencyDao) Currency(org.openlca.core.model.Currency) Test(org.junit.Test)

Example 8 with CurrencyDao

use of org.openlca.core.database.CurrencyDao in project olca-modules by GreenDelta.

the class ConversionTableTest method make.

private Currency make(String code, double factor) {
    CurrencyDao dao = new CurrencyDao(database);
    Currency c = new Currency();
    c.code = code;
    c.conversionFactor = factor;
    c.referenceCurrency = c;
    return dao.insert(c);
}
Also used : CurrencyDao(org.openlca.core.database.CurrencyDao) Currency(org.openlca.core.model.Currency)

Example 9 with CurrencyDao

use of org.openlca.core.database.CurrencyDao in project olca-modules by GreenDelta.

the class CurrencyImport method of.

@Override
public ImportStatus<Currency> of(String id) {
    var currency = imp.get(Currency.class, id);
    // check if we are in update mode
    var update = false;
    if (currency != null) {
        update = imp.shouldUpdate(currency);
        if (!update) {
            return ImportStatus.skipped(currency);
        }
    }
    // resolve the proto object
    var proto = imp.reader.getCurrency(id);
    if (proto == null)
        return currency != null ? ImportStatus.skipped(currency) : ImportStatus.error("Could not resolve Currency " + id);
    var wrap = ProtoWrap.of(proto);
    if (update) {
        if (imp.skipUpdate(currency, wrap))
            return ImportStatus.skipped(currency);
    }
    // map the data
    if (currency == null) {
        currency = new Currency();
    }
    wrap.mapTo(currency, imp);
    map(proto, currency);
    // insert it
    var dao = new CurrencyDao(imp.db);
    currency = update ? dao.update(currency) : dao.insert(currency);
    imp.putHandled(currency);
    return update ? ImportStatus.updated(currency) : ImportStatus.created(currency);
}
Also used : CurrencyDao(org.openlca.core.database.CurrencyDao) ProtoCurrency(org.openlca.proto.ProtoCurrency) Currency(org.openlca.core.model.Currency)

Example 10 with CurrencyDao

use of org.openlca.core.database.CurrencyDao in project olca-app by GreenDelta.

the class TotalRequirementsSection method renderTotalCosts.

private void renderTotalCosts(Composite comp, FormToolkit tk) {
    if (costs == Costs.NONE)
        return;
    String label = costs == Costs.NET_COSTS ? M.TotalNetcosts : M.TotalAddedValue;
    double v = costs == Costs.NET_COSTS ? result.totalCosts() : result.totalCosts() == 0 ? 0 : -result.totalCosts();
    var currency = new CurrencyDao(Database.get()).getReferenceCurrency();
    var symbol = currency != null && currency.code != null ? currency.code : "?";
    var value = Numbers.decimalFormat(v, 2) + " " + symbol;
    tk.createLabel(comp, label + ": " + value).setFont(UI.boldFont());
}
Also used : CurrencyDao(org.openlca.core.database.CurrencyDao)

Aggregations

CurrencyDao (org.openlca.core.database.CurrencyDao)12 Currency (org.openlca.core.model.Currency)9 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Comparator (java.util.Comparator)1 Collectors (java.util.stream.Collectors)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 ProjectResultData (org.openlca.app.editors.projects.ProjectResultData)1 ActorDao (org.openlca.core.database.ActorDao)1 CategoryDao (org.openlca.core.database.CategoryDao)1 DQSystemDao (org.openlca.core.database.DQSystemDao)1 FlowDao (org.openlca.core.database.FlowDao)1 FlowPropertyDao (org.openlca.core.database.FlowPropertyDao)1 IDatabase (org.openlca.core.database.IDatabase)1 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)1 ImpactMethodDao (org.openlca.core.database.ImpactMethodDao)1 LocationDao (org.openlca.core.database.LocationDao)1 NwSetDao (org.openlca.core.database.NwSetDao)1 ProcessDao (org.openlca.core.database.ProcessDao)1 ProductSystemDao (org.openlca.core.database.ProductSystemDao)1