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