Aman-Mittal commented on code in PR #155:
URL: 
https://github.com/apache/fineract-consumer-facing/pull/155#discussion_r4385517936


##########
consumer/src/main/java/org/apache/fineract/consumer/savings/command/service/SavingsCommandServiceImpl.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.consumer.savings.command.service;
+
+import java.time.LocalDate;
+import java.time.ZoneOffset;
+import java.util.Set;
+import java.util.UUID;
+import java.util.function.Supplier;
+import lombok.RequiredArgsConstructor;
+import org.apache.fineract.consumer.infrastructure.access.data.ConsumerAction;
+import 
org.apache.fineract.consumer.infrastructure.access.service.AccessPolicyEvaluator;
+import 
org.apache.fineract.consumer.infrastructure.access.service.OwnedAccountsCache;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.EnumOptionData;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.PostSavingsAccountsAccountIdRequest;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.PostSavingsAccountsAccountIdResponse;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.PostSavingsAccountsRequest;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.PostSavingsAccountsResponse;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.PutSavingsAccountsAccountIdRequest;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.PutSavingsAccountsAccountIdResponse;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.SavingsAccountData;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.service.FineractCaller;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.service.SavingsAccountApiClient;
+import 
org.apache.fineract.consumer.infrastructure.idempotency.service.IdempotencyKeyDeriver;
+import 
org.apache.fineract.consumer.infrastructure.idempotency.service.IdempotencyKeyHolder;
+import 
org.apache.fineract.consumer.savings.command.data.ModifySavingsApplicationCommand;
+import 
org.apache.fineract.consumer.savings.command.data.SavingsApplicationCommandData;
+import 
org.apache.fineract.consumer.savings.command.data.SubmitSavingsApplicationCommand;
+import 
org.apache.fineract.consumer.savings.command.data.WithdrawSavingsApplicationCommand;
+import 
org.apache.fineract.consumer.savings.command.exception.SavingsApplicationInvalidException;
+import 
org.apache.fineract.consumer.savings.command.exception.SavingsCommandAccessDeniedException;
+import 
org.apache.fineract.consumer.savings.command.exception.SavingsCommandInProgressException;
+import 
org.apache.fineract.consumer.savings.command.exception.SavingsCommandNotFoundException;
+import 
org.apache.fineract.consumer.savings.command.exception.SavingsCommandUpstreamUnavailableException;
+import org.apache.fineract.consumer.user.query.data.UserQueryData;
+import org.apache.fineract.consumer.user.query.service.UserQueryService;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.security.oauth2.jwt.Jwt;
+import org.springframework.stereotype.Service;
+
+@Service
+@RequiredArgsConstructor
+public class SavingsCommandServiceImpl implements SavingsCommandService {
+
+    private static final String LOCALE = "en";
+    private static final String DATE_FORMAT = "yyyy-MM-dd";
+    private static final Long SAVINGS_DEPOSIT_TYPE_ID = 100L;
+
+    @Value("${consumer.savings.command.allowed-product-ids:}")
+    private Set<Long> allowedProductIds;
+
+    private final UserQueryService userQueryService;
+    private final AccessPolicyEvaluator accessPolicyEvaluator;
+    private final OwnedAccountsCache ownedAccountsCache;
+    private final IdempotencyKeyHolder idempotencyKeyHolder;
+    private final SavingsAccountApiClient savingsAccountApiClient;
+
+    @Override
+    public SavingsApplicationCommandData submitApplication(Jwt jwt, 
SubmitSavingsApplicationCommand command) {
+        accessPolicyEvaluator.authorize(jwt, 
ConsumerAction.SAVINGS_APPLICATION_SUBMIT);
+        validateProductAllowList(command.getProductId());
+        Long clientId = resolveClientId(jwt);
+        LocalDate submittedOnDate = LocalDate.now(ZoneOffset.UTC);

Review Comment:
   **Blocking: UTC "today" isn't the date Fineract checks against.** 
`SavingsAccount` rejects `submittedOnDate` with `cannot.be.a.future.date` when 
`DateUtils.isAfterBusinessDate(...)` is true. The business date comes from the 
tenant context: the tenant time zone, or the stored business date when 
`enable-business-date` is on. Two cases fail:
   - **A tenant behind UTC** (e.g. UTC-5) after 19:00 local: UTC is already 
tomorrow, so every application and withdrawal (L116) in the evening is a 400.
   - **A tenant with business dates enabled** where COB hasn't advanced: every 
submit is a 400 until it does.
   
   CI passes only because the test Fineract is UTC with no business date. 
Please use Fineract's business date (`GET /businessdate/BUSINESS_DATE`, cached 
briefly), or at least the tenant time zone. Add a unit test with a fixed 
`Clock` around midnight.



##########
consumer/src/main/java/org/apache/fineract/consumer/savings/command/service/SavingsCommandServiceImpl.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.consumer.savings.command.service;
+
+import java.time.LocalDate;
+import java.time.ZoneOffset;
+import java.util.Set;
+import java.util.UUID;
+import java.util.function.Supplier;
+import lombok.RequiredArgsConstructor;
+import org.apache.fineract.consumer.infrastructure.access.data.ConsumerAction;
+import 
org.apache.fineract.consumer.infrastructure.access.service.AccessPolicyEvaluator;
+import 
org.apache.fineract.consumer.infrastructure.access.service.OwnedAccountsCache;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.EnumOptionData;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.PostSavingsAccountsAccountIdRequest;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.PostSavingsAccountsAccountIdResponse;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.PostSavingsAccountsRequest;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.PostSavingsAccountsResponse;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.PutSavingsAccountsAccountIdRequest;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.PutSavingsAccountsAccountIdResponse;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.generated.model.SavingsAccountData;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.service.FineractCaller;
+import 
org.apache.fineract.consumer.infrastructure.fineractclient.service.SavingsAccountApiClient;
+import 
org.apache.fineract.consumer.infrastructure.idempotency.service.IdempotencyKeyDeriver;
+import 
org.apache.fineract.consumer.infrastructure.idempotency.service.IdempotencyKeyHolder;
+import 
org.apache.fineract.consumer.savings.command.data.ModifySavingsApplicationCommand;
+import 
org.apache.fineract.consumer.savings.command.data.SavingsApplicationCommandData;
+import 
org.apache.fineract.consumer.savings.command.data.SubmitSavingsApplicationCommand;
+import 
org.apache.fineract.consumer.savings.command.data.WithdrawSavingsApplicationCommand;
+import 
org.apache.fineract.consumer.savings.command.exception.SavingsApplicationInvalidException;
+import 
org.apache.fineract.consumer.savings.command.exception.SavingsCommandAccessDeniedException;
+import 
org.apache.fineract.consumer.savings.command.exception.SavingsCommandInProgressException;
+import 
org.apache.fineract.consumer.savings.command.exception.SavingsCommandNotFoundException;
+import 
org.apache.fineract.consumer.savings.command.exception.SavingsCommandUpstreamUnavailableException;
+import org.apache.fineract.consumer.user.query.data.UserQueryData;
+import org.apache.fineract.consumer.user.query.service.UserQueryService;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.security.oauth2.jwt.Jwt;
+import org.springframework.stereotype.Service;
+
+@Service
+@RequiredArgsConstructor
+public class SavingsCommandServiceImpl implements SavingsCommandService {
+
+    private static final String LOCALE = "en";
+    private static final String DATE_FORMAT = "yyyy-MM-dd";
+    private static final Long SAVINGS_DEPOSIT_TYPE_ID = 100L;
+
+    @Value("${consumer.savings.command.allowed-product-ids:}")
+    private Set<Long> allowedProductIds;
+
+    private final UserQueryService userQueryService;
+    private final AccessPolicyEvaluator accessPolicyEvaluator;
+    private final OwnedAccountsCache ownedAccountsCache;
+    private final IdempotencyKeyHolder idempotencyKeyHolder;
+    private final SavingsAccountApiClient savingsAccountApiClient;
+
+    @Override
+    public SavingsApplicationCommandData submitApplication(Jwt jwt, 
SubmitSavingsApplicationCommand command) {
+        accessPolicyEvaluator.authorize(jwt, 
ConsumerAction.SAVINGS_APPLICATION_SUBMIT);
+        validateProductAllowList(command.getProductId());
+        Long clientId = resolveClientId(jwt);
+        LocalDate submittedOnDate = LocalDate.now(ZoneOffset.UTC);
+        PostSavingsAccountsRequest request = buildSubmitRequest(command, 
clientId, submittedOnDate);
+        PostSavingsAccountsResponse response = callWithIdempotency(jwt, 
command.getIdempotencyKey(),
+                () -> 
savingsAccountApiClient.submitSavingsApplication(request));
+        ownedAccountsCache.evict(clientId);
+        return SavingsApplicationCommandData.builder()
+                .savingsId(response.getSavingsId())
+                .resourceId(response.getResourceId())
+                .clientId(clientId)
+                .build();
+    }
+
+    @Override
+    public SavingsApplicationCommandData modifyApplication(Jwt jwt, 
ModifySavingsApplicationCommand command) {
+        accessPolicyEvaluator.authorize(jwt, 
ConsumerAction.SAVINGS_APPLICATION_MODIFY, command.getSavingsId(),
+                SavingsCommandAccessDeniedException::new);
+        validateProductAllowList(command.getProductId());
+        validateSavingsDepositType(command.getSavingsId());
+        Long clientId = resolveClientId(jwt);
+        LocalDate submittedOnDate = LocalDate.now(ZoneOffset.UTC);

Review Comment:
   **Blocking: modify rewrites the submission date to today.** Each modify 
(e.g. a product change) sends `submittedOnDate = now`, so an application 
submitted last week now says it was submitted today. Reports and the 
back-office queue will show the wrong date.
   
   Fineract's `validateForUpdate` treats each field as optional, so please 
don't send `submittedOnDate` on modify at all; send only `productId` (+ 
`locale`). A unit test asserting the PUT body has no `submittedOnDate` would 
pin it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to