Search in sources :

Example 1 with Currency

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

the class CurrencyDao method getReferenceCurrency.

/**
 * There should be only one currency that is the reference currency in the
 * database. This function returns the reference currency of the first
 * currency in the database (which should by the reference currency of all
 * other currencies by this definition). If there is no currency contained
 * in the database, this function will return null.
 */
public Currency getReferenceCurrency() {
    List<CurrencyDescriptor> all = getDescriptors();
    if (all.isEmpty())
        return null;
    Currency currency = getForId(all.get(0).id);
    return currency == null ? null : currency.referenceCurrency;
}
Also used : Currency(org.openlca.core.model.Currency) CurrencyDescriptor(org.openlca.core.model.descriptors.CurrencyDescriptor)

Example 2 with Currency

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

the class CurrencyReferenceSearchTest method createModel.

@Override
protected Currency createModel() {
    Currency currency = new Currency();
    currency.category = insertAndAddExpected("category", new Category());
    currency.referenceCurrency = insertAndAddExpected("referenceCurrency", new Currency());
    currency = db.insert(currency);
    currencies.add(currency);
    return currency;
}
Also used : Category(org.openlca.core.model.Category) Currency(org.openlca.core.model.Currency)

Example 3 with Currency

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

the class DataUtil method toDataSet.

static ProtoDataSet.Builder toDataSet(IDatabase db, RefEntity e) {
    var ds = ProtoDataSet.newBuilder();
    var conf = WriterConfig.of(db);
    if (e instanceof Actor)
        return ds.setActor(new ActorWriter(conf).write((Actor) e));
    if (e instanceof Category)
        return ds.setCategory(new CategoryWriter(conf).write((Category) e));
    if (e instanceof Currency)
        return ds.setCurrency(new CurrencyWriter(conf).write((Currency) e));
    if (e instanceof DQSystem)
        return ds.setDqSystem(new DQSystemWriter(conf).write((DQSystem) e));
    if (e instanceof Flow)
        return ds.setFlow(new FlowWriter(conf).write((Flow) e));
    if (e instanceof FlowProperty)
        return ds.setFlowProperty(new FlowPropertyWriter(conf).write((FlowProperty) e));
    if (e instanceof ImpactCategory)
        return ds.setImpactCategory(new ImpactCategoryWriter(conf).write((ImpactCategory) e));
    if (e instanceof ImpactMethod)
        return ds.setImpactMethod(new ImpactMethodWriter(conf).write((ImpactMethod) e));
    if (e instanceof Location)
        return ds.setLocation(new LocationWriter(conf).write((Location) e));
    if (e instanceof Parameter)
        return ds.setParameter(new ParameterWriter(conf).write((Parameter) e));
    if (e instanceof Process)
        return ds.setProcess(new ProcessWriter(conf).write((Process) e));
    if (e instanceof ProductSystem)
        return ds.setProductSystem(new ProductSystemWriter(conf).write((ProductSystem) e));
    if (e instanceof Project)
        return ds.setProject(new ProjectWriter(conf).write((Project) e));
    if (e instanceof SocialIndicator)
        return ds.setSocialIndicator(new SocialIndicatorWriter(conf).write((SocialIndicator) e));
    if (e instanceof Source)
        return ds.setSource(new SourceWriter(conf).write((Source) e));
    if (e instanceof UnitGroup)
        return ds.setUnitGroup(new UnitGroupWriter(conf).write((UnitGroup) e));
    return ds;
}
Also used : ImpactCategory(org.openlca.core.model.ImpactCategory) Category(org.openlca.core.model.Category) UnitGroup(org.openlca.core.model.UnitGroup) ImpactCategoryWriter(org.openlca.proto.io.output.ImpactCategoryWriter) ProductSystem(org.openlca.core.model.ProductSystem) Process(org.openlca.core.model.Process) UnitGroupWriter(org.openlca.proto.io.output.UnitGroupWriter) ImpactMethod(org.openlca.core.model.ImpactMethod) ProductSystemWriter(org.openlca.proto.io.output.ProductSystemWriter) Source(org.openlca.core.model.Source) CurrencyWriter(org.openlca.proto.io.output.CurrencyWriter) FlowPropertyWriter(org.openlca.proto.io.output.FlowPropertyWriter) Actor(org.openlca.core.model.Actor) Currency(org.openlca.core.model.Currency) CategoryWriter(org.openlca.proto.io.output.CategoryWriter) ImpactCategoryWriter(org.openlca.proto.io.output.ImpactCategoryWriter) FlowProperty(org.openlca.core.model.FlowProperty) FlowWriter(org.openlca.proto.io.output.FlowWriter) ImpactCategory(org.openlca.core.model.ImpactCategory) SourceWriter(org.openlca.proto.io.output.SourceWriter) Flow(org.openlca.core.model.Flow) LocationWriter(org.openlca.proto.io.output.LocationWriter) Project(org.openlca.core.model.Project) DQSystemWriter(org.openlca.proto.io.output.DQSystemWriter) ParameterWriter(org.openlca.proto.io.output.ParameterWriter) DQSystem(org.openlca.core.model.DQSystem) ActorWriter(org.openlca.proto.io.output.ActorWriter) ImpactMethodWriter(org.openlca.proto.io.output.ImpactMethodWriter) ProjectWriter(org.openlca.proto.io.output.ProjectWriter) Parameter(org.openlca.core.model.Parameter) SocialIndicator(org.openlca.core.model.SocialIndicator) ProcessWriter(org.openlca.proto.io.output.ProcessWriter) Location(org.openlca.core.model.Location) SocialIndicatorWriter(org.openlca.proto.io.output.SocialIndicatorWriter)

Example 4 with Currency

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

the class CurrencyTest method testCurrency.

@Test
public void testCurrency() {
    CurrencyDao dao = new CurrencyDao(Tests.getDb());
    Currency currency = createModel(dao);
    doExport(currency, dao);
    doImport(dao, currency);
    dao.delete(currency);
}
Also used : CurrencyDao(org.openlca.core.database.CurrencyDao) Currency(org.openlca.core.model.Currency) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 5 with Currency

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

the class ExchangeCostTest method createCurrency.

private Currency createCurrency() {
    Currency currency = new Currency();
    currency.refId = UUID.randomUUID().toString();
    currency.code = "USD";
    currency.conversionFactor = 1.0;
    currency.referenceCurrency = currency;
    currency = currencyDao.insert(currency);
    return currency;
}
Also used : Currency(org.openlca.core.model.Currency)

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