diff --git a/src/main/java/com/activeviam/apps/cfg/ApplicationManagerService.java b/src/main/java/com/activeviam/apps/cfg/ApplicationManagerService.java deleted file mode 100644 index 24c5e1a1..00000000 --- a/src/main/java/com/activeviam/apps/cfg/ApplicationManagerService.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) ActiveViam 2024 - * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY - * property of ActiveViam Limited. Any unauthorized use, - * reproduction or transfer of this material is strictly prohibited - */ -package com.activeviam.apps.cfg; - -import org.springframework.boot.context.event.ApplicationStartedEvent; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Component; - -import com.activeviam.activepivot.core.intf.api.cube.IActivePivotManager; -import com.activeviam.tech.core.api.agent.AgentException; - -import lombok.RequiredArgsConstructor; - -/** - * Spring configuration of the ActivePivot Application services - * - * @author ActiveViam - */ -@Component -@RequiredArgsConstructor -public class ApplicationManagerService { - private final IActivePivotManager activePivotManager; - - /** - * Initialize and start the ActivePivot Manager, after performing all the injections into the ActivePivot plug-ins. - * - * @throws AgentException any exception that occurred during the injection, the initialization or the starting - */ - @EventListener(ApplicationStartedEvent.class) - public void startManager() throws AgentException { - /* *********************************************** */ - /* Initialize the ActivePivot Manager and start it */ - /* *********************************************** */ - activePivotManager.init(null); - activePivotManager.start(); - } -} diff --git a/src/main/java/com/activeviam/apps/cfg/datastore/DatastoreConfig.java b/src/main/java/com/activeviam/apps/cfg/datastore/DatastoreConfig.java index 366e55b3..f310fed6 100644 --- a/src/main/java/com/activeviam/apps/cfg/datastore/DatastoreConfig.java +++ b/src/main/java/com/activeviam/apps/cfg/datastore/DatastoreConfig.java @@ -1,28 +1,19 @@ /* - * Copyright (C) ActiveViam 2024 + * Copyright (C) ActiveViam 2024-2025 * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY * property of ActiveViam Limited. Any unauthorized use, * reproduction or transfer of this material is strictly prohibited */ package com.activeviam.apps.cfg.datastore; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; -import com.activeviam.activepivot.core.datastore.api.builder.ApplicationWithDatastore; -import com.activeviam.activepivot.server.spring.api.config.IDatastoreConfig; -import com.activeviam.database.datastore.api.IDatastore; +import com.activeviam.apps.cfg.datastore.datamodel.StoreDefinitionsConfig; import lombok.RequiredArgsConstructor; @Configuration +@Import({StoreDefinitionsConfig.class, DatastoreSchemaConfig.class, DatastoreSelectionConfig.class}) @RequiredArgsConstructor -public class DatastoreConfig implements IDatastoreConfig { - private final ApplicationWithDatastore applicationWithDatastore; - - @Bean - @Override - public IDatastore database() { - return applicationWithDatastore.getDatastore(); - } -} +public class DatastoreConfig {} diff --git a/src/main/java/com/activeviam/apps/cfg/datastore/DatastoreSchemaConfig.java b/src/main/java/com/activeviam/apps/cfg/datastore/DatastoreSchemaConfig.java index e2378558..8a9c79d2 100644 --- a/src/main/java/com/activeviam/apps/cfg/datastore/DatastoreSchemaConfig.java +++ b/src/main/java/com/activeviam/apps/cfg/datastore/DatastoreSchemaConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (C) ActiveViam 2024 + * Copyright (C) ActiveViam 2024-2025 * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY * property of ActiveViam Limited. Any unauthorized use, * reproduction or transfer of this material is strictly prohibited @@ -9,7 +9,6 @@ import java.util.List; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import com.activeviam.activepivot.server.spring.api.config.IDatastoreSchemaDescriptionConfig; import com.activeviam.database.datastore.api.description.IDatastoreSchemaDescription; @@ -19,7 +18,6 @@ import lombok.RequiredArgsConstructor; -@Configuration @RequiredArgsConstructor public class DatastoreSchemaConfig implements IDatastoreSchemaDescriptionConfig { private final List storeDescriptions; diff --git a/src/main/java/com/activeviam/apps/cfg/datastore/DatastoreSelectionConfig.java b/src/main/java/com/activeviam/apps/cfg/datastore/DatastoreSelectionConfig.java index 1a7bb2c3..6d2580ff 100644 --- a/src/main/java/com/activeviam/apps/cfg/datastore/DatastoreSelectionConfig.java +++ b/src/main/java/com/activeviam/apps/cfg/datastore/DatastoreSelectionConfig.java @@ -7,7 +7,6 @@ package com.activeviam.apps.cfg.datastore; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import com.activeviam.activepivot.core.datastore.api.builder.StartBuilding; import com.activeviam.activepivot.core.intf.api.description.ISelectionDescription; @@ -16,7 +15,6 @@ import lombok.RequiredArgsConstructor; -@Configuration @RequiredArgsConstructor public class DatastoreSelectionConfig { private final IDatastoreSchemaDescription datastoreSchemaDescription; diff --git a/src/main/java/com/activeviam/apps/cfg/datastore/datamodel/StoresConfiguration.java b/src/main/java/com/activeviam/apps/cfg/datastore/datamodel/StoreDefinitionsConfig.java similarity index 98% rename from src/main/java/com/activeviam/apps/cfg/datastore/datamodel/StoresConfiguration.java rename to src/main/java/com/activeviam/apps/cfg/datastore/datamodel/StoreDefinitionsConfig.java index e345c822..1edf341a 100644 --- a/src/main/java/com/activeviam/apps/cfg/datastore/datamodel/StoresConfiguration.java +++ b/src/main/java/com/activeviam/apps/cfg/datastore/datamodel/StoreDefinitionsConfig.java @@ -26,7 +26,7 @@ import com.activeviam.database.datastore.api.description.impl.StoreDescription; @Configuration -public class StoresConfiguration { +public class StoreDefinitionsConfig { public static String referenceName(String from, String to) { return String.format("%s_to_%s", from, to); diff --git a/src/main/java/com/activeviam/apps/cfg/pivot/ActivePivotConfig.java b/src/main/java/com/activeviam/apps/cfg/pivot/ActivePivotConfig.java deleted file mode 100644 index d64c3ed9..00000000 --- a/src/main/java/com/activeviam/apps/cfg/pivot/ActivePivotConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) ActiveViam 2024 - * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY - * property of ActiveViam Limited. Any unauthorized use, - * reproduction or transfer of this material is strictly prohibited - */ -package com.activeviam.apps.cfg.pivot; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import com.activeviam.activepivot.core.datastore.api.builder.ApplicationWithDatastore; -import com.activeviam.activepivot.core.intf.api.cube.IActivePivotManager; -import com.activeviam.activepivot.server.spring.api.config.IActivePivotConfig; - -import lombok.RequiredArgsConstructor; - -@Configuration -@RequiredArgsConstructor -public class ActivePivotConfig implements IActivePivotConfig { - private final ApplicationWithDatastore applicationWithDatastore; - - @Bean - @Override - public IActivePivotManager activePivotManager() { - return applicationWithDatastore.getManager(); - } -} diff --git a/src/main/java/com/activeviam/apps/cfg/pivot/ActivePivotManagerConfig.java b/src/main/java/com/activeviam/apps/cfg/pivot/ActivePivotManagerConfig.java index a6051900..cfa2972e 100644 --- a/src/main/java/com/activeviam/apps/cfg/pivot/ActivePivotManagerConfig.java +++ b/src/main/java/com/activeviam/apps/cfg/pivot/ActivePivotManagerConfig.java @@ -7,7 +7,6 @@ package com.activeviam.apps.cfg.pivot; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import com.activeviam.activepivot.core.datastore.api.builder.StartBuilding; import com.activeviam.activepivot.core.intf.api.description.IActivePivotInstanceDescription; @@ -17,7 +16,6 @@ import lombok.RequiredArgsConstructor; -@Configuration @RequiredArgsConstructor public class ActivePivotManagerConfig implements IActivePivotManagerDescriptionConfig { /* *********************/ diff --git a/src/main/java/com/activeviam/apps/cfg/pivot/ActivePivotWithDatastoreConfig.java b/src/main/java/com/activeviam/apps/cfg/pivot/ActivePivotWithDatastoreConfig.java deleted file mode 100644 index aad47165..00000000 --- a/src/main/java/com/activeviam/apps/cfg/pivot/ActivePivotWithDatastoreConfig.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) ActiveViam 2024 - * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY - * property of ActiveViam Limited. Any unauthorized use, - * reproduction or transfer of this material is strictly prohibited - */ -package com.activeviam.apps.cfg.pivot; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import com.activeviam.activepivot.core.datastore.api.builder.ApplicationWithDatastore; -import com.activeviam.activepivot.core.datastore.api.builder.StartBuilding; -import com.activeviam.activepivot.core.intf.api.description.IActivePivotManagerDescription; -import com.activeviam.database.datastore.api.description.IDatastoreSchemaDescription; -import com.activeviam.tech.mvcc.api.policy.IEpochManagementPolicy; - -import lombok.RequiredArgsConstructor; - -@Configuration -@RequiredArgsConstructor -public class ActivePivotWithDatastoreConfig { - private final IDatastoreSchemaDescription datastoreSchemaDescription; - private final IActivePivotManagerDescription activePivotManagerDescription; - private final IEpochManagementPolicy epochManagementPolicy; - - @Bean - public ApplicationWithDatastore applicationWithDatastore() { - return StartBuilding.application() - .withDatastore(datastoreSchemaDescription) - .withManager(activePivotManagerDescription) - .withEpochPolicy(epochManagementPolicy) - .withoutBranchRestrictions() - .build(); - } -} diff --git a/src/main/java/com/activeviam/apps/cfg/pivot/ApplicationWithDatastoreConfig.java b/src/main/java/com/activeviam/apps/cfg/pivot/ApplicationWithDatastoreConfig.java new file mode 100644 index 00000000..41c4f897 --- /dev/null +++ b/src/main/java/com/activeviam/apps/cfg/pivot/ApplicationWithDatastoreConfig.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) ActiveViam 2024-2025 + * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY + * property of ActiveViam Limited. Any unauthorized use, + * reproduction or transfer of this material is strictly prohibited + */ +package com.activeviam.apps.cfg.pivot; + +import org.springframework.boot.context.event.ApplicationStartedEvent; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.context.event.EventListener; + +import com.activeviam.activepivot.core.datastore.api.builder.ApplicationWithDatastore; +import com.activeviam.activepivot.core.datastore.api.builder.StartBuilding; +import com.activeviam.activepivot.core.intf.api.cube.IActivePivotManager; +import com.activeviam.activepivot.core.intf.api.description.IActivePivotManagerDescription; +import com.activeviam.activepivot.server.spring.api.config.IActivePivotConfig; +import com.activeviam.activepivot.server.spring.api.config.IDatastoreConfig; +import com.activeviam.apps.cfg.datastore.DatastoreConfig; +import com.activeviam.database.datastore.api.IDatastore; +import com.activeviam.database.datastore.api.description.IDatastoreSchemaDescription; +import com.activeviam.tech.core.api.agent.AgentException; +import com.activeviam.tech.mvcc.api.policy.IEpochManagementPolicy; + +import lombok.RequiredArgsConstructor; + +@Configuration +@Import({DatastoreConfig.class, ActivePivotManagerConfig.class, CubeConfig.class}) +@RequiredArgsConstructor +public class ApplicationWithDatastoreConfig implements IActivePivotConfig, IDatastoreConfig { + private final IDatastoreSchemaDescription datastoreSchemaDescription; + private final IActivePivotManagerDescription activePivotManagerDescription; + private final IEpochManagementPolicy epochManagementPolicy; + + @Bean + public ApplicationWithDatastore applicationWithDatastore() { + return StartBuilding.application() + .withDatastore(datastoreSchemaDescription) + .withManager(activePivotManagerDescription) + .withEpochPolicy(epochManagementPolicy) + .withoutBranchRestrictions() + .build(); + } + + @Bean + @Override + public IActivePivotManager activePivotManager() { + return applicationWithDatastore().getManager(); + } + + @Bean + @Override + public IDatastore database() { + return applicationWithDatastore().getDatastore(); + } + /** + * Initialize and start the ActivePivot Manager, after performing all the injections into the ActivePivot plug-ins. + * + * @throws AgentException any exception that occurred during the injection, the initialization or the starting + */ + @EventListener(ApplicationStartedEvent.class) + public void startManager() throws AgentException { + /* *********************************************** */ + /* Initialize the ActivePivot Manager and start it */ + /* *********************************************** */ + activePivotManager().init(null); + activePivotManager().start(); + } +} diff --git a/src/main/java/com/activeviam/apps/cfg/pivot/CubeConfig.java b/src/main/java/com/activeviam/apps/cfg/pivot/CubeConfig.java index 48af38b2..1f7582d0 100644 --- a/src/main/java/com/activeviam/apps/cfg/pivot/CubeConfig.java +++ b/src/main/java/com/activeviam/apps/cfg/pivot/CubeConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (C) ActiveViam 2024 + * Copyright (C) ActiveViam 2024-2025 * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY * property of ActiveViam Limited. Any unauthorized use, * reproduction or transfer of this material is strictly prohibited @@ -13,7 +13,7 @@ import java.util.concurrent.TimeUnit; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import com.activeviam.activepivot.core.datastore.api.builder.StartBuilding; import com.activeviam.activepivot.core.impl.api.contextvalues.QueriesTimeLimit; @@ -21,16 +21,13 @@ import lombok.RequiredArgsConstructor; -@Configuration +@Import({Measures.class, Dimensions.class}) @RequiredArgsConstructor public class CubeConfig { public static final String CUBE_NAME = "Cube"; - private final Measures measures; - private final Dimensions dimensions; - @Bean - public IActivePivotInstanceDescription activePivotInstanceDescription() { + public IActivePivotInstanceDescription activePivotInstanceDescription(Dimensions dimensions, Measures measures) { return StartBuilding.cube(CUBE_NAME) .withContributorsCount() .withinFolder(NATIVE_MEASURES) diff --git a/src/main/java/com/activeviam/apps/cfg/pivot/Dimensions.java b/src/main/java/com/activeviam/apps/cfg/pivot/Dimensions.java index 961c4355..b114256e 100644 --- a/src/main/java/com/activeviam/apps/cfg/pivot/Dimensions.java +++ b/src/main/java/com/activeviam/apps/cfg/pivot/Dimensions.java @@ -10,15 +10,12 @@ import static com.activeviam.apps.constants.StoreAndFieldConstants.TRADE_DATE; import static com.activeviam.apps.constants.StoreAndFieldConstants.TRADE_ID; -import org.springframework.stereotype.Component; - import com.activeviam.activepivot.core.intf.api.cube.hierarchy.IDimension; import com.activeviam.activepivot.core.intf.api.cube.metadata.ILevelInfo; import com.activeviam.activepivot.core.intf.api.description.builder.dimension.ICanStartBuildingDimensions; import com.activeviam.apps.constants.StoreAndFieldConstants; import com.activeviam.tech.core.api.ordering.IComparator; -@Component public class Dimensions { public static final String TRADE_ATTRIBUTES_DIMENSION = "Trade Attributes"; diff --git a/src/main/java/com/activeviam/apps/cfg/pivot/Measures.java b/src/main/java/com/activeviam/apps/cfg/pivot/Measures.java index a4a193b4..d75e99e5 100644 --- a/src/main/java/com/activeviam/apps/cfg/pivot/Measures.java +++ b/src/main/java/com/activeviam/apps/cfg/pivot/Measures.java @@ -9,12 +9,9 @@ import static com.activeviam.apps.cfg.pivot.ActivePivotManagerConfig.DOUBLE_FORMATTER; import static com.activeviam.apps.constants.StoreAndFieldConstants.NOTIONAL; -import org.springframework.stereotype.Component; - import com.activeviam.activepivot.copper.api.Copper; import com.activeviam.activepivot.core.intf.api.copper.ICopperContext; -@Component public class Measures { public void build(ICopperContext context) { diff --git a/src/test/java/com/activeviam/apps/cfg/pivot/CubeTestConfig.java b/src/test/java/com/activeviam/apps/cfg/pivot/CubeTestConfig.java deleted file mode 100644 index 3e5ee9b9..00000000 --- a/src/test/java/com/activeviam/apps/cfg/pivot/CubeTestConfig.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) ActiveViam 2024 - * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY - * property of ActiveViam Limited. Any unauthorized use, - * reproduction or transfer of this material is strictly prohibited - */ -package com.activeviam.apps.cfg.pivot; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -import com.activeviam.activepivot.core.datastore.api.builder.StartBuilding; -import com.activeviam.activepivot.core.intf.api.description.IActivePivotManagerDescription; -import com.activeviam.apps.cfg.datastore.DatastoreConfig; -import com.activeviam.atoti.server.test.api.CubeTester; -import com.activeviam.database.datastore.api.IDatastore; -import com.activeviam.database.datastore.api.description.IDatastoreSchemaDescription; - -@Configuration -@ComponentScan(basePackageClasses = {DatastoreConfig.class, ActivePivotConfig.class}) -public class CubeTestConfig { - private final CubeTester cubeTester; - private final IDatastore datastore; - - public CubeTestConfig( - IActivePivotManagerDescription activePivotManagerDescription, - IDatastoreSchemaDescription datastoreSchemaDescription) { - var application = StartBuilding.application() - .withDatastore(datastoreSchemaDescription) - .withManager(activePivotManagerDescription) - .withoutBranchRestrictions() - .buildAndStart(); - cubeTester = CubeTester.from(application.getManager()); - datastore = application.getDatastore(); - } - - @Bean - public IDatastore datastore() { - return datastore; - } - - @Bean - public CubeTester cubeTester() { - return cubeTester; - } -} diff --git a/src/test/java/com/activeviam/apps/cfg/pivot/CubeTesterConfig.java b/src/test/java/com/activeviam/apps/cfg/pivot/CubeTesterConfig.java new file mode 100644 index 00000000..2bd2c9ac --- /dev/null +++ b/src/test/java/com/activeviam/apps/cfg/pivot/CubeTesterConfig.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) ActiveViam 2024-2025 + * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY + * property of ActiveViam Limited. Any unauthorized use, + * reproduction or transfer of this material is strictly prohibited + */ +package com.activeviam.apps.cfg.pivot; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; + +import com.activeviam.activepivot.core.datastore.api.builder.ApplicationWithDatastore; +import com.activeviam.atoti.server.test.api.CubeTester; +import com.activeviam.database.datastore.api.transaction.IOpenedTransaction; +import com.activeviam.tech.core.api.exceptions.ActiveViamRuntimeException; + +@Import({ApplicationWithDatastoreConfig.class}) +public class CubeTesterConfig { + + @Bean + public CubeTester cubeTester(ApplicationWithDatastore application) { + var manager = application.getManager(); + try { + manager.init(null); + manager.start(); + var datastore = application.getDatastore(); + datastore.edit(this::loadData); + return CubeTester.from(manager); + } catch (Exception e) { + throw new ActiveViamRuntimeException(e); + } + } + + public void loadData(IOpenedTransaction transaction) { + // Do nothing + } +} diff --git a/src/test/java/com/activeviam/apps/cfg/pivot/MeasuresTest.java b/src/test/java/com/activeviam/apps/cfg/pivot/MeasuresTest.java index 2fffe485..5cce26f9 100644 --- a/src/test/java/com/activeviam/apps/cfg/pivot/MeasuresTest.java +++ b/src/test/java/com/activeviam/apps/cfg/pivot/MeasuresTest.java @@ -14,34 +14,34 @@ import java.time.LocalDate; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.TestConfiguration; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import com.activeviam.activepivot.core.intf.api.cube.hierarchy.IHierarchy; import com.activeviam.activepivot.core.intf.api.cube.hierarchy.IMeasureHierarchy; import com.activeviam.atoti.server.test.api.CubeTester; -import com.activeviam.database.datastore.api.IDatastore; +import com.activeviam.database.datastore.api.transaction.IOpenedTransaction; -@SpringJUnitConfig({CubeTestConfig.class}) +@SpringJUnitConfig class MeasuresTest { private static final LocalDate TEST_DATE = LocalDate.parse("2019-03-13"); - @Autowired - CubeTester cubeTester; + @TestConfiguration + public static class MeasuresTestConfig extends CubeTesterConfig { + @Override + public void loadData(IOpenedTransaction t) { + t.addAll( + TRADES_STORE_NAME, + List.of(new Object[] {TEST_DATE, "T1", 100}, new Object[] {TEST_DATE, "T2", 350d}, new Object[] { + TEST_DATE, "T3", 300d + })); + } + } @Autowired - IDatastore datastore; - - @BeforeEach - public void initialLoad() { - datastore.edit(t -> t.addAll( - TRADES_STORE_NAME, - List.of(new Object[] {TEST_DATE, "T1", 100}, new Object[] {TEST_DATE, "T2", 350d}, new Object[] { - TEST_DATE, "T3", 300d - }))); - } + CubeTester cubeTester; /** * Here is the actual test. Check that the numbers sum up correctly