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