Search in sources :

Example 11 with CurrencyDao

use of org.openlca.core.database.CurrencyDao 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 12 with CurrencyDao

use of org.openlca.core.database.CurrencyDao 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

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