Merge remote-tracking branch 'nayan/unassignlo'

This commit is contained in:
Keith Woodlock
2013-02-10 20:04:30 +00:00
12 changed files with 519 additions and 39 deletions
@@ -9,9 +9,11 @@ public class MifosPlatformTenant {
private final String schemaServerPort;
private final String schemaUsername;
private final String schemaPassword;
private final String timezoneId;
public MifosPlatformTenant(final Long id, final String name, final String schemaName, final String schemaServer,
final String schemaServerPort, final String schemaUsername, final String schemaPassword) {
final String schemaServerPort, final String schemaUsername, final String schemaPassword, String timezoneId) {
this.id = id;
this.name = name;
this.schemaName = schemaName;
@@ -19,6 +21,8 @@ public class MifosPlatformTenant {
this.schemaServerPort = schemaServerPort;
this.schemaUsername = schemaUsername;
this.schemaPassword = schemaPassword;
this.timezoneId = timezoneId;
}
public Long getId() {
@@ -48,4 +52,9 @@ public class MifosPlatformTenant {
public String getSchemaPassword() {
return schemaPassword;
}
public String getTimezoneId() {
return timezoneId;
}
}
@@ -0,0 +1,25 @@
package org.mifosplatform.infrastructure.core.service;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.domain.MifosPlatformTenant;
public class DateUtils {
public static LocalDate getLocalDateOfTenant() {
LocalDate today = new LocalDate();
final MifosPlatformTenant tenant = ThreadLocalContextUtil.getTenant();
if (tenant != null) {
final DateTimeZone zone = DateTimeZone.forID(tenant.getTimezoneId());
if (zone != null) {
today = new LocalDate(zone);
}
}
return today;
}
}
@@ -34,7 +34,7 @@ public class JdbcTenantDetailsService implements TenantDetailsService {
try {
TenantMapper rm = new TenantMapper();
String sql = "select id, name, schema_name as schemaName, schema_server as schemaServer, schema_server_port as schemaServerPort, "
+ " schema_username as schemaUsername, schema_password as schemaPassword "
+ " schema_username as schemaUsername, schema_password as schemaPassword , timezone_id as timezoneId "
+ " from tenants t where t.identifier like ?";
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { tenantIdentifier });
@@ -55,8 +55,9 @@ public class JdbcTenantDetailsService implements TenantDetailsService {
String schemaServerPort = rs.getString("schemaServerPort");
String schemaUsername = rs.getString("schemaUsername");
String schemaPassword = rs.getString("schemaPassword");
return new MifosPlatformTenant(id, name, schemaName, schemaServer, schemaServerPort, schemaUsername, schemaPassword);
String timezoneId =rs.getString("timezoneId");
return new MifosPlatformTenant(id, name, schemaName, schemaServer, schemaServerPort, schemaUsername, schemaPassword ,timezoneId);
}
}
}
@@ -413,6 +413,14 @@ public class LoansApiResource {
final CommandWrapper commandRequest = builder.undoLoanApplicationDisbursal(loanId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
if (is(commandParam, "assignloanofficer")) {
final CommandWrapper commandRequest = builder.assignLoanOfficer(loanId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
} else if (is(commandParam, "unassignloanofficer")) {
final CommandWrapper commandRequest = builder.unassignLoanOfficer(loanId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
if (result == null) { throw new UnrecognizedQueryParamException("command", commandParam); }
@@ -445,30 +453,4 @@ public class LoansApiResource {
return this.loanOfficeTransferToApiJsonSerializer.serialize(settings, loanReassignmentData, RESPONSE_DATA_PARAMETERS);
}
@POST
@Path("{loanId}/assign")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String assignLoanOfficer(@PathParam("loanId") final Long loanId, final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().assignLoanOfficer(loanId).withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
}
@POST
@Path("{loanId}/unassign")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String unassignLoanOfficer(@PathParam("loanId") final Long loanId, final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().unassignLoanOfficer(loanId).withJson(apiRequestBodyAsJson)
.build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
}
}
@@ -35,6 +35,7 @@ import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
import org.mifosplatform.infrastructure.core.service.DateUtils;
import org.mifosplatform.infrastructure.security.service.RandomPasswordGenerator;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency;
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
@@ -48,6 +49,7 @@ import org.mifosplatform.portfolio.loanaccount.command.LoanChargeCommand;
import org.mifosplatform.portfolio.loanaccount.exception.InvalidLoanStateTransitionException;
import org.mifosplatform.portfolio.loanaccount.exception.InvalidLoanTransactionTypeException;
import org.mifosplatform.portfolio.loanaccount.exception.LoanOfficerAssignmentException;
import org.mifosplatform.portfolio.loanaccount.exception.LoanOfficerUnassignmentDateException;
import org.mifosplatform.portfolio.loanaccount.loanschedule.data.LoanScheduleData;
import org.mifosplatform.portfolio.loanaccount.loanschedule.data.LoanSchedulePeriodData;
import org.mifosplatform.portfolio.loanaccount.loanschedule.domain.AprCalculator;
@@ -1942,17 +1944,29 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
}
public void removeLoanOfficer(final LocalDate updatedDate) {
public void removeLoanOfficer(final LocalDate unassignDate) {
final LoanOfficerAssignmentHistory latestHistoryRecord = findLatestIncompleteHistoryRecord();
if (latestHistoryRecord != null) {
latestHistoryRecord.updateEndDate(updatedDate);
validateUnassignDate(latestHistoryRecord, unassignDate);
latestHistoryRecord.updateEndDate(unassignDate);
}
this.loanofficer = null;
}
private void validateUnassignDate(final LoanOfficerAssignmentHistory latestHistoryRecord, final LocalDate unassignDate) {
final LocalDate today = DateUtils.getLocalDateOfTenant();
if (latestHistoryRecord.getStartDate().isAfter(unassignDate)) {
throw new LoanOfficerUnassignmentDateException(this.getId(), this.getLoanOfficer().getId(), latestHistoryRecord.getStartDate(),
unassignDate);
} else if (unassignDate.isAfter(today)) { throw new LoanOfficerUnassignmentDateException(
this.getId()); }
}
private LoanOfficerAssignmentHistory findLatestIncompleteHistoryRecord() {
LoanOfficerAssignmentHistory latestRecordWithNoEndDate = null;
@@ -67,7 +67,7 @@ public class LoanOfficerAssignmentHistory extends AbstractAuditableCustom<AppUse
return getStartDate().isEqual(matchingDate);
}
private LocalDate getStartDate() {
public LocalDate getStartDate() {
return new LocalDate(startDate);
}
@@ -0,0 +1,19 @@
package org.mifosplatform.portfolio.loanaccount.exception;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
public class LoanOfficerUnassignmentDateException extends AbstractPlatformDomainRuleException {
public LoanOfficerUnassignmentDateException(final Long loanId, final Long loanofficerId, final LocalDate assignedDate,
final LocalDate unassignDate) {
super("error.msg.loan.unassign.loanofficer.invalid.pastedate", "Loan officer Unassign date(" + unassignDate
+ ") can not be less than assign date(" + assignedDate + ") for loan(" + loanId + ") with Loan Officer " + loanofficerId
+ ").", loanId);
}
public LoanOfficerUnassignmentDateException(final Long loanId) {
super("error.msg.loan.unassign.loanofficer.invalid.futuredate", "Unassign loan officer in future date is not supported.", loanId);
}
}
@@ -2,9 +2,9 @@ package org.mifosplatform.portfolio.loanaccount.exception;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
public class UnassignLoanOfficerException extends AbstractPlatformDomainRuleException {
public class LoanOfficerUnassignmentException extends AbstractPlatformDomainRuleException {
public UnassignLoanOfficerException(final Long loanId) {
public LoanOfficerUnassignmentException(final Long loanId) {
super("error.msg.loan.not.assigned.to.loan.officer", "Loan with identifier " + loanId
+ " is not assigned to any loan officer.", loanId);
}
@@ -45,7 +45,7 @@ import org.mifosplatform.portfolio.loanaccount.domain.LoanTransactionRepository;
import org.mifosplatform.portfolio.loanaccount.exception.LoanNotFoundException;
import org.mifosplatform.portfolio.loanaccount.exception.LoanOfficerAssignmentException;
import org.mifosplatform.portfolio.loanaccount.exception.LoanTransactionNotFoundException;
import org.mifosplatform.portfolio.loanaccount.exception.UnassignLoanOfficerException;
import org.mifosplatform.portfolio.loanaccount.exception.LoanOfficerUnassignmentException;
import org.mifosplatform.portfolio.loanaccount.serialization.LoanChargeCommandFromApiJsonDeserializer;
import org.mifosplatform.portfolio.loanaccount.serialization.LoanStateTransitionCommandFromApiJsonDeserializer;
import org.mifosplatform.portfolio.loanaccount.serialization.LoanTransactionCommandFromApiJsonDeserializer;
@@ -719,7 +719,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
final Loan loan = retrieveLoanBy(loanId);
if (loan.getLoanOfficer() == null) { throw new UnassignLoanOfficerException(loanId); }
if (loan.getLoanOfficer() == null) { throw new LoanOfficerUnassignmentException(loanId); }
loan.removeLoanOfficer(dateOfLoanOfficerunAssigned);