FINERACT-1017: Fixing LoanImport integration tests

This commit is contained in:
Petri Tuomola
2020-06-03 22:25:36 +02:00
committed by Michael Vorburger ⛑️
parent 7a2d459af3
commit 14b14aecac
5 changed files with 115 additions and 79 deletions
@@ -111,9 +111,9 @@ public class LoanImportHandler implements ImportHandler {
if (repaymentAmount!=null&&lastRepaymentDate!=null&&repaymentType!=null&&repaymentTypeId!=null) {
return LoanTransactionData.importInstance(repaymentAmount, lastRepaymentDate, repaymentTypeId,
row.getRowNum(), locale, dateFormat);
} else {
return null;
}
return null;
}
private DisbursementData readDisbursalData(Row row,String locale,String dateFormat) {
@@ -133,9 +133,9 @@ public class LoanImportHandler implements ImportHandler {
LocalDate approvedDate = ImportHandlerUtils.readAsDate(LoanConstants.APPROVED_DATE_COL, row);
if (approvedDate!=null) {
return LoanApprovalData.importInstance(approvedDate, row.getRowNum(), locale, dateFormat);
} else {
return null;
}
return null;
}
private LoanAccountData readLoan(Row row,String locale,String dateFormat) {
@@ -324,9 +324,9 @@ public class LoanImportHandler implements ImportHandler {
repaymentStrategyId, graceOnPrincipalPayment, graceOnInterestPayment, graceOnInterestCharged,
interestChargedFromDate, firstRepaymentOnDate, row.getRowNum(), externalId, linkAccountId,locale,dateFormat);
}
}else {
return null;
}
return null;
}
public Count importEntity(String dateFormat) {
@@ -419,7 +419,8 @@ public class LoanImportHandler implements ImportHandler {
.loanRepaymentTransaction(result.getLoanId()) //
.withJson(payload) //
.build(); //
final CommandProcessingResult loanRepaymentResult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
commandsSourceWritePlatformService.logCommandSource(commandRequest);
return 4;
}
@@ -436,14 +437,15 @@ public class LoanImportHandler implements ImportHandler {
.disburseLoanToSavingsApplication(result.getLoanId()) //
.withJson(payload) //
.build(); //
final CommandProcessingResult loanDisburseToSavingsResult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
commandsSourceWritePlatformService.logCommandSource(commandRequest);
} else {
String payload = gsonBuilder.create().toJson(disbusalData);
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.disburseLoanApplication(result.getLoanId()) //
.withJson(payload) //
.build(); //
final CommandProcessingResult loanDisburseResult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
}
return 3;
@@ -458,7 +460,8 @@ public class LoanImportHandler implements ImportHandler {
.approveLoanApplication(result.getLoanId()) //
.withJson(payload) //
.build(); //
final CommandProcessingResult loanapprovalresult = commandsSourceWritePlatformService.logCommandSource(commandRequest);
commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
return 2;
}
@@ -471,6 +474,7 @@ public class LoanImportHandler implements ImportHandler {
loanJsonOb.remove("isLoanProductLinkedToFloatingRate");
loanJsonOb.remove("isInterestRecalculationEnabled");
loanJsonOb.remove("isFloatingInterestRate");
loanJsonOb.remove("isRatesEnabled");
JsonArray chargesJsonAr=loanJsonOb.getAsJsonArray("charges");
if (chargesJsonAr!=null) {
for (int i = 0; i < chargesJsonAr.size(); i++) {
@@ -72,7 +72,7 @@ public class ExtrasSheetPopulator extends AbstractWorkbookPopulator {
int currencyCodeRowIndex = 1;
for (CurrencyData currencies : currencies) {
Row row;
if (currencyCodeRowIndex < paymentTypeRowIndex) {
if (currencyCodeRowIndex < paymentTypeRowIndex || currencyCodeRowIndex < fundRowIndex) {
row = extrasSheet.getRow(currencyCodeRowIndex++);
} else {
row = extrasSheet.createRow(currencyCodeRowIndex++);
@@ -18,7 +18,6 @@
*/
package org.apache.fineract.infrastructure.bulkimport.service;
import com.google.common.io.Files;
import com.sun.jersey.core.header.FormDataContentDisposition;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -33,10 +32,8 @@ import javax.ws.rs.core.Response;
import org.apache.fineract.infrastructure.bulkimport.data.BulkImportEvent;
import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
import org.apache.fineract.infrastructure.bulkimport.data.ImportData;
import org.apache.fineract.infrastructure.bulkimport.data.ImportFormatType;
import org.apache.fineract.infrastructure.bulkimport.domain.ImportDocument;
import org.apache.fineract.infrastructure.bulkimport.domain.ImportDocumentRepository;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler;
import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandlerUtils;
import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
@@ -61,7 +58,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
@Service
@@ -102,8 +98,6 @@ public class BulkImportWorkbookServiceImpl implements BulkImportWorkbookService
final Tika tika = new Tika();
final TikaInputStream tikaInputStream = TikaInputStream.get(clonedInputStream);
final String fileType = tika.detect(tikaInputStream);
final String fileExtension = Files.getFileExtension(fileDetail.getFileName()).toLowerCase();
ImportFormatType format = ImportFormatType.of(fileExtension);
if (!fileType.contains("msoffice") && !fileType.contains("application/vnd.ms-excel")) {
// We had a problem where we tried to upload the downloaded file from the import options, it was somehow changed the
// extension we use this fix.
@@ -114,7 +108,6 @@ public class BulkImportWorkbookServiceImpl implements BulkImportWorkbookService
Workbook workbook = new HSSFWorkbook(clonedInputStreamWorkbook);
GlobalEntityType entityType=null;
int primaryColumn=0;
ImportHandler importHandler = null;
if (entity.trim().equalsIgnoreCase(GlobalEntityType.CLIENTS_PERSON.toString())) {
entityType = GlobalEntityType.CLIENTS_PERSON;
primaryColumn = 0;
@@ -173,14 +166,15 @@ public class BulkImportWorkbookServiceImpl implements BulkImportWorkbookService
entityType = GlobalEntityType.USERS;
primaryColumn = 0;
}else{
workbook.close();
throw new GeneralPlatformDomainRuleException("error.msg.unable.to.find.resource",
"Unable to find requested resource");
}
return publishEvent(primaryColumn, fileDetail, clonedInputStreamWorkbook, entityType,
workbook, locale, dateFormat);
}else {
throw new GeneralPlatformDomainRuleException("error.msg.null","One or more of the given parameters not found");
}
throw new GeneralPlatformDomainRuleException("error.msg.null","One or more of the given parameters not found");
} catch (IOException e) {
LOG.error("Problem occurred in importWorkbook function",e);
throw new GeneralPlatformDomainRuleException("error.msg.io.exception","IO exception occured with "+fileDetail.getFileName()+" "+e.getMessage());
@@ -196,8 +190,6 @@ public class BulkImportWorkbookServiceImpl implements BulkImportWorkbookService
final String fileName = fileDetail.getFileName();
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
final Long documentId = this.documentWritePlatformService.createInternalDocument(
DocumentWritePlatformServiceJpaRepositoryImpl.DocumentManagementEntity.IMPORT.name(),
this.securityContext.authenticatedUser().getId(), null, clonedInputStreamWorkbook,
@@ -280,7 +272,7 @@ public class BulkImportWorkbookServiceImpl implements BulkImportWorkbookService
String fileName="Output"+documentData.fileName();
String fileLocation=documentData.fileLocation();
File file=new File(fileLocation);
final Response.ResponseBuilder response = Response.ok((Object)file);
final Response.ResponseBuilder response = Response.ok(file);
response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.header("Content-Type", "application/vnd.ms-excel");
return response.build();
@@ -295,7 +287,7 @@ public class BulkImportWorkbookServiceImpl implements BulkImportWorkbookService
return sql.toString();
}
@Override
public DocumentData mapRow (ResultSet rs,int rowNum) throws SQLException {
public DocumentData mapRow (ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException {
final String location = rs.getString("location");
final String fileName=rs.getString("file_name");
return new DocumentData(null,null,null,null,fileName,