Merge pull request #1060 from chandrikamohith/MIFOSX-1252Java
MIFOSX-1252 Assign/Unassign staff for Savings account-java srcs.MIFOSX-1...
This commit is contained in:
@@ -559,7 +559,15 @@ public class CommandWrapper {
|
||||
public boolean isAdjustSavingsAccountTransaction() {
|
||||
return this.actionName.equalsIgnoreCase("ADJUSTTRANSACTION") && this.entityName.equalsIgnoreCase("SAVINGSACCOUNT");
|
||||
}
|
||||
|
||||
public boolean isAssignStaffSavingsAccount(){
|
||||
return this.actionName.equalsIgnoreCase("ASSIGNFIELDOFFICER") && this.entityName.equalsIgnoreCase("SAVINGSACCOUNT");
|
||||
}
|
||||
|
||||
public boolean isUnAssignStaffSavingsAccount(){
|
||||
return this.actionName.equalsIgnoreCase("UNASSIGNFIELDOFFICER") && this.entityName.equalsIgnoreCase("SAVINGSACCOUNT");
|
||||
}
|
||||
|
||||
public boolean isSavingsAccountChargeResource() {
|
||||
return this.entityName.equalsIgnoreCase("SAVINGSACCOUNTCHARGE");
|
||||
}
|
||||
|
||||
+15
@@ -2049,5 +2049,20 @@ public class CommandWrapperBuilder {
|
||||
this.entityId = entityId;
|
||||
return this;
|
||||
}
|
||||
public CommandWrapperBuilder assignFieldOfficer(final Long accountId) {
|
||||
this.actionName = "ASSIGNFIELDOFFICER";
|
||||
this.entityName = "SAVINGSACCOUNT";
|
||||
this.entityId = accountId;
|
||||
this.href = "/savingsaccounts/" + accountId + "?command=assignFieldOfficer";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder unassignFieldOfficer(final Long accountId) {
|
||||
this.actionName = "UNASSIGNFIELDOFFICER";
|
||||
this.entityName = "SAVINGSACCOUNT";
|
||||
this.entityId = accountId;
|
||||
this.href = "/savingsaccounts/" + accountId + "?command=unassignFieldOfficer";
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
+6
-1
@@ -492,7 +492,12 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
||||
handler = this.applicationContext.getBean("savingsTransactionAdjustmentCommandHandler", NewCommandSourceHandler.class);
|
||||
} else if (wrapper.isSavingsAccountClose()) {
|
||||
handler = this.applicationContext.getBean("closeSavingsAccountCommandHandler", NewCommandSourceHandler.class);
|
||||
} else {
|
||||
}else if(wrapper.isAssignStaffSavingsAccount()) {
|
||||
handler = this.applicationContext.getBean("assignFieldOfficerSavingsAccountCommandHandler", NewCommandSourceHandler.class);
|
||||
}else if(wrapper.isUnAssignStaffSavingsAccount()) {
|
||||
handler = this.applicationContext.getBean("unassignFieldOfficerSavingsAccountCommandHandler", NewCommandSourceHandler.class);
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedCommandException(wrapper.commandName());
|
||||
}
|
||||
} else if (wrapper.isSavingsAccountChargeResource()) {
|
||||
|
||||
+10
-2
@@ -5,6 +5,8 @@
|
||||
*/
|
||||
package org.mifosplatform.portfolio.accountdetails.data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||
import org.mifosplatform.portfolio.loanaccount.data.LoanApplicationTimelineData;
|
||||
import org.mifosplatform.portfolio.loanaccount.data.LoanStatusEnumData;
|
||||
@@ -26,10 +28,13 @@ public class LoanAccountSummaryData {
|
||||
private final Integer loanCycle;
|
||||
private final LoanApplicationTimelineData timeline;
|
||||
private final Boolean inArrears;
|
||||
|
||||
private final BigDecimal originalLoan;
|
||||
private final BigDecimal loanBalance;
|
||||
private final BigDecimal amountPaid;
|
||||
|
||||
public LoanAccountSummaryData(final Long id, final String accountNo, final String externalId, final Long productId,
|
||||
final String loanProductName, final String shortLoanProductName, final LoanStatusEnumData loanStatus, final EnumOptionData loanType, final Integer loanCycle,
|
||||
final LoanApplicationTimelineData timeline, final Boolean inArrears) {
|
||||
final LoanApplicationTimelineData timeline, final Boolean inArrears,final BigDecimal originalLoan,final BigDecimal loanBalance,final BigDecimal amountPaid) {
|
||||
this.id = id;
|
||||
this.accountNo = accountNo;
|
||||
this.externalId = externalId;
|
||||
@@ -41,5 +46,8 @@ public class LoanAccountSummaryData {
|
||||
this.loanCycle = loanCycle;
|
||||
this.timeline = timeline;
|
||||
this.inArrears = inArrears;
|
||||
this.loanBalance = loanBalance;
|
||||
this.originalLoan = originalLoan;
|
||||
this.amountPaid = amountPaid;
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -241,6 +241,11 @@ public class AccountDetailsReadPlatformServiceJpaRepositoryImpl implements Accou
|
||||
accountsSummary
|
||||
.append(" l.product_id as productId, lp.name as productName, lp.short_name as shortProductName,")
|
||||
.append(" l.loan_status_id as statusId, l.loan_type_enum as loanType,")
|
||||
|
||||
.append("l.principal_disbursed_derived as originalLoan,")
|
||||
.append("l.total_outstanding_derived as loanBalance,")
|
||||
.append("l.total_repayment_derived as amountPaid,")
|
||||
|
||||
.append(" l.loan_product_counter as loanCycle,")
|
||||
|
||||
.append(" l.submittedon_date as submittedOnDate,")
|
||||
@@ -320,6 +325,10 @@ public class AccountDetailsReadPlatformServiceJpaRepositoryImpl implements Accou
|
||||
final String closedByUsername = rs.getString("closedByUsername");
|
||||
final String closedByFirstname = rs.getString("closedByFirstname");
|
||||
final String closedByLastname = rs.getString("closedByLastname");
|
||||
|
||||
final BigDecimal originalLoan = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs,"originalLoan");
|
||||
final BigDecimal loanBalance = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs,"loanBalance");
|
||||
final BigDecimal amountPaid = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs,"amountPaid");
|
||||
|
||||
final LocalDate writtenOffOnDate = JdbcSupport.getLocalDate(rs, "writtenOffOnDate");
|
||||
|
||||
@@ -339,7 +348,7 @@ public class AccountDetailsReadPlatformServiceJpaRepositoryImpl implements Accou
|
||||
expectedMaturityDate, writtenOffOnDate, closedByUsername, closedByFirstname, closedByLastname);
|
||||
|
||||
return new LoanAccountSummaryData(id, accountNo, externalId, productId, loanProductName, shortLoanProductName, loanStatus, loanType, loanCycle,
|
||||
timeline, inArrears);
|
||||
timeline, inArrears,originalLoan,loanBalance,amountPaid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -48,6 +48,7 @@ public class SavingsApiConstants {
|
||||
public static final String localeParamName = "locale";
|
||||
public static final String dateFormatParamName = "dateFormat";
|
||||
public static final String monthDayFormatParamName = "monthDayFormat";
|
||||
public static final String staffIdParamName = "staffId";
|
||||
|
||||
// savings product and account parameters
|
||||
public static final String idParamName = "id";
|
||||
@@ -172,7 +173,7 @@ public class SavingsApiConstants {
|
||||
"interestCalculationDaysInYearTypeOptions", "lockinPeriodFrequencyTypeOptions", "withdrawalFeeTypeOptions"));
|
||||
|
||||
public static final Set<String> SAVINGS_ACCOUNT_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName,
|
||||
dateFormatParamName, monthDayFormatParamName, accountNoParamName, externalIdParamName, clientIdParamName, groupIdParamName,
|
||||
dateFormatParamName, monthDayFormatParamName, staffIdParamName, accountNoParamName, externalIdParamName, clientIdParamName, groupIdParamName,
|
||||
productIdParamName, fieldOfficerIdParamName, submittedOnDateParamName, nominalAnnualInterestRateParamName,
|
||||
interestCompoundingPeriodTypeParamName, interestPostingPeriodTypeParamName, interestCalculationTypeParamName,
|
||||
interestCalculationDaysInYearTypeParamName, minRequiredOpeningBalanceParamName, lockinPeriodFrequencyParamName,
|
||||
@@ -187,7 +188,7 @@ public class SavingsApiConstants {
|
||||
* parameters to match those of request parameters.
|
||||
*/
|
||||
public static final Set<String> SAVINGS_ACCOUNT_RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList(idParamName, accountNoParamName,
|
||||
externalIdParamName, statusParamName, activatedOnDateParamName, clientIdParamName, "clientName", groupIdParamName, "groupName",
|
||||
externalIdParamName, statusParamName, activatedOnDateParamName,staffIdParamName, clientIdParamName, "clientName", groupIdParamName, "groupName",
|
||||
"savingsProductId", "savingsProductName", "currency", nominalAnnualInterestRateParamName,
|
||||
interestCompoundingPeriodTypeParamName, interestCalculationTypeParamName, interestCalculationDaysInYearTypeParamName,
|
||||
minRequiredOpeningBalanceParamName, lockinPeriodFrequencyParamName, lockinPeriodFrequencyTypeParamName,
|
||||
|
||||
+10
-1
@@ -248,12 +248,21 @@ public class SavingsAccountsApiResource {
|
||||
} else if (is(commandParam, "close")) {
|
||||
final CommandWrapper commandRequest = builder.closeSavingsAccountApplication(accountId).build();
|
||||
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
}else if (is(commandParam, "assignFieldOfficer")) {
|
||||
final CommandWrapper commandRequest = builder.assignFieldOfficer(accountId).build();
|
||||
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
} else if (is(commandParam, "unassignFieldOfficer")) {
|
||||
final CommandWrapper commandRequest = builder.unassignFieldOfficer(accountId).build();
|
||||
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
|
||||
if (result == null) {
|
||||
//
|
||||
throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "reject", "withdrawnByApplicant", "approve",
|
||||
"undoapproval", "activate", "calculateInterest", "postInterest", "close" });
|
||||
"undoapproval", "activate", "calculateInterest", "postInterest", "close" ,"assignFieldOfficer" ,"unassignFieldOfficer"});
|
||||
}
|
||||
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
|
||||
+50
@@ -32,9 +32,12 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawal
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
@@ -387,4 +390,51 @@ public class SavingsAccountDataValidator {
|
||||
}
|
||||
|
||||
}
|
||||
public void validateForAssignFieldOfficer(final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
final Set<String> supportedParametersUnassignStaff = new HashSet<>(Arrays.asList(SavingsApiConstants.staffIdParamName));
|
||||
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersUnassignStaff);
|
||||
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
|
||||
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
|
||||
.resource(SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME);
|
||||
|
||||
final String staffIdParameterName = SavingsApiConstants.staffIdParamName;
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).notNull().longGreaterThanZero();
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
|
||||
}
|
||||
|
||||
public void validateForUnAssignFieldOfficer(final String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
final Set<String> supportedParametersUnassignStaff = new HashSet<>(Arrays.asList(SavingsApiConstants.staffIdParamName));
|
||||
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersUnassignStaff);
|
||||
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
|
||||
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
|
||||
.resource(SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME);
|
||||
|
||||
final String staffIdParameterName = SavingsApiConstants.staffIdParamName;
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).notNull().longGreaterThanZero();
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+13
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package org.mifosplatform.portfolio.savings.domain;
|
||||
|
||||
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.allowOverdraftParamName;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.dueAsOfDateParamName;
|
||||
@@ -15,6 +16,7 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.lockinPeri
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.minRequiredBalanceParamName;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.overdraftLimitParamName;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeForTransfersParamName;
|
||||
import org.mifosplatform.organisation.staff.domain.Staff;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
@@ -1188,6 +1190,17 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
return office;
|
||||
}
|
||||
|
||||
public Staff getFieldOfficer() {
|
||||
return this.fieldOfficer;
|
||||
}
|
||||
|
||||
public void unassignFieldOfficer() {
|
||||
this.fieldOfficer = null;
|
||||
}
|
||||
|
||||
public void assignFieldOfficer(final Staff fieldOfficer) {
|
||||
this.fieldOfficer = fieldOfficer;
|
||||
}
|
||||
public Long clientId() {
|
||||
Long id = null;
|
||||
if (this.client != null) {
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package org.mifosplatform.portfolio.savings.handler;
|
||||
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.portfolio.savings.service.SavingsAccountWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class AssignFieldOfficerSavingsAccountCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final SavingsAccountWritePlatformService savingsWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public AssignFieldOfficerSavingsAccountCommandHandler(final SavingsAccountWritePlatformService savingAccountWritePlatformService) {
|
||||
this.savingsWritePlatformService = savingAccountWritePlatformService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||
return this.savingsWritePlatformService.assignFieldOfficer(command.entityId(), command);
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package org.mifosplatform.portfolio.savings.handler;
|
||||
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.portfolio.savings.service.SavingsAccountWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class UnassignFieldOfficerSavingsAccountCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final SavingsAccountWritePlatformService savingsWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public UnassignFieldOfficerSavingsAccountCommandHandler(final SavingsAccountWritePlatformService savingAccountWritePlatformService) {
|
||||
this.savingsWritePlatformService = savingAccountWritePlatformService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||
return this.savingsWritePlatformService.unassignFieldOfficer(command.entityId(), command);
|
||||
}
|
||||
|
||||
}
|
||||
+4
@@ -57,6 +57,10 @@ public interface SavingsAccountWritePlatformService {
|
||||
CommandProcessingResult payCharge(Long savingsAccountId, Long savingsAccountChargeId, JsonCommand command);
|
||||
|
||||
CommandProcessingResult inactivateCharge(Long savingsAccountId, Long savingsAccountChargeId);
|
||||
|
||||
CommandProcessingResult assignFieldOfficer(Long savingsAccountId, JsonCommand command);
|
||||
|
||||
CommandProcessingResult unassignFieldOfficer(Long savingsAccountId, JsonCommand command);
|
||||
|
||||
void applyChargeDue(final Long savingsAccountChargeId, final Long accountId);
|
||||
|
||||
|
||||
+78
-1
@@ -46,6 +46,7 @@ import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
|
||||
import org.mifosplatform.organisation.monetary.domain.Money;
|
||||
import org.mifosplatform.organisation.office.domain.Office;
|
||||
import org.mifosplatform.organisation.staff.domain.Staff;
|
||||
import org.mifosplatform.organisation.staff.domain.StaffRepositoryWrapper;
|
||||
import org.mifosplatform.organisation.workingdays.service.WorkingDaysWritePlatformService;
|
||||
import org.mifosplatform.portfolio.account.PortfolioAccountType;
|
||||
import org.mifosplatform.portfolio.account.service.AccountAssociationsReadPlatformService;
|
||||
@@ -53,6 +54,7 @@ import org.mifosplatform.portfolio.account.service.AccountTransfersReadPlatformS
|
||||
import org.mifosplatform.portfolio.charge.domain.Charge;
|
||||
import org.mifosplatform.portfolio.charge.domain.ChargeRepositoryWrapper;
|
||||
import org.mifosplatform.portfolio.client.domain.Client;
|
||||
import org.mifosplatform.portfolio.client.exception.ClientHasNoStaffException;
|
||||
import org.mifosplatform.portfolio.client.exception.ClientNotActiveException;
|
||||
import org.mifosplatform.portfolio.group.domain.Group;
|
||||
import org.mifosplatform.portfolio.group.exception.GroupNotActiveException;
|
||||
@@ -64,6 +66,7 @@ import org.mifosplatform.portfolio.savings.SavingsAccountTransactionType;
|
||||
import org.mifosplatform.portfolio.savings.SavingsApiConstants;
|
||||
import org.mifosplatform.portfolio.savings.SavingsTransactionBooleanValues;
|
||||
import org.mifosplatform.portfolio.savings.data.SavingsAccountChargeDataValidator;
|
||||
import org.mifosplatform.portfolio.savings.data.SavingsAccountDataValidator;
|
||||
import org.mifosplatform.portfolio.savings.data.SavingsAccountTransactionDTO;
|
||||
import org.mifosplatform.portfolio.savings.data.SavingsAccountTransactionDataValidator;
|
||||
import org.mifosplatform.portfolio.savings.domain.SavingsAccount;
|
||||
@@ -72,6 +75,7 @@ import org.mifosplatform.portfolio.savings.domain.SavingsAccountCharge;
|
||||
import org.mifosplatform.portfolio.savings.domain.SavingsAccountChargeRepositoryWrapper;
|
||||
import org.mifosplatform.portfolio.savings.domain.SavingsAccountDomainService;
|
||||
import org.mifosplatform.portfolio.savings.domain.SavingsAccountRepository;
|
||||
import org.mifosplatform.portfolio.savings.domain.SavingsAccountRepositoryWrapper;
|
||||
import org.mifosplatform.portfolio.savings.domain.SavingsAccountStatusType;
|
||||
import org.mifosplatform.portfolio.savings.domain.SavingsAccountTransaction;
|
||||
import org.mifosplatform.portfolio.savings.domain.SavingsAccountTransactionRepository;
|
||||
@@ -89,6 +93,9 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final SavingsAccountRepository savingAccountRepository;
|
||||
private final SavingsAccountDataValidator fromApiJsonDeserializer;
|
||||
private final SavingsAccountRepositoryWrapper savingsRepository;
|
||||
private final StaffRepositoryWrapper staffRepository;
|
||||
private final SavingsAccountTransactionRepository savingsAccountTransactionRepository;
|
||||
private final SavingsAccountAssembler savingAccountAssembler;
|
||||
private final SavingsAccountTransactionDataValidator savingsAccountTransactionDataValidator;
|
||||
@@ -120,7 +127,10 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
|
||||
final AccountAssociationsReadPlatformService accountAssociationsReadPlatformService,
|
||||
final ChargeRepositoryWrapper chargeRepository, final SavingsAccountChargeRepositoryWrapper savingsAccountChargeRepository,
|
||||
final HolidayWritePlatformService holidayWritePlatformService,
|
||||
final WorkingDaysWritePlatformService workingDaysWritePlatformService) {
|
||||
final WorkingDaysWritePlatformService workingDaysWritePlatformService,
|
||||
final SavingsAccountDataValidator fromApiJsonDeserializer,
|
||||
final SavingsAccountRepositoryWrapper savingsRepository,
|
||||
final StaffRepositoryWrapper staffRepository) {
|
||||
this.context = context;
|
||||
this.savingAccountRepository = savingAccountRepository;
|
||||
this.savingsAccountTransactionRepository = savingsAccountTransactionRepository;
|
||||
@@ -138,6 +148,9 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
|
||||
this.savingsAccountChargeRepository = savingsAccountChargeRepository;
|
||||
this.holidayWritePlatformService = holidayWritePlatformService;
|
||||
this.workingDaysWritePlatformService = workingDaysWritePlatformService;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.savingsRepository = savingsRepository;
|
||||
this.staffRepository = staffRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -1009,4 +1022,68 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandProcessingResult assignFieldOfficer(Long savingsAccountId,
|
||||
JsonCommand command) {
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final Map<String, Object> actualChanges = new LinkedHashMap<>(5);
|
||||
|
||||
this.fromApiJsonDeserializer.validateForAssignFieldOfficer(command.json());
|
||||
|
||||
final SavingsAccount savingsForUpdate = this.savingsRepository.findOneWithNotFoundDetection(savingsAccountId);
|
||||
|
||||
Staff staff = null;
|
||||
final Long staffId = command.longValueOfParameterNamed(SavingsApiConstants.staffIdParamName);
|
||||
if (staffId != null) {
|
||||
staff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(staffId, savingsForUpdate.office().getHierarchy());
|
||||
|
||||
savingsForUpdate.assignFieldOfficer(staff);
|
||||
}
|
||||
|
||||
this.savingsRepository.saveAndFlush(savingsForUpdate);
|
||||
|
||||
actualChanges.put(SavingsApiConstants.staffIdParamName, staffId);
|
||||
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withCommandId(command.commandId()) //
|
||||
.withOfficeId(savingsForUpdate.officeId()) //
|
||||
.withEntityId(savingsForUpdate.getId()) //
|
||||
.withClientId(savingsAccountId) //
|
||||
.with(actualChanges) //
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandProcessingResult unassignFieldOfficer(Long savingsAccountId,
|
||||
JsonCommand command) {
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final Map<String, Object> actualChanges = new LinkedHashMap<>(5);
|
||||
|
||||
this.fromApiJsonDeserializer.validateForUnAssignFieldOfficer(command.json());
|
||||
|
||||
final SavingsAccount savingsForUpdate = this.savingsRepository.findOneWithNotFoundDetection(savingsAccountId);
|
||||
|
||||
final Staff presentStaff = savingsForUpdate.getFieldOfficer();
|
||||
Long presentStaffId = null;
|
||||
if (presentStaff == null) { throw new ClientHasNoStaffException(savingsAccountId); }
|
||||
presentStaffId = presentStaff.getId();
|
||||
final String staffIdParamName = SavingsApiConstants.staffIdParamName;
|
||||
if (!command.isChangeInLongParameterNamed(staffIdParamName, presentStaffId)) {
|
||||
savingsForUpdate.unassignFieldOfficer();
|
||||
}
|
||||
this.savingsRepository.saveAndFlush(savingsForUpdate);
|
||||
|
||||
actualChanges.put(staffIdParamName, presentStaffId);
|
||||
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withCommandId(command.commandId()) //
|
||||
.withOfficeId(savingsForUpdate.officeId()) //
|
||||
.withEntityId(savingsForUpdate.getId()) //
|
||||
.withClientId(savingsAccountId) //
|
||||
.with(actualChanges) //
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user