diff --git a/moneyjinn-server/src/main/java/org/laladev/moneyjinn/server/controller/impl/EtfController.java b/moneyjinn-server/src/main/java/org/laladev/moneyjinn/server/controller/impl/EtfController.java index 4986e266..40c4cae4 100644 --- a/moneyjinn-server/src/main/java/org/laladev/moneyjinn/server/controller/impl/EtfController.java +++ b/moneyjinn-server/src/main/java/org/laladev/moneyjinn/server/controller/impl/EtfController.java @@ -96,14 +96,15 @@ public ResponseEntity listEtfOverview( final Year year = Year.of(requestYear); final LocalDateTime endOfMonth = LocalDateTime.of(requestYear.intValue(), month, 1, 23, 59, 59, 999999999) .with(TemporalAdjusters.lastDayOfMonth()); + final UserID userId = super.getUserId(); final ListEtfOverviewResponse response = new ListEtfOverviewResponse(); final List transports = new ArrayList<>(); final List etfs = this.etfService.getAllEtf(super.getUserId()); for (final Etf etf : etfs) { final EtfValue etfValue = this.etfService.getEtfValueEndOfMonth(etf.getIsin(), year, month); - final List allEtfFlows = this.etfService.getAllEtfFlowsUntil(etf.getId(), endOfMonth); - final List etfFlows = this.etfService.calculateEffectiveEtfFlows(allEtfFlows); + final List allEtfFlows = this.etfService.getAllEtfFlowsUntil(userId, etf.getId(), endOfMonth); + final List etfFlows = this.etfService.calculateEffectiveEtfFlows(userId, allEtfFlows); if (etfFlows != null && !etfFlows.isEmpty()) { final EtfSummaryTransport transport = new EtfSummaryTransport(); transport.setEtfId(etf.getId().getId()); @@ -151,12 +152,12 @@ public ResponseEntity listEtfFlowsById(@PathVariable("id") final ListEtfFlowsResponse response = this.getDefaultListEtfFlowsResponse(); - final List etfFlows = this.etfService.getAllEtfFlowsUntil(etfId, LocalDateTime.now()); + final List etfFlows = this.etfService.getAllEtfFlowsUntil(userId, etfId, LocalDateTime.now()); final List etfFlowTransports = super.mapList(etfFlows, EtfFlowTransport.class); response.setEtfFlowTransports(etfFlowTransports); final List etfEffectiveFlows = new ArrayList<>( - this.etfService.calculateEffectiveEtfFlows(etfFlows)); + this.etfService.calculateEffectiveEtfFlows(userId, etfFlows)); Collections.sort(etfEffectiveFlows, Collections.reverseOrder(new EtfFlowComparator())); final List etfEffectiveFlowTransports = super.mapList(etfEffectiveFlows, EtfEffectiveFlowTransport.class); @@ -199,6 +200,13 @@ public ResponseEntity calcEtfSale(@RequestBody final CalcEt return ResponseEntity.ok(response); } + final UserID userId = this.getUserId(); + final EtfID etfId = new EtfID(request.getEtfId()); + + if (this.etfService.getEtfById(userId, etfId) == null) { + return ResponseEntity.ok(response); + } + final BigDecimal pieces = request.getPieces().abs(); final BigDecimal askPrice = request.getAskPrice().abs(); final BigDecimal bidPrice = request.getBidPrice().abs(); @@ -208,14 +216,13 @@ public ResponseEntity calcEtfSale(@RequestBody final CalcEt this.settingService.setClientCalcEtfSaleTransactionCosts(this.getUserId(), new ClientCalcEtfSaleTransactionCosts(request.getTransactionCosts())); - final EtfID etfId = new EtfID(request.getEtfId()); BigDecimal openPieces = pieces; BigDecimal originalBuyPrice = BigDecimal.ZERO; BigDecimal overallPreliminaryLumpSum = BigDecimal.ZERO; - final List etfFlows = this.etfService.getAllEtfFlowsUntil(etfId, LocalDateTime.now()); + final List etfFlows = this.etfService.getAllEtfFlowsUntil(userId, etfId, LocalDateTime.now()); final List effectiveEtfFlows = new ArrayList<>( - this.etfService.calculateEffectiveEtfFlows(etfFlows)); + this.etfService.calculateEffectiveEtfFlows(userId, etfFlows)); if (effectiveEtfFlows != null && !effectiveEtfFlows.isEmpty()) { for (final EtfFlowWithTaxInfo etfFlow : effectiveEtfFlows) { diff --git a/moneyjinn-server/src/main/java/org/laladev/moneyjinn/server/controller/impl/crud/CrudEtfFlowController.java b/moneyjinn-server/src/main/java/org/laladev/moneyjinn/server/controller/impl/crud/CrudEtfFlowController.java index b08bfc51..d38fe842 100644 --- a/moneyjinn-server/src/main/java/org/laladev/moneyjinn/server/controller/impl/crud/CrudEtfFlowController.java +++ b/moneyjinn-server/src/main/java/org/laladev/moneyjinn/server/controller/impl/crud/CrudEtfFlowController.java @@ -26,6 +26,7 @@ import java.util.List; +import org.laladev.moneyjinn.model.access.UserID; import org.laladev.moneyjinn.model.etf.EtfFlow; import org.laladev.moneyjinn.model.etf.EtfFlowID; import org.laladev.moneyjinn.model.validation.ValidationResult; @@ -64,13 +65,14 @@ protected void addBeanMapper() { @Override public ResponseEntity create(@RequestBody final EtfFlowTransport etfFlowTransport, @RequestHeader(value = HEADER_PREFER, required = false) final List prefer) { + final UserID userId = super.getUserId(); final EtfFlow etfFlow = super.map(etfFlowTransport, EtfFlow.class); etfFlow.setId(null); - final ValidationResult validationResult = this.etfService.validateEtfFlow(etfFlow); + final ValidationResult validationResult = this.etfService.validateEtfFlow(userId, etfFlow); this.throwValidationExceptionIfInvalid(validationResult); - final EtfFlowID etfId = this.etfService.createEtfFlow(etfFlow); + final EtfFlowID etfId = this.etfService.createEtfFlow(userId, etfFlow); etfFlow.setId(etfId); @@ -81,21 +83,23 @@ public ResponseEntity create(@RequestBody final EtfFlowTranspo @Override public ResponseEntity update(@RequestBody final EtfFlowTransport etfFlowTransport, @RequestHeader(value = HEADER_PREFER, required = false) final List prefer) { + final UserID userId = super.getUserId(); final EtfFlow etfFlow = super.map(etfFlowTransport, EtfFlow.class); - final ValidationResult validationResult = this.etfService.validateEtfFlow(etfFlow); + final ValidationResult validationResult = this.etfService.validateEtfFlow(userId, etfFlow); this.throwValidationExceptionIfInvalid(validationResult); - this.etfService.updateEtfFlow(etfFlow); + this.etfService.updateEtfFlow(userId, etfFlow); return this.preferedReturn(prefer, etfFlow, EtfFlowTransport.class); } @Override public ResponseEntity delete(@PathVariable("id") final Long id) { + final UserID userId = super.getUserId(); final EtfFlowID etfFlowId = new EtfFlowID(id); - this.etfService.deleteEtfFlow(etfFlowId); + this.etfService.deleteEtfFlow(userId, etfFlowId); return ResponseEntity.noContent().build(); } diff --git a/moneyjinn-server/src/main/java/org/laladev/moneyjinn/server/controller/impl/crud/CrudEtfPreliminaryLumpSumController.java b/moneyjinn-server/src/main/java/org/laladev/moneyjinn/server/controller/impl/crud/CrudEtfPreliminaryLumpSumController.java index b9d9a23e..db31de79 100644 --- a/moneyjinn-server/src/main/java/org/laladev/moneyjinn/server/controller/impl/crud/CrudEtfPreliminaryLumpSumController.java +++ b/moneyjinn-server/src/main/java/org/laladev/moneyjinn/server/controller/impl/crud/CrudEtfPreliminaryLumpSumController.java @@ -27,6 +27,7 @@ import java.time.Year; import java.util.List; +import org.laladev.moneyjinn.model.access.UserID; import org.laladev.moneyjinn.model.etf.EtfID; import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSum; import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSumID; @@ -65,9 +66,10 @@ protected void addBeanMapper() { @Override public ResponseEntity> readAllYears(@PathVariable("etfId") final Long requestEtfId) { + final UserID userId = super.getUserId(); final EtfID etfId = new EtfID(requestEtfId); - final List allYears = this.etfService.getAllEtfPreliminaryLumpSumYears(etfId); + final List allYears = this.etfService.getAllEtfPreliminaryLumpSumYears(userId, etfId); return allYears.isEmpty() ? ResponseEntity.notFound().build() : ResponseEntity.ok(allYears.stream().map(Year::getValue).toList()); @@ -76,12 +78,13 @@ public ResponseEntity> readAllYears(@PathVariable("etfId") final L @Override public ResponseEntity readOne(@PathVariable("etfId") final Long requestEtfId, @PathVariable("year") final Integer requestYear) { + final UserID userId = super.getUserId(); final EtfID etfId = new EtfID(requestEtfId); final Year year = Year.of(requestYear); final EtfPreliminaryLumpSumID id = new EtfPreliminaryLumpSumID( new EtfPreliminaryLumpSumIDValues(etfId, year)); - final EtfPreliminaryLumpSum etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + final EtfPreliminaryLumpSum etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); return etfPreliminaryLumpSum == null ? ResponseEntity.notFound().build() : ResponseEntity.ok(super.map(etfPreliminaryLumpSum, EtfPreliminaryLumpSumTransport.class)); @@ -91,12 +94,14 @@ public ResponseEntity readOne(@PathVariable("etf public ResponseEntity create( @RequestBody final EtfPreliminaryLumpSumTransport transport, @RequestHeader(value = HEADER_PREFER, required = false) final List prefer) { + final UserID userId = super.getUserId(); final EtfPreliminaryLumpSum etfPreliminaryLumpSum = super.map(transport, EtfPreliminaryLumpSum.class); - final ValidationResult validationResult = this.etfService.validateEtfPreliminaryLumpSum(etfPreliminaryLumpSum); + final ValidationResult validationResult = this.etfService.validateEtfPreliminaryLumpSum(userId, + etfPreliminaryLumpSum); this.throwValidationExceptionIfInvalid(validationResult); - this.etfService.createEtfPreliminaryLumpSum(etfPreliminaryLumpSum); + this.etfService.createEtfPreliminaryLumpSum(userId, etfPreliminaryLumpSum); return this.preferedReturn(prefer, etfPreliminaryLumpSum, EtfPreliminaryLumpSumTransport.class); } @@ -105,12 +110,14 @@ public ResponseEntity create( public ResponseEntity update( @RequestBody final EtfPreliminaryLumpSumTransport transport, @RequestHeader(value = HEADER_PREFER, required = false) final List prefer) { + final UserID userId = super.getUserId(); final EtfPreliminaryLumpSum etfPreliminaryLumpSum = super.map(transport, EtfPreliminaryLumpSum.class); - final ValidationResult validationResult = this.etfService.validateEtfPreliminaryLumpSum(etfPreliminaryLumpSum); + final ValidationResult validationResult = this.etfService.validateEtfPreliminaryLumpSum(userId, + etfPreliminaryLumpSum); this.throwValidationExceptionIfInvalid(validationResult); - this.etfService.updateEtfPreliminaryLumpSum(etfPreliminaryLumpSum); + this.etfService.updateEtfPreliminaryLumpSum(userId, etfPreliminaryLumpSum); return this.preferedReturn(prefer, etfPreliminaryLumpSum, EtfPreliminaryLumpSumTransport.class); } @@ -118,12 +125,13 @@ public ResponseEntity update( @Override public ResponseEntity delete(@PathVariable("etfId") final Long requestEtfId, @PathVariable("year") final Integer requestYear) { + final UserID userId = super.getUserId(); final EtfID etfId = new EtfID(requestEtfId); final Year year = Year.of(requestYear); final EtfPreliminaryLumpSumID id = new EtfPreliminaryLumpSumID( new EtfPreliminaryLumpSumIDValues(etfId, year)); - this.etfService.deleteEtfPreliminaryLumpSum(id); + this.etfService.deleteEtfPreliminaryLumpSum(userId, id); return ResponseEntity.noContent().build(); } diff --git a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/businesslogic/service/impl/EtfServiceTest.java b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/businesslogic/service/impl/EtfServiceTest.java index 7b51192e..ae5e0b1b 100644 --- a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/businesslogic/service/impl/EtfServiceTest.java +++ b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/businesslogic/service/impl/EtfServiceTest.java @@ -4,7 +4,13 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.laladev.moneyjinn.AbstractTest; +import org.laladev.moneyjinn.model.access.Group; +import org.laladev.moneyjinn.model.access.GroupID; +import org.laladev.moneyjinn.model.access.User; +import org.laladev.moneyjinn.model.access.UserID; +import org.laladev.moneyjinn.model.etf.Etf; import org.laladev.moneyjinn.model.etf.EtfFlow; +import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSum; import org.laladev.moneyjinn.model.exception.BusinessException; import org.laladev.moneyjinn.service.api.IEtfService; @@ -15,18 +21,54 @@ class EtfServiceTest extends AbstractTest { private IEtfService etfService; @Test - void test_createWithInvalidEntity_raisesException() { + void test_createEtfFlowWithInvalidEntity_raisesException() { final EtfFlow etfFlow = new EtfFlow(); Assertions.assertThrows(BusinessException.class, () -> { - this.etfService.createEtfFlow(etfFlow); + this.etfService.createEtfFlow(new UserID(1L), etfFlow); }); } @Test - void test_updateWithInvalidEntity_raisesException() { + void test_updateEtfFlowWithInvalidEntity_raisesException() { final EtfFlow etfFlow = new EtfFlow(); Assertions.assertThrows(BusinessException.class, () -> { - this.etfService.updateEtfFlow(etfFlow); + this.etfService.updateEtfFlow(new UserID(1L), etfFlow); + }); + } + + @Test + void test_createEtfWithInvalidEntity_raisesException() { + final Etf etf = new Etf(); + etf.setUser(new User(new UserID(1L))); + etf.setGroup(new Group(new GroupID(2L))); + Assertions.assertThrows(BusinessException.class, () -> { + this.etfService.createEtf(etf); + }); + } + + @Test + void test_updateWithInvalidEntity_raisesException() { + final Etf etf = new Etf(); + etf.setUser(new User(new UserID(1L))); + etf.setGroup(new Group(new GroupID(2L))); + Assertions.assertThrows(BusinessException.class, () -> { + this.etfService.updateEtf(etf); + }); + } + + @Test + void test_createEtfPreliminaryLumpSumWithInvalidEntity_raisesException() { + final EtfPreliminaryLumpSum etfPreliminaryLumpSum = new EtfPreliminaryLumpSum(); + Assertions.assertThrows(BusinessException.class, () -> { + this.etfService.createEtfPreliminaryLumpSum(new UserID(1L), etfPreliminaryLumpSum); + }); + } + + @Test + void test_updateEtfPreliminaryLumpSumWithInvalidEntity_raisesException() { + final EtfPreliminaryLumpSum etfPreliminaryLumpSum = new EtfPreliminaryLumpSum(); + Assertions.assertThrows(BusinessException.class, () -> { + this.etfService.updateEtfPreliminaryLumpSum(new UserID(1L), etfPreliminaryLumpSum); }); } } diff --git a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etf/DeleteEtfTest.java b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etf/DeleteEtfTest.java index 12e000e1..f4674409 100644 --- a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etf/DeleteEtfTest.java +++ b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etf/DeleteEtfTest.java @@ -71,7 +71,7 @@ void test_etfWithoutDataSameGroup_Successful() throws Exception { @Test void test_etfFromOtherGroup_nothingHappened() throws Exception { final var etfId = new EtfID(EtfTransportBuilder.ETF_ID_2); - final var userId = new UserID(UserTransportBuilder.USER1_ID); + final var userId = new UserID(UserTransportBuilder.ADMIN_ID); var etf = this.etfService.getEtfById(userId, etfId); Assertions.assertNotNull(etf); diff --git a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfflow/CreateEtfFlowTest.java b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfflow/CreateEtfFlowTest.java index 4c47b2c4..a4a10126 100644 --- a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfflow/CreateEtfFlowTest.java +++ b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfflow/CreateEtfFlowTest.java @@ -8,9 +8,11 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.laladev.moneyjinn.core.error.ErrorCode; +import org.laladev.moneyjinn.model.access.UserID; import org.laladev.moneyjinn.model.etf.EtfFlowID; import org.laladev.moneyjinn.server.builder.EtfFlowTransportBuilder; import org.laladev.moneyjinn.server.builder.EtfTransportBuilder; +import org.laladev.moneyjinn.server.builder.UserTransportBuilder; import org.laladev.moneyjinn.server.builder.ValidationItemTransportBuilder; import org.laladev.moneyjinn.server.model.EtfFlowTransport; import org.laladev.moneyjinn.server.model.ValidationItemTransport; @@ -45,14 +47,15 @@ private void testError(final EtfFlowTransport transport, final ErrorCode errorCo void test_standardRequest_Successfull_MinimalReturn() throws Exception { final EtfFlowTransport transport = new EtfFlowTransportBuilder().forNewFlow().build(); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfFlowId = new EtfFlowID(EtfFlowTransportBuilder.NEXT_ID); - var etfFlow = this.etfService.getEtfFlowById(etfFlowId); + var etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); Assertions.assertNull(etfFlow); super.callUsecaseExpect204Minimal(transport); - etfFlow = this.etfService.getEtfFlowById(etfFlowId); + etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); Assertions.assertNotNull(etfFlow); } @@ -60,9 +63,10 @@ void test_standardRequest_Successfull_MinimalReturn() throws Exception { void test_standardRequest_Successfull_RepresentationReturn() throws Exception { final EtfFlowTransport transport = new EtfFlowTransportBuilder().forNewFlow().build(); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfFlowId = new EtfFlowID(EtfFlowTransportBuilder.NEXT_ID); - var etfFlow = this.etfService.getEtfFlowById(etfFlowId); + var etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); Assertions.assertNull(etfFlow); final EtfFlowTransport actualTransport = super.callUsecaseExpect200Representation(transport, @@ -70,7 +74,7 @@ void test_standardRequest_Successfull_RepresentationReturn() throws Exception { transport.setEtfflowid(EtfFlowTransportBuilder.NEXT_ID); Assertions.assertEquals(transport, actualTransport); - etfFlow = this.etfService.getEtfFlowById(etfFlowId); + etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); Assertions.assertNotNull(etfFlow); } @@ -78,14 +82,15 @@ void test_standardRequest_Successfull_RepresentationReturn() throws Exception { void test_standardRequest_Successfull_DefaultReturn() throws Exception { final EtfFlowTransport transport = new EtfFlowTransportBuilder().forNewFlow().build(); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfFlowId = new EtfFlowID(EtfFlowTransportBuilder.NEXT_ID); - var etfFlow = this.etfService.getEtfFlowById(etfFlowId); + var etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); Assertions.assertNull(etfFlow); super.callUsecaseExpect204(transport); - etfFlow = this.etfService.getEtfFlowById(etfFlowId); + etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); Assertions.assertNotNull(etfFlow); } @@ -94,14 +99,15 @@ void test_nanosecondsNotSet_Successfull_DefaultReturn() throws Exception { final EtfFlowTransport transport = new EtfFlowTransportBuilder().forNewFlow().build(); transport.setNanoseconds(null); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfFlowId = new EtfFlowID(EtfFlowTransportBuilder.NEXT_ID); - var etfFlow = this.etfService.getEtfFlowById(etfFlowId); + var etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); Assertions.assertNull(etfFlow); super.callUsecaseExpect204(transport); - etfFlow = this.etfService.getEtfFlowById(etfFlowId); + etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); Assertions.assertNotNull(etfFlow); } diff --git a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfflow/DeleteEtfFlowTest.java b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfflow/DeleteEtfFlowTest.java index 24e6bdad..7eafc1a6 100644 --- a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfflow/DeleteEtfFlowTest.java +++ b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfflow/DeleteEtfFlowTest.java @@ -3,8 +3,10 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.laladev.moneyjinn.model.access.UserID; import org.laladev.moneyjinn.model.etf.EtfFlowID; import org.laladev.moneyjinn.server.builder.EtfFlowTransportBuilder; +import org.laladev.moneyjinn.server.builder.UserTransportBuilder; import org.laladev.moneyjinn.service.api.IEtfService; import jakarta.inject.Inject; @@ -20,25 +22,27 @@ protected void loadMethod() { @Test void test_standardRequest_Succesful() throws Exception { + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfFlowId = new EtfFlowID(EtfFlowTransportBuilder.ETF_FLOW_10ID); - var etfFlow = this.etfService.getEtfFlowById(etfFlowId); + var etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); Assertions.assertNotNull(etfFlow); super.callUsecaseExpect204WithUriVariables(EtfFlowTransportBuilder.ETF_FLOW_10ID); - etfFlow = this.etfService.getEtfFlowById(etfFlowId); + etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); Assertions.assertNull(etfFlow); } @Test void test_notExisting_Succesful() throws Exception { + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfFlowId = new EtfFlowID(EtfFlowTransportBuilder.NON_EXISTING_ID); - var etfFlow = this.etfService.getEtfFlowById(etfFlowId); + var etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); Assertions.assertNull(etfFlow); super.callUsecaseExpect204WithUriVariables(EtfFlowTransportBuilder.NON_EXISTING_ID); - etfFlow = this.etfService.getEtfFlowById(etfFlowId); + etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); Assertions.assertNull(etfFlow); } diff --git a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfflow/UpdateEtfFlowTest.java b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfflow/UpdateEtfFlowTest.java index de156350..1a1d7c5d 100644 --- a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfflow/UpdateEtfFlowTest.java +++ b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfflow/UpdateEtfFlowTest.java @@ -10,9 +10,11 @@ import org.junit.jupiter.api.Test; import org.laladev.moneyjinn.core.error.ErrorCode; +import org.laladev.moneyjinn.model.access.UserID; import org.laladev.moneyjinn.model.etf.EtfFlowID; import org.laladev.moneyjinn.server.builder.EtfFlowTransportBuilder; import org.laladev.moneyjinn.server.builder.EtfTransportBuilder; +import org.laladev.moneyjinn.server.builder.UserTransportBuilder; import org.laladev.moneyjinn.server.builder.ValidationItemTransportBuilder; import org.laladev.moneyjinn.server.model.EtfFlowTransport; import org.laladev.moneyjinn.server.model.ValidationItemTransport; @@ -48,12 +50,13 @@ private void testError(final EtfFlowTransport transport, final ErrorCode errorCo void test_standardRequest_Successfull_MinimalReturn() throws Exception { final EtfFlowTransport transport = new EtfFlowTransportBuilder().forFlow11().build(); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfFlowId = new EtfFlowID(EtfFlowTransportBuilder.ETF_FLOW_11ID); transport.setAmount(BIGDECIMAL_123_01); super.callUsecaseExpect204Minimal(transport); - final var etfFlow = this.etfService.getEtfFlowById(etfFlowId); + final var etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); assertNotNull(etfFlow); assertEquals(BIGDECIMAL_123_01, etfFlow.getAmount()); } @@ -62,6 +65,7 @@ void test_standardRequest_Successfull_MinimalReturn() throws Exception { void test_standardRequest_Successfull_RepresentationReturn() throws Exception { final EtfFlowTransport transport = new EtfFlowTransportBuilder().forFlow11().build(); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfFlowId = new EtfFlowID(EtfFlowTransportBuilder.ETF_FLOW_11ID); transport.setAmount(BIGDECIMAL_123_01); @@ -70,7 +74,7 @@ void test_standardRequest_Successfull_RepresentationReturn() throws Exception { assertEquals(transport, actualTransport); - final var etfFlow = this.etfService.getEtfFlowById(etfFlowId); + final var etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); assertNotNull(etfFlow); assertEquals(BIGDECIMAL_123_01, etfFlow.getAmount()); } @@ -79,12 +83,13 @@ void test_standardRequest_Successfull_RepresentationReturn() throws Exception { void test_standardRequest_Successfull_DefaultReturn() throws Exception { final EtfFlowTransport transport = new EtfFlowTransportBuilder().forFlow11().build(); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfFlowId = new EtfFlowID(EtfFlowTransportBuilder.ETF_FLOW_11ID); transport.setAmount(BIGDECIMAL_123_01); super.callUsecaseExpect204(transport); - final var etfFlow = this.etfService.getEtfFlowById(etfFlowId); + final var etfFlow = this.etfService.getEtfFlowById(userId, etfFlowId); assertNotNull(etfFlow); assertEquals(BIGDECIMAL_123_01, etfFlow.getAmount()); } diff --git a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfpreliminarylumpsum/CreateEtfPreliminaryLumpSumTest.java b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfpreliminarylumpsum/CreateEtfPreliminaryLumpSumTest.java index 3e676966..91230e5e 100644 --- a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfpreliminarylumpsum/CreateEtfPreliminaryLumpSumTest.java +++ b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfpreliminarylumpsum/CreateEtfPreliminaryLumpSumTest.java @@ -8,11 +8,13 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.laladev.moneyjinn.core.error.ErrorCode; +import org.laladev.moneyjinn.model.access.UserID; import org.laladev.moneyjinn.model.etf.EtfID; import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSumID; import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSumIDValues; import org.laladev.moneyjinn.server.builder.EtfPreliminaryLumpSumTransportBuilder; import org.laladev.moneyjinn.server.builder.EtfTransportBuilder; +import org.laladev.moneyjinn.server.builder.UserTransportBuilder; import org.laladev.moneyjinn.server.builder.ValidationItemTransportBuilder; import org.laladev.moneyjinn.server.model.ErrorResponse; import org.laladev.moneyjinn.server.model.EtfPreliminaryLumpSumTransport; @@ -49,17 +51,18 @@ void test_standardRequest_Successfull_MinimalReturn() throws Exception { final EtfPreliminaryLumpSumTransport transport = new EtfPreliminaryLumpSumTransportBuilder().forNewYear() .build(); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfId = new EtfID(EtfTransportBuilder.ETF_ID_1); final var year = Year.of(EtfPreliminaryLumpSumTransportBuilder.NEW_YEAR); final EtfPreliminaryLumpSumID id = new EtfPreliminaryLumpSumID( new EtfPreliminaryLumpSumIDValues(etfId, year)); - var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertNull(etfPreliminaryLumpSum); super.callUsecaseExpect204Minimal(transport); - etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertNotNull(etfPreliminaryLumpSum); } @@ -68,12 +71,13 @@ void test_standardRequest_Successfull_RepresentationReturn() throws Exception { final EtfPreliminaryLumpSumTransport transport = new EtfPreliminaryLumpSumTransportBuilder().forNewYear() .build(); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfId = new EtfID(EtfTransportBuilder.ETF_ID_1); final var year = Year.of(EtfPreliminaryLumpSumTransportBuilder.NEW_YEAR); final EtfPreliminaryLumpSumID id = new EtfPreliminaryLumpSumID( new EtfPreliminaryLumpSumIDValues(etfId, year)); - var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertNull(etfPreliminaryLumpSum); final EtfPreliminaryLumpSumTransport actualTransport = super.callUsecaseExpect200Representation(transport, @@ -81,7 +85,7 @@ void test_standardRequest_Successfull_RepresentationReturn() throws Exception { Assertions.assertEquals(transport, actualTransport); - etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertNotNull(etfPreliminaryLumpSum); } @@ -90,17 +94,18 @@ void test_standardRequest_Successfull_DefaultReturn() throws Exception { final EtfPreliminaryLumpSumTransport transport = new EtfPreliminaryLumpSumTransportBuilder().forNewYear() .build(); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfId = new EtfID(EtfTransportBuilder.ETF_ID_1); final var year = Year.of(EtfPreliminaryLumpSumTransportBuilder.NEW_YEAR); final EtfPreliminaryLumpSumID id = new EtfPreliminaryLumpSumID( new EtfPreliminaryLumpSumIDValues(etfId, year)); - var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertNull(etfPreliminaryLumpSum); super.callUsecaseExpect204(transport); - etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertNotNull(etfPreliminaryLumpSum); } diff --git a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfpreliminarylumpsum/DeletePreliminaryLumpSumTest.java b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfpreliminarylumpsum/DeletePreliminaryLumpSumTest.java index acbff87e..4ba8fbd2 100644 --- a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfpreliminarylumpsum/DeletePreliminaryLumpSumTest.java +++ b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfpreliminarylumpsum/DeletePreliminaryLumpSumTest.java @@ -5,11 +5,13 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.laladev.moneyjinn.model.access.UserID; import org.laladev.moneyjinn.model.etf.EtfID; import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSumID; import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSumIDValues; import org.laladev.moneyjinn.server.builder.EtfPreliminaryLumpSumTransportBuilder; import org.laladev.moneyjinn.server.builder.EtfTransportBuilder; +import org.laladev.moneyjinn.server.builder.UserTransportBuilder; import org.laladev.moneyjinn.service.api.IEtfService; import jakarta.inject.Inject; @@ -28,11 +30,12 @@ void test_happyCase_SuccessfullNoContent() throws Exception { super.callUsecaseExpect204WithUriVariables(EtfTransportBuilder.ETF_ID_1, EtfPreliminaryLumpSumTransportBuilder.YEAR_2009); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfId = new EtfID(EtfTransportBuilder.ETF_ID_1); final var year = Year.of(EtfPreliminaryLumpSumTransportBuilder.YEAR_2009); final EtfPreliminaryLumpSumID id = new EtfPreliminaryLumpSumID( new EtfPreliminaryLumpSumIDValues(etfId, year)); - final var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + final var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertNull(etfPreliminaryLumpSum); } @@ -42,11 +45,12 @@ void test_nonExisting_SuccessfullNoContent() throws Exception { super.callUsecaseExpect204WithUriVariables(EtfTransportBuilder.NON_EXISTING_ID, EtfPreliminaryLumpSumTransportBuilder.YEAR_2009); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfId = new EtfID(EtfTransportBuilder.NON_EXISTING_ID); final var year = Year.of(EtfPreliminaryLumpSumTransportBuilder.YEAR_2009); final EtfPreliminaryLumpSumID id = new EtfPreliminaryLumpSumID( new EtfPreliminaryLumpSumIDValues(etfId, year)); - final var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + final var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertNull(etfPreliminaryLumpSum); } diff --git a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfpreliminarylumpsum/UpdateEtfPreliminaryLumpSumTest.java b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfpreliminarylumpsum/UpdateEtfPreliminaryLumpSumTest.java index fdf02288..a20b953c 100644 --- a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfpreliminarylumpsum/UpdateEtfPreliminaryLumpSumTest.java +++ b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/crud/etfpreliminarylumpsum/UpdateEtfPreliminaryLumpSumTest.java @@ -9,11 +9,13 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.laladev.moneyjinn.core.error.ErrorCode; +import org.laladev.moneyjinn.model.access.UserID; import org.laladev.moneyjinn.model.etf.EtfID; import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSumID; import org.laladev.moneyjinn.model.etf.EtfPreliminaryLumpSumIDValues; import org.laladev.moneyjinn.server.builder.EtfPreliminaryLumpSumTransportBuilder; import org.laladev.moneyjinn.server.builder.EtfTransportBuilder; +import org.laladev.moneyjinn.server.builder.UserTransportBuilder; import org.laladev.moneyjinn.server.builder.ValidationItemTransportBuilder; import org.laladev.moneyjinn.server.model.ErrorResponse; import org.laladev.moneyjinn.server.model.EtfPreliminaryLumpSumTransport; @@ -50,18 +52,19 @@ private void testError(final EtfPreliminaryLumpSumTransport transport, final Err void test_standardRequest_Successfull_MinimalReturn() throws Exception { final EtfPreliminaryLumpSumTransport transport = new EtfPreliminaryLumpSumTransportBuilder().for2009().build(); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfId = new EtfID(EtfTransportBuilder.ETF_ID_1); final var year = Year.of(EtfPreliminaryLumpSumTransportBuilder.YEAR_2009); final EtfPreliminaryLumpSumID id = new EtfPreliminaryLumpSumID( new EtfPreliminaryLumpSumIDValues(etfId, year)); - var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertEquals(transport.getAmountAugust(), etfPreliminaryLumpSum.getAmountAugust()); transport.setAmountAugust(TEN); super.callUsecaseExpect204Minimal(transport); - etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertEquals(TEN, etfPreliminaryLumpSum.getAmountAugust()); } @@ -69,12 +72,13 @@ void test_standardRequest_Successfull_MinimalReturn() throws Exception { void test_standardRequest_Successfull_RepresentationReturn() throws Exception { final EtfPreliminaryLumpSumTransport transport = new EtfPreliminaryLumpSumTransportBuilder().for2009().build(); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfId = new EtfID(EtfTransportBuilder.ETF_ID_1); final var year = Year.of(EtfPreliminaryLumpSumTransportBuilder.YEAR_2009); final EtfPreliminaryLumpSumID id = new EtfPreliminaryLumpSumID( new EtfPreliminaryLumpSumIDValues(etfId, year)); - var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertEquals(transport.getAmountAugust(), etfPreliminaryLumpSum.getAmountAugust()); transport.setAmountAugust(TEN); @@ -83,7 +87,7 @@ void test_standardRequest_Successfull_RepresentationReturn() throws Exception { Assertions.assertEquals(transport, actualTransport); - etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertEquals(TEN, etfPreliminaryLumpSum.getAmountAugust()); } @@ -91,18 +95,19 @@ void test_standardRequest_Successfull_RepresentationReturn() throws Exception { void test_standardRequest_Successfull_DefaultReturn() throws Exception { final EtfPreliminaryLumpSumTransport transport = new EtfPreliminaryLumpSumTransportBuilder().for2009().build(); + final UserID userId = new UserID(UserTransportBuilder.USER1_ID); final var etfId = new EtfID(EtfTransportBuilder.ETF_ID_1); final var year = Year.of(EtfPreliminaryLumpSumTransportBuilder.YEAR_2009); final EtfPreliminaryLumpSumID id = new EtfPreliminaryLumpSumID( new EtfPreliminaryLumpSumIDValues(etfId, year)); - var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + var etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertEquals(transport.getAmountAugust(), etfPreliminaryLumpSum.getAmountAugust()); transport.setAmountAugust(TEN); super.callUsecaseExpect204(transport); - etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(id); + etfPreliminaryLumpSum = this.etfService.getEtfPreliminaryLumpSum(userId, id); Assertions.assertEquals(TEN, etfPreliminaryLumpSum.getAmountAugust()); } diff --git a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/etf/CalcEtfSaleTest.java b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/etf/CalcEtfSaleTest.java index 9b117dcf..a6353844 100644 --- a/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/etf/CalcEtfSaleTest.java +++ b/moneyjinn-server/src/test/java/org/laladev/moneyjinn/server/controller/etf/CalcEtfSaleTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test; import org.laladev.moneyjinn.core.error.ErrorCode; import org.laladev.moneyjinn.server.builder.EtfTransportBuilder; +import org.laladev.moneyjinn.server.builder.UserTransportBuilder; import org.laladev.moneyjinn.server.controller.AbstractWebUserControllerTest; import org.laladev.moneyjinn.server.controller.api.EtfControllerApi; import org.laladev.moneyjinn.server.model.CalcEtfSaleRequest; @@ -45,6 +46,25 @@ void test_standardRequest_FullResponseObject() throws Exception { } + @Test + void test_etfOwnedByDifferentGroup_EmptyResponse() throws Exception { + super.setUsername(UserTransportBuilder.ADMIN_NAME); + super.setPassword(UserTransportBuilder.ADMIN_PASSWORD); + + final CalcEtfSaleRequest request = new CalcEtfSaleRequest(); + request.setAskPrice(SETTING_SALE_ASK_PRICE); + request.setBidPrice(SETTING_SALE_BID_PRICE); + request.setEtfId(SETTING_ETF_ID); + request.setPieces(SETTING_SALE_PIECES); + request.setTransactionCosts(SETTING_SALE_TRANSACTION_COSTS); + + final CalcEtfSaleResponse expected = new CalcEtfSaleResponse(); + final CalcEtfSaleResponse actual = super.callUsecaseExpect200(request, CalcEtfSaleResponse.class); + + Assertions.assertEquals(expected, actual); + + } + @Test void test_sellTooMuchPieces_ValidationError() throws Exception { diff --git a/moneyjinn-service-api/src/main/java/org/laladev/moneyjinn/service/api/IEtfService.java b/moneyjinn-service-api/src/main/java/org/laladev/moneyjinn/service/api/IEtfService.java index c985454a..02ce1102 100644 --- a/moneyjinn-service-api/src/main/java/org/laladev/moneyjinn/service/api/IEtfService.java +++ b/moneyjinn-service-api/src/main/java/org/laladev/moneyjinn/service/api/IEtfService.java @@ -66,36 +66,40 @@ public interface IEtfService { // ETF Flows // - List getAllEtfFlowsUntil(EtfID etfId, LocalDateTime timeUntil); + List getAllEtfFlowsUntil(UserID userId, EtfID etfId, LocalDateTime timeUntil); - EtfValue getEtfValueEndOfMonth(EtfIsin etfIsin, Year year, Month month); - - EtfFlow getEtfFlowById(EtfFlowID etfFlowId); + EtfFlow getEtfFlowById(UserID userId, EtfFlowID etfFlowId); - ValidationResult validateEtfFlow(EtfFlow etfFlow); + ValidationResult validateEtfFlow(UserID userId, EtfFlow etfFlow); - EtfFlowID createEtfFlow(EtfFlow etfFlow); + EtfFlowID createEtfFlow(UserID userId, EtfFlow etfFlow); - void updateEtfFlow(EtfFlow etfFlow); + void updateEtfFlow(UserID userId, EtfFlow etfFlow); - void deleteEtfFlow(EtfFlowID etfFlowId); + void deleteEtfFlow(UserID userId, EtfFlowID etfFlowId); - List calculateEffectiveEtfFlows(List etfFlows); + List calculateEffectiveEtfFlows(UserID userId, List etfFlows); // // ETF Preliminary Lump Sum // - EtfPreliminaryLumpSum getEtfPreliminaryLumpSum(EtfPreliminaryLumpSumID id); + EtfPreliminaryLumpSum getEtfPreliminaryLumpSum(UserID userId, EtfPreliminaryLumpSumID id); - List getAllEtfPreliminaryLumpSumYears(EtfID etfId); + List getAllEtfPreliminaryLumpSumYears(UserID userId, EtfID etfId); - ValidationResult validateEtfPreliminaryLumpSum(EtfPreliminaryLumpSum etfPreliminaryLumpSum); + ValidationResult validateEtfPreliminaryLumpSum(UserID userId, EtfPreliminaryLumpSum etfPreliminaryLumpSum); - void createEtfPreliminaryLumpSum(EtfPreliminaryLumpSum etfPreliminaryLumpSum); + void createEtfPreliminaryLumpSum(UserID userId, EtfPreliminaryLumpSum etfPreliminaryLumpSum); - void updateEtfPreliminaryLumpSum(EtfPreliminaryLumpSum etfPreliminaryLumpSum); + void updateEtfPreliminaryLumpSum(UserID userId, EtfPreliminaryLumpSum etfPreliminaryLumpSum); - void deleteEtfPreliminaryLumpSum(EtfPreliminaryLumpSumID id); + void deleteEtfPreliminaryLumpSum(UserID userId, EtfPreliminaryLumpSumID id); + + // + // ETF value + // + + EtfValue getEtfValueEndOfMonth(EtfIsin etfIsin, Year year, Month month); } diff --git a/moneyjinn-service-impl/src/main/java/org/laladev/moneyjinn/service/impl/EtfService.java b/moneyjinn-service-impl/src/main/java/org/laladev/moneyjinn/service/impl/EtfService.java index 10ce3c99..01aabbf2 100644 --- a/moneyjinn-service-impl/src/main/java/org/laladev/moneyjinn/service/impl/EtfService.java +++ b/moneyjinn-service-impl/src/main/java/org/laladev/moneyjinn/service/impl/EtfService.java @@ -221,19 +221,17 @@ public void deleteEtf(final UserID userId, final GroupID groupId, final EtfID et // @Override - public List getAllEtfFlowsUntil(final EtfID etfId, final LocalDateTime timeUntil) { - final List etfFlowData = this.etfDao.getAllFlowsUntil(etfId.getId(), timeUntil); - return super.mapList(etfFlowData, EtfFlow.class); - } - - @Override - public EtfValue getEtfValueEndOfMonth(final EtfIsin etfIsin, final Year year, final Month month) { - final EtfValueData etfValueData = this.etfDao.getEtfValueForMonth(etfIsin, year, month); - return super.map(etfValueData, EtfValue.class); + public List getAllEtfFlowsUntil(final UserID userId, final EtfID etfId, final LocalDateTime timeUntil) { + if (this.getEtfById(userId, etfId) != null) { + final List etfFlowData = this.etfDao.getAllFlowsUntil(etfId.getId(), timeUntil); + return super.mapList(etfFlowData, EtfFlow.class); + } + return Collections.emptyList(); } @Override - public ValidationResult validateEtfFlow(final EtfFlow etfFlow) { + public ValidationResult validateEtfFlow(final UserID userId, final EtfFlow etfFlow) { + Assert.notNull(userId, USER_ID_MUST_NOT_BE_NULL); Assert.notNull(etfFlow, "etfFlow must not be null!"); final ValidationResult validationResult = new ValidationResult(); @@ -255,8 +253,7 @@ public ValidationResult validateEtfFlow(final EtfFlow etfFlow) { if (etfFlow.getEtfId() == null || etfFlow.getEtfId().getId() == null) { addResult.accept(ErrorCode.NO_ETF_SPECIFIED); } else { - // TODO Issue #54 - final EtfData etfData = this.etfDao.getEtfById(666L, etfFlow.getEtfId().getId()); + final EtfData etfData = this.etfDao.getEtfById(userId.getId(), etfFlow.getEtfId().getId()); if (etfData == null) { addResult.accept(ErrorCode.NO_ETF_SPECIFIED); } @@ -266,7 +263,11 @@ public ValidationResult validateEtfFlow(final EtfFlow etfFlow) { } @Override - public ValidationResult validateEtfPreliminaryLumpSum(final EtfPreliminaryLumpSum etfPreliminaryLumpSum) { + public ValidationResult validateEtfPreliminaryLumpSum(final UserID userId, + final EtfPreliminaryLumpSum etfPreliminaryLumpSum) { + Assert.notNull(userId, USER_ID_MUST_NOT_BE_NULL); + Assert.notNull(etfPreliminaryLumpSum, "etfPreliminaryLumpSum must not be null!"); + final ValidationResult validationResult = new ValidationResult(); final Consumer addResult = (final ErrorCode errorCode) -> validationResult.addValidationResultItem( new ValidationResultItem(null, errorCode)); @@ -280,8 +281,7 @@ public ValidationResult validateEtfPreliminaryLumpSum(final EtfPreliminaryLumpSu if (idValues.getEtfId() == null || idValues.getEtfId().getId() == null) { addResult.accept(ErrorCode.NO_ETF_SPECIFIED); } else { - // TODO Issue #54 - final EtfData etfData = this.etfDao.getEtfById(666L, + final EtfData etfData = this.etfDao.getEtfById(userId.getId(), etfPreliminaryLumpSum.getId().getId().getEtfId().getId()); if (etfData == null) { addResult.accept(ErrorCode.NO_ETF_SPECIFIED); @@ -297,15 +297,23 @@ public ValidationResult validateEtfPreliminaryLumpSum(final EtfPreliminaryLumpSu } @Override - public EtfFlow getEtfFlowById(final EtfFlowID etfFlowId) { + public EtfFlow getEtfFlowById(final UserID userId, final EtfFlowID etfFlowId) { + Assert.notNull(userId, USER_ID_MUST_NOT_BE_NULL); Assert.notNull(etfFlowId, "etfFlowId must not be null!"); final EtfFlowData etfFlowData = this.etfDao.getEtfFowById(etfFlowId.getId()); - return super.map(etfFlowData, EtfFlow.class); + if (etfFlowData != null) { + final EtfFlow etfFlow = super.map(etfFlowData, EtfFlow.class); + if (this.getEtfById(userId, etfFlow.getEtfId()) != null) { + return etfFlow; + } + } + return null; } @Override - public EtfFlowID createEtfFlow(final EtfFlow etfFlow) { - final ValidationResult validationResult = this.validateEtfFlow(etfFlow); + public EtfFlowID createEtfFlow(final UserID userId, final EtfFlow etfFlow) { + Assert.notNull(userId, USER_ID_MUST_NOT_BE_NULL); + final ValidationResult validationResult = this.validateEtfFlow(userId, etfFlow); if (!validationResult.isValid() && !validationResult.getValidationResultItems().isEmpty()) { final ValidationResultItem validationResultItem = validationResult.getValidationResultItems().get(0); throw new BusinessException("EtfFlow creation failed!", validationResultItem.getError()); @@ -316,8 +324,9 @@ public EtfFlowID createEtfFlow(final EtfFlow etfFlow) { } @Override - public void updateEtfFlow(final EtfFlow etfFlow) { - final ValidationResult validationResult = this.validateEtfFlow(etfFlow); + public void updateEtfFlow(final UserID userId, final EtfFlow etfFlow) { + Assert.notNull(userId, USER_ID_MUST_NOT_BE_NULL); + final ValidationResult validationResult = this.validateEtfFlow(userId, etfFlow); if (!validationResult.isValid() && !validationResult.getValidationResultItems().isEmpty()) { final ValidationResultItem validationResultItem = validationResult.getValidationResultItems().get(0); throw new BusinessException("EtfFlow update failed!", validationResultItem.getError()); @@ -327,13 +336,18 @@ public void updateEtfFlow(final EtfFlow etfFlow) { } @Override - public void deleteEtfFlow(final EtfFlowID etfFlowId) { + public void deleteEtfFlow(final UserID userId, final EtfFlowID etfFlowId) { + Assert.notNull(userId, USER_ID_MUST_NOT_BE_NULL); Assert.notNull(etfFlowId, "etfFlowId must not be null!"); - this.etfDao.deleteEtfFlow(etfFlowId.getId()); + + final EtfFlow etfFlow = this.getEtfFlowById(userId, etfFlowId); + if (etfFlow != null) { + this.etfDao.deleteEtfFlow(etfFlowId.getId()); + } } @Override - public List calculateEffectiveEtfFlows(final List allEtfFlows) { + public List calculateEffectiveEtfFlows(final UserID userId, final List allEtfFlows) { final LocalDateTime now = LocalDate.now().atTime(LocalTime.MAX); final Map> etfFlowsByEtfIdMap = allEtfFlows.stream() .collect(Collectors.groupingBy(EtfFlow::getEtfId)); @@ -341,7 +355,8 @@ public List calculateEffectiveEtfFlows(final List a final List relevantEtfFlows = new ArrayList<>(); for (final var etfFlowsByEtfIdMapEntry : etfFlowsByEtfIdMap.entrySet()) { final var etfFlows = etfFlowsByEtfIdMapEntry.getValue(); - final var etfPreliminaryLumpSums = this.getAllEtfPreliminaryLumpSums(etfFlowsByEtfIdMapEntry.getKey()); + final var etfPreliminaryLumpSums = this.getAllEtfPreliminaryLumpSums(userId, + etfFlowsByEtfIdMapEntry.getKey()); final List etfBuyFlows = this.calculateEffectiveEtfFlowsUntil(etfFlows, now); // initialize accumulated preliminary lump sum to 0 for each effective flow @@ -447,34 +462,59 @@ private List calculateEffectiveEtfFlowsUntil(final List etfFlo // Etf Preliminary Lump Sum // - private List getAllEtfPreliminaryLumpSums(final EtfID etfId) { - final List datas = this.etfDao.getAllPreliminaryLumpSum(etfId.getId()); - return super.mapList(datas, EtfPreliminaryLumpSum.class); + private List getAllEtfPreliminaryLumpSums(final UserID userId, final EtfID etfId) { + Assert.notNull(userId, USER_ID_MUST_NOT_BE_NULL); + Assert.notNull(etfId, "etfId must not be null!"); + + final Etf etf = this.getEtfById(userId, etfId); + if (etf != null) { + final List datas = this.etfDao.getAllPreliminaryLumpSum(etfId.getId()); + return super.mapList(datas, EtfPreliminaryLumpSum.class); + } else { + return null; + } } @Override - public EtfPreliminaryLumpSum getEtfPreliminaryLumpSum(final EtfPreliminaryLumpSumID id) { + public EtfPreliminaryLumpSum getEtfPreliminaryLumpSum(final UserID userId, final EtfPreliminaryLumpSumID id) { + Assert.notNull(userId, USER_ID_MUST_NOT_BE_NULL); + Assert.notNull(id, "id must not be null!"); + final var idValues = id.getId(); - final EtfPreliminaryLumpSumData data = this.etfDao.getPreliminaryLumpSum(idValues.getEtfId().getId(), - idValues.getYear()); - return super.map(data, EtfPreliminaryLumpSum.class); + final Etf etf = this.getEtfById(userId, idValues.getEtfId()); + if (etf != null) { + final EtfPreliminaryLumpSumData data = this.etfDao.getPreliminaryLumpSum(idValues.getEtfId().getId(), + idValues.getYear()); + return super.map(data, EtfPreliminaryLumpSum.class); + } else { + return null; + } } @Override - public List getAllEtfPreliminaryLumpSumYears(final EtfID etfId) { - final List datas = this.etfDao.getAllPreliminaryLumpSumYears(etfId.getId()); - return datas.stream().map(Year::of).toList(); + public List getAllEtfPreliminaryLumpSumYears(final UserID userId, final EtfID etfId) { + Assert.notNull(userId, USER_ID_MUST_NOT_BE_NULL); + Assert.notNull(etfId, "etfId must not be null!"); + final Etf etf = this.getEtfById(userId, etfId); + if (etf != null) { + final List datas = this.etfDao.getAllPreliminaryLumpSumYears(etfId.getId()); + return datas.stream().map(Year::of).toList(); + } else { + return Collections.emptyList(); + } } @Override - public void createEtfPreliminaryLumpSum(final EtfPreliminaryLumpSum etfPreliminaryLumpSum) { - final ValidationResult validationResult = this.validateEtfPreliminaryLumpSum(etfPreliminaryLumpSum); + public void createEtfPreliminaryLumpSum(final UserID userId, final EtfPreliminaryLumpSum etfPreliminaryLumpSum) { + Assert.notNull(userId, USER_ID_MUST_NOT_BE_NULL); + Assert.notNull(etfPreliminaryLumpSum, "etfPreliminaryLumpSum must not be null!"); + final ValidationResult validationResult = this.validateEtfPreliminaryLumpSum(userId, etfPreliminaryLumpSum); if (!validationResult.isValid() && !validationResult.getValidationResultItems().isEmpty()) { final ValidationResultItem validationResultItem = validationResult.getValidationResultItems().get(0); throw new BusinessException("EtfPreliminaryLumpSum creation failed!", validationResultItem.getError()); } - final var etfPreliminaryLumpSumExists = this.getEtfPreliminaryLumpSum(etfPreliminaryLumpSum.getId()); + final var etfPreliminaryLumpSumExists = this.getEtfPreliminaryLumpSum(userId, etfPreliminaryLumpSum.getId()); if (etfPreliminaryLumpSumExists != null) { throw new BusinessException("EtfPreliminaryLumpSum already exists!", ErrorCode.ETF_PRELIMINARY_LUMP_SUM_ALREADY_EXISTS); @@ -484,13 +524,15 @@ public void createEtfPreliminaryLumpSum(final EtfPreliminaryLumpSum etfPrelimina } @Override - public void updateEtfPreliminaryLumpSum(final EtfPreliminaryLumpSum etfPreliminaryLumpSum) { - final ValidationResult validationResult = this.validateEtfPreliminaryLumpSum(etfPreliminaryLumpSum); + public void updateEtfPreliminaryLumpSum(final UserID userId, final EtfPreliminaryLumpSum etfPreliminaryLumpSum) { + Assert.notNull(userId, USER_ID_MUST_NOT_BE_NULL); + Assert.notNull(etfPreliminaryLumpSum, "etfPreliminaryLumpSum must not be null!"); + final ValidationResult validationResult = this.validateEtfPreliminaryLumpSum(userId, etfPreliminaryLumpSum); if (!validationResult.isValid() && !validationResult.getValidationResultItems().isEmpty()) { final ValidationResultItem validationResultItem = validationResult.getValidationResultItems().get(0); throw new BusinessException("EtfPreliminaryLumpSum creation failed!", validationResultItem.getError()); } - final var etfPreliminaryLumpSumExists = this.getEtfPreliminaryLumpSum(etfPreliminaryLumpSum.getId()); + final var etfPreliminaryLumpSumExists = this.getEtfPreliminaryLumpSum(userId, etfPreliminaryLumpSum.getId()); if (etfPreliminaryLumpSumExists == null) { throw new BusinessException("EtfPreliminaryLumpSum does not exist!", ErrorCode.ETF_PRELIMINARY_LUMP_SUM_DOES_NOT_EXIST); @@ -500,7 +542,8 @@ public void updateEtfPreliminaryLumpSum(final EtfPreliminaryLumpSum etfPrelimina } @Override - public void deleteEtfPreliminaryLumpSum(final EtfPreliminaryLumpSumID id) { + public void deleteEtfPreliminaryLumpSum(final UserID userId, final EtfPreliminaryLumpSumID id) { + Assert.notNull(userId, USER_ID_MUST_NOT_BE_NULL); Assert.notNull(id, "ID must not be null!"); final var idValues = id.getId(); Assert.notNull(idValues, "ID must not be null!"); @@ -508,7 +551,19 @@ public void deleteEtfPreliminaryLumpSum(final EtfPreliminaryLumpSumID id) { Assert.notNull(idValues.getEtfId().getId(), "ISIN must not be null!"); Assert.notNull(idValues.getYear(), "year must not be null!"); - this.etfDao.deletePreliminaryLumpSum(idValues.getEtfId().getId(), idValues.getYear()); + final Etf etf = this.getEtfById(userId, idValues.getEtfId()); + if (etf != null) { + this.etfDao.deletePreliminaryLumpSum(idValues.getEtfId().getId(), idValues.getYear()); + } } + // + // ETF value + // + + @Override + public EtfValue getEtfValueEndOfMonth(final EtfIsin etfIsin, final Year year, final Month month) { + final EtfValueData etfValueData = this.etfDao.getEtfValueForMonth(etfIsin, year, month); + return super.map(etfValueData, EtfValue.class); + } } diff --git a/moneyjinn-service-impl/src/main/resources/org/laladev/moneyjinn/service/dao/mapper/IEtfDaoMapper.xml b/moneyjinn-service-impl/src/main/resources/org/laladev/moneyjinn/service/dao/mapper/IEtfDaoMapper.xml index d8dc9b7a..da6ec930 100644 --- a/moneyjinn-service-impl/src/main/resources/org/laladev/moneyjinn/service/dao/mapper/IEtfDaoMapper.xml +++ b/moneyjinn-service-impl/src/main/resources/org/laladev/moneyjinn/service/dao/mapper/IEtfDaoMapper.xml @@ -60,10 +60,10 @@ SELECT FROM vw_etf WHERE etfid = #{etfid} + AND mar_mau_userid = #{mauUserId} AND NOW() BETWEEN maf_validfrom AND maf_validtil LIMIT 1 -