Merge branch 'MIFOSX-1175' of git://github.com/Musoni/mifosx into Musoni-MIFOSX-1175

Conflicts:
	mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java
	mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java
This commit is contained in:
Vishwas Babu A J
2014-11-05 17:33:49 +05:30
12 changed files with 291 additions and 5 deletions
+19
View File
@@ -5979,6 +5979,25 @@ Request Body:
<h4>Assign a Staff</h4> <h4>Assign a Staff</h4>
<p>Allows you to assign <i>Staff</i> to an existing Group.</p> <p>Allows you to assign <i>Staff</i> to an existing Group.</p>
<p>The selected Staff should be belong to the same office (or an office higher up in the hierarchy) as this group</p> <p>The selected Staff should be belong to the same office (or an office higher up in the hierarchy) as this group</p>
<table class=matrixHeading>
<tr class="matrixHeadingBG">
<td><div class="mifosXHeading2">Mandatory Fields</div></td>
</tr>
<tr class=alt>
<td>staffId</td>
</tr>
</table>
<table class=matrixHeading>
<tr class="matrixHeadingBG">
<td><div class="mifosXHeading2">Optional Fields</div></td>
</tr>
<tr class=alt>
<td>inheritStaffForClientAccounts</td>
</tr>
<tr>
<td class=fielddesc>Optional: Boolean if true all members of the group (i.e all clients with active loans and savings ) will inherit the staffId</td>
</tr>
</table>
</div> </div>
<div class="method-example"> <div class="method-example">
<code class="method-declaration">POST https://Domain Name/api/v1/groups/{groupId}?command=assignStaff</code> <code class="method-declaration">POST https://Domain Name/api/v1/groups/{groupId}?command=assignStaff</code>
@@ -5,10 +5,12 @@
*/ */
package org.mifosplatform.integrationtests; package org.mifosplatform.integrationtests;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mifosplatform.integrationtests.common.ClientHelper; import org.mifosplatform.integrationtests.common.ClientHelper;
import org.mifosplatform.integrationtests.common.GroupHelper; import org.mifosplatform.integrationtests.common.GroupHelper;
import org.mifosplatform.integrationtests.common.StaffHelper;
import org.mifosplatform.integrationtests.common.Utils; import org.mifosplatform.integrationtests.common.Utils;
import com.jayway.restassured.builder.RequestSpecBuilder; import com.jayway.restassured.builder.RequestSpecBuilder;
@@ -16,6 +18,16 @@ import com.jayway.restassured.builder.ResponseSpecBuilder;
import com.jayway.restassured.http.ContentType; import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification; import com.jayway.restassured.specification.ResponseSpecification;
import org.mifosplatform.integrationtests.common.accounting.Account;
import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder;
import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder;
import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper;
import java.util.HashMap;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
/** /**
* Group Test for checking Group: Creation, Activation, Client Association, * Group Test for checking Group: Creation, Activation, Client Association,
@@ -25,6 +37,12 @@ public class GroupTest {
private ResponseSpecification responseSpec; private ResponseSpecification responseSpec;
private RequestSpecification requestSpec; private RequestSpecification requestSpec;
private LoanTransactionHelper loanTransactionHelper;
private String principal = "10000.00";
private String accountingRule = "1";
private String numberOfRepayments = "5";
private String interestRatePerPeriod = "18";
@Before @Before
public void setup() { public void setup() {
@@ -32,6 +50,8 @@ public class GroupTest {
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
} }
@Test @Test
@@ -58,4 +78,90 @@ public class GroupTest {
// GroupHelper.deleteGroup(this.requestSpec, this.responseSpec, groupID.toString()); // GroupHelper.deleteGroup(this.requestSpec, this.responseSpec, groupID.toString());
// GroupHelper.verifyGroupDeleted(this.requestSpec, this.responseSpec, groupID); // GroupHelper.verifyGroupDeleted(this.requestSpec, this.responseSpec, groupID);
} }
@Test
public void assignStaffToGroup(){
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec);
GroupHelper.verifyGroupCreatedOnServer(this.requestSpec, this.responseSpec, groupID);
final String updateGroupName = Utils.randomNameGenerator("Savings Group Help_",5);
groupID = GroupHelper.activateGroup(this.requestSpec, this.responseSpec, groupID.toString());
Integer updateGroupId = GroupHelper.updateGroup(this.requestSpec,this.responseSpec,updateGroupName,groupID.toString());
//create client and add client to group
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
GroupHelper.verifyGroupMembers(this.requestSpec, this.responseSpec, groupID, clientID);
//create staff
Integer createStaffId1 = StaffHelper.createStaff(this.requestSpec, this.responseSpec) ;
System.out.println("--------------creating first staff with id-------------" + createStaffId1);
Assert.assertNotNull(createStaffId1);
Integer createStaffId2 = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
System.out.println("--------------creating second staff with id-------------" + createStaffId2);
Assert.assertNotNull(createStaffId2);
//assign staff "createStaffId1" to group
HashMap assignStaffGroupId = (HashMap)GroupHelper.assignStaff(this.requestSpec,this.responseSpec,groupID.toString(),createStaffId1.longValue());
assertEquals("Verify assigned staff id is the same as id sent",assignStaffGroupId.get("staffId"),createStaffId1);
//assign staff "createStaffId2" to client
final HashMap assignStaffToClientChanges = (HashMap)ClientHelper.assignStaffToClient(this.requestSpec,this.responseSpec,clientID.toString(),createStaffId2.toString());
assertEquals("Verify assigned staff id is the same as id sent", assignStaffToClientChanges.get("staffId"),createStaffId2);
final Integer loanProductId = this.createLoanProduct();
final Integer loanId = this.applyForLoanApplication(clientID,loanProductId,this.principal);
this.loanTransactionHelper.approveLoan("20 September 2014",loanId);
this.loanTransactionHelper.disburseLoan("20 September 2014",loanId);
final HashMap assignStaffAndInheritStaffForClientAccounts = (HashMap)GroupHelper.assignStaffInheritStaffForClientAccounts(this.requestSpec,this.responseSpec,groupID.toString(),createStaffId1.toString());
final Integer getClientStaffId = ClientHelper.getClient(this.requestSpec,this.responseSpec,clientID.toString());
//assert if client staff officer has change Note client was assigned staff with createStaffId2
assertNotEquals("Verify if client stuff has changed", assignStaffAndInheritStaffForClientAccounts.get("staffId"), createStaffId2);
assertEquals("Verify if client inherited staff assigned above", assignStaffAndInheritStaffForClientAccounts.get("staffId"), getClientStaffId);
//assert if clients loan officer has changed
final Integer loanOfficerId = this.loanTransactionHelper.getLoanOfficerId(loanId.toString());
assertEquals("Verify if client loan inherited staff", assignStaffAndInheritStaffForClientAccounts.get("staffId"), loanOfficerId);
}
private Integer createLoanProduct() {
final String loanProductJSON = new LoanProductTestBuilder()
.withPrincipal(this.principal)
.withNumberOfRepayments(this.numberOfRepayments)
.withinterestRatePerPeriod(this.interestRatePerPeriod)
.withInterestRateFrequencyTypeAsYear()
.build(null);
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
}
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID, String principal) {
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
final String loanApplicationJSON = new LoanApplicationTestBuilder() //
.withPrincipal(principal) //
.withLoanTermFrequency("4") //
.withLoanTermFrequencyAsMonths() //
.withNumberOfRepayments("4") //
.withRepaymentEveryAfter("1") //
.withRepaymentFrequencyTypeAsMonths() //
.withInterestRatePerPeriod("2") //
.withAmortizationTypeAsEqualInstallments() //
.withInterestTypeAsDecliningBalance() //
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod() //
.withExpectedDisbursementDate("20 September 2014") //
.withSubmittedOnDate("20 September 2014") //
.build(clientID.toString(), loanProductID.toString(), null);
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
}
} }
@@ -33,6 +33,24 @@ public class ClientHelper {
"clientId"); "clientId");
} }
public static Object assignStaffToClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String clientId, final String staffId) {
final String CLIENT_ASSIGN_STAFF_URL = "/mifosng-provider/api/v1/clients/" + clientId + "?" + Utils.TENANT_IDENTIFIER + "&command=assignStaff";
System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, CLIENT_ASSIGN_STAFF_URL, assignStaffToClientAsJson(staffId),
"changes");
}
public static Integer getClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String clientId){
final String GET_CLIENT_URL = "/mifosng-provider/api/v1/clients/" + clientId + "?" + Utils.TENANT_IDENTIFIER ;
System.out.println("---------------------------------GET A CLIENT---------------------------------------------");
return Utils.performServerGet(requestSpec, responseSpec, GET_CLIENT_URL,"staffId");
}
public static String getTestClientAsJSON(final String dateOfJoining, final String officeId) { public static String getTestClientAsJSON(final String dateOfJoining, final String officeId) {
final HashMap<String, String> map = new HashMap<>(); final HashMap<String, String> map = new HashMap<>();
map.put("officeId", officeId); map.put("officeId", officeId);
@@ -47,6 +65,13 @@ public class ClientHelper {
return new Gson().toJson(map); return new Gson().toJson(map);
} }
public static String assignStaffToClientAsJson(final String staffId){
final HashMap<String, String> map = new HashMap<>();
map.put("staffId", staffId);
System.out.println("map : " + map);
return new Gson().toJson(map);
}
public static void verifyClientCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static void verifyClientCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer generatedClientID) { final Integer generatedClientID) {
System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n"); System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n");
@@ -76,6 +76,19 @@ public class GroupHelper {
return Utils.performServerDelete(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, "groupId"); return Utils.performServerDelete(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, "groupId");
} }
public static Object assignStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String groupId,final Long staffId){
final String GROUP_ASSIGN_STAFF_URL = "/mifosng-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER + "&command=assignStaff";
System.out.println("---------------------------------DELETE GROUP---------------------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSIGN_STAFF_URL,assignStaffAsJSON(staffId),"changes");
}
public static Object assignStaffInheritStaffForClientAccounts(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String groupId,final String staffId){
final String GROUP_ASSIGN_STAFF_URL = "/mifosng-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER + "&command=assignStaff";
System.out.println("---------------------------------DELETE GROUP---------------------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSIGN_STAFF_URL,assignStaffAndInheritStaffForClientAccountsAsJSON(staffId),"changes");
}
public static String getTestGroupAsJSON(final boolean active, final String activationDate) { public static String getTestGroupAsJSON(final boolean active, final String activationDate) {
final HashMap<String, String> map = new HashMap<>(); final HashMap<String, String> map = new HashMap<>();
map.put("officeId", "1"); map.put("officeId", "1");
@@ -125,6 +138,20 @@ public class GroupHelper {
System.out.println("map : " + map); System.out.println("map : " + map);
return new Gson().toJson(map); return new Gson().toJson(map);
} }
public static String assignStaffAsJSON(final Long staffId) {
final HashMap<String, Object> map = new HashMap<>();
map.put("staffId", staffId);
System.out.println("map : " + map);
return new Gson().toJson(map);
}
public static String assignStaffAndInheritStaffForClientAccountsAsJSON(final String staffId) {
final HashMap<String, String> map = new HashMap<>();
map.put("staffId", staffId);
map.put("inheritStaffForClientAccounts","true");
System.out.println("map : " + map);
return new Gson().toJson(map);
}
public static void verifyGroupCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static void verifyGroupCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer generatedGroupID) { final Integer generatedGroupID) {
@@ -0,0 +1,60 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.integrationtests.common;
import com.google.gson.Gson;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import java.util.HashMap;
public class StaffHelper {
private static final String TRANSFER_STAFF_URL = "/mifosng-provider/api/v1/groups";
private static final String CREATE_STAFF_URL = "/mifosng-provider/api/v1/staff";
private static final String RESOURCE_ID = "resourceId";
public static final String GROUP_ID = "groupId";
public static Integer transferStaffToGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer groupId,final Integer staffToTransfer ,final String note){
final String url = TRANSFER_STAFF_URL + "/" + groupId + "?command=transferStaff&"+Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(requestSpec, responseSpec, url, transferStaffToGroupAsJSON(staffToTransfer, note), GROUP_ID);
}
public static String transferStaffToGroupAsJSON(final Integer staffToTransferId,final String note) {
final HashMap<String, Object> map = new HashMap<>();
map.put("staffId", staffToTransferId);
map.put("note", note);
System.out.println("map : " + map);
return new Gson().toJson(map);
}
public static Integer createStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
final String url = CREATE_STAFF_URL +"?"+ Utils.TENANT_IDENTIFIER ;
return Utils.performServerPost(requestSpec, responseSpec, url, createStaffAsJSON(), RESOURCE_ID);
}
public static String createStaffAsJSON(){
final HashMap<String, Object> map = new HashMap<>();
map.put("officeId",1);
map.put("firstname", Utils.randomNameGenerator("michael_",5));
map.put("lastname", Utils.randomNameGenerator("Doe_",4));
map.put("isLoanOfficer", true);
System.out.println("map : " + map);
return new Gson().toJson(map);
}
}
@@ -48,6 +48,11 @@ public class LoanTransactionHelper {
public Integer getLoanId(final String loanApplicationJSON) { public Integer getLoanId(final String loanApplicationJSON) {
return Utils.performServerPost(this.requestSpec, this.responseSpec, APPLY_LOAN_URL, loanApplicationJSON, "loanId"); return Utils.performServerPost(this.requestSpec, this.responseSpec, APPLY_LOAN_URL, loanApplicationJSON, "loanId");
} }
public Integer getLoanOfficerId(final String loanId) {
final String GET_LOAN_URL = "/mifosng-provider/api/v1/loans/" + loanId + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerGet(this.requestSpec, this.responseSpec, GET_LOAN_URL, "loanOfficerId");
}
public Integer updateLoan(final Integer id, final String loanApplicationJSON) { public Integer updateLoan(final Integer id, final String loanApplicationJSON) {
return Utils.performServerPut(this.requestSpec, this.responseSpec, "/mifosng-provider/api/v1/loans/" + id return Utils.performServerPut(this.requestSpec, this.responseSpec, "/mifosng-provider/api/v1/loans/" + id
@@ -43,6 +43,7 @@ public class GroupingTypesApiConstants {
public static final String groupMembersParamName = "groupMembers"; public static final String groupMembersParamName = "groupMembers";
public static final String submittedOnDateParamName = "submittedOnDate"; public static final String submittedOnDateParamName = "submittedOnDate";
public static final String inheritStaffForClientAccounts = "inheritStaffForClientAccounts";
// group parameters // group parameters
public static final String centerIdParamName = "centerId"; public static final String centerIdParamName = "centerId";
@@ -617,4 +617,7 @@ public final class Group extends AbstractPersistable<Long> {
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
} }
public Set<Client> getClientMembers() {
return this.clientMembers;
}
} }
@@ -368,7 +368,7 @@ public final class GroupingTypesDataValidator {
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType(); final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
final Set<String> supportedParametersAssignStaff = new HashSet<>(Arrays.asList(GroupingTypesApiConstants.staffIdParamName)); final Set<String> supportedParametersAssignStaff = new HashSet<>(Arrays.asList(GroupingTypesApiConstants.staffIdParamName,GroupingTypesApiConstants.inheritStaffForClientAccounts));
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersAssignStaff); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersAssignStaff);
final JsonElement element = this.fromApiJsonHelper.parse(json); final JsonElement element = this.fromApiJsonHelper.parse(json);
@@ -382,6 +382,11 @@ public final class GroupingTypesDataValidator {
final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element); final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element);
baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).notNull().longGreaterThanZero(); baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).notNull().longGreaterThanZero();
final String inheritStaffForClientAccountsParamName = GroupingTypesApiConstants.inheritStaffForClientAccounts;
final Boolean inheritStaffForClientAccounts= this.fromApiJsonHelper.extractBooleanNamed(inheritStaffForClientAccountsParamName,element);
baseDataValidator.reset().parameter(inheritStaffForClientAccountsParamName).value(inheritStaffForClientAccounts).ignoreIfNull().notBlank().isOneOfTheseValues(true, false);
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
} }
@@ -88,6 +88,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
private final CommandProcessingService commandProcessingService; private final CommandProcessingService commandProcessingService;
private final CalendarInstanceRepository calendarInstanceRepository; private final CalendarInstanceRepository calendarInstanceRepository;
private final ConfigurationDomainService configurationDomainService; private final ConfigurationDomainService configurationDomainService;
private final SavingsAccountRepository savingsAccountRepository;
@Autowired @Autowired
public GroupingTypesWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, public GroupingTypesWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
@@ -96,7 +97,8 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
final GroupLevelRepository groupLevelRepository, final GroupingTypesDataValidator fromApiJsonDeserializer, final GroupLevelRepository groupLevelRepository, final GroupingTypesDataValidator fromApiJsonDeserializer,
final LoanRepository loanRepository, final SavingsAccountRepository savingsRepository, final LoanRepository loanRepository, final SavingsAccountRepository savingsRepository,
final CodeValueRepositoryWrapper codeValueRepository, final CommandProcessingService commandProcessingService, final CodeValueRepositoryWrapper codeValueRepository, final CommandProcessingService commandProcessingService,
final CalendarInstanceRepository calendarInstanceRepository, final ConfigurationDomainService configurationDomainService) { final CalendarInstanceRepository calendarInstanceRepository, final ConfigurationDomainService configurationDomainService,
final SavingsAccountRepository savingsAccountRepository) {
this.context = context; this.context = context;
this.groupRepository = groupRepository; this.groupRepository = groupRepository;
this.clientRepositoryWrapper = clientRepositoryWrapper; this.clientRepositoryWrapper = clientRepositoryWrapper;
@@ -111,6 +113,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
this.commandProcessingService = commandProcessingService; this.commandProcessingService = commandProcessingService;
this.calendarInstanceRepository = calendarInstanceRepository; this.calendarInstanceRepository = calendarInstanceRepository;
this.configurationDomainService = configurationDomainService; this.configurationDomainService = configurationDomainService;
this.savingsAccountRepository = savingsAccountRepository;
} }
private CommandProcessingResult createGroupingType(final JsonCommand command, final GroupTypes groupingType, final Long centerId) { private CommandProcessingResult createGroupingType(final JsonCommand command, final GroupTypes groupingType, final Long centerId) {
@@ -427,7 +430,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
} }
@Override @Override
public CommandProcessingResult assignGroupOrCenterStaff(final Long grouptId, final JsonCommand command) { public CommandProcessingResult assignGroupOrCenterStaff(final Long groupId, final JsonCommand command) {
this.context.authenticatedUser(); this.context.authenticatedUser();
@@ -435,13 +438,45 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
this.fromApiJsonDeserializer.validateForAssignStaff(command.json()); this.fromApiJsonDeserializer.validateForAssignStaff(command.json());
final Group groupForUpdate = this.groupRepository.findOneWithNotFoundDetection(grouptId); final Group groupForUpdate = this.groupRepository.findOneWithNotFoundDetection(groupId);
Staff staff = null; Staff staff = null;
final Long staffId = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName); final Long staffId = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName);
final boolean inheritStaffForClientAccounts = command
.booleanPrimitiveValueOfParameterNamed(GroupingTypesApiConstants.inheritStaffForClientAccounts);
staff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(staffId, groupForUpdate.getOffice().getHierarchy()); staff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(staffId, groupForUpdate.getOffice().getHierarchy());
groupForUpdate.updateStaff(staff); groupForUpdate.updateStaff(staff);
if (inheritStaffForClientAccounts) {
LocalDate loanOfficerReassignmentDate = LocalDate.now();
/*
* update loan officer for client and update loan officer for
* clients loans and savings
*/
Set<Client> clients = groupForUpdate.getClientMembers();
if (clients != null) {
for (Client client : clients) {
client.updateStaff(staff);
if (this.loanRepository.doNonClosedLoanAccountsExistForClient(client.getId())) {
for (final Loan loan : this.loanRepository.findLoanByClientId(client.getId())) {
if (loan.isDisbursed() && !loan.isClosed()) {
loan.reassignLoanOfficer(staff, loanOfficerReassignmentDate);
}
}
}
if (this.savingsAccountRepository.doNonClosedSavingAccountsExistForClient(client.getId())) {
for (final SavingsAccount savingsAccount : this.savingsAccountRepository
.findSavingAccountByClientId(client.getId())) {
if (!savingsAccount.isClosed()) {
savingsAccount.update(staff);
}
}
}
}
}
}
this.groupRepository.saveAndFlush(groupForUpdate); this.groupRepository.saveAndFlush(groupForUpdate);
actualChanges.put(GroupingTypesApiConstants.staffIdParamName, staffId); actualChanges.put(GroupingTypesApiConstants.staffIdParamName, staffId);
@@ -449,7 +484,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
return new CommandProcessingResultBuilder() // return new CommandProcessingResultBuilder() //
.withOfficeId(groupForUpdate.officeId()) // .withOfficeId(groupForUpdate.officeId()) //
.withEntityId(groupForUpdate.getId()) // .withEntityId(groupForUpdate.getId()) //
.withGroupId(grouptId) // .withGroupId(groupId) //
.with(actualChanges) // .with(actualChanges) //
.build(); .build();
} }