Search in sources :

Example 16 with Currency

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

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

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

the class CostDialog method setCurrencyContent.

private void setCurrencyContent(ComboViewer combo) {
    combo.setContentProvider(ArrayContentProvider.getInstance());
    CurrencyDao dao = new CurrencyDao(Database.get());
    List<Currency> all = dao.getAll();
    Collections.sort(all, (c1, c2) -> Strings.compare(c1.name, c2.name));
    combo.setInput(all);
    currency = exchange.currency;
    if (currency == null)
        currency = dao.getReferenceCurrency();
    if (currency != null) {
        combo.setSelection(new StructuredSelection(currency));
        exchange.currency = currency;
    }
}
Also used : CurrencyDao(org.openlca.core.database.CurrencyDao) Currency(org.openlca.core.model.Currency) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 19 with Currency

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

the class CostDialog method createCurrencyRow.

private void createCurrencyRow(Composite body, FormToolkit tk) {
    Combo widget = UI.formCombo(body, tk, M.Currency);
    currencyCombo = new ComboViewer(widget);
    currencyCombo.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object obj) {
            if (!(obj instanceof Currency))
                return super.getText(obj);
            return ((Currency) obj).name;
        }
    });
    setCurrencyContent(currencyCombo);
    currencyCombo.addSelectionChangedListener(e -> {
        currency = Selections.firstOf(e);
        exchange.currency = currency;
        updateCurrencyLabels();
    });
    UI.filler(body, tk);
}
Also used : ComboViewer(org.eclipse.jface.viewers.ComboViewer) Currency(org.openlca.core.model.Currency) Combo(org.eclipse.swt.widgets.Combo) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 20 with Currency

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

the class RefCurrencyUpdate method run.

@Override
public void run() {
    try {
        CurrencyDao dao = new CurrencyDao(Database.get());
        c.lastChange = Calendar.getInstance().getTimeInMillis();
        Version.incUpdate(c);
        c = dao.update(c);
        double f = c.conversionFactor;
        for (Currency o : dao.getAll()) {
            o.referenceCurrency = c;
            o.lastChange = Calendar.getInstance().getTimeInMillis();
            Version.incUpdate(o);
            if (Objects.equals(c, o)) {
                o.conversionFactor = 1.0;
                c = dao.update(o);
            } else {
                o.conversionFactor = o.conversionFactor / f;
                dao.update(o);
            }
        }
    } catch (Exception e) {
        Logger log = LoggerFactory.getLogger(getClass());
        log.error("failed to update reference currency", e);
    }
}
Also used : CurrencyDao(org.openlca.core.database.CurrencyDao) Currency(org.openlca.core.model.Currency) Logger(org.slf4j.Logger)

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