adamsaghy commented on code in PR #4319:
URL: https://github.com/apache/fineract/pull/4319#discussion_r1950623469


##########
fineract-migration-loan/src/main/java/org/apache/fineract/migrationloan/service/LoanMigrationWritePlatformServiceImpl.java:
##########
@@ -0,0 +1,77 @@
+/**
+ * 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.migrationloan.service;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
+import java.util.Locale;
+import lombok.AllArgsConstructor;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import 
org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
+import org.apache.fineract.infrastructure.core.domain.ExternalId;
+import 
org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
+import org.apache.fineract.migrationloan.domain.LoanMigration;
+import org.apache.fineract.migrationloan.domain.LoanMigrationRepository;
+import org.apache.fineract.portfolio.loanaccount.domain.Loan;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@AllArgsConstructor
+@Transactional
+public class LoanMigrationWritePlatformServiceImpl implements 
LoanMigrationWritePlatformService {
+
+    private final LoanMigrationRepository loanMigrationRepository;
+    private final LoanRepositoryWrapper loanRepositoryWrapper;
+
+    @Override
+    public CommandProcessingResult createMigration(ExternalId loanExternalId, 
String date, String dateFormat, String locale,
+            String action) {
+        Loan loan = 
loanRepositoryWrapper.findOneWithNotFoundDetection(loanExternalId);
+        return processMigrationCreation(loan, date, dateFormat, locale, 
action);
+    }
+
+    @Override
+    public CommandProcessingResult createMigration(Long loanId, String date, 
String dateFormat, String locale, String action) {
+        Loan loan = loanRepositoryWrapper.findOneWithNotFoundDetection(loanId);
+        return processMigrationCreation(loan, date, dateFormat, locale, 
action);
+    }
+
+    private CommandProcessingResult processMigrationCreation(Loan loan, String 
date, String dateFormat, String locale, String action) {
+        LocalDateTime migrationDate = parseDate(date, dateFormat, locale);
+
+        LoanMigration migration = LoanMigration.newInstance(loan, 
migrationDate, action);

Review Comment:
   Please add validations:
   - We cannot mark completed or failed migration if it was never started for 
the loan: only loans where migration is IN PROGRESS can be marked as FAILED or 
COMPLETED
   - We cannot mark loan as IN PROGRESS twice...
   etc.



-- 
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