Search in sources :

Example 11 with Currency

use of org.openlca.core.model.Currency in project olca-modules by GreenDelta.

the class CurrencyImport method copy.

private void copy(Currency srcCurrency) {
    Currency destCurrency = srcCurrency.copy();
    if (Objects.equal(srcCurrency, srcCurrency.referenceCurrency)) {
        destCurrency.referenceCurrency = destCurrency;
    } else {
        destCurrency.referenceCurrency = refs.switchRef(srcCurrency.referenceCurrency);
    }
    destCurrency = destDao.insert(destCurrency);
    seq.put(seq.CURRENCY, srcCurrency.refId, destCurrency.id);
}
Also used : Currency(org.openlca.core.model.Currency)

Example 12 with Currency

use of org.openlca.core.model.Currency in project olca-modules by GreenDelta.

the class CurrencyTest method createModel.

private Currency createModel(CurrencyDao dao) {
    Currency currency = new Currency();
    currency.name = "currency";
    currency.refId = UUID.randomUUID().toString();
    dao.insert(currency);
    return currency;
}
Also used : Currency(org.openlca.core.model.Currency)

Example 13 with Currency

use of org.openlca.core.model.Currency in project olca-modules by GreenDelta.

the class CurrencyTest method doImport.

private void doImport(CurrencyDao dao, Currency currency) {
    with(zip -> {
        JsonImport jImport = new JsonImport(zip, Tests.getDb());
        jImport.run();
    });
    Assert.assertTrue(dao.contains(currency.refId));
    Currency clone = dao.getForRefId(currency.refId);
    Assert.assertEquals(currency.name, clone.name);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) Currency(org.openlca.core.model.Currency)

Example 14 with Currency

use of org.openlca.core.model.Currency in project olca-modules by GreenDelta.

the class ExchangeCostTest method testCostAttributes.

@Test
public void testCostAttributes() {
    Currency currency = createCurrency();
    Process process = createProcess(currency);
    with(zip -> {
        JsonExport export = new JsonExport(Tests.getDb(), zip);
        export.write(process);
    });
    delete(currency, process);
    with(zip -> {
        JsonImport jImport = new JsonImport(zip, Tests.getDb());
        jImport.run();
    });
    checkImport(process);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) Currency(org.openlca.core.model.Currency) Process(org.openlca.core.model.Process) JsonExport(org.openlca.jsonld.output.JsonExport) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 15 with Currency

use of org.openlca.core.model.Currency 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)

Aggregations

Currency (org.openlca.core.model.Currency)20 CurrencyDao (org.openlca.core.database.CurrencyDao)9 Test (org.junit.Test)3 Category (org.openlca.core.model.Category)2 Process (org.openlca.core.model.Process)2 AbstractZipTest (org.openlca.jsonld.AbstractZipTest)2 JsonImport (org.openlca.jsonld.input.JsonImport)2 ArrayList (java.util.ArrayList)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Actor (org.openlca.core.model.Actor)1 DQSystem (org.openlca.core.model.DQSystem)1 Flow (org.openlca.core.model.Flow)1 FlowProperty (org.openlca.core.model.FlowProperty)1 ImpactCategory (org.openlca.core.model.ImpactCategory)1 ImpactMethod (org.openlca.core.model.ImpactMethod)1 Location (org.openlca.core.model.Location)1