├── doc └── .gitignore ├── olca-core ├── src │ ├── main │ │ ├── proto │ │ │ └── gen.bat │ │ └── java │ │ │ └── org │ │ │ └── openlca │ │ │ ├── jsonld │ │ │ ├── input │ │ │ │ └── UpdateMode.java │ │ │ ├── output │ │ │ │ ├── JsonWriter.java │ │ │ │ ├── FlowPropertyWriter.java │ │ │ │ ├── CurrencyWriter.java │ │ │ │ ├── SourceWriter.java │ │ │ │ ├── ActorWriter.java │ │ │ │ └── UnitGroupWriter.java │ │ │ ├── upgrades │ │ │ │ └── Upgrades.java │ │ │ └── SchemaVersion.java │ │ │ ├── core │ │ │ ├── model │ │ │ │ ├── ProcessType.java │ │ │ │ ├── FlowPropertyType.java │ │ │ │ ├── FlowType.java │ │ │ │ ├── descriptors │ │ │ │ │ ├── RootDescriptor.java │ │ │ │ │ ├── UnitDescriptor.java │ │ │ │ │ ├── NwSetDescriptor.java │ │ │ │ │ ├── EpdDescriptor.java │ │ │ │ │ ├── ActorDescriptor.java │ │ │ │ │ ├── ResultDescriptor.java │ │ │ │ │ ├── SourceDescriptor.java │ │ │ │ │ ├── ProjectDescriptor.java │ │ │ │ │ ├── CurrencyDescriptor.java │ │ │ │ │ ├── DQSystemDescriptor.java │ │ │ │ │ ├── ParameterDescriptor.java │ │ │ │ │ ├── UnitGroupDescriptor.java │ │ │ │ │ ├── FlowPropertyDescriptor.java │ │ │ │ │ ├── ProductSystemDescriptor.java │ │ │ │ │ ├── LocationDescriptor.java │ │ │ │ │ ├── SocialIndicatorDescriptor.java │ │ │ │ │ ├── CategoryDescriptor.java │ │ │ │ │ └── ImpactMethodDescriptor.java │ │ │ │ ├── RiskLevel.java │ │ │ │ ├── Direction.java │ │ │ │ ├── UncertaintyType.java │ │ │ │ ├── MappingFile.java │ │ │ │ ├── EpdType.java │ │ │ │ ├── TypedRefId.java │ │ │ │ ├── RefEntity.java │ │ │ │ ├── ParameterScope.java │ │ │ │ ├── CalculationTarget.java │ │ │ │ ├── ProviderType.java │ │ │ │ └── Source.java │ │ │ ├── matrix │ │ │ │ ├── format │ │ │ │ │ ├── EntryFunction.java │ │ │ │ │ ├── ByteEntryFunction.java │ │ │ │ │ ├── ByteMatrix.java │ │ │ │ │ ├── Util.java │ │ │ │ │ └── ByteMatrixReader.java │ │ │ │ ├── uncertainties │ │ │ │ │ ├── EntryFunction.java │ │ │ │ │ └── UCell.java │ │ │ │ ├── linking │ │ │ │ │ ├── ITechIndexBuilder.java │ │ │ │ │ ├── Link.java │ │ │ │ │ ├── NodeState.java │ │ │ │ │ └── ProviderLinking.java │ │ │ │ ├── index │ │ │ │ │ └── IndexConsumer.java │ │ │ │ ├── solvers │ │ │ │ │ ├── UmfFactorizedMatrix.java │ │ │ │ │ ├── mkl │ │ │ │ │ │ └── OS.java │ │ │ │ │ └── Umfpack.java │ │ │ │ ├── io │ │ │ │ │ └── index │ │ │ │ │ │ └── IxFormat.java │ │ │ │ └── cache │ │ │ │ │ └── CacheUtil.java │ │ │ ├── math │ │ │ │ ├── rand │ │ │ │ │ ├── Discrete.java │ │ │ │ │ ├── Normal.java │ │ │ │ │ ├── Uniform.java │ │ │ │ │ └── Triangular.java │ │ │ │ └── data_quality │ │ │ │ │ ├── AggregationType.java │ │ │ │ │ └── NAHandling.java │ │ │ ├── io │ │ │ │ └── Cancelable.java │ │ │ ├── database │ │ │ │ ├── internal │ │ │ │ │ ├── ScriptHandler.java │ │ │ │ │ └── Resource.java │ │ │ │ ├── ExchangeDao.java │ │ │ │ ├── ProcessGroupSetDao.java │ │ │ │ ├── EpdDao.java │ │ │ │ ├── IDatabaseListener.java │ │ │ │ ├── UnitDao.java │ │ │ │ ├── ResultDao.java │ │ │ │ ├── ActorDao.java │ │ │ │ ├── SourceDao.java │ │ │ │ ├── ProjectDao.java │ │ │ │ ├── usage │ │ │ │ │ ├── EmptyUseSearch.java │ │ │ │ │ ├── SocialIndicatorUseSearch.java │ │ │ │ │ ├── UnitGroupUseSearch.java │ │ │ │ │ ├── ImpactMethodUseSearch.java │ │ │ │ │ ├── ProductSystemUseSearch.java │ │ │ │ │ ├── ProcessUseSearch.java │ │ │ │ │ ├── CurrencyUseSearch.java │ │ │ │ │ └── ImpactCategoryUseSearch.java │ │ │ │ ├── FlowPropertyDao.java │ │ │ │ ├── SocialIndicatorDao.java │ │ │ │ ├── descriptors │ │ │ │ │ ├── EpdDescriptors.java │ │ │ │ │ ├── ActorDescriptors.java │ │ │ │ │ ├── ResultDescriptors.java │ │ │ │ │ ├── SourceDescriptors.java │ │ │ │ │ ├── ProjectDescriptors.java │ │ │ │ │ ├── CurrencyDescriptors.java │ │ │ │ │ ├── DQSystemDescriptors.java │ │ │ │ │ ├── UnitGroupDescriptors.java │ │ │ │ │ ├── FlowPropertyDescriptors.java │ │ │ │ │ ├── ImpactMethodDescriptors.java │ │ │ │ │ ├── SocialIndicatorDescriptors.java │ │ │ │ │ └── Util.java │ │ │ │ ├── upgrades │ │ │ │ │ ├── Upgrade15.java │ │ │ │ │ ├── VersionState.java │ │ │ │ │ ├── IUpgrade.java │ │ │ │ │ ├── Upgrade09.java │ │ │ │ │ └── Upgrade13.java │ │ │ │ ├── DatabaseException.java │ │ │ │ ├── DbUtils.java │ │ │ │ └── IDao.java │ │ │ ├── results │ │ │ │ ├── ImpactValue.java │ │ │ │ ├── TechFlowValue.java │ │ │ │ ├── agroups │ │ │ │ │ └── Tree.java │ │ │ │ └── EnviFlowValue.java │ │ │ ├── library │ │ │ │ └── MountAction.java │ │ │ └── services │ │ │ │ └── Response.java │ │ │ ├── util │ │ │ ├── Pair.java │ │ │ ├── Lists.java │ │ │ ├── Copy.java │ │ │ ├── Exceptions.java │ │ │ └── Doubles.java │ │ │ ├── geo │ │ │ ├── geojson │ │ │ │ └── Geometry.java │ │ │ └── lcia │ │ │ │ └── GeoAggregation.java │ │ │ └── text │ │ │ └── WordBuffer.java │ └── test │ │ ├── java │ │ ├── org │ │ │ └── openlca │ │ │ │ ├── core │ │ │ │ ├── library │ │ │ │ │ └── LibraryInventoryTest.java │ │ │ │ ├── matrix │ │ │ │ │ ├── solvers │ │ │ │ │ │ └── mkl │ │ │ │ │ │ │ ├── LibraryTest.java │ │ │ │ │ │ │ └── SparseTest.java │ │ │ │ │ └── index │ │ │ │ │ │ ├── ImpactIndexTest.java │ │ │ │ │ │ └── IndexFlowTest.java │ │ │ │ ├── ListUtils.java │ │ │ │ ├── model │ │ │ │ │ ├── DescriptorsTest.java │ │ │ │ │ └── CloneProcessTest.java │ │ │ │ ├── database │ │ │ │ │ ├── config │ │ │ │ │ │ └── MySqlConfigTest.java │ │ │ │ │ ├── descriptors │ │ │ │ │ │ ├── LocationDescriptorTest.java │ │ │ │ │ │ └── DescriptorReaderTest.java │ │ │ │ │ ├── ResultIOTest.java │ │ │ │ │ ├── LibraryTest.java │ │ │ │ │ ├── ParameterDaoTest.java │ │ │ │ │ ├── usage │ │ │ │ │ │ └── UnitGroupUseSearchTest.java │ │ │ │ │ ├── SafeEnumTest.java │ │ │ │ │ └── ProjectVariantIOTest.java │ │ │ │ └── services │ │ │ │ │ └── JsonRefTest.java │ │ │ │ ├── geo │ │ │ │ └── calc │ │ │ │ │ ├── IntersectionShareTest.java │ │ │ │ │ └── WebMercatorTest.java │ │ │ │ └── jsonld │ │ │ │ ├── AbstractZipTest.java │ │ │ │ └── io │ │ │ │ └── ReOpenTest.java │ │ └── examples │ │ │ ├── NpyExample.java │ │ │ ├── FeatureValidationExample.java │ │ │ ├── LibraryUsageExample.java │ │ │ ├── ImpactBuilderExample.java │ │ │ ├── DbLibrarySwapExample.java │ │ │ ├── LibraryCalculatorExample.java │ │ │ ├── LibraryExportExample.java │ │ │ ├── EachOneResultExample.java │ │ │ └── GeoFactorExample.java │ │ └── resources │ │ ├── org │ │ └── openlca │ │ │ ├── geo │ │ │ └── geojson │ │ │ │ ├── point.geojson │ │ │ │ ├── linestring.geojson │ │ │ │ └── polygon.geojson │ │ │ └── jsonld │ │ │ └── input │ │ │ ├── unit_sync-all.zip │ │ │ ├── nw_set_sync-all.zip │ │ │ ├── exchange_sync-all.zip │ │ │ ├── exchange_sync-process.zip │ │ │ ├── unit_sync-unit_group.zip │ │ │ ├── nw_set_sync-impact_method.zip │ │ │ ├── flow_property_factor_sync-all.zip │ │ │ └── flow_property_factor_sync-flow.zip │ │ └── logback-test.xml └── README.md ├── .gitattributes ├── olca-io └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── openlca │ │ │ └── io │ │ │ ├── xls │ │ │ ├── systems │ │ │ │ ├── IExcelHeaderEntry.java │ │ │ │ ├── package-info.java │ │ │ │ └── SystemExportConfig.java │ │ │ ├── process │ │ │ │ ├── OutEntitySync.java │ │ │ │ ├── SectionReader.java │ │ │ │ ├── InProviderSync.java │ │ │ │ ├── InConfig.java │ │ │ │ ├── RowReader.java │ │ │ │ ├── Tab.java │ │ │ │ └── Styles.java │ │ │ └── results │ │ │ │ ├── system │ │ │ │ └── MatrixPage.java │ │ │ │ └── DQColors.java │ │ │ ├── openepd │ │ │ ├── Jsonable.java │ │ │ ├── Ec3OrgInfo.java │ │ │ ├── io │ │ │ │ └── MappingModel.java │ │ │ ├── Ec3Certifier.java │ │ │ └── Util.java │ │ │ ├── smartepd │ │ │ ├── SmartStage.java │ │ │ ├── SmartIndicatorType.java │ │ │ ├── SmartEpdReader.java │ │ │ ├── SmartPcr.java │ │ │ └── SmartMethod.java │ │ │ ├── Import.java │ │ │ ├── hestia │ │ │ ├── HestiaRef.java │ │ │ ├── HestiaObject.java │ │ │ ├── SearchResult.java │ │ │ ├── Site.java │ │ │ ├── Util.java │ │ │ ├── GlossaryFileInfo.java │ │ │ └── UnitMap.java │ │ │ ├── refdata │ │ │ ├── CsvRow.java │ │ │ └── LocationImport.java │ │ │ ├── pubchem │ │ │ ├── Property.java │ │ │ ├── PropertyValue.java │ │ │ ├── Compound.java │ │ │ └── PropertyUrn.java │ │ │ ├── UnitMappingEntry.java │ │ │ ├── ecospold1 │ │ │ ├── input │ │ │ │ ├── FlowBucket.java │ │ │ │ ├── ImportConfig.java │ │ │ │ └── FlowTypes.java │ │ │ └── output │ │ │ │ └── ExportConfig.java │ │ │ ├── ilcd │ │ │ ├── output │ │ │ │ └── ImpactMethodExport.java │ │ │ └── input │ │ │ │ └── models │ │ │ │ └── Link.java │ │ │ ├── oneclick │ │ │ └── Module.java │ │ │ ├── CategoryPath.java │ │ │ ├── ecospold2 │ │ │ └── output │ │ │ │ └── Units.java │ │ │ └── maps │ │ │ └── MapFactor.java │ └── melody │ │ └── openepd │ │ ├── indicators │ │ ├── mr.mdy │ │ ├── eh.mdy │ │ ├── ep-fresh.mdy │ │ ├── ep-terr.mdy │ │ ├── pocp.mdy │ │ ├── gwp-biogenic.mdy │ │ ├── gwp-lulcu.mdy │ │ ├── ap.mdy │ │ ├── ep.mdy │ │ └── odp.mdy │ │ ├── methods │ │ ├── cml.mdy │ │ ├── ipcc.mdy │ │ ├── traci.mdy │ │ └── ef.mdy │ │ └── units │ │ ├── kgO3e.mdy │ │ ├── molNe.mdy │ │ ├── kgCO2e.mdy │ │ ├── kgNe.mdy │ │ ├── kgSO2e.mdy │ │ ├── kgCFC11e.mdy │ │ └── kgPO4e.mdy │ └── test │ ├── java │ ├── org │ │ └── openlca │ │ │ └── io │ │ │ ├── Tests.java │ │ │ ├── pubchem │ │ │ └── PubChemClientTest.java │ │ │ ├── oneclick │ │ │ └── PackagingMatcherTest.java │ │ │ ├── maps │ │ │ └── CountryInfoTest.java │ │ │ ├── smartepd │ │ │ └── ProjectSettingsTest.java │ │ │ └── xls │ │ │ └── process │ │ │ └── Example.java │ └── examples │ │ └── HestiaEcoinventFlowMapExample.java │ └── resources │ └── logback-test.xml ├── olca-proto-io ├── .gitignore ├── .editorconfig ├── src │ ├── main │ │ ├── java │ │ │ └── org │ │ │ │ └── openlca │ │ │ │ └── proto │ │ │ │ └── io │ │ │ │ ├── input │ │ │ │ ├── EntityReader.java │ │ │ │ ├── ResultReader.java │ │ │ │ ├── SourceReader.java │ │ │ │ ├── ImportStatus.java │ │ │ │ ├── LocationReader.java │ │ │ │ └── ActorReader.java │ │ │ │ ├── output │ │ │ │ ├── DependencyHandler.java │ │ │ │ ├── ProjectWriter.java │ │ │ │ ├── SourceWriter.java │ │ │ │ ├── CurrencyWriter.java │ │ │ │ ├── LocationWriter.java │ │ │ │ └── ActorWriter.java │ │ │ │ └── server │ │ │ │ └── Response.java │ │ └── proto │ │ │ └── commons.proto │ └── test │ │ ├── resources │ │ └── logback-test.xml │ │ └── java │ │ └── org │ │ └── openlca │ │ └── proto │ │ └── io │ │ ├── Tests.java │ │ ├── ImportExample.java │ │ ├── input │ │ └── NullSafetyTest.java │ │ ├── EnumTest.java │ │ └── examples │ │ └── ProvidersExample.java └── build_server.py ├── olca-git └── src │ ├── main │ └── java │ │ └── org │ │ └── openlca │ │ └── git │ │ ├── model │ │ └── DiffType.java │ │ ├── actions │ │ ├── LibraryResolver.java │ │ ├── ConflictException.java │ │ ├── GitProgressAction.java │ │ ├── GitRemoteAction.java │ │ └── GitStashDrop.java │ │ └── util │ │ ├── Constants.java │ │ ├── BinaryResolver.java │ │ ├── Path.java │ │ ├── ModelRefSet.java │ │ ├── ModelRefMap.java │ │ └── ProgressMonitor.java │ └── test │ └── resources │ └── logback-test.xml ├── olca-ipc ├── .gitignore ├── server_readme.txt └── src │ ├── main │ └── java │ │ └── org │ │ └── openlca │ │ └── ipc │ │ ├── Rpc.java │ │ ├── Cache.java │ │ ├── handlers │ │ ├── Effect.java │ │ └── RuntimeHandler.java │ │ └── RpcError.java │ └── test │ └── resources │ └── logback-test.xml ├── .gitignore └── .editorconfig /doc/.gitignore: -------------------------------------------------------------------------------- 1 | *.pdf 2 | -------------------------------------------------------------------------------- /olca-core/src/main/proto/gen.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | protoc ix.proto --java_out=..\java 4 | protoc geo.proto --java_out=..\java 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.dylib filter=lfs diff=lfs merge=lfs -text 2 | *.so filter=lfs diff=lfs merge=lfs -text 3 | *.dll filter=lfs diff=lfs merge=lfs -text 4 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/library/LibraryInventoryTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.library; 2 | 3 | public class LibraryInventoryTest { 4 | } 5 | -------------------------------------------------------------------------------- /olca-core/src/test/resources/org/openlca/geo/geojson/point.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Point", 3 | "coordinates": [ 4 | 13.28, 5 | 52.51 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/jsonld/input/UpdateMode.java: -------------------------------------------------------------------------------- 1 | package org.openlca.jsonld.input; 2 | 3 | public enum UpdateMode { 4 | 5 | NEVER, IF_NEWER, ALWAYS; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/ProcessType.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | public enum ProcessType { 4 | 5 | LCI_RESULT, 6 | 7 | UNIT_PROCESS 8 | 9 | } 10 | -------------------------------------------------------------------------------- /olca-core/src/test/resources/org/openlca/jsonld/input/unit_sync-all.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreenDelta/olca-modules/HEAD/olca-core/src/test/resources/org/openlca/jsonld/input/unit_sync-all.zip -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/xls/systems/IExcelHeaderEntry.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.xls.systems; 2 | 3 | interface IExcelHeaderEntry { 4 | 5 | String getValue(int count); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/FlowPropertyType.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | public enum FlowPropertyType { 4 | 5 | ECONOMIC, 6 | 7 | PHYSICAL 8 | 9 | } 10 | -------------------------------------------------------------------------------- /olca-core/src/test/resources/org/openlca/jsonld/input/nw_set_sync-all.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreenDelta/olca-modules/HEAD/olca-core/src/test/resources/org/openlca/jsonld/input/nw_set_sync-all.zip -------------------------------------------------------------------------------- /olca-proto-io/.gitignore: -------------------------------------------------------------------------------- 1 | jre/ 2 | 3 | # Maven output 4 | target/ 5 | 6 | # IDE files 7 | .idea/ 8 | *.iml 9 | .classpath 10 | .project 11 | .settings/ 12 | .vscode 13 | 14 | *.exe 15 | *.log 16 | -------------------------------------------------------------------------------- /olca-core/src/test/resources/org/openlca/jsonld/input/exchange_sync-all.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreenDelta/olca-modules/HEAD/olca-core/src/test/resources/org/openlca/jsonld/input/exchange_sync-all.zip -------------------------------------------------------------------------------- /olca-core/src/test/resources/org/openlca/jsonld/input/exchange_sync-process.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreenDelta/olca-modules/HEAD/olca-core/src/test/resources/org/openlca/jsonld/input/exchange_sync-process.zip -------------------------------------------------------------------------------- /olca-core/src/test/resources/org/openlca/jsonld/input/unit_sync-unit_group.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreenDelta/olca-modules/HEAD/olca-core/src/test/resources/org/openlca/jsonld/input/unit_sync-unit_group.zip -------------------------------------------------------------------------------- /olca-git/src/main/java/org/openlca/git/model/DiffType.java: -------------------------------------------------------------------------------- 1 | package org.openlca.git.model; 2 | 3 | public enum DiffType { 4 | 5 | ADDED, 6 | 7 | MODIFIED, 8 | 9 | MOVED, 10 | 11 | DELETED; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/openepd/Jsonable.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.openepd; 2 | 3 | import com.google.gson.JsonElement; 4 | 5 | interface Jsonable { 6 | 7 | JsonElement toJson(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /olca-core/src/test/resources/org/openlca/geo/geojson/linestring.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "LineString", 3 | "coordinates": [ 4 | [ 13.26, 52.52 ], 5 | [ 13.27, 52.51 ], 6 | [ 13.28, 52.51 ] 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /olca-core/src/test/resources/org/openlca/jsonld/input/nw_set_sync-impact_method.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreenDelta/olca-modules/HEAD/olca-core/src/test/resources/org/openlca/jsonld/input/nw_set_sync-impact_method.zip -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/indicators/mr.mdy: -------------------------------------------------------------------------------- 1 | either { 2 | ; 3 | some of not ; 4 | } 5 | either { 6 | "mr"; 7 | "mfr"; 8 | } 9 | either { 10 | ; 11 | some of not ; 12 | } 13 | -------------------------------------------------------------------------------- /olca-core/src/test/resources/org/openlca/jsonld/input/flow_property_factor_sync-all.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreenDelta/olca-modules/HEAD/olca-core/src/test/resources/org/openlca/jsonld/input/flow_property_factor_sync-all.zip -------------------------------------------------------------------------------- /olca-ipc/.gitignore: -------------------------------------------------------------------------------- 1 | # Maven output 2 | target/ 3 | 4 | # IDE files 5 | .idea/ 6 | *.iml 7 | 8 | # Eclipse files 9 | .settings/ 10 | .project 11 | .classpath 12 | 13 | # VSCode files 14 | .vscode 15 | 16 | derby.log 17 | -------------------------------------------------------------------------------- /olca-core/src/test/resources/org/openlca/jsonld/input/flow_property_factor_sync-flow.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GreenDelta/olca-modules/HEAD/olca-core/src/test/resources/org/openlca/jsonld/input/flow_property_factor_sync-flow.zip -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/indicators/eh.mdy: -------------------------------------------------------------------------------- 1 | either { 2 | ; 3 | some of not ; 4 | } 5 | 6 | either { 7 | "eh"; 8 | "eet"; 9 | } 10 | 11 | either { 12 | ; 13 | some of not ; 14 | } 15 | -------------------------------------------------------------------------------- /olca-ipc/server_readme.txt: -------------------------------------------------------------------------------- 1 | # openLCA IPC Server - JSON-RPC 2 | 3 | This is a stand-alone for the openLCA IPC Server using the JSON-RPC protocol. 4 | See the official documentation at 5 | https://greendelta.github.io/openLCA-ApiDoc/ipc/. 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IDE files and folders 2 | **/.idea/ 3 | *.iml 4 | **/.settings/ 5 | .classpath 6 | .project 7 | **/.vscode/ 8 | 9 | # generated files 10 | **/apidocs/ 11 | **/target/ 12 | **/bin/ 13 | *.log 14 | 15 | *.*~ 16 | *.DS_Store 17 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/format/EntryFunction.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.format; 2 | 3 | @FunctionalInterface 4 | public interface EntryFunction { 5 | 6 | void value(int row, int col, double value); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/format/ByteEntryFunction.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.format; 2 | 3 | @FunctionalInterface 4 | public interface ByteEntryFunction { 5 | 6 | void value(int row, int col, byte value); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/util/Pair.java: -------------------------------------------------------------------------------- 1 | package org.openlca.util; 2 | 3 | public record Pair(F first, S second) { 4 | 5 | public static Pair of(F first, S second) { 6 | return new Pair<>(first, second); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/methods/cml.mdy: -------------------------------------------------------------------------------- 1 | ahead { 2 | any of ; 3 | ; 4 | "cml"; 5 | ; 6 | } 7 | ahead { 8 | any of ; 9 | ; 10 | "2007"; 11 | ; 12 | } 13 | any of ; 14 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/methods/ipcc.mdy: -------------------------------------------------------------------------------- 1 | ahead { 2 | any of ; 3 | ; 4 | "ipcc"; 5 | ; 6 | } 7 | ahead { 8 | any of ; 9 | ; 10 | "ar5"; 11 | ; 12 | } 13 | any of ; 14 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/math/rand/Discrete.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.math.rand; 2 | 3 | record Discrete(double val) implements NumberGenerator { 4 | 5 | @Override 6 | public double next() { 7 | return val; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/uncertainties/EntryFunction.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.uncertainties; 2 | 3 | @FunctionalInterface 4 | public interface EntryFunction { 5 | 6 | void accept(int row, int col, UCell cell); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/smartepd/SmartStage.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.smartepd; 2 | 3 | public enum SmartStage { 4 | 5 | PRODUCTION, 6 | 7 | CONSTRUCTION, 8 | 9 | USE, 10 | 11 | END_OF_LIFE, 12 | 13 | BENEFITS; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/methods/traci.mdy: -------------------------------------------------------------------------------- 1 | ahead { 2 | any of ; 3 | ; 4 | "traci"; 5 | ; 6 | } 7 | ahead { 8 | any of ; 9 | ; 10 | "2.1"; 11 | ; 12 | } 13 | any of ; 14 | -------------------------------------------------------------------------------- /olca-git/src/main/java/org/openlca/git/actions/LibraryResolver.java: -------------------------------------------------------------------------------- 1 | package org.openlca.git.actions; 2 | 3 | import org.openlca.core.library.Library; 4 | 5 | public interface LibraryResolver { 6 | 7 | Library resolve(String libraryId); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /olca-core/src/test/resources/org/openlca/geo/geojson/polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Polygon", 3 | "coordinates": [ 4 | [ 5 | [ 13.30, 52.52 ], 6 | [ 13.25, 52.50 ], 7 | [ 13.29, 52.51 ], 8 | [ 13.30, 52.52 ] 9 | ] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/xls/process/OutEntitySync.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.xls.process; 2 | 3 | import org.openlca.core.model.RootEntity; 4 | 5 | interface OutEntitySync { 6 | 7 | void flush(); 8 | 9 | void visit(RootEntity entity); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/FlowType.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | /** 4 | * Enumeration of available flow types 5 | */ 6 | public enum FlowType { 7 | 8 | ELEMENTARY_FLOW, 9 | 10 | PRODUCT_FLOW, 11 | 12 | WASTE_FLOW 13 | 14 | } 15 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/xls/results/system/MatrixPage.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.xls.results.system; 2 | 3 | public enum MatrixPage { 4 | 5 | DIRECT_IMPACTS, 6 | DIRECT_INVENTORIES, 7 | FLOW_IMPACTS, 8 | TOTAL_IMPACTS, 9 | TOTAL_INVENTORIES 10 | 11 | } 12 | -------------------------------------------------------------------------------- /olca-proto-io/.editorconfig: -------------------------------------------------------------------------------- 1 | # see https://editorconfig.org/ 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | 10 | [*.{java,xml}] 11 | indent_style = tab 12 | indent_size = 2 13 | tab_width = 2 14 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/io/Cancelable.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.io; 2 | 3 | /** 4 | * Describes a process that can be cancelled. 5 | */ 6 | public interface Cancelable extends Runnable { 7 | 8 | void cancel(); 9 | 10 | boolean isCanceled(); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/math/data_quality/AggregationType.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.math.data_quality; 2 | 3 | public enum AggregationType { 4 | 5 | WEIGHTED_AVERAGE, 6 | 7 | WEIGHTED_SQUARED_AVERAGE, 8 | 9 | MAXIMUM, 10 | 11 | NONE 12 | 13 | } 14 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/internal/ScriptHandler.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.internal; 2 | 3 | /** 4 | * The interface for handlers of SQL script events. 5 | */ 6 | interface ScriptHandler { 7 | 8 | void statement(String statement) throws Exception; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/format/ByteMatrix.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.format; 2 | 3 | /** 4 | * An interface for matrices of (signed) byte values. 5 | */ 6 | public interface ByteMatrix extends ByteMatrixReader { 7 | 8 | void set(int row, int col, byte value); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/math/data_quality/NAHandling.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.math.data_quality; 2 | 3 | /** 4 | * Lists the different types of how to process n.a. values in data quality 5 | * calculation 6 | */ 7 | public enum NAHandling { 8 | 9 | EXCLUDE, 10 | 11 | USE_MAX 12 | 13 | } 14 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/Import.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io; 2 | 3 | import org.openlca.core.io.Cancelable; 4 | import org.openlca.core.io.ImportLog; 5 | 6 | public interface Import extends Cancelable { 7 | 8 | /** 9 | * Returns the import log of this import. 10 | */ 11 | ImportLog log(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/ExchangeDao.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import org.openlca.core.model.Exchange; 4 | 5 | public class ExchangeDao extends BaseDao { 6 | 7 | public ExchangeDao(IDatabase database) { 8 | super(Exchange.class, database); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/linking/ITechIndexBuilder.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.linking; 2 | 3 | import org.openlca.core.matrix.index.TechFlow; 4 | import org.openlca.core.matrix.index.TechIndex; 5 | 6 | public interface ITechIndexBuilder { 7 | 8 | TechIndex build(TechFlow refProduct); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | insert_final_newline = true 6 | trim_trailing_whitespace = true 7 | 8 | [*.{groovy,mdy}] 9 | indent_style = space 10 | indent_size = 2 11 | tab_width = 2 12 | 13 | [*.{java,xml}] 14 | indent_style = tab 15 | indent_size = 2 16 | tab_width = 2 17 | ij_continuation_indent_size = 2 18 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/hestia/HestiaRef.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.hestia; 2 | 3 | import org.openlca.jsonld.Json; 4 | 5 | import com.google.gson.JsonObject; 6 | 7 | public record HestiaRef(JsonObject json) implements HestiaObject { 8 | 9 | public String name() { 10 | return Json.getString(json, "name"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/smartepd/SmartIndicatorType.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.smartepd; 2 | 3 | public enum SmartIndicatorType { 4 | 5 | /// Environmental impact assessment indicators 6 | IMPACT, 7 | 8 | /// Resource use indicators 9 | RESOURCE, 10 | 11 | /// Output indicators, like waste etc. 12 | OUTPUT; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/index/IndexConsumer.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.index; 2 | 3 | /** 4 | * Like the normal consumer function but with an index of the respective object 5 | * as first argument. 6 | */ 7 | @FunctionalInterface 8 | public interface IndexConsumer { 9 | 10 | void accept(int index, T obj); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/java/org/openlca/proto/io/input/EntityReader.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io.input; 2 | 3 | import org.openlca.core.model.RootEntity; 4 | 5 | import com.google.protobuf.Message; 6 | 7 | interface EntityReader { 8 | 9 | E read(P proto); 10 | 11 | void update(E entity, P proto); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/jsonld/output/JsonWriter.java: -------------------------------------------------------------------------------- 1 | package org.openlca.jsonld.output; 2 | 3 | import org.openlca.core.model.RefEntity; 4 | 5 | import com.google.gson.JsonObject; 6 | 7 | /** 8 | * Converts an entity to a JSON object. 9 | */ 10 | public interface JsonWriter { 11 | 12 | JsonObject write(T entity); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/units/kgO3e.mdy: -------------------------------------------------------------------------------- 1 | 2 | let .eq = { 3 | "e"; 4 | option of "q"; 5 | option of "."; 6 | option of "quivalents"; 7 | } 8 | 9 | either { 10 | ; 11 | any of not ; 12 | } 13 | 14 | "kg"; 15 | any of not ; 16 | "O3"; 17 | any of not ; 18 | .eq; 19 | either { 20 | ; 21 | any of not ; 22 | } 23 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/units/molNe.mdy: -------------------------------------------------------------------------------- 1 | 2 | let .eq = { 3 | "e"; 4 | option of "q"; 5 | option of "."; 6 | option of "quivalents"; 7 | } 8 | 9 | either { 10 | ; 11 | any of not ; 12 | } 13 | 14 | "mol"; 15 | any of not ; 16 | "N"; 17 | any of not ; 18 | .eq; 19 | either { 20 | ; 21 | any of not ; 22 | } 23 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/geo/geojson/Geometry.java: -------------------------------------------------------------------------------- 1 | package org.openlca.geo.geojson; 2 | 3 | import org.openlca.commons.Copyable; 4 | 5 | import com.google.gson.JsonObject; 6 | 7 | public abstract class Geometry implements Copyable { 8 | 9 | public abstract JsonObject toJson(); 10 | 11 | @Override 12 | public abstract Geometry copy(); 13 | } 14 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/java/org/openlca/proto/io/output/DependencyHandler.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io.output; 2 | 3 | import org.openlca.core.model.RootEntity; 4 | import org.openlca.core.model.descriptors.RootDescriptor; 5 | 6 | public interface DependencyHandler { 7 | 8 | void push(RootEntity entity); 9 | 10 | void push(RootDescriptor descriptor); 11 | } 12 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/ProcessGroupSetDao.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import org.openlca.core.model.ProcessGroupSet; 4 | 5 | public class ProcessGroupSetDao extends BaseDao { 6 | 7 | public ProcessGroupSetDao(IDatabase database) { 8 | super(ProcessGroupSet.class, database); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/RootDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | public class RootDescriptor extends Descriptor { 4 | 5 | public Long category; 6 | 7 | @Override 8 | public RootDescriptor copy() { 9 | var copy = new RootDescriptor(); 10 | copyFields(this, copy); 11 | return copy; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /olca-io/src/test/java/org/openlca/io/Tests.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io; 2 | 3 | import org.openlca.core.database.Derby; 4 | import org.openlca.core.database.IDatabase; 5 | 6 | public class Tests { 7 | 8 | private static IDatabase db; 9 | 10 | public static IDatabase getDb() { 11 | if (db == null) 12 | db = Derby.createInMemory(); 13 | return db; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/EpdDao.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import org.openlca.core.model.Epd; 4 | import org.openlca.core.model.descriptors.EpdDescriptor; 5 | 6 | public class EpdDao extends RootEntityDao { 7 | 8 | public EpdDao(IDatabase db) { 9 | super(Epd.class, EpdDescriptor.class, db); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/indicators/ep-fresh.mdy: -------------------------------------------------------------------------------- 1 | let .eutrophication = { 2 | ; 3 | "eutrophication"; 4 | ; 5 | } 6 | 7 | let .ep = { 8 | ; 9 | "ep"; 10 | ; 11 | } 12 | 13 | ahead { 14 | any of ; 15 | "fresh"; 16 | } 17 | any of ; 18 | either { 19 | .eutrophication; 20 | .ep; 21 | } 22 | any of ; 23 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/IDatabaseListener.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import org.openlca.core.model.descriptors.Descriptor; 4 | 5 | public interface IDatabaseListener { 6 | 7 | void modelInserted(Descriptor descriptor); 8 | 9 | void modelUpdated(Descriptor descriptor); 10 | 11 | void modelDeleted(Descriptor descriptor); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/math/rand/Normal.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.math.rand; 2 | 3 | import java.util.concurrent.ThreadLocalRandom; 4 | 5 | record Normal(double mean, double std) implements NumberGenerator { 6 | 7 | @Override 8 | public double next() { 9 | var rand = ThreadLocalRandom.current().nextGaussian(); 10 | return rand * std + mean; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/xls/systems/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package contains the product system excel export ported from openLCA 1.3. 3 | * The classes in this package are not intended to be used in other packages and 4 | * this packages is more designed as a stand-alone in order to be able to move 5 | * it to another module. 6 | */ 7 | package org.openlca.io.xls.systems; -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/units/kgCO2e.mdy: -------------------------------------------------------------------------------- 1 | let .ws = { 2 | any of ; 3 | } 4 | 5 | let .eq = { 6 | .ws; 7 | option of "-"; 8 | .ws; 9 | option of either { 10 | match { 11 | "e"; 12 | option of "q"; 13 | option of "."; 14 | } 15 | "equivalents"; 16 | } 17 | .ws; 18 | } 19 | 20 | .ws; 21 | "kg"; 22 | .ws; 23 | "CO2"; 24 | .eq; 25 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/units/kgNe.mdy: -------------------------------------------------------------------------------- 1 | let .ws = { 2 | any of ; 3 | } 4 | 5 | let .eq = { 6 | .ws; 7 | option of "-"; 8 | .ws; 9 | option of either { 10 | match { 11 | "e"; 12 | option of "q"; 13 | option of "."; 14 | } 15 | "equivalents"; 16 | } 17 | .ws; 18 | } 19 | 20 | .ws; 21 | "kg"; 22 | .ws; 23 | "N"; 24 | .eq; 25 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/units/kgSO2e.mdy: -------------------------------------------------------------------------------- 1 | let .ws = { 2 | any of ; 3 | } 4 | 5 | let .eq = { 6 | .ws; 7 | option of "-"; 8 | .ws; 9 | option of either { 10 | match { 11 | "e"; 12 | option of "q"; 13 | option of "."; 14 | } 15 | "equivalents"; 16 | } 17 | .ws; 18 | } 19 | 20 | .ws; 21 | "kg"; 22 | .ws; 23 | "SO2"; 24 | .eq; 25 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/UnitDao.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import org.openlca.core.model.Unit; 4 | import org.openlca.core.model.descriptors.UnitDescriptor; 5 | 6 | public class UnitDao extends RefEntityDao { 7 | 8 | public UnitDao(IDatabase database) { 9 | super(Unit.class, UnitDescriptor.class, database); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/ResultDao.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import org.openlca.core.model.Result; 4 | import org.openlca.core.model.descriptors.ResultDescriptor; 5 | 6 | public class ResultDao extends RootEntityDao { 7 | 8 | public ResultDao(IDatabase db) { 9 | super(Result.class, ResultDescriptor.class, db); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /olca-ipc/src/main/java/org/openlca/ipc/Rpc.java: -------------------------------------------------------------------------------- 1 | package org.openlca.ipc; 2 | 3 | import static java.lang.annotation.ElementType.METHOD; 4 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 5 | 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.Target; 8 | 9 | @Retention(RUNTIME) 10 | @Target(METHOD) 11 | public @interface Rpc { 12 | 13 | String value(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/ActorDao.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import org.openlca.core.model.Actor; 4 | import org.openlca.core.model.descriptors.ActorDescriptor; 5 | 6 | public class ActorDao extends RootEntityDao { 7 | 8 | public ActorDao(IDatabase database) { 9 | super(Actor.class, ActorDescriptor.class, database); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/indicators/ep-terr.mdy: -------------------------------------------------------------------------------- 1 | let .eutrophication = { 2 | ; 3 | "eutrophication"; 4 | ; 5 | } 6 | 7 | let .ep = { 8 | ; 9 | "ep"; 10 | ; 11 | } 12 | 13 | ahead { 14 | any of ; 15 | "terr"; 16 | option of "estrial"; 17 | } 18 | 19 | any of ; 20 | either { 21 | .eutrophication; 22 | .ep; 23 | } 24 | any of ; 25 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/SourceDao.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import org.openlca.core.model.Source; 4 | import org.openlca.core.model.descriptors.SourceDescriptor; 5 | 6 | public class SourceDao extends RootEntityDao { 7 | 8 | public SourceDao(IDatabase database) { 9 | super(Source.class, SourceDescriptor.class, database); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/solvers/UmfFactorizedMatrix.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.solvers; 2 | 3 | import org.openlca.julia.Julia; 4 | 5 | public class UmfFactorizedMatrix { 6 | final long pointer; 7 | 8 | UmfFactorizedMatrix(long pointer) { 9 | this.pointer = pointer; 10 | } 11 | 12 | public void dispose() { 13 | Julia.umfDispose(pointer); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/hestia/HestiaObject.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.hestia; 2 | 3 | import org.openlca.jsonld.Json; 4 | 5 | import com.google.gson.JsonObject; 6 | 7 | public interface HestiaObject { 8 | 9 | JsonObject json(); 10 | 11 | default String id() { 12 | return Json.getString(json(), "@id"); 13 | } 14 | 15 | default String type() { 16 | return Json.getString(json(), "@type"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/units/kgCFC11e.mdy: -------------------------------------------------------------------------------- 1 | let .ws = { 2 | any of ; 3 | } 4 | 5 | let .eq = { 6 | .ws; 7 | option of "-"; 8 | .ws; 9 | option of either { 10 | match { 11 | "e"; 12 | option of "q"; 13 | option of "."; 14 | } 15 | "equivalents"; 16 | } 17 | .ws; 18 | } 19 | 20 | .ws; 21 | "kg"; 22 | .ws; 23 | "CFC"; 24 | .ws; 25 | option of "-"; 26 | .ws; 27 | "11"; 28 | .eq; 29 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/units/kgPO4e.mdy: -------------------------------------------------------------------------------- 1 | 2 | let .eq = { 3 | "e"; 4 | option of "q"; 5 | option of "."; 6 | option of "quivalents"; 7 | } 8 | 9 | either { 10 | ; 11 | any of not ; 12 | } 13 | 14 | "kg"; 15 | any of not ; 16 | "PO4"; 17 | any of not ; 18 | option of "3-"; 19 | any of not ; 20 | .eq; 21 | any of not ; 22 | 23 | either { 24 | ; 25 | any of not ; 26 | } 27 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/ProjectDao.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import org.openlca.core.model.Project; 4 | import org.openlca.core.model.descriptors.ProjectDescriptor; 5 | 6 | public class ProjectDao extends 7 | RootEntityDao { 8 | 9 | public ProjectDao(IDatabase database) { 10 | super(Project.class, ProjectDescriptor.class, database); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/RiskLevel.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | public enum RiskLevel { 4 | 5 | NO_OPPORTUNITY, 6 | 7 | HIGH_OPPORTUNITY, 8 | 9 | MEDIUM_OPPORTUNITY, 10 | 11 | LOW_OPPORTUNITY, 12 | 13 | NO_RISK, 14 | 15 | VERY_LOW_RISK, 16 | 17 | LOW_RISK, 18 | 19 | MEDIUM_RISK, 20 | 21 | HIGH_RISK, 22 | 23 | VERY_HIGH_RISK, 24 | 25 | NO_DATA, 26 | 27 | NOT_APPLICABLE 28 | 29 | } 30 | -------------------------------------------------------------------------------- /olca-git/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %green([%thread]) %highlight(%level) %logger{50} - %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/refdata/CsvRow.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.refdata; 2 | 3 | import org.apache.commons.csv.CSVRecord; 4 | 5 | record CsvRow(CSVRecord record) { 6 | 7 | String get(int i) { 8 | return Csv.get(record, i); 9 | } 10 | 11 | double getDouble(int i) { 12 | return Csv.getDouble(record, i); 13 | } 14 | 15 | Double getOptionalDouble(int i) { 16 | return Csv.getOptionalDouble(record, i); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /olca-io/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %green([%thread]) %highlight(%level) %logger{50} - %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /olca-ipc/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %green([%thread]) %highlight(%level) %logger{50} - %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /olca-core/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %green([%thread]) %highlight(%level) %logger{50} - %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /olca-proto-io/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %green([%thread]) %highlight(%level) %logger{50} - %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/hestia/SearchResult.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.hestia; 2 | 3 | import org.openlca.jsonld.Json; 4 | 5 | import com.google.gson.JsonObject; 6 | 7 | public record SearchResult(JsonObject json) implements HestiaObject { 8 | 9 | public String name() { 10 | return Json.getString(json, "name"); 11 | } 12 | 13 | public double score() { 14 | return Json.getDouble(json, "_score", 0.0); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /olca-ipc/src/main/java/org/openlca/ipc/Cache.java: -------------------------------------------------------------------------------- 1 | package org.openlca.ipc; 2 | 3 | import java.util.HashMap; 4 | 5 | public class Cache { 6 | 7 | private final HashMap cache = new HashMap<>(); 8 | 9 | public Object get(String id) { 10 | return cache.get(id); 11 | } 12 | 13 | public void put(String id, Object obj) { 14 | cache.put(id, obj); 15 | } 16 | 17 | public Object remove(String id) { 18 | return cache.remove(id); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/usage/EmptyUseSearch.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.usage; 2 | 3 | import java.util.Collections; 4 | import java.util.Set; 5 | 6 | import org.openlca.core.model.descriptors.RootDescriptor; 7 | 8 | import gnu.trove.set.TLongSet; 9 | 10 | record EmptyUseSearch() implements UsageSearch { 11 | @Override 12 | public Set find(TLongSet ids) { 13 | return Collections.emptySet(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/matrix/solvers/mkl/LibraryTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.solvers.mkl; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | 5 | import org.junit.Assume; 6 | import org.junit.Test; 7 | 8 | public class LibraryTest { 9 | 10 | @Test 11 | public void testIsLibFolder() { 12 | Assume.assumeTrue(MKL.loadFromDefault()); 13 | assertTrue(MKL.isDefaultLibraryDir()); 14 | assertTrue(MKL.loadFromDefault()); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/FlowPropertyDao.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import org.openlca.core.model.FlowProperty; 4 | import org.openlca.core.model.descriptors.FlowPropertyDescriptor; 5 | 6 | public class FlowPropertyDao extends 7 | RootEntityDao { 8 | 9 | public FlowPropertyDao(IDatabase database) { 10 | super(FlowProperty.class, FlowPropertyDescriptor.class, database); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/SocialIndicatorDao.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import org.openlca.core.model.SocialIndicator; 4 | import org.openlca.core.model.descriptors.SocialIndicatorDescriptor; 5 | 6 | public class SocialIndicatorDao 7 | extends RootEntityDao { 8 | 9 | public SocialIndicatorDao(IDatabase database) { 10 | super(SocialIndicator.class, SocialIndicatorDescriptor.class, database); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /olca-proto-io/src/test/java/org/openlca/proto/io/Tests.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io; 2 | 3 | import org.openlca.core.database.Derby; 4 | import org.openlca.core.database.IDatabase; 5 | 6 | public class Tests { 7 | 8 | private static IDatabase db; 9 | 10 | public static IDatabase db() { 11 | if (db != null) 12 | return db; 13 | synchronized (Tests.class) { 14 | if (db != null) 15 | return db; 16 | db = Derby.createInMemory(); 17 | return db; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /olca-core/src/test/java/examples/NpyExample.java: -------------------------------------------------------------------------------- 1 | package examples; 2 | 3 | import java.io.File; 4 | 5 | import org.openlca.npy.Array2d; 6 | 7 | public class NpyExample { 8 | 9 | public static void main(String[] args) { 10 | 11 | var npy = "C:/Users/ms/openLCA-data-1.4/libraries/eora_199.82.000/A.npy"; 12 | var col3 = Array2d.readColumn(new File(npy), 3) 13 | .asDoubleArray() 14 | .data(); 15 | for (int i = 0; i < col3.length; i++) { 16 | System.out.printf("%05d %.4f%n", i, col3[i]); 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /olca-io/src/test/java/org/openlca/io/pubchem/PubChemClientTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.pubchem; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | public class PubChemClientTest { 8 | 9 | @Test 10 | public void getCompoundsByName() { 11 | try (var client = PubChemClient.create()) { 12 | var ethanol = client 13 | .getCompoundsByName("ethanol") 14 | .orElseThrow() 15 | .getFirst(); 16 | assertEquals(Long.valueOf(702), ethanol.id()); 17 | } 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/math/rand/Uniform.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.math.rand; 2 | 3 | import java.util.concurrent.ThreadLocalRandom; 4 | 5 | class Uniform implements NumberGenerator { 6 | 7 | private final double min; 8 | private final double range; 9 | 10 | Uniform(double min, double max) { 11 | this.min = min; 12 | this.range = max - min; 13 | } 14 | 15 | @Override 16 | public double next() { 17 | var rand = ThreadLocalRandom.current(); 18 | return min + rand.nextDouble() * range; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/indicators/pocp.mdy: -------------------------------------------------------------------------------- 1 | 2 | let .code = { 3 | either { 4 | ; 5 | some of not ; 6 | } 7 | "pocp"; 8 | either { 9 | ; 10 | some of not ; 11 | } 12 | } 13 | 14 | let .formation = { 15 | ahead { 16 | any of ; 17 | "ozone"; 18 | } 19 | ahead { 20 | any of ; 21 | either { 22 | "formation"; 23 | "creation"; 24 | } 25 | } 26 | any of ; 27 | } 28 | 29 | either { 30 | .formation; 31 | .code; 32 | } 33 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/util/Lists.java: -------------------------------------------------------------------------------- 1 | package org.openlca.util; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | public final class Lists { 7 | 8 | private Lists() { 9 | } 10 | 11 | public static boolean isEmpty(List list) { 12 | return list == null || list.isEmpty(); 13 | } 14 | 15 | public static Optional first(List list) { 16 | if (list == null || list.isEmpty()) 17 | return Optional.empty(); 18 | var first = list.get(0); 19 | return Optional.ofNullable(first); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/pubchem/Property.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.pubchem; 2 | 3 | import org.openlca.jsonld.Json; 4 | 5 | import com.google.gson.JsonObject; 6 | 7 | public record Property(JsonObject json) { 8 | 9 | public PropertyUrn urn() { 10 | var urnObj = Json.getObject(json, "urn"); 11 | return urnObj != null ? new PropertyUrn(urnObj) : null; 12 | } 13 | 14 | public PropertyValue value() { 15 | var valueObj = Json.getObject(json, "value"); 16 | return valueObj != null ? new PropertyValue(valueObj) : null; 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/format/Util.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.format; 2 | 3 | class Util { 4 | 5 | private Util() { 6 | } 7 | 8 | /** 9 | * Returns the (maximum) number of columns of the given (row) values. 10 | * 11 | * @param values the values as an array of rows 12 | */ 13 | static int columnsOf(double[][] values) { 14 | if (values == null) 15 | return 0; 16 | int columns = 0; 17 | for (double[] row : values) { 18 | columns = Math.max(columns, row.length); 19 | } 20 | return columns; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/descriptors/EpdDescriptors.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import org.openlca.core.database.EpdDao; 4 | import org.openlca.core.database.IDatabase; 5 | import org.openlca.core.model.descriptors.EpdDescriptor; 6 | 7 | public class EpdDescriptors 8 | extends RootDescriptorReader { 9 | 10 | private EpdDescriptors(IDatabase db) { 11 | super(new EpdDao(db)); 12 | } 13 | 14 | public static EpdDescriptors of(IDatabase db) { 15 | return new EpdDescriptors(db); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/util/Copy.java: -------------------------------------------------------------------------------- 1 | package org.openlca.util; 2 | 3 | import org.openlca.commons.Copyable; 4 | 5 | public final class Copy { 6 | 7 | private Copy() { 8 | } 9 | 10 | /** 11 | * A null-safe method for copying the given element. **NOTE:** this method 12 | * only works if the copy method of T returns an instance or a sub-type of T. 13 | */ 14 | @SuppressWarnings("unchecked") 15 | public static > T of(T copyable) { 16 | return copyable == null 17 | ? null 18 | : (T) copyable.copy(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/descriptors/ActorDescriptors.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import org.openlca.core.database.ActorDao; 4 | import org.openlca.core.database.IDatabase; 5 | import org.openlca.core.model.descriptors.ActorDescriptor; 6 | 7 | public class ActorDescriptors extends RootDescriptorReader { 8 | 9 | private ActorDescriptors(IDatabase db) { 10 | super(new ActorDao(db)); 11 | } 12 | 13 | public static ActorDescriptors of(IDatabase db) { 14 | return new ActorDescriptors(db); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/results/ImpactValue.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.results; 2 | 3 | import java.util.Objects; 4 | 5 | import org.openlca.core.model.descriptors.ImpactDescriptor; 6 | 7 | public record ImpactValue(ImpactDescriptor impact, double value) { 8 | 9 | public ImpactValue(ImpactDescriptor impact, double value) { 10 | this.impact = Objects.requireNonNull(impact); 11 | this.value = value; 12 | } 13 | 14 | public static ImpactValue of(ImpactDescriptor impact, double value) { 15 | return new ImpactValue(impact, value); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/util/Exceptions.java: -------------------------------------------------------------------------------- 1 | package org.openlca.util; 2 | 3 | public final class Exceptions { 4 | 5 | private Exceptions() { 6 | } 7 | 8 | /** 9 | * Wraps the given exception into a runtime exception and throws it. 10 | */ 11 | public static void unchecked(String msg, Throwable cause) { 12 | throw new RuntimeException(msg, cause); 13 | } 14 | 15 | /** 16 | * Wraps the given exception into a runtime exception and throws it. 17 | */ 18 | public static void unchecked(Throwable cause) { 19 | throw new RuntimeException(cause); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/hestia/Site.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.hestia; 2 | 3 | import org.openlca.jsonld.Json; 4 | 5 | import com.google.gson.JsonObject; 6 | 7 | public record Site(JsonObject json) implements HestiaObject { 8 | 9 | public String name() { 10 | return Json.getString(json, "name"); 11 | } 12 | 13 | public String siteType() { 14 | return Json.getString(json, "siteType"); 15 | } 16 | 17 | public Term country() { 18 | var obj = Json.getObject(json, "country"); 19 | return obj != null 20 | ? new Term(obj) 21 | : null; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/upgrades/Upgrade15.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.upgrades; 2 | 3 | import org.openlca.core.database.IDatabase; 4 | 5 | public class Upgrade15 implements IUpgrade { 6 | 7 | @Override 8 | public int[] getInitialVersions() { 9 | return new int[]{14}; 10 | } 11 | 12 | @Override 13 | public int getEndVersion() { 14 | return 15; 15 | } 16 | 17 | @Override 18 | public void exec(IDatabase db) { 19 | var u = new DbUtil(db); 20 | u.createColumn("tbl_exchanges", "default_provider_type SMALLINT default 0"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/UnitMappingEntry.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io; 2 | 3 | import org.openlca.core.model.FlowProperty; 4 | import org.openlca.core.model.Unit; 5 | import org.openlca.core.model.UnitGroup; 6 | 7 | public class UnitMappingEntry { 8 | 9 | public String unitName; 10 | public Unit unit; 11 | public UnitGroup unitGroup; 12 | public FlowProperty flowProperty; 13 | public Double factor; 14 | 15 | public boolean isValid() { 16 | return unit != null 17 | && unitGroup != null 18 | && flowProperty != null 19 | && factor != null; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/descriptors/ResultDescriptors.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import org.openlca.core.database.IDatabase; 4 | import org.openlca.core.database.ResultDao; 5 | import org.openlca.core.model.descriptors.ResultDescriptor; 6 | 7 | public class ResultDescriptors 8 | extends RootDescriptorReader { 9 | 10 | private ResultDescriptors(IDatabase db) { 11 | super(new ResultDao(db)); 12 | } 13 | 14 | public static ResultDescriptors of(IDatabase db) { 15 | return new ResultDescriptors(db); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/descriptors/SourceDescriptors.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import org.openlca.core.database.IDatabase; 4 | import org.openlca.core.database.SourceDao; 5 | import org.openlca.core.model.descriptors.SourceDescriptor; 6 | 7 | public class SourceDescriptors 8 | extends RootDescriptorReader { 9 | 10 | private SourceDescriptors(IDatabase db) { 11 | super(new SourceDao(db)); 12 | } 13 | 14 | public static SourceDescriptors of(IDatabase db) { 15 | return new SourceDescriptors(db); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /olca-git/src/main/java/org/openlca/git/actions/ConflictException.java: -------------------------------------------------------------------------------- 1 | package org.openlca.git.actions; 2 | 3 | import org.openlca.core.model.ModelType; 4 | import org.openlca.git.model.ModelRef; 5 | 6 | public class ConflictException extends RuntimeException { 7 | 8 | private static final long serialVersionUID = -6048314745581027571L; 9 | 10 | public ConflictException(ModelRef ref) { 11 | this(ref.type, ref.refId); 12 | } 13 | 14 | public ConflictException(ModelType type, String refId) { 15 | super("No resolution for conflict with model " + type.name() + " " + refId); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/descriptors/ProjectDescriptors.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import org.openlca.core.database.IDatabase; 4 | import org.openlca.core.database.ProjectDao; 5 | import org.openlca.core.model.descriptors.ProjectDescriptor; 6 | 7 | public class ProjectDescriptors 8 | extends RootDescriptorReader { 9 | 10 | private ProjectDescriptors(IDatabase db) { 11 | super(new ProjectDao(db)); 12 | } 13 | 14 | public static ProjectDescriptors of(IDatabase db) { 15 | return new ProjectDescriptors(db); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/geo/lcia/GeoAggregation.java: -------------------------------------------------------------------------------- 1 | package org.openlca.geo.lcia; 2 | 3 | /** 4 | * Defines how the values of a numeric property of set of geometric features 5 | * are aggregated. 6 | */ 7 | public enum GeoAggregation { 8 | 9 | WEIGHTED_AVERAGE, 10 | 11 | AVERAGE, 12 | 13 | MINIMUM, 14 | 15 | MAXIMUM; 16 | 17 | @Override 18 | public String toString() { 19 | return switch (this) { 20 | case WEIGHTED_AVERAGE -> "Weighted average"; 21 | case AVERAGE -> "Average"; 22 | case MINIMUM -> "Minimum"; 23 | case MAXIMUM -> "Maximum"; 24 | }; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/descriptors/CurrencyDescriptors.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import org.openlca.core.database.CurrencyDao; 4 | import org.openlca.core.database.IDatabase; 5 | import org.openlca.core.model.descriptors.CurrencyDescriptor; 6 | 7 | public class CurrencyDescriptors 8 | extends RootDescriptorReader { 9 | 10 | private CurrencyDescriptors(IDatabase db) { 11 | super(new CurrencyDao(db)); 12 | } 13 | 14 | public static CurrencyDescriptors of(IDatabase db) { 15 | return new CurrencyDescriptors(db); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/descriptors/DQSystemDescriptors.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import org.openlca.core.database.DQSystemDao; 4 | import org.openlca.core.database.IDatabase; 5 | import org.openlca.core.model.descriptors.DQSystemDescriptor; 6 | 7 | public class DQSystemDescriptors 8 | extends RootDescriptorReader { 9 | 10 | private DQSystemDescriptors(IDatabase db) { 11 | super(new DQSystemDao(db)); 12 | } 13 | 14 | public static DQSystemDescriptors of(IDatabase db) { 15 | return new DQSystemDescriptors(db); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/UnitDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | public class UnitDescriptor extends Descriptor { 4 | 5 | @Override 6 | public UnitDescriptor copy() { 7 | var copy = new UnitDescriptor(); 8 | copyFields(this, copy); 9 | return copy; 10 | } 11 | 12 | public static Builder create() { 13 | return new Builder(new UnitDescriptor()); 14 | } 15 | 16 | public static class Builder extends DescriptorBuilder { 17 | private Builder(UnitDescriptor descriptor) { 18 | super(descriptor); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/jsonld/output/FlowPropertyWriter.java: -------------------------------------------------------------------------------- 1 | package org.openlca.jsonld.output; 2 | 3 | import org.openlca.core.model.FlowProperty; 4 | import org.openlca.jsonld.Json; 5 | 6 | import com.google.gson.JsonObject; 7 | 8 | public record FlowPropertyWriter(JsonExport exp) 9 | implements JsonWriter { 10 | 11 | @Override 12 | public JsonObject write(FlowProperty prop) { 13 | var obj = Util.init(exp, prop); 14 | Json.put(obj, "flowPropertyType", prop.flowPropertyType); 15 | Json.put(obj, "unitGroup", exp.handleRef(prop.unitGroup)); 16 | return obj; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/hestia/Util.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.hestia; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | final class Util { 6 | 7 | private Util() { 8 | } 9 | 10 | static double firstValueOf(JsonObject json) { 11 | if (json == null) 12 | return 0; 13 | var array = json.getAsJsonArray("value"); 14 | if (array == null) 15 | return 0; 16 | for (var e : array) { 17 | if (!e.isJsonPrimitive()) 18 | continue; 19 | var prim = e.getAsJsonPrimitive(); 20 | if (prim.isNumber()) 21 | return prim.getAsDouble(); 22 | } 23 | return 0; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/upgrades/VersionState.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.upgrades; 2 | 3 | import org.openlca.core.database.IDatabase; 4 | 5 | public enum VersionState { 6 | 7 | UP_TO_DATE, 8 | 9 | NEEDS_UPGRADE, 10 | 11 | HIGHER_VERSION, 12 | 13 | ERROR; 14 | 15 | public static VersionState get(IDatabase db) { 16 | int v = db.getVersion(); 17 | if (v < 1) 18 | return ERROR; 19 | if (v == IDatabase.CURRENT_VERSION) 20 | return UP_TO_DATE; 21 | if (v < IDatabase.CURRENT_VERSION) 22 | return NEEDS_UPGRADE; 23 | return HIGHER_VERSION; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/jsonld/output/CurrencyWriter.java: -------------------------------------------------------------------------------- 1 | package org.openlca.jsonld.output; 2 | 3 | import org.openlca.core.model.Currency; 4 | import org.openlca.jsonld.Json; 5 | 6 | import com.google.gson.JsonObject; 7 | 8 | public record CurrencyWriter(JsonExport exp) implements JsonWriter { 9 | 10 | @Override 11 | public JsonObject write(Currency c) { 12 | var obj = Util.init(exp, c); 13 | Json.put(obj, "code", c.code); 14 | Json.put(obj, "conversionFactor", c.conversionFactor); 15 | Json.put(obj, "refCurrency", exp.handleRef(c.referenceCurrency)); 16 | return obj; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/descriptors/UnitGroupDescriptors.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import org.openlca.core.database.IDatabase; 4 | import org.openlca.core.database.UnitGroupDao; 5 | import org.openlca.core.model.descriptors.UnitGroupDescriptor; 6 | 7 | public class UnitGroupDescriptors 8 | extends RootDescriptorReader { 9 | 10 | private UnitGroupDescriptors(IDatabase db) { 11 | super(new UnitGroupDao(db)); 12 | } 13 | 14 | public static UnitGroupDescriptors of(IDatabase db) { 15 | return new UnitGroupDescriptors(db); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/methods/ef.mdy: -------------------------------------------------------------------------------- 1 | 2 | let .full_name = { 3 | ahead { 4 | any of ; 5 | ; 6 | "environmental"; 7 | ; 8 | } 9 | ahead { 10 | any of ; 11 | ; 12 | "footprint"; 13 | ; 14 | } 15 | } 16 | 17 | let .code = { 18 | ahead { 19 | any of ; 20 | ; 21 | "ef"; 22 | ; 23 | } 24 | } 25 | 26 | either { 27 | .full_name; 28 | .code; 29 | } 30 | ahead { 31 | any of ; 32 | ; 33 | option of "v"; 34 | "3.0"; 35 | ; 36 | } 37 | any of ; 38 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/indicators/gwp-biogenic.mdy: -------------------------------------------------------------------------------- 1 | let .climate_change = { 2 | ahead { 3 | any of ; 4 | "climate"; 5 | } 6 | ahead { 7 | any of ; 8 | "change"; 9 | } 10 | any of ; 11 | } 12 | 13 | 14 | let .global_warming = { 15 | ahead { 16 | any of ; 17 | "global"; 18 | } 19 | ahead { 20 | any of ; 21 | "warming"; 22 | } 23 | any of ; 24 | } 25 | 26 | let .gwp = { 27 | any of ; 28 | "gwp"; 29 | any of ; 30 | } 31 | 32 | either { 33 | .climate_change; 34 | .global_warming; 35 | .gwp; 36 | } 37 | "biogenic"; 38 | -------------------------------------------------------------------------------- /olca-ipc/src/main/java/org/openlca/ipc/handlers/Effect.java: -------------------------------------------------------------------------------- 1 | package org.openlca.ipc.handlers; 2 | 3 | import org.openlca.ipc.RpcResponse; 4 | 5 | /** 6 | * An effect encodes the result of some internal IPC call. On success, it will 7 | * contain a value and an RPC error when the call failed. 8 | */ 9 | record Effect(T value, RpcResponse error) { 10 | 11 | static Effect ok(T value) { 12 | return new Effect<>(value, null); 13 | } 14 | 15 | static Effect error(RpcResponse err) { 16 | return new Effect<>(null, err); 17 | } 18 | 19 | boolean isError() { 20 | return error != null; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/pubchem/PropertyValue.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.pubchem; 2 | 3 | import org.openlca.jsonld.Json; 4 | 5 | import com.google.gson.JsonObject; 6 | 7 | public record PropertyValue(JsonObject json) { 8 | 9 | public Integer intValue() { 10 | var opt = Json.getInt(json, "ival"); 11 | return opt.isPresent() ? opt.getAsInt() : null; 12 | } 13 | 14 | public Double floatValue() { 15 | var opt = Json.getDouble(json, "fval"); 16 | return opt.isPresent() ? opt.getAsDouble() : null; 17 | } 18 | 19 | public String stringValue() { 20 | return Json.getString(json, "sval"); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/io/index/IxFormat.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.io.index; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * An enumeration of the standard formats in which a matrix index can be saved. 7 | */ 8 | public enum IxFormat { 9 | 10 | CSV(".csv"), 11 | 12 | PROTO(".bin"); 13 | 14 | private final String extension; 15 | 16 | IxFormat(String extension) { 17 | this.extension = extension; 18 | } 19 | 20 | String name(String base) { 21 | return base + extension; 22 | } 23 | 24 | File file(File folder, String base) { 25 | return new File(folder, name(base)); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /olca-io/src/test/java/org/openlca/io/oneclick/PackagingMatcherTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.oneclick; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class PackagingMatcherTest { 7 | 8 | @Test 9 | public void testMatching() { 10 | var matcher = PackagingMatcher.createDefault(); 11 | var label = "market for packaging glass, green | " + 12 | "packaging glass, green | Cutoff, U"; 13 | Assert.assertTrue(matcher.matches(label)); 14 | } 15 | 16 | @Test 17 | public void testPattern() { 18 | var matcher = PackagingMatcher.createDefault(); 19 | Assert.assertNotNull(matcher.pattern()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/internal/Resource.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.internal; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | public enum Resource { 9 | 10 | CURRENT_SCHEMA_DERBY("current_schema_derby.sql"); 11 | 12 | private final String file; 13 | 14 | Resource(String file) { 15 | this.file = file; 16 | } 17 | 18 | public InputStream getStream() { 19 | Logger log = LoggerFactory.getLogger(getClass()); 20 | log.trace("load resource {} as stream", file); 21 | return getClass().getResourceAsStream(file); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/xls/process/SectionReader.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.xls.process; 2 | 3 | import org.apache.poi.ss.usermodel.Cell; 4 | import org.apache.poi.ss.usermodel.Sheet; 5 | 6 | class SectionReader implements CellReader { 7 | 8 | private final Sheet sheet; 9 | private final FieldMap fields; 10 | 11 | SectionReader(Sheet sheet, FieldMap fields) { 12 | this.sheet = sheet; 13 | this.fields = fields; 14 | } 15 | 16 | @Override 17 | public Cell cellOf(Field field) { 18 | var row = fields.posOf(field); 19 | return row.isPresent() 20 | ? In.cell(sheet, row.getAsInt(), 1) 21 | : null; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/descriptors/FlowPropertyDescriptors.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import org.openlca.core.database.FlowPropertyDao; 4 | import org.openlca.core.database.IDatabase; 5 | import org.openlca.core.model.descriptors.FlowPropertyDescriptor; 6 | 7 | public class FlowPropertyDescriptors 8 | extends RootDescriptorReader { 9 | 10 | private FlowPropertyDescriptors(IDatabase db) { 11 | super(new FlowPropertyDao(db)); 12 | } 13 | 14 | public static FlowPropertyDescriptors of(IDatabase db) { 15 | return new FlowPropertyDescriptors(db); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/descriptors/ImpactMethodDescriptors.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import org.openlca.core.database.IDatabase; 4 | import org.openlca.core.database.ImpactMethodDao; 5 | import org.openlca.core.model.descriptors.ImpactMethodDescriptor; 6 | 7 | public class ImpactMethodDescriptors 8 | extends RootDescriptorReader { 9 | 10 | private ImpactMethodDescriptors(IDatabase db) { 11 | super(new ImpactMethodDao(db)); 12 | } 13 | 14 | public static ImpactMethodDescriptors of(IDatabase db) { 15 | return new ImpactMethodDescriptors(db); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/format/ByteMatrixReader.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.format; 2 | 3 | public interface ByteMatrixReader { 4 | 5 | int rows(); 6 | 7 | int columns(); 8 | 9 | byte get(int row, int col); 10 | 11 | byte[] getColumn(int col); 12 | 13 | byte[] getRow(int row); 14 | 15 | default void iterate(ByteEntryFunction fn) { 16 | if (fn == null) 17 | return; 18 | for (int col = 0; col < columns(); col++) { 19 | for (int row = 0; row < rows(); row++) { 20 | byte val = get(row, col); 21 | if (val != 0) { 22 | fn.value(row, col, val); 23 | } 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-core/README.md: -------------------------------------------------------------------------------- 1 | ## olca-core 2 | This package contains the core model, data persistence, and calculation 3 | functionalities of the openLCA framework. 4 | 5 | ## Persistence 6 | We use [EclipseLink](http://www.eclipse.org/eclipselink/) as persistence 7 | framework with support for MySQL and Derby in embedded mode. 8 | The schema files for these databases can be found in the 9 | [resources folder](src/main/resources/org/openlca/core/database/internal) 10 | (current_schema_derby.sql is the schema for Derby, current_schema_mysql.sql 11 | is the schema for MySQL). In this folder, also the openLCA reference data are 12 | contained as SQL scripts. 13 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/hestia/GlossaryFileInfo.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.hestia; 2 | 3 | import org.openlca.jsonld.Json; 4 | 5 | import com.google.gson.JsonObject; 6 | 7 | public record GlossaryFileInfo(JsonObject json) implements HestiaObject { 8 | 9 | public String termType() { 10 | return Json.getString(json, "termType"); 11 | } 12 | 13 | public String filename() { 14 | return Json.getString(json, "filename"); 15 | } 16 | 17 | public String filepath() { 18 | return Json.getString(json, "filepath"); 19 | } 20 | 21 | public String description() { 22 | return Json.getString(json, "description"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/jsonld/output/SourceWriter.java: -------------------------------------------------------------------------------- 1 | package org.openlca.jsonld.output; 2 | 3 | import org.openlca.core.model.Source; 4 | import org.openlca.jsonld.Json; 5 | 6 | import com.google.gson.JsonObject; 7 | 8 | public record SourceWriter(JsonExport exp) implements JsonWriter { 9 | 10 | @Override 11 | public JsonObject write(Source source) { 12 | var obj = Util.init(exp, source); 13 | Json.put(obj, "url", source.url); 14 | Json.put(obj, "externalFile", source.externalFile); 15 | Json.put(obj, "textReference", source.textReference); 16 | Json.put(obj, "year", source.year); 17 | return obj; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/xls/process/InProviderSync.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.xls.process; 2 | 3 | class InProviderSync { 4 | 5 | private final InConfig config; 6 | 7 | InProviderSync(InConfig config) { 8 | this.config = config; 9 | } 10 | 11 | static void sync(InConfig config) { 12 | new InProviderSync(config).sync(); 13 | } 14 | 15 | private void sync() { 16 | var sheet = config.getSheet(Tab.PROVIDERS); 17 | if (sheet == null) 18 | return; 19 | sheet.eachRow(row -> { 20 | var name = row.str(Field.NAME); 21 | var refId = row.str(Field.UUID); 22 | config.index().addProvider(name, refId); 23 | }); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/ListUtils.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core; 2 | 3 | import java.util.List; 4 | 5 | import org.openlca.core.model.descriptors.Descriptor; 6 | 7 | public class ListUtils { 8 | 9 | /** 10 | * Returns the descriptor with the given ID from the given list, or null if 11 | * no such descriptor is contained in the list 12 | */ 13 | public static T findDescriptor(long id, 14 | List descriptors) { 15 | if (descriptors == null) 16 | return null; 17 | for (T descriptor : descriptors) { 18 | if (id == descriptor.id) 19 | return descriptor; 20 | } 21 | return null; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /olca-git/src/main/java/org/openlca/git/actions/GitProgressAction.java: -------------------------------------------------------------------------------- 1 | package org.openlca.git.actions; 2 | 3 | import java.io.IOException; 4 | 5 | import org.eclipse.jgit.api.errors.GitAPIException; 6 | import org.openlca.git.util.ProgressMonitor; 7 | 8 | public abstract class GitProgressAction { 9 | 10 | protected ProgressMonitor progressMonitor = ProgressMonitor.NULL; 11 | 12 | public GitProgressAction withProgress(ProgressMonitor progressMonitor) { 13 | this.progressMonitor = progressMonitor != null ? progressMonitor : ProgressMonitor.NULL; 14 | return this; 15 | } 16 | 17 | public abstract T run() throws IOException, GitAPIException; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/smartepd/SmartEpdReader.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.smartepd; 2 | 3 | import java.util.Objects; 4 | 5 | import org.openlca.core.model.Epd; 6 | 7 | public class SmartEpdReader { 8 | 9 | private final SmartEpd smartEpd; 10 | 11 | private SmartEpdReader(SmartEpd smartEpd) { 12 | this.smartEpd = Objects.requireNonNull(smartEpd); 13 | } 14 | 15 | public static SmartEpdReader of(SmartEpd smartEpd) { 16 | return new SmartEpdReader(smartEpd); 17 | } 18 | 19 | public Epd read() { 20 | var epd = new Epd(); 21 | update(epd); 22 | return epd; 23 | } 24 | 25 | public void update(Epd epd) { 26 | // TODO 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/descriptors/SocialIndicatorDescriptors.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import org.openlca.core.database.IDatabase; 4 | import org.openlca.core.database.SocialIndicatorDao; 5 | import org.openlca.core.model.descriptors.SocialIndicatorDescriptor; 6 | 7 | public class SocialIndicatorDescriptors 8 | extends RootDescriptorReader { 9 | 10 | private SocialIndicatorDescriptors(IDatabase db) { 11 | super(new SocialIndicatorDao(db)); 12 | } 13 | 14 | public static SocialIndicatorDescriptors of(IDatabase db) { 15 | return new SocialIndicatorDescriptors(db); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/openepd/Ec3OrgInfo.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.openepd; 2 | 3 | import java.util.Optional; 4 | 5 | import org.openlca.jsonld.Json; 6 | 7 | import com.google.gson.JsonElement; 8 | 9 | public class Ec3OrgInfo { 10 | 11 | public String id; 12 | public String name; 13 | 14 | public static Optional fromJson(JsonElement elem) { 15 | if (elem == null || !elem.isJsonObject()) 16 | return Optional.empty(); 17 | var obj = elem.getAsJsonObject(); 18 | var info = new Ec3OrgInfo(); 19 | info.id = Json.getString(obj, "id"); 20 | info.name = Json.getString(obj, "name"); 21 | return Optional.of(info); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/java/org/openlca/proto/io/input/ResultReader.java: -------------------------------------------------------------------------------- 1 | 2 | package org.openlca.proto.io.input; 3 | 4 | import org.openlca.core.io.EntityResolver; 5 | import org.openlca.core.model.Result; 6 | import org.openlca.proto.ProtoResult; 7 | 8 | public record ResultReader(EntityResolver resolver) 9 | implements EntityReader { 10 | 11 | @Override 12 | public Result read(ProtoResult proto) { 13 | var result = new Result(); 14 | update(result, proto); 15 | return result; 16 | } 17 | 18 | @Override 19 | public void update(Result result, ProtoResult proto) { 20 | Util.mapBase(result, ProtoBox.of(proto), resolver); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/math/rand/Triangular.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.math.rand; 2 | 3 | import java.util.concurrent.ThreadLocalRandom; 4 | 5 | record Triangular( 6 | double min, double mode, double max 7 | ) implements NumberGenerator { 8 | 9 | /// see http://en.wikipedia.org/wiki/Triangular_distribution 10 | @Override 11 | public double next() { 12 | if (max == min) 13 | return mode; 14 | double u = ThreadLocalRandom.current().nextDouble(); 15 | double fMode = (mode - min) / (max - min); 16 | return u <= fMode 17 | ? min + Math.sqrt(u * (max - min) * (mode - min)) 18 | : max - Math.sqrt((1 - u) * (max - min) * (max - mode)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /olca-git/src/main/java/org/openlca/git/util/Constants.java: -------------------------------------------------------------------------------- 1 | package org.openlca.git.util; 2 | 3 | public interface Constants { 4 | 5 | public static String DEFAULT_REMOTE = "origin"; 6 | public static String DEFAULT_BRANCH = "main"; 7 | public static String LOCAL_BRANCH = "HEAD"; 8 | public static String LOCAL_REF = "refs/heads/" + DEFAULT_BRANCH; 9 | public static String REMOTE_BRANCH = DEFAULT_REMOTE + "/" + DEFAULT_BRANCH; 10 | public static String REMOTE_REF = "refs/remotes/" + REMOTE_BRANCH; 11 | public static String DEFAULT_FETCH_SPEC = "+" + Constants.LOCAL_REF + ":" + Constants.REMOTE_REF; 12 | public static String STASH_REF = org.eclipse.jgit.lib.Constants.R_STASH; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/library/MountAction.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.library; 2 | 3 | /** 4 | * Describes the action that should be performed, when a library is mounted to 5 | * a database. 6 | */ 7 | public enum MountAction { 8 | 9 | /** 10 | * The library is added with all data as new library. 11 | */ 12 | ADD, 13 | 14 | /** The library is skipped. */ 15 | SKIP, 16 | 17 | /** 18 | * All library data are updated in the database. 19 | */ 20 | UPDATE, 21 | 22 | /** 23 | * Only the tags of the library data are changed in the database, but 24 | * process exchanges and impact factors are may deleted from the database. 25 | */ 26 | RETAG 27 | 28 | } 29 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/ecospold1/input/FlowBucket.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.ecospold1.input; 2 | 3 | import org.openlca.core.model.Flow; 4 | import org.openlca.core.model.FlowProperty; 5 | import org.openlca.core.model.Unit; 6 | 7 | /** 8 | * A simple structure that holds a flow and conversion factor used for the 9 | * import. The conversion factor is relevant for the mapped flows and should be 10 | * 1 for the other case. 11 | */ 12 | class FlowBucket { 13 | 14 | Flow flow; 15 | double conversionFactor; 16 | FlowProperty flowProperty; 17 | Unit unit; 18 | 19 | boolean isValid() { 20 | return flow != null && flowProperty != null && unit != null; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/model/DescriptorsTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | import org.openlca.core.model.descriptors.Descriptor; 7 | 8 | public class DescriptorsTest { 9 | 10 | @Test 11 | public void testToDescriptor() throws Exception { 12 | for (ModelType t : ModelType.values()) { 13 | var e = t.modelClass.getDeclaredConstructor().newInstance(); 14 | e.name = t.name(); 15 | e.refId = t.name(); 16 | Descriptor d = Descriptor.of(e); 17 | assertEquals(t, d.type); 18 | assertEquals(e.name, d.name); 19 | assertEquals(e.refId, d.refId); 20 | } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/ilcd/output/ImpactMethodExport.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.ilcd.output; 2 | 3 | import org.openlca.core.model.ImpactMethod; 4 | 5 | public class ImpactMethodExport { 6 | 7 | private final Export exp; 8 | private final ImpactMethod method; 9 | 10 | public ImpactMethodExport(Export exp, ImpactMethod method) { 11 | this.exp = exp; 12 | this.method = method; 13 | } 14 | 15 | public void write() { 16 | if (method == null) 17 | return; 18 | for (var impact : method.impactCategories) { 19 | if (exp.store.contains( 20 | org.openlca.ilcd.methods.ImpactMethod.class, impact.refId)) 21 | continue; 22 | exp.write(impact); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/NwSetDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | public class NwSetDescriptor extends Descriptor { 4 | 5 | public String weightedScoreUnit; 6 | 7 | @Override 8 | public NwSetDescriptor copy() { 9 | var copy = new NwSetDescriptor(); 10 | copyFields(this, copy); 11 | copy.weightedScoreUnit = weightedScoreUnit; 12 | return copy; 13 | } 14 | 15 | public static Builder create() { 16 | return new Builder(new NwSetDescriptor()); 17 | } 18 | 19 | public static class Builder extends DescriptorBuilder { 20 | private Builder(NwSetDescriptor descriptor) { 21 | super(descriptor); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /olca-core/src/test/java/examples/FeatureValidationExample.java: -------------------------------------------------------------------------------- 1 | package examples; 2 | 3 | import java.io.File; 4 | 5 | import org.openlca.core.DataDir; 6 | import org.openlca.geo.calc.FeatureValidation; 7 | import org.openlca.geo.lcia.GeoFactorSetup; 8 | 9 | public class FeatureValidationExample { 10 | 11 | public static void main(String[] args) { 12 | try (var db = DataDir.get().openDatabase("lc-impact-tests")) { 13 | var setupFile = new File("/home/ms/Desktop/lc-impact-pocp-setup.json"); 14 | var setup = GeoFactorSetup.read(setupFile, db); 15 | var validation = FeatureValidation.of(setup.features); 16 | validation.run(); 17 | System.out.println(validation.stats()); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/xls/process/InConfig.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.xls.process; 2 | 3 | import org.apache.poi.ss.usermodel.Workbook; 4 | import org.openlca.core.database.IDatabase; 5 | import org.openlca.core.io.ExchangeProviderQueue; 6 | import org.openlca.core.io.ImportLog; 7 | import org.openlca.core.model.Process; 8 | 9 | record InConfig( 10 | XlsProcessReader reader, 11 | Workbook wb, 12 | Process process, 13 | EntityIndex index, 14 | IDatabase db, 15 | ImportLog log, 16 | ExchangeProviderQueue providers) { 17 | 18 | SheetReader getSheet(Tab tab) { 19 | var sheet = wb.getSheet(tab.label()); 20 | return sheet != null 21 | ? new SheetReader(sheet) 22 | : null; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /olca-proto-io/src/test/java/org/openlca/proto/io/ImportExample.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io; 2 | 3 | import java.io.File; 4 | 5 | import org.openlca.core.database.Derby; 6 | import org.openlca.proto.io.input.ProtoImport; 7 | 8 | public class ImportExample { 9 | 10 | public static void main(String[] args) { 11 | var zipPath = "C:/Users/ms/Desktop/rems/test_json.zip"; 12 | var dbPath = "C:/Users/ms/openLCA-data-1.4/databases/proto_test"; 13 | try (var store = ZipStore.open(new File(zipPath)); 14 | var db = new Derby(new File(dbPath))) { 15 | var imp = new ProtoImport(store, db); 16 | imp.run(); 17 | } catch (Exception e) { 18 | e.printStackTrace(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/EpdDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class EpdDescriptor extends RootDescriptor { 6 | 7 | public EpdDescriptor() { 8 | this.type = ModelType.EPD; 9 | } 10 | 11 | @Override 12 | public EpdDescriptor copy() { 13 | var copy = new EpdDescriptor(); 14 | copyFields(this, copy); 15 | return copy; 16 | } 17 | 18 | public static Builder create() { 19 | return new Builder(new EpdDescriptor()); 20 | } 21 | 22 | public static class Builder extends DescriptorBuilder { 23 | private Builder(EpdDescriptor descriptor) { 24 | super(descriptor); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/cache/CacheUtil.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.cache; 2 | 3 | final class CacheUtil { 4 | 5 | private CacheUtil() { 6 | } 7 | 8 | /** 9 | * Converts the given set of 64-bit integers in to a SQL string that can be 10 | * used in 'in'-queries; e.g. [1,2,3] is converted to (1,2,3). 11 | */ 12 | public static String asSql(Iterable ids) { 13 | if (ids == null) 14 | return "()"; 15 | var b = new StringBuilder(); 16 | b.append('('); 17 | boolean first = true; 18 | for (Long id : ids) { 19 | if (!first) 20 | b.append(','); 21 | else 22 | first = false; 23 | b.append(id); 24 | } 25 | b.append(')'); 26 | return b.toString(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/oneclick/Module.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.oneclick; 2 | 3 | import org.apache.poi.ss.usermodel.Row; 4 | import org.openlca.io.xls.Excel; 5 | 6 | enum Module { 7 | 8 | MATERIALS("A1 Raw materials", "PRODUCT_MATERIALS"), 9 | ENERGY("A3 Energy use", "PRODUCT_ENERGY"), 10 | PACKAGING("A3 Packaging materials", "PRODUCT_PACKAGING"), 11 | WASTE("A3 Manufacturing waste", "PRODUCT_WASTE"); 12 | 13 | private final String module; 14 | private final String className; 15 | 16 | Module(String module, String className) { 17 | this.module = module; 18 | this.className = className; 19 | } 20 | 21 | void writeTo(Row row) { 22 | Excel.cell(row, 0, module); 23 | Excel.cell(row, 1, className); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/ActorDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class ActorDescriptor extends RootDescriptor { 6 | 7 | public ActorDescriptor() { 8 | this.type = ModelType.ACTOR; 9 | } 10 | 11 | @Override 12 | public ActorDescriptor copy() { 13 | var copy = new ActorDescriptor(); 14 | copyFields(this, copy); 15 | return copy; 16 | } 17 | 18 | public static Builder create() { 19 | return new Builder(new ActorDescriptor()); 20 | } 21 | 22 | public static class Builder extends DescriptorBuilder { 23 | private Builder(ActorDescriptor descriptor) { 24 | super(descriptor); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-core/src/test/java/examples/LibraryUsageExample.java: -------------------------------------------------------------------------------- 1 | package examples; 2 | 3 | import org.openlca.core.DataDir; 4 | import org.openlca.core.database.LibraryUsage; 5 | 6 | public class LibraryUsageExample { 7 | 8 | public static void main(String[] args) { 9 | var dir = DataDir.get().getDatabasesDir(); 10 | var lib = "ecoinvent v3.10 EN15804GD Unit-Processes 2024-10-23"; 11 | var dbs = LibraryUsage 12 | .allDatabasesOf(dir, lib) 13 | .orElseThrow(); 14 | 15 | if(dbs.isEmpty()) { 16 | System.out.println("Library not used: " + lib); 17 | return; 18 | } 19 | 20 | System.out.printf("Library %s used in %d database(s):%n", lib, dbs.size()); 21 | for (var db : dbs) { 22 | System.out.println(" - " + db); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/ResultDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class ResultDescriptor extends RootDescriptor { 6 | 7 | public ResultDescriptor() { 8 | this.type = ModelType.RESULT; 9 | } 10 | 11 | @Override 12 | public ResultDescriptor copy() { 13 | var copy = new ResultDescriptor(); 14 | copyFields(this, copy); 15 | return copy; 16 | } 17 | 18 | public static Builder create() { 19 | return new Builder(new ResultDescriptor()); 20 | } 21 | 22 | public static class Builder extends DescriptorBuilder { 23 | private Builder(ResultDescriptor descriptor) { 24 | super(descriptor); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/SourceDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class SourceDescriptor extends RootDescriptor { 6 | 7 | public SourceDescriptor() { 8 | this.type = ModelType.SOURCE; 9 | } 10 | 11 | @Override 12 | public SourceDescriptor copy() { 13 | var copy = new SourceDescriptor(); 14 | copyFields(this, copy); 15 | return copy; 16 | } 17 | 18 | public static Builder create() { 19 | return new Builder(new SourceDescriptor()); 20 | } 21 | 22 | public static class Builder extends DescriptorBuilder { 23 | private Builder(SourceDescriptor descriptor) { 24 | super(descriptor); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/java/org/openlca/proto/io/output/ProjectWriter.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io.output; 2 | 3 | import org.openlca.core.model.Project; 4 | import org.openlca.proto.ProtoProject; 5 | import org.openlca.proto.ProtoType; 6 | 7 | public class ProjectWriter { 8 | 9 | private final WriterConfig config; 10 | 11 | public ProjectWriter(WriterConfig config) { 12 | this.config = config; 13 | } 14 | 15 | public ProtoProject write(Project project) { 16 | var proto = ProtoProject.newBuilder(); 17 | if (project == null) 18 | return proto.build(); 19 | proto.setType(ProtoType.Project); 20 | Out.map(project, proto); 21 | 22 | // model specific fields 23 | // TODO 24 | 25 | return proto.build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/Direction.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | public enum Direction { 4 | 5 | INPUT, 6 | 7 | OUTPUT; 8 | 9 | /** 10 | * Tries to determine the direction from the given string. The rule is very 11 | * simple: if the given string starts with {@code i} or {@code I} it returns 12 | * {@code INPUT}, if it starts with {@code o} or {@code O} it returns 13 | * {@code OUTPUT}, and in all other cases it returns {@code null}. 14 | */ 15 | public static Direction from(String s) { 16 | if (s == null || s.isEmpty()) 17 | return null; 18 | char first = s.charAt(0); 19 | return switch (first) { 20 | case 'i', 'I' -> INPUT; 21 | case 'o', 'O' -> OUTPUT; 22 | default -> null; 23 | }; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/ProjectDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class ProjectDescriptor extends RootDescriptor { 6 | 7 | public ProjectDescriptor() { 8 | this.type = ModelType.PROJECT; 9 | } 10 | 11 | @Override 12 | public ProjectDescriptor copy() { 13 | var copy = new ProjectDescriptor(); 14 | copyFields(this, copy); 15 | return copy; 16 | } 17 | 18 | public static Builder create() { 19 | return new Builder(new ProjectDescriptor()); 20 | } 21 | 22 | public static class Builder extends DescriptorBuilder { 23 | private Builder(ProjectDescriptor descriptor) { 24 | super(descriptor); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/CategoryPath.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io; 2 | 3 | import org.openlca.commons.Strings; 4 | import org.openlca.core.model.Category; 5 | 6 | public class CategoryPath { 7 | 8 | private CategoryPath() { 9 | } 10 | 11 | public static String getFull(Category category) { 12 | return category != null 13 | ? category.toPath() 14 | : ""; 15 | } 16 | 17 | /** 18 | * Max. 2 category names and 75 characters 19 | */ 20 | public static String getShort(Category category) { 21 | if (category == null) 22 | return ""; 23 | if (category.category == null) 24 | return category.name; 25 | String shortPath = category.category.name + "/" 26 | + category.name; 27 | return Strings.cutEnd(shortPath, 75); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/CurrencyDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class CurrencyDescriptor extends RootDescriptor { 6 | 7 | public CurrencyDescriptor() { 8 | this.type = ModelType.CURRENCY; 9 | } 10 | 11 | @Override 12 | public CurrencyDescriptor copy() { 13 | var copy = new CurrencyDescriptor(); 14 | copyFields(this, copy); 15 | return copy; 16 | } 17 | 18 | public static Builder create() { 19 | return new Builder(new CurrencyDescriptor()); 20 | } 21 | 22 | public static class Builder extends DescriptorBuilder { 23 | private Builder(CurrencyDescriptor descriptor) { 24 | super(descriptor); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/jsonld/upgrades/Upgrades.java: -------------------------------------------------------------------------------- 1 | package org.openlca.jsonld.upgrades; 2 | 3 | import org.openlca.jsonld.JsonStoreReader; 4 | import org.openlca.jsonld.PackageInfo; 5 | import org.openlca.jsonld.SchemaVersion; 6 | 7 | public class Upgrades { 8 | 9 | public static JsonStoreReader chain(JsonStoreReader reader) { 10 | if (reader instanceof Upgrade) 11 | return reader; 12 | var version = PackageInfo.readFrom(reader) 13 | .schemaVersion() 14 | .value(); 15 | if (version >= SchemaVersion.CURRENT) 16 | return reader; 17 | 18 | var chain = reader; 19 | 20 | if (version < 2) { 21 | chain = new Upgrade2(chain); 22 | } 23 | if (version < 3) { 24 | chain = new Upgrade3(chain); 25 | } 26 | return chain; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /olca-io/src/test/java/org/openlca/io/maps/CountryInfoTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.maps; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | public class CountryInfoTest { 8 | 9 | @Test 10 | public void testCountryInfo() { 11 | var infos = CountryInfo.getAll(); 12 | 13 | var afg = infos.getFirst(); 14 | assertEquals("Afghanistan", afg.name()); 15 | 16 | var pol = infos.stream() 17 | .filter(c -> c.alpha2().equals("PL")) 18 | .findFirst() 19 | .orElseThrow(); 20 | assertEquals("POL", pol.alpha3()); 21 | assertEquals("Poland", pol.name()); 22 | assertEquals("28840420-4e3d-3522-a930-8317344a285d", pol.refId()); 23 | 24 | var ala = infos.getLast(); 25 | assertEquals("AX", ala.alpha2()); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/descriptors/Util.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import java.sql.ResultSet; 4 | 5 | import org.openlca.core.model.descriptors.RootDescriptor; 6 | 7 | final class Util { 8 | 9 | private Util() { 10 | } 11 | 12 | static RuntimeException ex(String message, Exception e) { 13 | return new RuntimeException(message, e); 14 | } 15 | 16 | static void fill(RootDescriptor d, DescriptorReader r, ResultSet row) { 17 | d.id = r.getId(row); 18 | d.refId = r.getRefIf(row); 19 | d.name = r.getName(row); 20 | d.version = r.getVersion(row); 21 | d.lastChange = r.getLastChange(row); 22 | d.category = r.getCategory(row); 23 | d.library = r.getLibrary(row); 24 | d.tags = r.getTags(row); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/usage/SocialIndicatorUseSearch.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.usage; 2 | 3 | import java.util.Collections; 4 | import java.util.Set; 5 | 6 | import org.openlca.core.database.IDatabase; 7 | import org.openlca.core.model.Process; 8 | import org.openlca.core.model.descriptors.RootDescriptor; 9 | 10 | import gnu.trove.set.TLongSet; 11 | 12 | public record SocialIndicatorUseSearch(IDatabase db) implements UsageSearch { 13 | 14 | @Override 15 | public Set find(TLongSet ids) { 16 | if (ids.isEmpty()) 17 | return Collections.emptySet(); 18 | return Query.of(db, Process.class, 19 | "select f_process from tbl_social_aspects where f_indicator " 20 | + Search.eqIn(ids)) 21 | .call(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/DQSystemDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class DQSystemDescriptor extends RootDescriptor { 6 | 7 | public DQSystemDescriptor() { 8 | this.type = ModelType.DQ_SYSTEM; 9 | } 10 | 11 | @Override 12 | public DQSystemDescriptor copy() { 13 | var copy = new DQSystemDescriptor(); 14 | copyFields(this, copy); 15 | return copy; 16 | } 17 | 18 | public static Builder create() { 19 | return new Builder(new DQSystemDescriptor()); 20 | } 21 | 22 | public static class Builder extends DescriptorBuilder { 23 | 24 | private Builder(DQSystemDescriptor descriptor) { 25 | super(descriptor); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/ParameterDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class ParameterDescriptor extends RootDescriptor { 6 | 7 | public ParameterDescriptor() { 8 | this.type = ModelType.PARAMETER; 9 | } 10 | 11 | @Override 12 | public ParameterDescriptor copy() { 13 | var copy = new ParameterDescriptor(); 14 | copyFields(this, copy); 15 | return copy; 16 | } 17 | 18 | public static Builder create() { 19 | return new Builder(new ParameterDescriptor()); 20 | } 21 | 22 | public static class Builder extends DescriptorBuilder { 23 | private Builder(ParameterDescriptor descriptor) { 24 | super(descriptor); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/UnitGroupDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class UnitGroupDescriptor extends RootDescriptor { 6 | 7 | public UnitGroupDescriptor() { 8 | this.type = ModelType.UNIT_GROUP; 9 | } 10 | 11 | @Override 12 | public UnitGroupDescriptor copy() { 13 | var copy = new UnitGroupDescriptor(); 14 | copyFields(this, copy); 15 | return copy; 16 | } 17 | 18 | public static Builder create() { 19 | return new Builder(new UnitGroupDescriptor()); 20 | } 21 | 22 | public static class Builder extends DescriptorBuilder { 23 | private Builder(UnitGroupDescriptor descriptor) { 24 | super(descriptor); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/usage/UnitGroupUseSearch.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.usage; 2 | 3 | import java.util.Collections; 4 | import java.util.Set; 5 | 6 | import org.openlca.core.database.IDatabase; 7 | import org.openlca.core.model.FlowProperty; 8 | import org.openlca.core.model.descriptors.RootDescriptor; 9 | 10 | import gnu.trove.set.TLongSet; 11 | 12 | public record UnitGroupUseSearch(IDatabase db) implements UsageSearch { 13 | 14 | @Override 15 | public Set find(TLongSet ids) { 16 | if (ids.isEmpty()) 17 | return Collections.emptySet(); 18 | return Query.of(db, FlowProperty.class, 19 | "select id from tbl_flow_properties " + 20 | "where f_unit_group " + Search.eqIn(ids)) 21 | .call(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /olca-git/src/main/java/org/openlca/git/actions/GitRemoteAction.java: -------------------------------------------------------------------------------- 1 | package org.openlca.git.actions; 2 | 3 | import org.eclipse.jgit.api.errors.GitAPIException; 4 | import org.eclipse.jgit.lib.ProgressMonitor; 5 | import org.eclipse.jgit.transport.CredentialsProvider; 6 | 7 | public abstract class GitRemoteAction { 8 | 9 | protected ProgressMonitor monitor; 10 | protected CredentialsProvider credentialsProvider; 11 | 12 | public GitRemoteAction withProgress(ProgressMonitor monitor) { 13 | this.monitor = monitor; 14 | return this; 15 | } 16 | 17 | public GitRemoteAction authorizeWith(CredentialsProvider credentialsProvider) { 18 | this.credentialsProvider = credentialsProvider; 19 | return this; 20 | } 21 | 22 | public abstract T run() throws GitAPIException; 23 | 24 | } -------------------------------------------------------------------------------- /olca-git/src/main/java/org/openlca/git/actions/GitStashDrop.java: -------------------------------------------------------------------------------- 1 | package org.openlca.git.actions; 2 | 3 | import java.io.IOException; 4 | 5 | import org.eclipse.jgit.lib.Constants; 6 | import org.eclipse.jgit.lib.Repository; 7 | 8 | public class GitStashDrop { 9 | 10 | private final Repository repo; 11 | 12 | private GitStashDrop(Repository repo) { 13 | this.repo = repo; 14 | } 15 | 16 | public static GitStashDrop from(Repository repo) { 17 | return new GitStashDrop(repo); 18 | } 19 | 20 | public void run() throws IOException { 21 | if (repo == null) 22 | throw new IllegalStateException("Git repository must be set"); 23 | var update = repo.updateRef(Constants.R_STASH); 24 | update.disableRefLog(); 25 | update.setForceUpdate(true); 26 | update.delete(); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/ilcd/input/models/Link.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.ilcd.input.models; 2 | 3 | import org.openlca.core.model.Exchange; 4 | 5 | /** 6 | * Represents a link in an eILCD model: a provider of an output is linked to an 7 | * input of a recipient. 8 | */ 9 | class Link { 10 | 11 | /** 12 | * This is a graph internal ID of the link. It is set when the link is added 13 | * to the graph. 14 | */ 15 | int id; 16 | Exchange output; 17 | Exchange input; 18 | Node provider; 19 | Node recipient; 20 | 21 | @Override 22 | public String toString() { 23 | int from = provider != null ? provider.id : -1; 24 | int to = recipient != null ? recipient.id : -1; 25 | return "Link [ id=" + id + " : node[" + from 26 | + "] -> node[" + to + "] ]"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/DatabaseException.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import java.io.Serial; 4 | 5 | import org.slf4j.Logger; 6 | 7 | /** 8 | * Unchecked exception for errors while invoking database operations. These 9 | * exceptions are already logged and are only thrown so interested caller can 10 | * handle exceptions 11 | */ 12 | public class DatabaseException extends RuntimeException { 13 | 14 | @Serial 15 | private static final long serialVersionUID = 6126554045860754115L; 16 | 17 | static void logAndThrow(Logger log, String message, Throwable e) { 18 | log.error(message, e); 19 | throw new DatabaseException(message, e); 20 | } 21 | 22 | public DatabaseException(String message, Throwable e) { 23 | super(message, e); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/UncertaintyType.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | /** 4 | * The uncertainty distribution types that are currently supported by 5 | * openLCA. Note that these types are currently stored by their ordinal 6 | * values in the database so DO NOT REORDER THEM. 7 | */ 8 | public enum UncertaintyType { 9 | 10 | NONE, 11 | 12 | LOG_NORMAL, 13 | 14 | NORMAL, 15 | 16 | TRIANGLE, 17 | 18 | UNIFORM; 19 | 20 | public static byte byteIndexOf(UncertaintyType type) { 21 | if (type == null || type == NONE) 22 | return 0; 23 | return switch (type) { 24 | case LOG_NORMAL -> (byte) 1; 25 | case NORMAL -> (byte) 2; 26 | case TRIANGLE -> (byte) 3; 27 | case UNIFORM -> (byte) 4; 28 | default -> (byte) 0; 29 | }; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/indicators/gwp-lulcu.mdy: -------------------------------------------------------------------------------- 1 | let .climate_change = { 2 | ahead { 3 | any of ; 4 | "climate"; 5 | } 6 | ahead { 7 | any of ; 8 | "change"; 9 | } 10 | any of ; 11 | } 12 | 13 | 14 | let .global_warming = { 15 | ahead { 16 | any of ; 17 | "global"; 18 | } 19 | ahead { 20 | any of ; 21 | "warming"; 22 | } 23 | any of ; 24 | } 25 | 26 | let .gwp = { 27 | any of ; 28 | either { 29 | ; 30 | some of not ; 31 | } 32 | "gwp"; 33 | either { 34 | ; 35 | some of not ; 36 | } 37 | any of ; 38 | } 39 | 40 | either { 41 | .climate_change; 42 | .global_warming; 43 | .gwp; 44 | } 45 | 46 | either { 47 | "land"; 48 | "luluc"; 49 | } 50 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/upgrades/IUpgrade.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.upgrades; 2 | 3 | import org.openlca.core.database.IDatabase; 4 | 5 | /** 6 | * Updates an openLCA database from one or more defined versions to a newer 7 | * version. 8 | */ 9 | interface IUpgrade { 10 | 11 | /** 12 | * The initial versions for which this upgrade is valid. The upgrade must 13 | * run safely with all of these database versions and produce an identical 14 | * database schema for all these versions. 15 | */ 16 | int[] getInitialVersions(); 17 | 18 | /** 19 | * The version that the database has after the update. 20 | */ 21 | int getEndVersion(); 22 | 23 | /** 24 | * Executes the update on the given database. 25 | */ 26 | void exec(IDatabase database); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/jsonld/SchemaVersion.java: -------------------------------------------------------------------------------- 1 | package org.openlca.jsonld; 2 | 3 | public record SchemaVersion(int value) { 4 | 5 | static final int FALLBACK = 1; 6 | public static final int CURRENT = 5; 7 | 8 | /** 9 | * Get the current schema version that is supported by this API. 10 | */ 11 | public static SchemaVersion current() { 12 | return new SchemaVersion(CURRENT); 13 | } 14 | 15 | /** 16 | * Get the fallback version of the schema. 17 | */ 18 | public static SchemaVersion fallback() { 19 | return new SchemaVersion(FALLBACK); 20 | } 21 | 22 | public boolean isCurrent() { 23 | return value == CURRENT; 24 | } 25 | 26 | public boolean isOlder() { 27 | return value < CURRENT; 28 | } 29 | 30 | public boolean isNewer() { 31 | return value > CURRENT; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/database/config/MySqlConfigTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.config; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Ignore; 6 | import org.junit.Test; 7 | import org.openlca.core.DataDir; 8 | import org.openlca.core.database.IDatabase; 9 | 10 | public class MySqlConfigTest { 11 | 12 | /** 13 | * In order to run this test, you need a MySQL driver in the classpath and a 14 | * running MySQL server. 15 | */ 16 | @Test 17 | @Ignore 18 | public void testConnect() { 19 | var db = new MySqlConfig() 20 | .name("openlca") 21 | .host("localhost") 22 | .port(3306) 23 | .user("root") 24 | .connect(DataDir.get().getDatabasesDir()); 25 | assertEquals(IDatabase.CURRENT_VERSION, db.getVersion()); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/FlowPropertyDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class FlowPropertyDescriptor extends RootDescriptor { 6 | 7 | public FlowPropertyDescriptor() { 8 | this.type = ModelType.FLOW_PROPERTY; 9 | } 10 | 11 | @Override 12 | public FlowPropertyDescriptor copy() { 13 | var copy = new FlowPropertyDescriptor(); 14 | copyFields(this, copy); 15 | return copy; 16 | } 17 | 18 | public static Builder create() { 19 | return new Builder(new FlowPropertyDescriptor()); 20 | } 21 | 22 | public static class Builder extends DescriptorBuilder { 23 | private Builder(FlowPropertyDescriptor descriptor) { 24 | super(descriptor); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/jsonld/output/ActorWriter.java: -------------------------------------------------------------------------------- 1 | package org.openlca.jsonld.output; 2 | 3 | import org.openlca.core.model.Actor; 4 | import org.openlca.jsonld.Json; 5 | 6 | import com.google.gson.JsonObject; 7 | 8 | public record ActorWriter(JsonExport exp) implements JsonWriter { 9 | 10 | @Override 11 | public JsonObject write(Actor actor) { 12 | var obj = Util.init(exp, actor); 13 | Json.put(obj, "address", actor.address); 14 | Json.put(obj, "city", actor.city); 15 | Json.put(obj, "country", actor.country); 16 | Json.put(obj, "email", actor.email); 17 | Json.put(obj, "telefax", actor.telefax); 18 | Json.put(obj, "telephone", actor.telephone); 19 | Json.put(obj, "website", actor.website); 20 | Json.put(obj, "zipCode", actor.zipCode); 21 | return obj; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/DbUtils.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | class DbUtils { 7 | 8 | private DbUtils() { 9 | } 10 | 11 | /** 12 | * Returns the version of the given database, or -1 if an error occured. 13 | */ 14 | static int getVersion(IDatabase database) { 15 | try { 16 | final int[] version = new int[1]; 17 | NativeSql.on(database).query("select version from openlca_version", 18 | result -> { 19 | version[0] = result.getInt(1); 20 | return true; 21 | }); 22 | return version[0]; 23 | } catch (Exception e) { 24 | Logger log = LoggerFactory.getLogger(DbUtils.class); 25 | log.error("failed to get the database version", e); 26 | return -1; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/ProductSystemDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class ProductSystemDescriptor extends RootDescriptor { 6 | 7 | public ProductSystemDescriptor() { 8 | this.type = ModelType.PRODUCT_SYSTEM; 9 | } 10 | 11 | @Override 12 | public ProductSystemDescriptor copy() { 13 | var copy = new ProductSystemDescriptor(); 14 | copyFields(this, copy); 15 | return copy; 16 | } 17 | 18 | public static Builder create() { 19 | return new Builder(new ProductSystemDescriptor()); 20 | } 21 | 22 | public static class Builder extends DescriptorBuilder { 23 | private Builder(ProductSystemDescriptor descriptor) { 24 | super(descriptor); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/LocationDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class LocationDescriptor extends RootDescriptor { 6 | 7 | public String code; 8 | 9 | public LocationDescriptor() { 10 | this.type = ModelType.LOCATION; 11 | } 12 | 13 | @Override 14 | public LocationDescriptor copy() { 15 | var copy = new LocationDescriptor(); 16 | copyFields(this, copy); 17 | copy.code = code; 18 | return copy; 19 | } 20 | 21 | public static Builder create() { 22 | return new Builder(new LocationDescriptor()); 23 | } 24 | 25 | public static class Builder extends DescriptorBuilder { 26 | private Builder(LocationDescriptor descriptor) { 27 | super(descriptor); 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/SocialIndicatorDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class SocialIndicatorDescriptor extends RootDescriptor { 6 | 7 | public SocialIndicatorDescriptor() { 8 | this.type = ModelType.SOCIAL_INDICATOR; 9 | } 10 | 11 | @Override 12 | public SocialIndicatorDescriptor copy() { 13 | var copy = new SocialIndicatorDescriptor(); 14 | copyFields(this, copy); 15 | return copy; 16 | } 17 | 18 | public static Builder create() { 19 | return new Builder(new SocialIndicatorDescriptor()); 20 | } 21 | 22 | public static class Builder extends DescriptorBuilder { 23 | private Builder(SocialIndicatorDescriptor descriptor) { 24 | super(descriptor); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-core/src/test/java/examples/ImpactBuilderExample.java: -------------------------------------------------------------------------------- 1 | package examples; 2 | 3 | import java.io.File; 4 | 5 | import org.openlca.core.DataDir; 6 | import org.openlca.core.matrix.ImpactBuilder; 7 | import org.openlca.core.matrix.index.EnviIndex; 8 | import org.openlca.core.matrix.index.ImpactIndex; 9 | import org.openlca.core.matrix.io.NpyMatrix; 10 | 11 | public class ImpactBuilderExample { 12 | 13 | public static void main(String[] args) throws Exception { 14 | try (var db = DataDir.get().openDatabase("ei22")) { 15 | var impactIndex = ImpactIndex.of(db); 16 | var enviIndex = EnviIndex.create(db, impactIndex); 17 | var data = ImpactBuilder.of(db, enviIndex) 18 | .withImpacts(impactIndex) 19 | .build(); 20 | NpyMatrix.write( 21 | new File("./target"), "impact_factors", data.impactMatrix); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/database/descriptors/LocationDescriptorTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | import org.openlca.core.Tests; 7 | import org.openlca.core.database.LocationDao; 8 | import org.openlca.core.model.Location; 9 | 10 | public class LocationDescriptorTest { 11 | 12 | @Test 13 | public void test() { 14 | 15 | var loc = new Location(); 16 | loc.name = "LOC"; 17 | loc.refId = "LOC"; 18 | loc.code = "LOC"; 19 | 20 | var dao = new LocationDao(Tests.getDb()); 21 | loc = dao.insert(loc); 22 | var d = dao.descriptorMap().get(loc.id); 23 | dao.delete(loc); 24 | 25 | assertEquals(loc.name, d.name); 26 | assertEquals(loc.refId, d.refId); 27 | assertEquals(loc.code, d.code); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/xls/results/DQColors.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.xls.results; 2 | 3 | import java.awt.Color; 4 | 5 | class DQColors { 6 | 7 | static Color get(int index, int total) { 8 | if (index == 0) 9 | return new Color(255, 255, 255); 10 | if (index == 1) 11 | return new Color(125, 250, 125); 12 | if (index == total) 13 | return new Color(250, 125, 125); 14 | int median = total / 2 + 1; 15 | if (index == median) 16 | return new Color(250, 250, 125); 17 | if (index < median) { 18 | int divisor = median - 1; 19 | int factor = index - 1; 20 | return new Color(125 + (125 * factor / divisor), 250, 125); 21 | } 22 | int divisor = median - 1; 23 | int factor = index - median; 24 | return new Color(250, 250 - (125 * factor / divisor), 125); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/results/TechFlowValue.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.results; 2 | 3 | import java.util.Objects; 4 | 5 | import org.openlca.core.matrix.index.TechFlow; 6 | import org.openlca.core.model.descriptors.FlowDescriptor; 7 | import org.openlca.core.model.descriptors.RootDescriptor; 8 | 9 | public record TechFlowValue(TechFlow techFlow, double value) { 10 | 11 | public static TechFlowValue of(TechFlow techFlow, double value) { 12 | return new TechFlowValue(techFlow, value); 13 | } 14 | 15 | public TechFlowValue(TechFlow techFlow, double value) { 16 | this.techFlow = Objects.requireNonNull(techFlow); 17 | this.value = value; 18 | } 19 | 20 | public RootDescriptor provider() { 21 | return techFlow.provider(); 22 | } 23 | 24 | public FlowDescriptor flow() { 25 | return techFlow.flow(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/geo/calc/IntersectionShareTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.geo.calc; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.util.List; 6 | 7 | import org.junit.Test; 8 | import org.openlca.geo.geojson.Feature; 9 | import org.openlca.geo.geojson.Point; 10 | 11 | public class IntersectionShareTest { 12 | 13 | @Test 14 | public void testMakeRelative() { 15 | var g =JTS.fromGeoJSON(new Point()); 16 | var shares = IntersectionShare.makeRelative(List.of( 17 | IntersectionShare.of(new Feature(), g, 2.0), 18 | IntersectionShare.of(new Feature(), g, 10.0), 19 | IntersectionShare.of(new Feature(), g, 5.0))); 20 | assertEquals(0.2, shares.get(0).value(), 1e-16); 21 | assertEquals(1.0, shares.get(1).value(), 1e-16); 22 | assertEquals(0.5, shares.get(2).value(), 1e-16); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/MappingFile.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | import jakarta.persistence.Column; 4 | import jakarta.persistence.Entity; 5 | import jakarta.persistence.Table; 6 | 7 | /** 8 | * A mapping file is used to store mappings of entities from other data formats 9 | * (like ILCD, EcoSpold etc.) to openLCA entities or the other way around. See 10 | * the olca-io module for the use of such mapping files in imports and exports. 11 | * We just store the name of the file as string and its content as BLOB (which 12 | * normally contains the compressed content). 13 | */ 14 | @Entity 15 | @Table(name = "tbl_mapping_files") 16 | public class MappingFile extends AbstractEntity { 17 | 18 | @Column(name = "file_name") 19 | public String name; 20 | 21 | @Column(name = "content") 22 | public byte[] content; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/CategoryDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | public class CategoryDescriptor extends RootDescriptor { 6 | 7 | public ModelType categoryType; 8 | 9 | public CategoryDescriptor() { 10 | this.type = ModelType.CATEGORY; 11 | } 12 | 13 | @Override 14 | public CategoryDescriptor copy() { 15 | var copy = new CategoryDescriptor(); 16 | copyFields(this, copy); 17 | copy.categoryType = categoryType; 18 | return copy; 19 | } 20 | 21 | public static Builder create() { 22 | return new Builder(new CategoryDescriptor()); 23 | } 24 | 25 | public static class Builder extends DescriptorBuilder { 26 | private Builder(CategoryDescriptor descriptor) { 27 | super(descriptor); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/util/Doubles.java: -------------------------------------------------------------------------------- 1 | package org.openlca.util; 2 | 3 | public class Doubles { 4 | 5 | public static double min(double[] values) { 6 | if (values == null || values.length == 0) 7 | return Double.NaN; 8 | double min = values[0]; 9 | for (int i = 1; i < values.length; i++) 10 | min = Math.min(min, values[i]); 11 | return min; 12 | } 13 | 14 | public static double max(double[] values) { 15 | if (values == null || values.length == 0) 16 | return Double.NaN; 17 | double max = values[0]; 18 | for (int i = 1; i < values.length; i++) 19 | max = Math.max(max, values[i]); 20 | return max; 21 | } 22 | 23 | public static double sum(double[] values) { 24 | if (values == null) 25 | return 0; 26 | double sum = 0; 27 | for (double val : values) 28 | sum += val; 29 | return sum; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/database/ResultIOTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertFalse; 5 | import static org.junit.Assert.assertTrue; 6 | 7 | import org.junit.Test; 8 | import org.openlca.core.Tests; 9 | import org.openlca.core.model.Result; 10 | 11 | public class ResultIOTest { 12 | 13 | private final IDatabase db = Tests.getDb(); 14 | 15 | @Test 16 | public void testSimpleIO() { 17 | var r = Result.of("result"); 18 | db.insert(r); 19 | db.clearCache(); 20 | var clone = db.get(Result.class, r.id); 21 | assertEquals(r, clone); 22 | var dao = new ResultDao(db); 23 | var all = dao.getAll(); 24 | assertTrue(all.contains(r)); 25 | db.delete(r); 26 | all = dao.getAll(); 27 | assertFalse(all.contains(r)); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/matrix/solvers/mkl/SparseTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.solvers.mkl; 2 | 3 | import static org.junit.Assert.assertArrayEquals; 4 | 5 | import org.junit.Assume; 6 | import org.junit.BeforeClass; 7 | import org.junit.Test; 8 | 9 | public class SparseTest { 10 | 11 | @BeforeClass 12 | public static void setup() { 13 | Assume.assumeTrue(MKL.loadFromDefault()); 14 | } 15 | 16 | @Test 17 | public void testSolveNative() { 18 | double[] x = new double[5]; 19 | MKL.solveSparse( 20 | 5, 21 | new double[]{2., 3., 3., -1., 4., 4., -3., 1., 2., 2., 6., 1.}, 22 | new int[]{0, 1, 0, 2, 4, 1, 2, 3, 4, 2, 1, 4}, 23 | new int[]{0, 2, 5, 9, 10, 12}, 24 | new double[]{8., 45., -3., 3., 19.}, 25 | x 26 | ); 27 | assertArrayEquals( 28 | new double[]{1d, 2d, 3d, 4d, 5d}, x, 1e-8); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/xls/process/RowReader.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.xls.process; 2 | 3 | import org.apache.poi.ss.usermodel.Cell; 4 | import org.apache.poi.ss.usermodel.Row; 5 | 6 | class RowReader implements CellReader { 7 | 8 | private final Row row; 9 | private final FieldMap fields; 10 | 11 | private RowReader(Row row, FieldMap fields) { 12 | this.row = row; 13 | this.fields = fields; 14 | } 15 | 16 | static RowReader of(Row row, FieldMap fields) { 17 | return new RowReader(row, fields); 18 | } 19 | 20 | int rowNum() { 21 | return row.getRowNum(); 22 | } 23 | 24 | Cell cell(int col) { 25 | return row.getCell(col); 26 | } 27 | 28 | @Override 29 | public Cell cellOf(Field field) { 30 | var col = fields.posOf(field); 31 | return col.isPresent() 32 | ? In.cell(row, col.getAsInt()) 33 | : null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/geo/calc/WebMercatorTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.geo.calc; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | import org.openlca.geo.geojson.Point; 6 | 7 | public class WebMercatorTest { 8 | 9 | @Test 10 | public void testProjectUnproject() { 11 | for (int zoom = 0; zoom < 10; zoom++) { 12 | for (int lon = -180; lon <= 180; lon+=10) { 13 | for (int lat = -80; lat <= 80; lat+=10) { 14 | Point p = new Point(); 15 | p.x = lon; 16 | p.y = lat; 17 | WebMercator.apply(p, zoom); 18 | WebMercator.inverse(p, zoom); 19 | Assert.assertEquals(lon, p.x, 1e-10); 20 | Assert.assertEquals(lat, p.y, 1e-10); 21 | } 22 | } 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/java/org/openlca/proto/io/output/SourceWriter.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io.output; 2 | 3 | import org.openlca.commons.Strings; 4 | import org.openlca.core.model.Source; 5 | import org.openlca.proto.ProtoSource; 6 | import org.openlca.proto.ProtoType; 7 | 8 | public class SourceWriter { 9 | 10 | public ProtoSource write(Source source) { 11 | var proto = ProtoSource.newBuilder(); 12 | if (source == null) 13 | return proto.build(); 14 | proto.setType(ProtoType.Source); 15 | Out.map(source, proto); 16 | 17 | proto.setExternalFile(Strings.notNull(source.externalFile)); 18 | proto.setTextReference(Strings.notNull(source.textReference)); 19 | proto.setUrl(Strings.notNull(source.url)); 20 | if (source.year != null) { 21 | proto.setYear(source.year); 22 | } 23 | return proto.build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/IDao.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import java.util.Collection; 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | public interface IDao { 9 | 10 | boolean contains(long id); 11 | 12 | Map contains(Set ids); 13 | 14 | void delete(long id); 15 | 16 | void delete(T entity); 17 | 18 | void deleteAll(Collection entities); 19 | 20 | T update(T entity); 21 | 22 | T insert(T entity); 23 | 24 | T getForId(long id); 25 | 26 | List getForIds(Set ids); 27 | 28 | List getAll(); 29 | 30 | List getAll(String jpql, Map parameters); 31 | 32 | T getFirst(String jpql, Map parameters); 33 | 34 | long getCount(String jpql, Map parameters); 35 | 36 | void deleteAll(); 37 | 38 | } -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/linking/Link.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.linking; 2 | 3 | /** 4 | * Describes a link of a product input or waste output to a provider flow. 5 | */ 6 | class Link { 7 | 8 | /** 9 | * The amount of the linked product input or waste output in the process. 10 | */ 11 | final double amount; 12 | 13 | /** 14 | * The node that describes the provider of the product or waste treatment. 15 | */ 16 | final Node provider; 17 | 18 | /** 19 | * The scaled amount that needs to be provided by the linked process. 20 | */ 21 | double demand; 22 | 23 | /** The ID of the respective exchange. */ 24 | long exchangeId; 25 | 26 | Link(Node provider, long exchangeId, double amount, double demand) { 27 | this.provider = provider; 28 | this.exchangeId = exchangeId; 29 | this.amount = amount; 30 | this.demand = demand; 31 | } 32 | } -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/linking/NodeState.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.linking; 2 | 3 | /** 4 | * The different states a node can take when building the product graph. 5 | */ 6 | enum NodeState { 7 | 8 | /** 9 | * The node is in the waiting queue for the next iteration. 10 | */ 11 | WAITING, 12 | 13 | /** 14 | * The node will be handled in the current iteration. 15 | */ 16 | PROGRESS, 17 | 18 | /** 19 | * The node was handled in an iteration and all inputs were followed. 20 | */ 21 | FOLLOWED, 22 | 23 | /** 24 | * The node was created in an iteration but it was excluded because its 25 | * demand is smaller than the cutoff. 26 | */ 27 | EXCLUDED, 28 | 29 | /** 30 | * The node was handled in a current re-scaling process (and should be 31 | * not rescaled again to avoid endless loops). 32 | */ 33 | RESCALED 34 | 35 | } 36 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/descriptors/ImpactMethodDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model.descriptors; 2 | 3 | import org.openlca.core.model.ModelType; 4 | 5 | /** 6 | * The descriptor class for impact assessment methods. 7 | */ 8 | public class ImpactMethodDescriptor extends RootDescriptor { 9 | 10 | public ImpactMethodDescriptor() { 11 | this.type = ModelType.IMPACT_METHOD; 12 | } 13 | 14 | @Override 15 | public ImpactMethodDescriptor copy() { 16 | var copy = new ImpactMethodDescriptor(); 17 | copyFields(this, copy); 18 | return copy; 19 | } 20 | 21 | public static Builder create() { 22 | return new Builder(new ImpactMethodDescriptor()); 23 | } 24 | 25 | public static class Builder extends DescriptorBuilder { 26 | private Builder(ImpactMethodDescriptor descriptor) { 27 | super(descriptor); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /olca-proto-io/src/test/java/org/openlca/proto/io/input/NullSafetyTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io.input; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import org.junit.Test; 7 | import org.openlca.proto.ProtoCurrency; 8 | import org.openlca.proto.ProtoFlowProperty; 9 | import org.openlca.proto.ProtoFlowPropertyType; 10 | 11 | public class NullSafetyTest { 12 | 13 | @Test 14 | public void testRefId() { 15 | var proto = ProtoCurrency.newBuilder().build(); 16 | var refId = proto.getRefCurrency().getId(); 17 | assertEquals("", refId); 18 | } 19 | 20 | @Test 21 | public void testEnumItem() { 22 | var proto = ProtoFlowProperty.newBuilder().build(); 23 | var type = proto.getFlowPropertyType(); 24 | assertNotNull(type); 25 | assertEquals(ProtoFlowPropertyType.UNDEFINED_FLOW_PROPERTY_TYPE, type); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-core/src/test/java/examples/DbLibrarySwapExample.java: -------------------------------------------------------------------------------- 1 | package examples; 2 | 3 | import org.openlca.core.DataDir; 4 | import org.openlca.core.database.upgrades.Upgrades; 5 | import org.openlca.core.library.DbLibrarySwap; 6 | import org.openlca.core.library.reader.LibReader; 7 | 8 | public class DbLibrarySwapExample { 9 | 10 | public static void main(String[] args) { 11 | try (var db = DataDir.get().openDatabase("infinite_en15804")) { 12 | Upgrades.on(db); 13 | 14 | var lib = DataDir.get().getLibraryDir() 15 | .getLibrary("en15804_00.00.001") 16 | .orElseThrow(); 17 | var reader = LibReader.of(lib, db).create(); 18 | 19 | var swap = new DbLibrarySwap(db, reader); 20 | var start = System.nanoTime(); 21 | swap.run(); 22 | var time = (System.nanoTime() - start) / 1e9; 23 | System.out.printf("Swapped library in %.3f seconds", time); 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/java/org/openlca/proto/io/input/SourceReader.java: -------------------------------------------------------------------------------- 1 | 2 | package org.openlca.proto.io.input; 3 | 4 | import org.openlca.core.io.EntityResolver; 5 | import org.openlca.core.model.Source; 6 | import org.openlca.proto.ProtoSource; 7 | 8 | public record SourceReader(EntityResolver resolver) 9 | implements EntityReader { 10 | 11 | @Override 12 | public Source read(ProtoSource proto) { 13 | var source = new Source(); 14 | update(source, proto); 15 | return source; 16 | } 17 | 18 | @Override 19 | public void update(Source source, ProtoSource proto) { 20 | Util.mapBase(source, ProtoBox.of(proto), resolver); 21 | source.url = proto.getUrl(); 22 | source.externalFile = proto.getExternalFile(); 23 | source.textReference = proto.getTextReference(); 24 | if (proto.hasYear()) { 25 | source.year = (short) proto.getYear(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/java/org/openlca/proto/io/output/CurrencyWriter.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io.output; 2 | 3 | import org.openlca.commons.Strings; 4 | import org.openlca.core.model.Currency; 5 | import org.openlca.proto.ProtoCurrency; 6 | import org.openlca.proto.ProtoType; 7 | 8 | public class CurrencyWriter { 9 | 10 | private final WriterConfig config; 11 | 12 | public CurrencyWriter(WriterConfig config) { 13 | this.config = config; 14 | } 15 | 16 | public ProtoCurrency write(Currency c) { 17 | var proto = ProtoCurrency.newBuilder(); 18 | if (c == null) 19 | return proto.build(); 20 | proto.setType(ProtoType.Currency); 21 | Out.map(c, proto); 22 | proto.setCode(Strings.notNull(c.code)); 23 | proto.setConversionFactor(c.conversionFactor); 24 | config.dep(c.referenceCurrency, proto::setRefCurrency); 25 | return proto.build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-proto-io/src/test/java/org/openlca/proto/io/EnumTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | import org.openlca.proto.ProtoFlow; 6 | import org.openlca.proto.ProtoFlowType; 7 | 8 | import com.google.protobuf.util.JsonFormat; 9 | 10 | public class EnumTest { 11 | 12 | @Test 13 | public void testFlowType() throws Exception { 14 | var flow = ProtoFlow.newBuilder() 15 | .setName("CO2") 16 | .setFlowType(ProtoFlowType.ELEMENTARY_FLOW) 17 | .build(); 18 | var json = JsonFormat.printer().print(flow); 19 | Assert.assertTrue(json.contains("ELEMENTARY_FLOW")); 20 | 21 | var clone = ProtoFlow.newBuilder(); 22 | JsonFormat.parser().merge(json, clone); 23 | Assert.assertEquals("CO2", clone.getName()); 24 | Assert.assertEquals(ProtoFlowType.ELEMENTARY_FLOW, clone.getFlowType()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /olca-ipc/src/main/java/org/openlca/ipc/handlers/RuntimeHandler.java: -------------------------------------------------------------------------------- 1 | package org.openlca.ipc.handlers; 2 | 3 | import org.openlca.ipc.Responses; 4 | import org.openlca.ipc.Rpc; 5 | import org.openlca.ipc.RpcRequest; 6 | import org.openlca.ipc.RpcResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | public class RuntimeHandler { 11 | 12 | private final HandlerContext context; 13 | 14 | public RuntimeHandler(HandlerContext context) { 15 | this.context = context; 16 | } 17 | 18 | @Rpc("runtime/shutdown") 19 | public RpcResponse shutdown(RpcRequest req) { 20 | Logger log = LoggerFactory.getLogger(getClass()); 21 | log.info("Shutdown server and close database"); 22 | try { 23 | context.server().stop(); 24 | context.db().close(); 25 | return Responses.ok(req); 26 | } catch (Exception e) { 27 | return Responses.serverError(e, req); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/java/org/openlca/proto/io/input/ImportStatus.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io.input; 2 | 3 | import java.util.Objects; 4 | 5 | import org.openlca.core.model.RootEntity; 6 | 7 | public record ImportStatus( 8 | T model, Status status, String error) { 9 | 10 | public enum Status { 11 | CREATED, UPDATED, SKIPPED, ERROR 12 | } 13 | 14 | public ImportStatus(T model, Status status, String error) { 15 | this.model = model; 16 | this.status = Objects.requireNonNull(status); 17 | this.error = error; 18 | } 19 | 20 | public boolean isCreated() { 21 | return status == Status.CREATED; 22 | } 23 | 24 | public boolean isUpdated() { 25 | return status == Status.UPDATED; 26 | } 27 | 28 | public boolean isSkipped() { 29 | return status == Status.SKIPPED; 30 | } 31 | 32 | public boolean isError() { 33 | return status == Status.ERROR; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/ecospold2/output/Units.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.ecospold2.output; 2 | 3 | import java.util.Objects; 4 | 5 | import org.openlca.core.model.Unit; 6 | 7 | import spold2.Exchange; 8 | import spold2.UserMasterData; 9 | 10 | final class Units { 11 | 12 | private Units() { 13 | } 14 | 15 | static void map(Unit unit, Exchange exchange, UserMasterData masterData) { 16 | if (unit == null || exchange == null) 17 | return; 18 | exchange.unit = unit.name; 19 | exchange.unitId = unit.refId; 20 | if (masterData == null) 21 | return; 22 | for (spold2.Unit es2Unit : masterData.units) { 23 | if (Objects.equals(unit.refId, es2Unit.id)) 24 | return; 25 | } 26 | spold2.Unit es2Unit = new spold2.Unit(); 27 | es2Unit.comment = unit.description; 28 | es2Unit.id = unit.refId; 29 | es2Unit.name = unit.name; 30 | masterData.units.add(es2Unit); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/smartepd/SmartPcr.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.smartepd; 2 | 3 | import java.util.Optional; 4 | 5 | import org.openlca.jsonld.Json; 6 | 7 | import com.google.gson.JsonElement; 8 | import com.google.gson.JsonObject; 9 | 10 | public record SmartPcr(JsonObject json) { 11 | 12 | public static Optional of(JsonElement e) { 13 | if (e == null || !e.isJsonObject()) 14 | return Optional.empty(); 15 | var obj = e.getAsJsonObject(); 16 | return Optional.of(new SmartPcr(obj)); 17 | } 18 | 19 | public String id() { 20 | return Json.getString(json, "id"); 21 | } 22 | 23 | public SmartPcr id(String id) { 24 | Json.put(json, "id", id); 25 | return this; 26 | } 27 | 28 | public String name() { 29 | return Json.getString(json, "name"); 30 | } 31 | 32 | public SmartPcr name(String name) { 33 | Json.put(json, "name", name); 34 | return this; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /olca-proto-io/build_server.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import shutil 3 | import subprocess 4 | 5 | 6 | def main(): 7 | print('Build the server application ...') 8 | subprocess.run([ 9 | 'mvn', 'clean', 'package', '-P', 'server-app'], 10 | shell=True) 11 | 12 | print('Generate the README.pdf ...') 13 | subprocess.run([ 14 | 'pandoc', 15 | '-o', 16 | 'target\\olca-grpc-server\\README.pdf', 17 | 'server-doc.md']) 18 | 19 | print('Copy the JRE ...') 20 | shutil.copytree('./jre', './target/olca-grpc-server/jre') 21 | 22 | print('Create the distribution package ...') 23 | suffix = '_win64_%s' % datetime.date.today() 24 | shutil.make_archive( 25 | './target/olca-grpc-server' + suffix, 26 | 'zip', 27 | './target/olca-grpc-server') 28 | 29 | print('All done!') 30 | 31 | 32 | if __name__ == '__main__': 33 | main() 34 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/solvers/mkl/OS.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.solvers.mkl; 2 | 3 | import java.util.Locale; 4 | 5 | enum OS { 6 | 7 | Linux(new String[]{ 8 | "libmkl_rt.so.2", 9 | "libolcamkl.so" 10 | }), 11 | 12 | MacOS(new String[]{ 13 | "libmkl_rt.2.dylib", 14 | "libolcamkl.dylib" 15 | }), 16 | 17 | Windows(new String[]{ 18 | "mkl_rt.2.dll", 19 | "olcamkl.dll", 20 | }); 21 | 22 | private final String[] libraries; 23 | 24 | OS(String[] libraries) { 25 | this.libraries = libraries; 26 | } 27 | 28 | static OS detect() { 29 | var os = System.getProperty("os.name", "generic") 30 | .toLowerCase(Locale.ENGLISH); 31 | if (os.contains("mac") || os.contains("darwin")) 32 | return OS.MacOS; 33 | if (os.contains("win")) 34 | return OS.Windows; 35 | return OS.Linux; 36 | } 37 | 38 | String[] libraries() { 39 | return libraries; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/EpdType.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | import java.util.Locale; 4 | import java.util.Optional; 5 | 6 | public enum EpdType { 7 | 8 | GENERIC_DATASET("generic dataset"), 9 | REPRESENTATIVE_DATASET("representative dataset"), 10 | AVERAGE_DATASET("average dataset"), 11 | SPECIFIC_DATASET("specific dataset"), 12 | TEMPLATE_DATASET("template dataset"); 13 | 14 | private final String label; 15 | 16 | EpdType(String label) { 17 | this.label = label; 18 | } 19 | 20 | public static Optional fromString(String s) { 21 | if (s == null) 22 | return Optional.empty(); 23 | var lo = s.strip().toLowerCase(Locale.US); 24 | for (var v : values()) { 25 | if (lo.equals(v.label)) 26 | return Optional.of(v); 27 | } 28 | return Optional.empty(); 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return label; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/text/WordBuffer.java: -------------------------------------------------------------------------------- 1 | package org.openlca.text; 2 | 3 | import java.util.ArrayList; 4 | 5 | public final class WordBuffer { 6 | 7 | private final ArrayList buffer; 8 | 9 | public WordBuffer() { 10 | this(10); 11 | } 12 | 13 | public WordBuffer(int capacity) { 14 | buffer = new ArrayList<>(capacity); 15 | } 16 | 17 | int size() { 18 | return buffer.size(); 19 | } 20 | 21 | boolean isEmpty() { 22 | return buffer.isEmpty(); 23 | } 24 | 25 | String get(int i) { 26 | return buffer.get(i); 27 | } 28 | 29 | void add(String word) { 30 | buffer.add(word); 31 | } 32 | 33 | void reset() { 34 | if (buffer.isEmpty()) 35 | return; 36 | buffer.clear(); 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return buffer.toString(); 42 | } 43 | 44 | public String[] toArray() { 45 | return buffer.toArray(String[]::new); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/java/org/openlca/proto/io/server/Response.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io.server; 2 | 3 | import com.google.protobuf.Empty; 4 | 5 | import io.grpc.Status; 6 | import io.grpc.stub.StreamObserver; 7 | 8 | final class Response { 9 | 10 | private Response() { 11 | } 12 | 13 | static void invalidArg(StreamObserver resp, String error) { 14 | resp.onError(Status.INVALID_ARGUMENT.withDescription(error).asException()); 15 | } 16 | 17 | static void notFound(StreamObserver resp, String error) { 18 | resp.onError(Status.NOT_FOUND.withDescription(error).asException()); 19 | } 20 | 21 | static void serverError(StreamObserver resp, String error) { 22 | resp.onError(Status.INTERNAL.withDescription(error).asException()); 23 | } 24 | 25 | static void ok(StreamObserver resp) { 26 | resp.onNext(Empty.newBuilder().build()); 27 | resp.onCompleted(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/TypedRefId.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | import java.util.Objects; 4 | 5 | public class TypedRefId { 6 | 7 | public final ModelType type; 8 | public final String refId; 9 | 10 | public TypedRefId(ModelType type, String refId) { 11 | this.type = type; 12 | this.refId = refId; 13 | } 14 | 15 | @Override 16 | public int hashCode() { 17 | return Objects.hash(type, refId); 18 | } 19 | 20 | @Override 21 | public boolean equals(Object obj) { 22 | if (!(obj instanceof TypedRefId)) 23 | return false; 24 | var o = (TypedRefId) obj; 25 | return type == o.type && Objects.equals(refId, o.refId); 26 | } 27 | 28 | protected String fieldsToString() { 29 | return "type=" + type + ", refId=" + refId; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return getClass().getSimpleName() + "[" + fieldsToString() + "]"; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/results/agroups/Tree.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.results.agroups; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.openlca.core.matrix.index.TechFlow; 7 | import org.openlca.core.results.LcaResult; 8 | 9 | record Tree( 10 | String group, 11 | TechFlow techFlow, 12 | int index, 13 | double scaling, 14 | double amount, 15 | List childs 16 | ) { 17 | 18 | static Tree rootOf(LcaResult result, GroupMap groups) { 19 | var demand = result.demand(); 20 | var techFlow = result.demand().techFlow(); 21 | var amount = demand.value(); 22 | var index = result.techIndex().of(techFlow); 23 | double aii = result.provider().techValueOf(index, index); 24 | return new Tree( 25 | groups.top(), techFlow, index, amount / aii, amount, new ArrayList<>() 26 | ); 27 | } 28 | 29 | long pid() { 30 | return techFlow.providerId(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/RefEntity.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | import org.openlca.commons.Copyable; 4 | 5 | import jakarta.persistence.Column; 6 | import jakarta.persistence.Lob; 7 | import jakarta.persistence.MappedSuperclass; 8 | 9 | /** 10 | * A RefEntity is an entity that can be referenced by a unique ID, the reference 11 | * ID or short `refId`. 12 | */ 13 | @MappedSuperclass 14 | public abstract class RefEntity 15 | extends AbstractEntity implements Copyable { 16 | 17 | @Column(name = "ref_id") 18 | public String refId; 19 | 20 | @Column(name = "name") 21 | public String name; 22 | 23 | @Lob 24 | @Column(name = "description") 25 | public String description; 26 | 27 | @Override 28 | public String toString() { 29 | return "RootEntity [type=" 30 | + getClass().getSimpleName() 31 | + ", refId=" + refId 32 | + ", name=" + name + "]"; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/matrix/index/ImpactIndexTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.index; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | import org.openlca.core.model.descriptors.ImpactDescriptor; 8 | 9 | public class ImpactIndexTest { 10 | 11 | @Test 12 | public void testIndex() { 13 | var index = new ImpactIndex(); 14 | for (int i = 1; i < 11; i++) { 15 | var d = new ImpactDescriptor(); 16 | d.id = i; 17 | index.add(d); 18 | } 19 | assertEquals(10, index.size()); 20 | 21 | assertEquals(10, index.size()); 22 | for (int i = 1; i < 11; i++) { 23 | assertTrue(index.contains(i)); 24 | assertEquals(i - 1, index.of(i)); 25 | ImpactDescriptor d = index.at(i - 1); 26 | assertEquals(i - 1, index.of(d)); 27 | assertTrue(index.contains(d)); 28 | assertEquals(i, d.id); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/jsonld/AbstractZipTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.jsonld; 2 | 3 | import java.io.File; 4 | import java.nio.file.Files; 5 | import java.util.function.Consumer; 6 | 7 | import org.junit.After; 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | 11 | public class AbstractZipTest { 12 | 13 | private File tempDir; 14 | protected File zipFile; 15 | 16 | @Before 17 | public void setUp() throws Exception { 18 | tempDir = Files.createTempDirectory("olca-json_").toFile(); 19 | zipFile = new File(tempDir, "test_zip.zip"); 20 | } 21 | 22 | @After 23 | public void tearDown() { 24 | Assert.assertTrue(zipFile.delete()); 25 | Assert.assertTrue(tempDir.delete()); 26 | } 27 | 28 | protected void with(Consumer fn) { 29 | try (ZipStore zip = ZipStore.open(zipFile)) { 30 | fn.accept(zip); 31 | } catch (Exception e) { 32 | throw new RuntimeException(e); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /olca-git/src/main/java/org/openlca/git/util/BinaryResolver.java: -------------------------------------------------------------------------------- 1 | package org.openlca.git.util; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import org.openlca.git.model.Diff; 8 | 9 | public interface BinaryResolver { 10 | 11 | BinaryResolver NULL = new BinaryResolver() { 12 | 13 | @Override 14 | public byte[] resolve(Diff change, String relativePath) throws IOException { 15 | return null; 16 | } 17 | 18 | @Override 19 | public List list(Diff change, String relativePath) { 20 | return new ArrayList<>(); 21 | } 22 | 23 | @Override 24 | public boolean isDirectory(Diff change, String relativePath) { 25 | return false; 26 | } 27 | }; 28 | 29 | List list(Diff change, String relativePath); 30 | 31 | boolean isDirectory(Diff change, String relativePath); 32 | 33 | byte[] resolve(Diff change, String relativePath) throws IOException; 34 | 35 | } -------------------------------------------------------------------------------- /olca-git/src/main/java/org/openlca/git/util/Path.java: -------------------------------------------------------------------------------- 1 | package org.openlca.git.util; 2 | 3 | import org.openlca.core.model.Category; 4 | import org.openlca.core.model.ModelType; 5 | import org.openlca.core.model.descriptors.RootDescriptor; 6 | import org.openlca.util.Categories; 7 | import org.openlca.util.Categories.PathBuilder; 8 | 9 | public class Path { 10 | 11 | public static String of(ModelType t) { 12 | return t.name(); 13 | } 14 | 15 | public static String of(Category c) { 16 | var paths = Categories.path(c); 17 | paths.add(0, c.modelType.name()); 18 | return String.join("/", paths); 19 | } 20 | 21 | public static String of(PathBuilder categoryPaths, RootDescriptor d) { 22 | if (d.type == ModelType.CATEGORY) 23 | return d.type.name() + "/" + categoryPaths.pathOf(d.id); 24 | var categoryPath = categoryPaths.pathOf(d.category); 25 | return GitUtil.toDatasetPath(d.type, categoryPath, d.refId); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/ecospold1/output/ExportConfig.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.ecospold1.output; 2 | 3 | public class ExportConfig { 4 | 5 | private boolean singleFile = false; 6 | private boolean schemaValid = false; 7 | private boolean createDefaults = false; 8 | 9 | public static ExportConfig getDefault() { 10 | return new ExportConfig(); 11 | } 12 | 13 | public boolean isSingleFile() { 14 | return singleFile; 15 | } 16 | 17 | public void setSingleFile(boolean singleFile) { 18 | this.singleFile = singleFile; 19 | } 20 | 21 | public boolean isSchemaValid() { 22 | return schemaValid; 23 | } 24 | 25 | public void setSchemaValid(boolean schemaValid) { 26 | this.schemaValid = schemaValid; 27 | } 28 | 29 | public boolean isCreateDefaults() { 30 | return createDefaults; 31 | } 32 | 33 | public void setCreateDefaults(boolean createDefaults) { 34 | this.createDefaults = createDefaults; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/refdata/LocationImport.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.refdata; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.openlca.core.model.Location; 6 | import org.openlca.core.model.ModelType; 7 | 8 | class LocationImport implements Runnable { 9 | 10 | private final ImportConfig config; 11 | 12 | LocationImport(ImportConfig config) { 13 | this.config = config; 14 | } 15 | 16 | @Override 17 | public void run() { 18 | var locations = new ArrayList(); 19 | config.eachRowOf("locations.csv", row -> { 20 | var loc = new Location(); 21 | loc.refId = row.get(0); 22 | loc.name = row.get(1); 23 | loc.description = row.get(2); 24 | loc.category = config.category(ModelType.LOCATION, row.get(3)); 25 | loc.code = row.get(4); 26 | loc.latitude = row.getDouble(5); 27 | loc.longitude = row.getDouble(6); 28 | locations.add(loc); 29 | }); 30 | config.insert(locations); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/usage/ImpactMethodUseSearch.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.usage; 2 | 3 | import java.util.Collections; 4 | import java.util.Set; 5 | 6 | import org.openlca.core.database.IDatabase; 7 | import org.openlca.core.model.Project; 8 | import org.openlca.core.model.Result; 9 | import org.openlca.core.model.descriptors.RootDescriptor; 10 | 11 | import gnu.trove.set.TLongSet; 12 | 13 | public record ImpactMethodUseSearch(IDatabase db) implements UsageSearch { 14 | 15 | @Override 16 | public Set find(TLongSet ids) { 17 | if (ids.isEmpty()) 18 | return Collections.emptySet(); 19 | var suffix = Search.eqIn(ids); 20 | return QueryPlan.of(db) 21 | .submit(Project.class, 22 | "select id from tbl_projects where f_impact_method " + suffix) 23 | .submit(Result.class, 24 | "select id from tbl_results where f_impact_method " + suffix) 25 | .exec(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/model/CloneProcessTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | import org.openlca.core.TestProcess; 8 | import org.openlca.core.Tests; 9 | 10 | public class CloneProcessTest { 11 | 12 | @Test 13 | public void testInternalExchangeIDs() { 14 | Process p1 = TestProcess.refProduct("steel", 1.0, "kg") 15 | .elemOut("CO2", 2, "kg").get(); 16 | assertEquals(2, p1.lastInternalId); 17 | for (Exchange e : p1.exchanges) { 18 | assertTrue(e.internalId > 0); 19 | assertEquals(e, p1.getExchange(e.internalId)); 20 | } 21 | Process p2 = p1.copy(); 22 | assertEquals(2, p2.lastInternalId); 23 | for (Exchange e : p2.exchanges) { 24 | assertTrue(e.internalId > 0); 25 | assertEquals(e, p2.getExchange(e.internalId)); 26 | } 27 | Tests.getDb().clear(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /olca-git/src/main/java/org/openlca/git/util/ModelRefSet.java: -------------------------------------------------------------------------------- 1 | package org.openlca.git.util; 2 | 3 | import java.util.Collection; 4 | 5 | import org.openlca.git.model.ModelRef; 6 | import org.openlca.util.TypedRefIdSet; 7 | 8 | public class ModelRefSet extends TypedRefIdSet { 9 | 10 | public ModelRefSet() { 11 | super(); 12 | } 13 | 14 | public ModelRefSet(Collection refs) { 15 | addAll(refs); 16 | } 17 | 18 | public void add(ModelRef ref) { 19 | if (ref.isCategory) { 20 | add(ref.type, ref.path); 21 | } else { 22 | add(ref.type, ref.refId); 23 | } 24 | } 25 | 26 | public boolean contains(ModelRef ref) { 27 | if (ref.isCategory) 28 | return contains(ref.type, ref.path); 29 | return contains(ref.type, ref.refId); 30 | } 31 | 32 | public void remove(ModelRef ref) { 33 | if (ref.isCategory) { 34 | remove(ref.type, ref.path); 35 | } else { 36 | remove(ref.type, ref.refId); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /olca-git/src/main/java/org/openlca/git/util/ModelRefMap.java: -------------------------------------------------------------------------------- 1 | package org.openlca.git.util; 2 | 3 | import org.openlca.git.model.ModelRef; 4 | import org.openlca.util.TypedRefIdMap; 5 | 6 | public class ModelRefMap extends TypedRefIdMap { 7 | 8 | public ModelRefMap put(ModelRef ref, T value) { 9 | if (ref.isCategory) { 10 | put(ref.type, ref.path, value); 11 | } else { 12 | put(ref.type, ref.refId, value); 13 | } 14 | return this; 15 | } 16 | 17 | public boolean contains(ModelRef ref) { 18 | if (ref.isCategory) 19 | return contains(ref.type, ref.path); 20 | return contains(ref.type, ref.refId); 21 | } 22 | 23 | public T get(ModelRef ref) { 24 | if (ref.isCategory) 25 | return get(ref.type, ref.path); 26 | return get(ref.type, ref.refId); 27 | } 28 | 29 | public T remove(ModelRef ref) { 30 | if (ref.isCategory) 31 | return remove(ref.type, ref.path); 32 | return remove(ref.type, ref.refId); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/indicators/ap.mdy: -------------------------------------------------------------------------------- 1 | let .ws = { 2 | any of ; 3 | } 4 | 5 | let .opt_parens_open = { 6 | .ws; 7 | option of "("; 8 | .ws; 9 | } 10 | 11 | let .opt_parens_close = { 12 | .ws; 13 | option of ")"; 14 | .ws; 15 | } 16 | 17 | let .potential = { 18 | .ws; 19 | option of either { 20 | "potential"; 21 | "pot."; 22 | } 23 | .ws; 24 | } 25 | 26 | let .opt_total = { 27 | .ws; 28 | option of either { 29 | ","; 30 | "-"; 31 | } 32 | .ws; 33 | option of "total"; 34 | .ws; 35 | } 36 | 37 | let .ap = { 38 | .opt_parens_open; 39 | "ap"; 40 | .opt_total; 41 | .opt_parens_close; 42 | } 43 | 44 | let .suffix = { 45 | .potential; 46 | .opt_parens_open; 47 | option of "ap"; 48 | .opt_total; 49 | .opt_parens_close; 50 | } 51 | 52 | let .acidification = { 53 | .ws; 54 | "acidification"; 55 | .suffix; 56 | } 57 | 58 | either { 59 | .ap; 60 | .acidification; 61 | } 62 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/java/org/openlca/proto/io/output/LocationWriter.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io.output; 2 | 3 | import org.openlca.commons.Strings; 4 | import org.openlca.core.model.Location; 5 | import org.openlca.proto.ProtoLocation; 6 | import org.openlca.proto.ProtoType; 7 | 8 | import com.google.protobuf.ByteString; 9 | 10 | public class LocationWriter { 11 | 12 | public ProtoLocation write(Location location) { 13 | var proto = ProtoLocation.newBuilder(); 14 | if (location == null) 15 | return proto.build(); 16 | proto.setType(ProtoType.Location); 17 | Out.map(location, proto); 18 | 19 | proto.setCode(Strings.notNull(location.code)); 20 | proto.setLatitude(location.latitude); 21 | proto.setLongitude(location.longitude); 22 | if (location.geodata != null) { 23 | proto.setGeometryBytes( 24 | ByteString.copyFrom(location.geodata)); 25 | } 26 | 27 | return proto.build(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/java/org/openlca/proto/io/input/LocationReader.java: -------------------------------------------------------------------------------- 1 | 2 | package org.openlca.proto.io.input; 3 | 4 | import org.openlca.core.io.EntityResolver; 5 | import org.openlca.core.model.Location; 6 | import org.openlca.proto.ProtoLocation; 7 | 8 | public record LocationReader(EntityResolver resolver) 9 | implements EntityReader { 10 | 11 | @Override 12 | public Location read(ProtoLocation proto) { 13 | var location = new Location(); 14 | update(location, proto); 15 | return location; 16 | } 17 | 18 | @Override 19 | public void update(Location location, ProtoLocation proto) { 20 | Util.mapBase(location, ProtoBox.of(proto), resolver); 21 | location.code = proto.getCode(); 22 | location.latitude = proto.getLatitude(); 23 | location.longitude = proto.getLongitude(); 24 | var geom = proto.getGeometryBytes(); 25 | if (!geom.isEmpty()) { 26 | location.geodata = geom.toByteArray(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/ParameterScope.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | /** 4 | * Parameters can be defined globally, in processes, or LCIA categories. They 5 | * can be redefined in calculation setups on the project and product system 6 | * level, but the initial definition is always only global, in processes, or 7 | * LCIA category. 8 | */ 9 | public enum ParameterScope { 10 | 11 | PROCESS, 12 | 13 | IMPACT, 14 | 15 | GLOBAL; 16 | 17 | /** 18 | * Same as valueOf but it returns {@code null} instead of throwing an 19 | * exception when the given string does not match a constant of this 20 | * enumeration. Also, lower case constant names are allowed. 21 | */ 22 | public static ParameterScope fromString(String s) { 23 | if (s == null || s.isBlank()) 24 | return null; 25 | for (var v : values()) { 26 | if (s.equalsIgnoreCase(v.name())) 27 | return v; 28 | } 29 | return null; 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/pubchem/Compound.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.pubchem; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.openlca.jsonld.Json; 7 | 8 | import com.google.gson.JsonObject; 9 | 10 | public record Compound(JsonObject json) { 11 | 12 | public Long id() { 13 | var top = Json.getObject(json, "id"); 14 | var sub = Json.getObject(top, "id"); 15 | var id = Json.getLong(sub, "cid"); 16 | return id.isPresent() 17 | ? id.getAsLong() 18 | : null; 19 | } 20 | 21 | public int charge() { 22 | return Json.getInt(json, "charge", 0); 23 | } 24 | 25 | public List properties() { 26 | var array = Json.getArray(json, "props"); 27 | if (array == null) 28 | return List.of(); 29 | var props = new ArrayList(); 30 | for (var e : array) { 31 | if (e.isJsonObject()) { 32 | props.add(new Property(e.getAsJsonObject())); 33 | } 34 | } 35 | return props; 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/pubchem/PropertyUrn.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.pubchem; 2 | 3 | import org.openlca.jsonld.Json; 4 | 5 | import com.google.gson.JsonObject; 6 | 7 | public record PropertyUrn(JsonObject json) { 8 | 9 | public String label() { 10 | return Json.getString(json, "label"); 11 | } 12 | 13 | public String name() { 14 | return Json.getString(json, "name"); 15 | } 16 | 17 | public int datatype() { 18 | return Json.getInt(json, "datatype", 0); 19 | } 20 | 21 | public String implementation() { 22 | return Json.getString(json, "implementation"); 23 | } 24 | 25 | public String version() { 26 | return Json.getString(json, "version"); 27 | } 28 | 29 | public String software() { 30 | return Json.getString(json, "software"); 31 | } 32 | 33 | public String source() { 34 | return Json.getString(json, "source"); 35 | } 36 | 37 | public String release() { 38 | return Json.getString(json, "release"); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/CalculationTarget.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | /** 4 | * The target of a calculation setup can be an instance of {@link Process} or 5 | * {@link ProductSystem}. This is a tagging interface to mark these classes as 6 | * calculable. 7 | */ 8 | public sealed interface CalculationTarget permits Process, ProductSystem { 9 | 10 | default boolean isProcess() { 11 | return this instanceof Process; 12 | } 13 | 14 | default Process asProcess() { 15 | return (Process) this; 16 | } 17 | 18 | default boolean isProductSystem() { 19 | return this instanceof ProductSystem; 20 | } 21 | 22 | default ProductSystem asProductSystem() { 23 | return (ProductSystem) this; 24 | } 25 | 26 | default Exchange quantitativeReference() { 27 | if (isProcess()) 28 | return asProcess().quantitativeReference; 29 | if (isProductSystem()) 30 | return asProductSystem().referenceExchange; 31 | return null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/proto/commons.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package protolca.services; 3 | 4 | option java_package = "org.openlca.proto.generated.data"; 5 | option java_multiple_files = true; 6 | option java_outer_classname = "DataProto"; 7 | 8 | option csharp_namespace = "ProtoLCA.Services"; 9 | option go_package = ".;protolca"; 10 | 11 | import "olca.proto"; 12 | 13 | message DataSet { 14 | oneof model { 15 | Actor actor = 1; 16 | Category category = 2; 17 | Currency currency = 3; 18 | DQSystem dq_system = 4; 19 | Flow flow = 5; 20 | FlowProperty flow_property = 6; 21 | ImpactCategory impact_category = 7; 22 | ImpactMethod impact_method = 8; 23 | Location location = 9; 24 | Parameter parameter = 10; 25 | Process process = 11; 26 | ProductSystem product_system = 12; 27 | Project project = 13; 28 | SocialIndicator social_indicator = 14; 29 | Source source = 15; 30 | UnitGroup unit_group = 16; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /olca-io/src/test/java/org/openlca/io/smartepd/ProjectSettingsTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.smartepd; 2 | 3 | import org.openlca.jsonld.Json; 4 | 5 | public class ProjectSettingsTest { 6 | 7 | public static void main(String[] args) { 8 | var client = SmartEpdClient.of( 9 | "https://smart-epd.herokuapp.com/", 10 | "b960428ac1db13f3868e239f4076069b73b418bd01670e880e407aa125d8217f"); 11 | 12 | for (var project : client.getProjects().value()) { 13 | System.out.println(project.name()); 14 | var settings = client.getProjectSettings(project.id()).value(); 15 | var json = Json.toPrettyString(settings.json()); 16 | System.out.println(json); 17 | 18 | for (var method : settings.impactSettings().methods()) { 19 | System.out.println("method: " + method); 20 | } 21 | 22 | for (var indicator : settings.impactSettings().indicators()) { 23 | System.out.println("indicator: " + indicator); 24 | } 25 | 26 | break; 27 | } 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/java/org/openlca/proto/io/input/ActorReader.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io.input; 2 | 3 | import org.openlca.core.io.EntityResolver; 4 | import org.openlca.core.model.Actor; 5 | import org.openlca.proto.ProtoActor; 6 | 7 | public record ActorReader(EntityResolver resolver) 8 | implements EntityReader { 9 | 10 | @Override 11 | public Actor read(ProtoActor proto) { 12 | var actor = new Actor(); 13 | update(actor, proto); 14 | return actor; 15 | } 16 | 17 | @Override 18 | public void update(Actor actor, ProtoActor proto) { 19 | Util.mapBase(actor, ProtoBox.of(proto), resolver); 20 | actor.address = proto.getAddress(); 21 | actor.city = proto.getCity(); 22 | actor.country = proto.getCountry(); 23 | actor.email = proto.getEmail(); 24 | actor.telefax = proto.getTelefax(); 25 | actor.telephone = proto.getTelephone(); 26 | actor.website = proto.getWebsite(); 27 | actor.zipCode = proto.getZipCode(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/solvers/Umfpack.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.solvers; 2 | 3 | import org.openlca.core.matrix.format.CSCMatrix; 4 | import org.openlca.julia.Julia; 5 | 6 | public class Umfpack { 7 | 8 | public static double[] solve(CSCMatrix m, double[] demand) { 9 | double[] result = new double[demand.length]; 10 | Julia.umfSolve(m.rows, 11 | m.columnPointers, 12 | m.rowIndices, 13 | m.values, 14 | demand, 15 | result); 16 | return result; 17 | } 18 | 19 | public static UmfFactorizedMatrix factorize(CSCMatrix m) { 20 | long pointer = Julia.umfFactorize( 21 | m.rows, 22 | m.columnPointers, 23 | m.rowIndices, 24 | m.values); 25 | return new UmfFactorizedMatrix(pointer); 26 | } 27 | 28 | public static double[] solve(UmfFactorizedMatrix m, double[] demand) { 29 | double[] result = new double[demand.length]; 30 | Julia.umfSolveFactorized(m.pointer, demand, result); 31 | return result; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /olca-core/src/test/java/examples/LibraryCalculatorExample.java: -------------------------------------------------------------------------------- 1 | package examples; 2 | 3 | import java.io.File; 4 | 5 | import org.openlca.core.database.Derby; 6 | import org.openlca.core.math.SystemCalculator; 7 | import org.openlca.core.model.CalculationSetup; 8 | import org.openlca.core.model.ProductSystem; 9 | 10 | public class LibraryCalculatorExample { 11 | 12 | public static void main(String[] args) throws Exception { 13 | 14 | var workspace = "C:/Users/Win10/openLCA-data-1.4"; 15 | var db = new Derby(new File(workspace + "/databases/libre2")); 16 | 17 | var system = db.get(ProductSystem.class, 18 | "6b32cda2-5aa4-44b9-b32a-c654da48436d"); 19 | var setup = CalculationSetup.of(system); 20 | 21 | var result = new SystemCalculator(db).calculate(setup); 22 | 23 | var flow = result.enviIndex().at(0); 24 | System.out.println(flow.flow().name 25 | + " => " + result.getTotalFlowValueOf(flow)); 26 | result.dispose(); 27 | db.close(); 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/database/LibraryTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import static org.junit.Assert.assertFalse; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | import org.openlca.core.Tests; 8 | 9 | public class LibraryTest { 10 | 11 | @Test 12 | public void testDatabaseLibraries() { 13 | var db = Tests.getDb(); 14 | 15 | // add libraries 16 | for (int i = 1; i < 4; i++) { 17 | db.addLibrary("lib " + i); 18 | } 19 | var libs = db.getLibraries(); 20 | for (int i = 1; i < 4; i++) { 21 | assertTrue(libs.contains("lib " + i)); 22 | } 23 | 24 | // remove a library 25 | assertTrue(db.getLibraries().contains("lib 3")); 26 | db.removeLibrary("lib 3"); 27 | assertFalse(db.getLibraries().contains("lib 3")); 28 | 29 | // delete all libraries 30 | for (int i = 1; i < 4; i++) { 31 | db.removeLibrary("lib " + i); 32 | } 33 | assertTrue(db.getLibraries().isEmpty()); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/usage/ProductSystemUseSearch.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.usage; 2 | 3 | import java.util.Collections; 4 | import java.util.Set; 5 | 6 | import org.openlca.core.database.IDatabase; 7 | import org.openlca.core.model.Project; 8 | import org.openlca.core.model.Result; 9 | import org.openlca.core.model.descriptors.RootDescriptor; 10 | 11 | import gnu.trove.set.TLongSet; 12 | 13 | public record ProductSystemUseSearch(IDatabase db) implements UsageSearch { 14 | 15 | @Override 16 | public Set find(TLongSet ids) { 17 | if (ids.isEmpty()) 18 | return Collections.emptySet(); 19 | var suffix = Search.eqIn(ids); 20 | return QueryPlan.of(db) 21 | .submit(Result.class, 22 | "select id from tbl_results where f_product_system " 23 | + suffix) 24 | .submit(Project.class, 25 | "select f_project from tbl_project_variants where f_product_system " 26 | + suffix) 27 | .exec(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/database/descriptors/DescriptorReaderTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.descriptors; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | 5 | import org.junit.Test; 6 | import org.openlca.core.Tests; 7 | import org.openlca.core.database.IDatabase; 8 | import org.openlca.core.model.ModelType; 9 | import org.openlca.core.model.descriptors.Descriptor; 10 | 11 | public class DescriptorReaderTest { 12 | 13 | private final IDatabase db = Tests.getDb(); 14 | 15 | @Test 16 | public void testGetAll() throws Exception { 17 | for (var type : ModelType.values()) { 18 | var e = type.getModelClass() 19 | .getDeclaredConstructor() 20 | .newInstance(); 21 | e.name = "some"; 22 | db.insert(e); 23 | var d = Descriptor.of(e); 24 | var ds = DescriptorReader.of(db, type); 25 | assertTrue(ds.getAll().contains(d)); 26 | assertTrue(ds.getAll( 27 | r -> e.name.equals(ds.getName(r))).contains(d)); 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /olca-proto-io/src/main/java/org/openlca/proto/io/output/ActorWriter.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io.output; 2 | 3 | import org.openlca.commons.Strings; 4 | import org.openlca.core.model.Actor; 5 | import org.openlca.proto.ProtoActor; 6 | import org.openlca.proto.ProtoType; 7 | 8 | public class ActorWriter { 9 | 10 | public ProtoActor write(Actor a) { 11 | var proto = ProtoActor.newBuilder(); 12 | if (a == null) 13 | return proto.build(); 14 | proto.setType(ProtoType.Actor); 15 | Out.map(a, proto); 16 | 17 | proto.setAddress(Strings.notNull(a.address)); 18 | proto.setCity(Strings.notNull(a.city)); 19 | proto.setCountry(Strings.notNull(a.country)); 20 | proto.setEmail(Strings.notNull(a.email)); 21 | proto.setTelefax(Strings.notNull(a.telefax)); 22 | proto.setTelephone(Strings.notNull(a.telephone)); 23 | proto.setWebsite(Strings.notNull(a.website)); 24 | proto.setZipCode(Strings.notNull(a.zipCode)); 25 | return proto.build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/ecospold1/input/ImportConfig.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.ecospold1.input; 2 | 3 | import org.openlca.core.database.IDatabase; 4 | import org.openlca.core.io.maps.FlowMap; 5 | import org.openlca.io.UnitMapping; 6 | 7 | public class ImportConfig { 8 | 9 | public final IDatabase db; 10 | 11 | private FlowMap flowMap; 12 | private UnitMapping unitMapping; 13 | 14 | public ImportConfig(IDatabase db) { 15 | this.db = db; 16 | } 17 | 18 | public FlowMap getFlowMap() { 19 | if (flowMap == null) { 20 | flowMap = FlowMap.empty(); 21 | } 22 | return flowMap; 23 | } 24 | 25 | public void setFlowMap(FlowMap flowMap) { 26 | this.flowMap = flowMap; 27 | } 28 | 29 | public void setUnitMapping(UnitMapping unitMapping) { 30 | this.unitMapping = unitMapping; 31 | } 32 | 33 | public UnitMapping getUnitMapping() { 34 | if (unitMapping == null) { 35 | unitMapping = UnitMapping.createDefault(db); 36 | } 37 | return unitMapping; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/hestia/UnitMap.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.hestia; 2 | 3 | import org.openlca.core.database.IDatabase; 4 | import org.openlca.io.UnitMapping; 5 | import org.openlca.io.UnitMappingEntry; 6 | 7 | class UnitMap { 8 | 9 | private final UnitMapping units; 10 | 11 | private UnitMap(UnitMapping units) { 12 | this.units = units; 13 | } 14 | 15 | static UnitMap of(IDatabase db) { 16 | return new UnitMap(UnitMapping.createDefault(db)); 17 | } 18 | 19 | UnitMappingEntry get(String symbol) { 20 | if (symbol == null) 21 | return null; 22 | var s = symbol.strip(); 23 | var e = units.getEntry(s); 24 | if (e != null) 25 | return e; 26 | if (s.startsWith("kg ")) 27 | return units.getEntry("kg"); 28 | 29 | return switch (s) { 30 | case "kg/functional unit/Cycle" -> units.getEntry("kg"); 31 | case "number/Cycle", "number" -> units.getEntry("Item(s)"); 32 | case "% area" -> units.getEntry("are"); 33 | default -> null; 34 | }; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /olca-ipc/src/main/java/org/openlca/ipc/RpcError.java: -------------------------------------------------------------------------------- 1 | package org.openlca.ipc; 2 | 3 | import com.google.gson.JsonElement; 4 | 5 | /** 6 | * When a rpc call encounters an error, the Response Object MUST contain the 7 | * error member with a value that is an Object. 8 | * 9 | * see: ... 10 | */ 11 | public class RpcError { 12 | 13 | /** 14 | * A Number that indicates the error type that occurred. 15 | * This MUST be an integer. 16 | */ 17 | public int code; 18 | 19 | /** 20 | * A String providing a short description of the error. 21 | * The message SHOULD be limited to a concise single sentence. 22 | */ 23 | public String message; 24 | 25 | /** 26 | * A Primitive or Structured value that contains additional information 27 | * about the error. This may be omitted. 28 | * The value of this member is defined by the Server (e.g. detailed error 29 | * information, nested errors etc.). 30 | */ 31 | public JsonElement data; 32 | } 33 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/database/ParameterDaoTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import java.util.List; 4 | import java.util.UUID; 5 | 6 | import org.junit.Before; 7 | import org.openlca.core.Tests; 8 | import org.openlca.core.model.Parameter; 9 | import org.openlca.core.model.ParameterScope; 10 | import org.openlca.core.model.descriptors.ParameterDescriptor; 11 | 12 | public class ParameterDaoTest { 13 | 14 | @Before 15 | public void clearDb() { 16 | new ParameterDao(Tests.getDb()).deleteAll(); 17 | } 18 | 19 | private void insertParameter(ParameterDao dao, String name) { 20 | Parameter p = new Parameter(); 21 | p.name = name; 22 | p.refId = UUID.randomUUID().toString(); 23 | p.scope = ParameterScope.GLOBAL; 24 | dao.insert(p); 25 | } 26 | 27 | private ParameterDescriptor find(List list, String name) { 28 | for (ParameterDescriptor d: list) 29 | if (d.name.equals(name)) 30 | return d; 31 | return null; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/matrix/index/IndexFlowTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.index; 2 | 3 | import static org.junit.Assert.assertNotEquals; 4 | 5 | import java.util.List; 6 | 7 | import org.junit.Test; 8 | import org.openlca.core.model.descriptors.FlowDescriptor; 9 | import org.openlca.core.model.descriptors.LocationDescriptor; 10 | 11 | 12 | public class IndexFlowTest { 13 | 14 | @Test 15 | public void testZeroIdNonEqual() { 16 | var flows = List.of( 17 | EnviFlow.inputOf(new FlowDescriptor()), 18 | EnviFlow.inputOf(new FlowDescriptor()), 19 | EnviFlow.outputOf(new FlowDescriptor()), 20 | EnviFlow.inputOf(new FlowDescriptor(), new LocationDescriptor()), 21 | EnviFlow.inputOf(new FlowDescriptor(), new LocationDescriptor()), 22 | EnviFlow.outputOf(new FlowDescriptor(), new LocationDescriptor())); 23 | for (var a : flows) { 24 | for (var b : flows) { 25 | if (a == b) 26 | continue; 27 | assertNotEquals(a, b); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/jsonld/io/ReOpenTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.jsonld.io; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.io.File; 6 | import java.nio.file.Files; 7 | import java.nio.file.Path; 8 | 9 | import org.junit.Test; 10 | import org.openlca.jsonld.ZipStore; 11 | 12 | public class ReOpenTest { 13 | 14 | @Test 15 | public void testReOpen() throws Exception { 16 | Path p = Files.createTempFile("_olca_", ".zip"); 17 | Files.delete(p); 18 | File f = p.toFile(); 19 | ZipStore store = ZipStore.open(f); 20 | store.put("test/file.txt", "Test".getBytes()); 21 | store.close(); 22 | 23 | store = ZipStore.open(f); 24 | byte[] data = store.getBytes("test/file.txt"); 25 | assertEquals("Test", new String(data)); 26 | store.put("test/file.txt", "Next".getBytes()); 27 | store.close(); 28 | 29 | store = ZipStore.open(f); 30 | data = store.getBytes("test/file.txt"); 31 | assertEquals("Next", new String(data)); 32 | f.delete(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/xls/process/Tab.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.xls.process; 2 | 3 | /** 4 | * A tab (sheet) in a process workbook. 5 | */ 6 | enum Tab { 7 | 8 | ACTORS("Actors"), 9 | ALLOCATION("Allocation"), 10 | COMPLIANCE_DECLARATIONS("Compliance declarations"), 11 | CURRENCIES("Currencies"), 12 | DOCUMENTATION("Documentation"), 13 | FLOW_PROPERTIES("Flow properties"), 14 | FLOW_PROPERTY_FACTORS("Flow property factors"), 15 | FLOWS("Flows"), 16 | GENERAL_INFO("General information"), 17 | INPUTS("Inputs"), 18 | LOCATIONS("Locations"), 19 | OUTPUTS("Outputs"), 20 | PARAMETERS("Parameters"), 21 | PROVIDERS("Providers"), 22 | REVIEWS("Reviews"), 23 | SOURCES("Sources"), 24 | UNIT_GROUPS("Unit groups"), 25 | UNITS("Units"); 26 | 27 | private final String label; 28 | 29 | Tab(String label) { 30 | this.label = label; 31 | } 32 | 33 | public String label() { 34 | return label; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return label; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/usage/ProcessUseSearch.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.usage; 2 | 3 | import java.util.Collections; 4 | import java.util.Set; 5 | 6 | import org.openlca.core.database.IDatabase; 7 | import org.openlca.core.model.Process; 8 | import org.openlca.core.model.ProductSystem; 9 | import org.openlca.core.model.descriptors.RootDescriptor; 10 | 11 | import gnu.trove.set.TLongSet; 12 | 13 | public record ProcessUseSearch(IDatabase db) implements UsageSearch { 14 | 15 | @Override 16 | public Set find(TLongSet ids) { 17 | if (ids.isEmpty()) 18 | return Collections.emptySet(); 19 | var suffix = Search.eqIn(ids); 20 | return QueryPlan.of(db) 21 | .submit(ProductSystem.class, 22 | "select f_product_system from tbl_product_system_processes " + 23 | "where f_process " + suffix) 24 | .submit(Process.class, 25 | "select f_owner from tbl_exchanges " + 26 | "where f_default_provider " + suffix) 27 | .exec(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/database/usage/UnitGroupUseSearchTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.usage; 2 | 3 | import org.junit.After; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.openlca.core.Tests; 7 | import org.openlca.core.database.IDatabase; 8 | import org.openlca.core.model.FlowProperty; 9 | import org.openlca.core.model.UnitGroup; 10 | 11 | public class UnitGroupUseSearchTest { 12 | 13 | private final IDatabase db = Tests.getDb(); 14 | private UnitGroup group; 15 | 16 | @Before 17 | public void setup() { 18 | group = db.insert(UnitGroup.of("group", "kg")); 19 | } 20 | 21 | @After 22 | public void tearDown() { 23 | db.delete(group); 24 | } 25 | 26 | @Test 27 | public void testFindNoUsage() { 28 | UsageTests.expectEmpty(group); 29 | } 30 | 31 | @Test 32 | public void testFindInFlowProperties() { 33 | var property = db.insert(FlowProperty.of("prop", group)); 34 | UsageTests.expectOne(group, property); 35 | db.delete(property); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/xls/systems/SystemExportConfig.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.xls.systems; 2 | 3 | import org.openlca.core.database.EntityCache; 4 | import org.openlca.core.database.IDatabase; 5 | import org.openlca.core.model.AllocationMethod; 6 | import org.openlca.core.model.ProductSystem; 7 | import org.openlca.core.model.descriptors.ImpactMethodDescriptor; 8 | 9 | class SystemExportConfig { 10 | 11 | public final ProductSystem system; 12 | public final IDatabase database; 13 | public ImpactMethodDescriptor impactMethod; 14 | public AllocationMethod allocationMethod; 15 | public String olcaVersion = "1.8"; 16 | 17 | private EntityCache entityCache; 18 | 19 | public SystemExportConfig( 20 | ProductSystem system, 21 | IDatabase database) { 22 | this.system = system; 23 | this.database = database; 24 | } 25 | 26 | EntityCache getEntityCache() { 27 | if (entityCache == null) { 28 | entityCache = EntityCache.create(database); 29 | } 30 | return entityCache; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/results/EnviFlowValue.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.results; 2 | 3 | import java.util.Objects; 4 | 5 | import org.openlca.core.matrix.index.EnviFlow; 6 | import org.openlca.core.model.descriptors.FlowDescriptor; 7 | import org.openlca.core.model.descriptors.LocationDescriptor; 8 | 9 | public record EnviFlowValue(EnviFlow enviFlow, double value) { 10 | 11 | public EnviFlowValue(EnviFlow enviFlow, double value) { 12 | this.enviFlow = Objects.requireNonNull(enviFlow); 13 | this.value = value; 14 | } 15 | 16 | public static EnviFlowValue of(EnviFlow indexFlow, double value) { 17 | return new EnviFlowValue(indexFlow, value); 18 | } 19 | 20 | public boolean isInput() { 21 | return enviFlow.isInput(); 22 | } 23 | 24 | public FlowDescriptor flow() { 25 | return enviFlow.flow(); 26 | } 27 | 28 | public LocationDescriptor location() { 29 | return enviFlow.location(); 30 | } 31 | 32 | public boolean hasLocation() { 33 | return enviFlow.location() != null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /olca-core/src/test/java/examples/LibraryExportExample.java: -------------------------------------------------------------------------------- 1 | package examples; 2 | 3 | import java.io.File; 4 | 5 | import org.openlca.core.DataDir; 6 | import org.openlca.core.database.upgrades.Upgrades; 7 | import org.openlca.core.library.export.LibraryExport; 8 | import org.openlca.core.model.AllocationMethod; 9 | import org.openlca.nativelib.NativeLib; 10 | 11 | public class LibraryExportExample { 12 | 13 | public static void main(String[] args) throws Exception { 14 | NativeLib.loadFrom(DataDir.get().root()); 15 | try (var db = DataDir.get().openDatabase("ei22")) { 16 | Upgrades.on(db); 17 | System.out.println("Start export"); 18 | long start = System.currentTimeMillis(); 19 | new LibraryExport(db, new File("target/data/lib")) 20 | .withUncertainties(true) 21 | .withAllocation(AllocationMethod.PHYSICAL) 22 | .run(); 23 | double time = (System.currentTimeMillis() - start) / 1000d; 24 | System.out.println( 25 | "Done, it took " + String.format("%.0f seconds", time)); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/openepd/io/MappingModel.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.openepd.io; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.openlca.core.database.IDatabase; 7 | import org.openlca.core.model.Epd; 8 | import org.openlca.io.openepd.EpdDoc; 9 | 10 | public record MappingModel(List mappings) { 11 | 12 | public static MappingModel empty() { 13 | return new MappingModel(new ArrayList<>(0)); 14 | } 15 | 16 | public static MappingModel initFrom(Epd epd) { 17 | return ExportMapping.build(epd); 18 | } 19 | 20 | public static MappingModel initFrom(EpdDoc doc, IDatabase db) { 21 | return ImportMapping.build(doc, db); 22 | } 23 | 24 | public boolean hasEmptyMappings() { 25 | for (var m : mappings) { 26 | if (m.method() == null || m.epdMethod() == null) 27 | return true; 28 | for (var e : m.entries()) { 29 | if (e.indicator() == null || e.epdIndicator() == null) 30 | return true; 31 | } 32 | } 33 | return false; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/ProviderType.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | /// The provider type in process links. 4 | public interface ProviderType { 5 | 6 | /// PROCESS is always the default provider type if not specified. 7 | byte PROCESS = 0; 8 | byte SUB_SYSTEM = 1; 9 | byte RESULT = 2; 10 | 11 | static byte of(ModelType type) { 12 | if (type == null) 13 | return PROCESS; 14 | return switch (type) { 15 | case PRODUCT_SYSTEM -> SUB_SYSTEM; 16 | case RESULT -> RESULT; 17 | default -> PROCESS; 18 | }; 19 | } 20 | 21 | static ModelType toModelType(byte type) { 22 | return switch (type) { 23 | case SUB_SYSTEM -> ModelType.PRODUCT_SYSTEM; 24 | case RESULT -> ModelType.RESULT; 25 | default -> ModelType.PROCESS; 26 | }; 27 | } 28 | 29 | static Class toModelClass(byte type) { 30 | return switch (type) { 31 | case SUB_SYSTEM -> ProductSystem.class; 32 | case RESULT -> Result.class; 33 | default -> Process.class; 34 | }; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/indicators/ep.mdy: -------------------------------------------------------------------------------- 1 | let .ws = { 2 | any of ; 3 | } 4 | 5 | let .opt_parens_open = { 6 | .ws; 7 | option of "("; 8 | .ws; 9 | } 10 | 11 | let .opt_parens_close = { 12 | .ws; 13 | option of ")"; 14 | .ws; 15 | } 16 | 17 | let .potential = { 18 | .ws; 19 | option of either { 20 | "potential"; 21 | "pot."; 22 | } 23 | .ws; 24 | } 25 | 26 | let .marine = { 27 | .ws; 28 | option of either { 29 | ","; 30 | "-"; 31 | } 32 | .ws; 33 | option of "marine"; 34 | .ws; 35 | } 36 | 37 | let .ep = { 38 | .opt_parens_open; 39 | "ep"; 40 | .marine; 41 | .opt_parens_close; 42 | } 43 | 44 | let .suffix = { 45 | .potential; 46 | .marine; 47 | .opt_parens_open; 48 | option of "ep"; 49 | .opt_parens_close; 50 | } 51 | 52 | let .eutrophication = { 53 | .ws; 54 | option of "aquatic"; 55 | .ws; 56 | option of "marine"; 57 | .ws; 58 | "eutrophication"; 59 | .suffix; 60 | } 61 | 62 | either { 63 | .ep; 64 | .eutrophication; 65 | } 66 | -------------------------------------------------------------------------------- /olca-io/src/test/java/examples/HestiaEcoinventFlowMapExample.java: -------------------------------------------------------------------------------- 1 | package examples; 2 | 3 | import java.io.File; 4 | 5 | import org.openlca.core.DataDir; 6 | import org.openlca.core.io.maps.FlowMap; 7 | import org.openlca.io.hestia.EcoinventFlowMap; 8 | import org.openlca.io.hestia.HestiaClient; 9 | import org.openlca.jsonld.Json; 10 | 11 | public class HestiaEcoinventFlowMapExample { 12 | 13 | public static void main(String[] args) { 14 | var dataDir = DataDir.get(); 15 | var apiKey = Json.readObject(new File(dataDir.root(), ".hestia.json")) 16 | .orElseThrow() 17 | .get("apiKey") 18 | .getAsString(); 19 | 20 | var dbName = "ecoinvent 3.11 Cutoff Unit-Processes 2025-01-31"; 21 | try (var db = dataDir.openDatabase(dbName); 22 | var client = HestiaClient.of(apiKey)) { 23 | var dir = new File("target/hestia-glossary"); 24 | var flowMap = EcoinventFlowMap 25 | .buildFrom(db, client, dir) 26 | .orElseThrow(); 27 | FlowMap.toCsv(flowMap, new File("target/HESTIA_EI.csv")); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/usage/CurrencyUseSearch.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.usage; 2 | 3 | import java.util.Collections; 4 | import java.util.Set; 5 | 6 | import org.openlca.core.database.IDatabase; 7 | import org.openlca.core.model.Currency; 8 | import org.openlca.core.model.Process; 9 | import org.openlca.core.model.descriptors.RootDescriptor; 10 | 11 | import gnu.trove.set.TLongSet; 12 | 13 | /** 14 | * Searches for the use of currencies in other entities. 15 | */ 16 | public record CurrencyUseSearch(IDatabase db) implements UsageSearch { 17 | 18 | @Override 19 | public Set find(TLongSet ids) { 20 | if (ids.isEmpty()) 21 | return Collections.emptySet(); 22 | var suffix = Search.eqIn(ids); 23 | return QueryPlan.of(db) 24 | .submit(Process.class, 25 | "select f_owner from tbl_exchanges where f_currency " + suffix) 26 | .submit(Currency.class, 27 | "select id from tbl_currencies where f_reference_currency " + suffix) 28 | .exec(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/usage/ImpactCategoryUseSearch.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.usage; 2 | 3 | import java.util.Collections; 4 | import java.util.Set; 5 | 6 | import org.openlca.core.database.IDatabase; 7 | import org.openlca.core.model.ImpactMethod; 8 | import org.openlca.core.model.Result; 9 | import org.openlca.core.model.descriptors.RootDescriptor; 10 | 11 | import gnu.trove.set.TLongSet; 12 | 13 | public record ImpactCategoryUseSearch(IDatabase db) implements UsageSearch { 14 | 15 | @Override 16 | public Set find(TLongSet ids) { 17 | if (ids.isEmpty()) 18 | return Collections.emptySet(); 19 | var suffix = Search.eqIn(ids); 20 | return QueryPlan.of(db) 21 | .submit(ImpactMethod.class, 22 | "select f_impact_method from tbl_impact_links " + 23 | "where f_impact_category " + suffix) 24 | .submit(Result.class, 25 | "select f_result from tbl_impact_results " + 26 | "where f_impact_category " + suffix) 27 | .exec(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/linking/ProviderLinking.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.linking; 2 | 3 | /** 4 | * Indicates how default providers of product inputs or waste outputs in 5 | * processes should be considered in the linking of a product system. 6 | */ 7 | public enum ProviderLinking { 8 | 9 | /** 10 | * Default provider settings are ignored in the linking process. This 11 | * means that the linker can also select another provider even when a 12 | * default provider is set. 13 | */ 14 | IGNORE_DEFAULTS, 15 | 16 | /** 17 | * When a default provider is set for a product input or waste output 18 | * the linker will always select this process. For other exchanges it 19 | * will select the provider according to its other rules. 20 | */ 21 | PREFER_DEFAULTS, 22 | 23 | /** 24 | * Means that links should be created only for product inputs or waste 25 | * outputs where a default provider is defined which are then linked 26 | * exactly to this provider. 27 | */ 28 | ONLY_DEFAULTS 29 | 30 | } -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/jsonld/output/UnitGroupWriter.java: -------------------------------------------------------------------------------- 1 | package org.openlca.jsonld.output; 2 | 3 | import java.util.Objects; 4 | 5 | import org.openlca.core.model.UnitGroup; 6 | import org.openlca.jsonld.Json; 7 | 8 | import com.google.gson.JsonArray; 9 | import com.google.gson.JsonObject; 10 | 11 | public record UnitGroupWriter(JsonExport exp) implements JsonWriter { 12 | 13 | @Override 14 | public JsonObject write(UnitGroup ug) { 15 | var obj = Util.init(exp, ug); 16 | Json.put(obj, "defaultFlowProperty", exp.handleRef(ug.defaultFlowProperty)); 17 | mapUnits(ug, obj); 18 | return obj; 19 | } 20 | 21 | private void mapUnits(UnitGroup group, JsonObject json) { 22 | var units = new JsonArray(); 23 | for (var unit : group.units) { 24 | var obj = new JsonObject(); 25 | UnitWriter.map(unit, obj); 26 | if (Objects.equals(unit, group.referenceUnit)) { 27 | Json.put(obj, "isRefUnit", true); 28 | } 29 | units.add(obj); 30 | } 31 | Json.put(json, "units", units); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/smartepd/SmartMethod.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.smartepd; 2 | 3 | import java.util.Optional; 4 | 5 | public enum SmartMethod { 6 | 7 | IPCC_AR5_GWP100("IPCC AR5 GWP 100"), 8 | 9 | IPCC_AR5_GWP50("IPCC AR5 GWP 50"), 10 | 11 | IPCC_AR5_GWP20("IPCC AR5 GWP 20"), 12 | 13 | IPCC_AR6_GWP100("IPCC AR6 GWP 100"), 14 | 15 | TRACI_2_1("TRACI 2.1"), 16 | 17 | AWARE("AWARE"), 18 | 19 | RECIPE_2016("ReCiPe 2016 v1.1"), 20 | 21 | CML_2016("CML 2016 v4.8"), 22 | 23 | EF_3_0("EF3.0"), 24 | 25 | EF_3_1("EF3.1"), 26 | 27 | UNKNOWN("Unknown LCIA"); 28 | 29 | private final String id; 30 | 31 | SmartMethod(String id) { 32 | this.id = id; 33 | } 34 | 35 | public String id() { 36 | return id; 37 | } 38 | 39 | public static Optional of(String id) { 40 | for (var m : values()) { 41 | if (m.id.equalsIgnoreCase(id)) 42 | return Optional.of(m); 43 | } 44 | return Optional.empty(); 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return id; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/ecospold1/input/FlowTypes.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.ecospold1.input; 2 | 3 | import org.openlca.core.model.FlowType; 4 | 5 | class FlowTypes { 6 | 7 | private FlowTypes() { 8 | } 9 | 10 | public static FlowType forInputGroup(int inputGroup) { 11 | switch (inputGroup) { 12 | case 1: 13 | return FlowType.PRODUCT_FLOW; 14 | case 2: 15 | return FlowType.PRODUCT_FLOW; 16 | case 3: 17 | return FlowType.PRODUCT_FLOW; 18 | case 4: 19 | return FlowType.ELEMENTARY_FLOW; 20 | case 5: 21 | return FlowType.PRODUCT_FLOW; 22 | default: 23 | return null; 24 | } 25 | } 26 | 27 | public static FlowType forOutputGroup(int outputGroup) { 28 | switch (outputGroup) { 29 | case 0: 30 | return FlowType.PRODUCT_FLOW; 31 | case 1: 32 | return FlowType.PRODUCT_FLOW; 33 | case 2: 34 | return FlowType.PRODUCT_FLOW; 35 | case 3: 36 | return FlowType.WASTE_FLOW; 37 | case 4: 38 | return FlowType.ELEMENTARY_FLOW; 39 | default: 40 | return null; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/services/JsonRefTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.services; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import java.util.UUID; 7 | 8 | import org.junit.Test; 9 | import org.openlca.core.model.ModelType; 10 | 11 | import com.google.gson.JsonObject; 12 | 13 | public class JsonRefTest { 14 | 15 | @Test 16 | public void testDescriptorTypes() { 17 | for (var type : ModelType.values()) { 18 | var id = UUID.randomUUID().toString(); 19 | var name = id + "_name"; 20 | var json = new JsonObject(); 21 | json.addProperty("@id", id); 22 | json.addProperty("name", name); 23 | json.addProperty("@type", type.getModelClass().getSimpleName()); 24 | 25 | assertEquals(id, JsonRef.idOf(json)); 26 | assertEquals(type, JsonRef.typeOf(json)); 27 | var d = JsonRef.descriptorOf(json); 28 | assertNotNull(d); 29 | assertEquals(type, d.type); 30 | assertEquals(id, d.refId); 31 | assertEquals(name, d.name); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /olca-io/src/main/melody/openepd/indicators/odp.mdy: -------------------------------------------------------------------------------- 1 | let .ws = { 2 | any of ; 3 | } 4 | 5 | let .opt_parens_open = { 6 | .ws; 7 | option of "("; 8 | .ws; 9 | } 10 | 11 | let .opt_parens_close = { 12 | .ws; 13 | option of ")"; 14 | .ws; 15 | } 16 | 17 | let .potential = { 18 | .ws; 19 | option of either { 20 | "potential"; 21 | "pot."; 22 | } 23 | .ws; 24 | } 25 | 26 | let .opt_total = { 27 | .ws; 28 | option of either { 29 | ","; 30 | "-"; 31 | } 32 | .ws; 33 | option of "total"; 34 | .ws; 35 | } 36 | 37 | let .odp = { 38 | .opt_parens_open; 39 | "odp"; 40 | .opt_total; 41 | .opt_parens_close; 42 | } 43 | 44 | let .suffix = { 45 | .potential; 46 | .opt_parens_open; 47 | option of "odp"; 48 | .opt_total; 49 | .opt_parens_close; 50 | } 51 | 52 | let .full_name = { 53 | .ws; 54 | option of "stratospheric"; 55 | .ws; 56 | "ozone"; 57 | .ws; 58 | option of "layer"; 59 | .ws; 60 | "depletion"; 61 | .suffix; 62 | } 63 | 64 | either { 65 | .odp; 66 | .full_name; 67 | } 68 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/matrix/uncertainties/UCell.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.matrix.uncertainties; 2 | 3 | import org.openlca.commons.Copyable; 4 | import org.openlca.core.model.UncertaintyType; 5 | import org.openlca.expressions.FormulaInterpreter; 6 | 7 | /** 8 | * Describes a matrix cell with a value that is possibly generated from one or 9 | * more uncertainty distributions. 10 | */ 11 | public interface UCell extends Copyable { 12 | 13 | /** 14 | * Generates the next value of the underlying distribution of this matrix cell. 15 | * If formulas are linked to this cell the injected interpreter should be used 16 | * to evaluate them as possibly values of dependent parameters with uncertainty 17 | * distributions may changed. 18 | */ 19 | double next(FormulaInterpreter interpreter); 20 | 21 | /** 22 | * Get the uncertainty distribution type of the cell; 23 | */ 24 | UncertaintyType type(); 25 | 26 | /** 27 | * Get the parameter values of the uncertainty distribution of this cell. 28 | */ 29 | double[] values(); 30 | } 31 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/model/Source.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.model; 2 | 3 | import jakarta.persistence.Column; 4 | import jakarta.persistence.Entity; 5 | import jakarta.persistence.Lob; 6 | import jakarta.persistence.Table; 7 | 8 | @Entity 9 | @Table(name = "tbl_sources") 10 | public class Source extends RootEntity { 11 | 12 | @Column(name = "url") 13 | public String url; 14 | 15 | @Lob 16 | @Column(name = "text_reference") 17 | public String textReference; 18 | 19 | @Column(name = "source_year") 20 | public Short year; 21 | 22 | @Column(name = "external_file") 23 | public String externalFile; 24 | 25 | public static Source of(String name) { 26 | var source = new Source(); 27 | Entities.init(source, name); 28 | return source; 29 | } 30 | 31 | @Override 32 | public Source copy() { 33 | var clone = new Source(); 34 | Entities.copyFields(this, clone); 35 | clone.url = url; 36 | clone.textReference = textReference; 37 | clone.year = year; 38 | clone.externalFile = externalFile; 39 | return clone; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /olca-core/src/test/java/examples/EachOneResultExample.java: -------------------------------------------------------------------------------- 1 | package examples; 2 | 3 | import org.openlca.core.DataDir; 4 | import org.openlca.core.database.IDatabase; 5 | import org.openlca.core.database.upgrades.Upgrades; 6 | import org.openlca.core.results.EachOneResult; 7 | 8 | public class EachOneResultExample { 9 | 10 | public static void main(String[] args) { 11 | try (var db = DataDir.get().openDatabase("ei22")) { 12 | if (db.getVersion() < IDatabase.CURRENT_VERSION) { 13 | Upgrades.on(db); 14 | } 15 | int i = 0; 16 | for (var pair : EachOneResult.of(db).get()) { 17 | var product = pair.first(); 18 | var result = pair.second(); 19 | System.out.printf("Calculated result for %s%n%n", product.provider().refId); 20 | result.impactIndex().each((_i, impact) -> { 21 | var r = result.getTotalImpactValueOf(impact); 22 | System.out.printf("%s;%.5f;%s%n", 23 | impact.name, r, impact.referenceUnit); 24 | }); 25 | result.dispose(); 26 | i++; 27 | if (i > 3) 28 | break; 29 | } 30 | 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /olca-core/src/test/java/examples/GeoFactorExample.java: -------------------------------------------------------------------------------- 1 | package examples; 2 | 3 | import java.io.File; 4 | import java.util.List; 5 | 6 | import org.openlca.core.DataDir; 7 | import org.openlca.core.model.Location; 8 | import org.openlca.geo.lcia.GeoFactorCalculator; 9 | import org.openlca.geo.lcia.GeoFactorSetup; 10 | 11 | public class GeoFactorExample { 12 | 13 | public static void main(String[] args) { 14 | 15 | try (var db = DataDir.get().openDatabase("lc-impact-tests")) { 16 | var setupFile = new File("/home/ms/Desktop/lc-impact-pocp-setup_fixed.json"); 17 | var setup = GeoFactorSetup.read(setupFile, db); 18 | var afg = db.get(Location.class, "f0357a3f-154b-32ff-a2bf-f55055457068"); 19 | var factors = GeoFactorCalculator.of(db, setup, List.of(afg)).calculate(); 20 | for (var factor : factors) { 21 | var loc = factor.location != null 22 | ? factor.location.code 23 | : "GLO"; 24 | System.out.printf("%s - %s : %.4e%n", 25 | factor.flow.name, 26 | loc, 27 | factor.value 28 | ); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/openepd/Ec3Certifier.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.openepd; 2 | 3 | import java.util.Optional; 4 | 5 | import org.openlca.jsonld.Json; 6 | 7 | import com.google.gson.JsonElement; 8 | import com.google.gson.JsonObject; 9 | 10 | public class Ec3Certifier implements Jsonable { 11 | 12 | public String name; 13 | public String email; 14 | public EpdOrg org; 15 | 16 | public static Optional fromJson(JsonElement elem) { 17 | if (elem == null || !elem.isJsonObject()) 18 | return Optional.empty(); 19 | var obj = elem.getAsJsonObject(); 20 | var certifier = new Ec3Certifier(); 21 | certifier.name = Json.getString(obj, "name"); 22 | certifier.email = Json.getString(obj, "email"); 23 | certifier.org = EpdOrg.fromJson(obj.get("org")).orElse(null); 24 | return Optional.of(certifier); 25 | } 26 | 27 | @Override 28 | public JsonObject toJson() { 29 | var obj = new JsonObject(); 30 | Json.put(obj, "name", name); 31 | Json.put(obj, "email", email); 32 | Util.put(obj,"org", org); 33 | return obj; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/upgrades/Upgrade09.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.upgrades; 2 | 3 | import org.openlca.core.database.IDatabase; 4 | 5 | class Upgrade09 implements IUpgrade { 6 | 7 | @Override 8 | public int[] getInitialVersions() { 9 | return new int[] { 8 }; 10 | } 11 | 12 | @Override 13 | public int getEndVersion() { 14 | return 9; 15 | } 16 | 17 | @Override 18 | public void exec(IDatabase db) { 19 | var u = new DbUtil(db); 20 | // add tags and library fields 21 | String[] tables = { 22 | "tbl_actors", 23 | "tbl_categories", 24 | "tbl_currencies", 25 | "tbl_dq_systems", 26 | "tbl_flows", 27 | "tbl_flow_properties", 28 | "tbl_impact_categories", 29 | "tbl_impact_methods", 30 | "tbl_locations", 31 | "tbl_parameters", 32 | "tbl_processes", 33 | "tbl_product_systems", 34 | "tbl_projects", 35 | "tbl_social_indicators", 36 | "tbl_sources", 37 | "tbl_unit_groups" 38 | }; 39 | for (String table : tables) { 40 | u.createColumn(table, "tags VARCHAR(255)"); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/database/upgrades/Upgrade13.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database.upgrades; 2 | 3 | import org.openlca.core.database.IDatabase; 4 | 5 | class Upgrade13 implements IUpgrade { 6 | 7 | @Override 8 | public int[] getInitialVersions() { 9 | return new int[]{12}; 10 | } 11 | 12 | @Override 13 | public int getEndVersion() { 14 | return 13; 15 | } 16 | 17 | @Override 18 | public void exec(IDatabase db) { 19 | var u = new DbUtil(db); 20 | u.createColumn("tbl_epds", "epd_type VARCHAR(255)"); 21 | u.createColumn("tbl_epds", "valid_from DATE"); 22 | u.createColumn("tbl_epds", "valid_until DATE"); 23 | u.createColumn("tbl_epds", "f_location BIGINT"); 24 | u.createColumn("tbl_epds", "f_original_epd BIGINT"); 25 | u.createColumn("tbl_epds", "manufacturing CLOB(64 K)"); 26 | u.createColumn("tbl_epds", "product_usage CLOB(64 K)"); 27 | u.createColumn("tbl_epds", "use_advice CLOB(64 K)"); 28 | u.createColumn("tbl_epds", "registration_id VARCHAR(2048)"); 29 | u.createColumn("tbl_epds", "f_data_generator BIGINT"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/database/SafeEnumTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNull; 5 | 6 | import org.junit.Test; 7 | import org.openlca.core.Tests; 8 | import org.openlca.core.model.Flow; 9 | import org.openlca.core.model.FlowType; 10 | 11 | public class SafeEnumTest { 12 | 13 | private final IDatabase db = Tests.getDb(); 14 | 15 | @Test 16 | public void testFlowType() { 17 | var flow = db.insert(Flow.product("Some flow", null)); 18 | var d = new FlowDao(db).getDescriptor(flow.id); 19 | assertEquals(FlowType.PRODUCT_FLOW, d.flowType); 20 | NativeSql.on(db).runUpdate("update tbl_flows set " + 21 | "flow_type = 'something else' where id = " + flow.id); 22 | d = new FlowDao(db).getDescriptor(flow.id); 23 | assertNull(d.flowType); 24 | // var flow = db.get(Flow.class, flowId); // this would fail 25 | NativeSql.on(db).runUpdate("update tbl_flows set " + 26 | "flow_type = null where id = " + flow.id); 27 | db.delete(flow); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /olca-git/src/main/java/org/openlca/git/util/ProgressMonitor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.git.util; 2 | 3 | import org.openlca.core.model.ModelType; 4 | import org.openlca.git.model.ModelRef; 5 | 6 | public interface ProgressMonitor { 7 | 8 | static ProgressMonitor NULL = new ProgressMonitor() { 9 | }; 10 | 11 | default void beginTask(String name) { 12 | beginTask(name, -1); 13 | } 14 | 15 | default void beginTask(String name, int totalWork) { 16 | } 17 | 18 | default void subTask(String name) { 19 | } 20 | 21 | default void subTask(ModelRef ref) { 22 | var type = ref.isCategory 23 | ? "Category" 24 | : getLabel(ref.type); 25 | var path = ref.path.substring(ref.path.indexOf("/") + 1); 26 | subTask(type + " " + path); 27 | } 28 | 29 | default void worked(int work) { 30 | } 31 | 32 | default boolean isCanceled() { 33 | return false; 34 | } 35 | 36 | private static String getLabel(ModelType type) { 37 | if (type == null) 38 | return ""; 39 | return type.name().charAt(0) + type.name().substring(1).toLowerCase().replace("_", " "); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /olca-io/src/test/java/org/openlca/io/xls/process/Example.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.xls.process; 2 | 3 | import java.io.File; 4 | import java.util.concurrent.ThreadLocalRandom; 5 | 6 | import org.openlca.core.DataDir; 7 | import org.openlca.core.database.ProcessDao; 8 | 9 | public class Example { 10 | 11 | public static void main(String[] args) { 12 | // this example exports a random process from a database to an 13 | // Excel file and then imports the process from that file 14 | // into an empty database. 15 | var file = new File("target/example.xlsx"); 16 | try (var db = DataDir.get().openDatabase("ei39_cutoff")) { 17 | var ps = new ProcessDao(db).getDescriptors(); 18 | var rand = ThreadLocalRandom.current(); 19 | var i = rand.nextInt(ps.size()); 20 | XlsProcessWriter.of(db) 21 | .write(ps.get(i), file); 22 | } 23 | 24 | try (var db = DataDir.get().openDatabase("empty")) { 25 | var process = XlsProcessReader.of(db) 26 | .sync(file) 27 | .orElseThrow(); 28 | System.out.println("transferred process: " + process.name); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /olca-core/src/test/java/org/openlca/core/database/ProjectVariantIOTest.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.database; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | import org.openlca.core.Tests; 6 | import org.openlca.core.model.Project; 7 | import org.openlca.core.model.ProjectVariant; 8 | import org.openlca.core.model.UnitGroup; 9 | 10 | public class ProjectVariantIOTest { 11 | 12 | private final IDatabase db = Tests.getDb(); 13 | 14 | @Test 15 | public void testInsertDelete() { 16 | var project = Project.of("project"); 17 | var variant = new ProjectVariant(); 18 | variant.name = "A project variant"; 19 | project.variants.add(variant); 20 | db.insert(project); 21 | Assert.assertTrue(variant.id > 0L); 22 | 23 | var units = db.insert(UnitGroup.of("Mass units", "kg")); 24 | variant.unit = units.referenceUnit; 25 | db.update(project); 26 | 27 | db.clearCache(); 28 | var clone = db.get(Project.class, project.id); 29 | Assert.assertEquals( 30 | units.referenceUnit, 31 | clone.variants.get(0).unit); 32 | 33 | db.delete(project, units); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/maps/MapFactor.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.maps; 2 | 3 | /** 4 | * Describes a conversion factor when mapping to a given entity type. For example 5 | * if there is a flow from a format A that is mapped to a format B a 6 | * {@code MapFactor} could describe the factor for conversion of amounts for the 7 | * flow in format A to the flow amounts in B. 8 | * 9 | * @param the entity type 10 | */ 11 | public class MapFactor { 12 | 13 | private final T entity; 14 | private final double factor; 15 | 16 | public MapFactor(T entity, double factor) { 17 | this.entity = entity; 18 | this.factor = factor; 19 | } 20 | 21 | public T getEntity() { 22 | return entity; 23 | } 24 | 25 | public double getFactor() { 26 | return factor; 27 | } 28 | 29 | /** 30 | * Applies this factor to the given value. In the entity mappings conversion 31 | * factors should be always applied by multiplication which is what this 32 | * method does. 33 | */ 34 | public double apply(double value) { 35 | return factor * value; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /olca-proto-io/src/test/java/org/openlca/proto/io/examples/ProvidersExample.java: -------------------------------------------------------------------------------- 1 | package org.openlca.proto.io.examples; 2 | 3 | import org.openlca.proto.grpc.DataFetchServiceGrpc; 4 | 5 | import com.google.protobuf.Empty; 6 | 7 | import io.grpc.ManagedChannelBuilder; 8 | 9 | public class ProvidersExample { 10 | 11 | public static void main(String[] args) { 12 | var channel = ManagedChannelBuilder.forAddress("localhost", 8080) 13 | .usePlaintext() 14 | .build(); 15 | var fetch = DataFetchServiceGrpc.newBlockingStub(channel); 16 | 17 | var techFlows = fetch.getTechFlows(Empty.newBuilder().build()); 18 | var productCount = 0; 19 | var wasteCount = 0; 20 | while (techFlows.hasNext()) { 21 | var next = techFlows.next(); 22 | if (next.hasProduct()) { 23 | productCount++; 24 | } else if (next.hasWaste()) { 25 | wasteCount++; 26 | } 27 | } 28 | 29 | System.out.printf("found %d provider flows with %d " + 30 | "product flows and %d waste flows%n", 31 | productCount + wasteCount, productCount, wasteCount); 32 | channel.shutdownNow(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/openepd/Util.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.openepd; 2 | 3 | import java.time.LocalDate; 4 | 5 | import org.openlca.jsonld.Json; 6 | 7 | import com.google.gson.JsonObject; 8 | 9 | class Util { 10 | 11 | static LocalDate getDate(JsonObject obj, String field) { 12 | var s = Json.getString(obj, field); 13 | if (s == null) 14 | return null; 15 | try { 16 | return LocalDate.parse(s); 17 | } catch (Exception e) { 18 | return null; 19 | } 20 | } 21 | 22 | static void put(JsonObject obj, String field, LocalDate date) { 23 | if (obj == null || field == null || date == null) 24 | return; 25 | Json.put(obj, field, date + "T00:00"); 26 | } 27 | 28 | static void put(JsonObject obj, String field, Jsonable v) { 29 | if (obj == null || field == null || v == null) 30 | return; 31 | Json.put(obj, field, v.toJson()); 32 | } 33 | 34 | static EpdQuantity getQuantity(JsonObject obj, String field) { 35 | if (obj == null || field == null) 36 | return null; 37 | return EpdQuantity.fromJson(obj.get(field)) 38 | .orElse(null); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /olca-io/src/main/java/org/openlca/io/xls/process/Styles.java: -------------------------------------------------------------------------------- 1 | package org.openlca.io.xls.process; 2 | 3 | import org.apache.poi.ss.usermodel.CellStyle; 4 | import org.apache.poi.ss.usermodel.HorizontalAlignment; 5 | import org.apache.poi.ss.usermodel.VerticalAlignment; 6 | import org.apache.poi.ss.usermodel.Workbook; 7 | 8 | record Styles( 9 | CellStyle bold, 10 | CellStyle date, 11 | CellStyle pairLabel, 12 | CellStyle pairValue 13 | ) { 14 | 15 | static Styles of(Workbook wb) { 16 | var boldFont = wb.createFont(); 17 | boldFont.setBold(true); 18 | var bold = wb.createCellStyle(); 19 | bold.setFont(boldFont); 20 | 21 | var date = wb.createCellStyle(); 22 | var dateFmt = wb.createDataFormat(); 23 | date.setDataFormat(dateFmt.getFormat("mm/dd/yyyy hh:mm")); 24 | date.setAlignment(HorizontalAlignment.LEFT); 25 | 26 | var pairLabel = wb.createCellStyle(); 27 | pairLabel.setVerticalAlignment(VerticalAlignment.TOP); 28 | var pairValue = wb.createCellStyle(); 29 | pairValue.setWrapText(true); 30 | 31 | return new Styles(bold, date, pairLabel, pairValue); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /olca-core/src/main/java/org/openlca/core/services/Response.java: -------------------------------------------------------------------------------- 1 | package org.openlca.core.services; 2 | 3 | import java.util.function.Function; 4 | 5 | public record Response(T value, String error) { 6 | 7 | public static Response empty() { 8 | return new Response<>(null, null); 9 | } 10 | 11 | public static Response of(T value) { 12 | return new Response<>(value, null); 13 | } 14 | 15 | public static Response error(String err) { 16 | return new Response<>(null, err); 17 | } 18 | 19 | public static Response error(Exception e) { 20 | return new Response<>(null, e.getMessage()); 21 | } 22 | 23 | public boolean isValue() { 24 | return value != null; 25 | } 26 | 27 | public boolean isEmpty() { 28 | return value == null && error == null; 29 | } 30 | 31 | public boolean isError() { 32 | return error != null; 33 | } 34 | 35 | public Response map(Function fn) { 36 | if (isEmpty()) 37 | return Response.empty(); 38 | if (isError()) 39 | return Response.error(error); 40 | return Response.of(fn.apply(value)); 41 | } 42 | 43 | } 44 | --------------------------------------------------------------------------------