cleaning up client lifecycle additions

This commit is contained in:
Vishwas Babu A J
2014-12-05 00:30:23 -08:00
parent 6515d18b73
commit 27b8761011
4 changed files with 73 additions and 90 deletions
+37 -9
View File
@@ -196,7 +196,7 @@
<tr>
<td></td>
<td>clients/{clientId}?command=reject</td>
<td><a href="#clients_reject">Reject a Client</a></td>
<td><a href="#clients_reject">Reject a Client Application</a></td>
<td></td>
<td></td>
<td></td>
@@ -204,7 +204,7 @@
<tr>
<td></td>
<td>clients/{clientId}?command=withdraw</td>
<td><a href="#clients_withdraw">Withdraw a Client</a></td>
<td><a href="#clients_withdraw">Withdraw a Client Application</a></td>
<td></td>
<td></td>
<td></td>
@@ -3544,9 +3544,19 @@ Request Body:
<div class="method-section">
<div class="method-description">
<h4>Reject a Client</h4>
<p>Clients can be rejected when client is in pending status. This API exists to reject a client .</p>
<p>If the client is any other status results in error.</p>
<p>Clients can be rejected when client is in pending for activation status.</p>
<p>If the client is any other status, this API throws an error.</p>
<table class=matrixHeading>
<tr class="matrixHeadingBG">
<td><div class="mifosXHeading2">Mandatory Fields</div></td>
</tr>
<tr class=alt>
<td>rejectDate, rejectReasonId<br>
</td>
</tr>
</table>
</div>
<div class="method-example">
<code class="method-declaration">POST https://Domain Name/api/v1/clients/{clientId}?command=reject</code>
<code class="method-request">POST clients/1?command=reject
@@ -3572,8 +3582,17 @@ Request Body:
<div class="method-section">
<div class="method-description">
<h4>Withdraw a Client</h4>
<p>Clients can be withdrawn when client is in pending status. This API exists to withdraw a client .</p>
<p>If the client is any other status results in error.</p>
<p>Client applications can be withdrawn when client is in a pending for activation status.</p>
<p>If the client is any other status, this API throws an error.</p>
<table class=matrixHeading>
<tr class="matrixHeadingBG">
<td><div class="mifosXHeading2">Mandatory Fields</div></td>
</tr>
<tr class=alt>
<td>withdrawDate, withdrawReasonId<br>
</td>
</tr>
</table>
</div>
<div class="method-example">
<code class="method-declaration">POST https://Domain Name/api/v1/clients/{clientId}?command=withdraw</code>
@@ -3601,9 +3620,18 @@ Request Body:
<a id="clients_reactivate" name="clients_reactivate" class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
<h4>Reactivating a Client</h4>
<p>Clients can be reactivated when client is in closed status. This API exists to reactivate a client .</p>
<p>If the client is any other status results in error.</p>
<h4>Reactivate a Client</h4>
<p>Clients can be reactivated after they have been closed.</p>
<p>Trying to reactivate a client in any other state throws an error.</p>
<table class=matrixHeading>
<tr class="matrixHeadingBG">
<td><div class="mifosXHeading2">Mandatory Fields</div></td>
</tr>
<tr class=alt>
<td>reactivationDate<br>
</td>
</tr>
</table>
</div>
<div class="method-example">
<code class="method-declaration">POST https://Domain Name/api/v1/clients/{clientId}?command=reactivate</code>
@@ -156,7 +156,7 @@ public final class Client extends AbstractPersistable<Long> {
@ManyToOne(optional = true)
@JoinColumn(name = "withdraw_on_userid", nullable = true)
private AppUser withdrawnBy;
@Column(name = "reactivated_on_date", nullable = true)
@Temporal(TemporalType.DATE)
private Date reactivateDate;
@@ -165,7 +165,6 @@ public final class Client extends AbstractPersistable<Long> {
@JoinColumn(name = "reactivated_on_userid", nullable = true)
private AppUser reactivatedBy;
@ManyToOne(optional = true)
@JoinColumn(name = "closedon_userid", nullable = true)
private AppUser closedBy;
@@ -811,6 +810,10 @@ public final class Client extends AbstractPersistable<Long> {
return clientClassificationId;
}
public LocalDate getClosureDate() {
return (LocalDate) ObjectUtils.defaultIfNull(new LocalDate(this.closureDate), null);
}
public CodeValue gender() {
return this.gender;
}
@@ -866,6 +869,7 @@ public final class Client extends AbstractPersistable<Long> {
this.status = ClientStatus.WITHDRAWN.getValue();
}
public void reActivate(AppUser currentUser, Date reactivateDate) {
this.reactivateDate = reactivateDate;
this.reactivatedBy = currentUser;
@@ -610,17 +610,17 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
final CodeValue rejectReason = this.codeValueRepository.findOneByCodeNameAndIdWithNotFoundDetection(
ClientApiConstants.CLIENT_REJECT_REASON, rejectReasonId);
if (ClientStatus.fromInt(client.getStatus()).isRejected()) {
final String errorMessage = "Client is already rejected.";
throw new InvalidClientStateTransitionException("rejected", "is.already.rejected", errorMessage);
} else if (client.isNotPending() || client.getSubmittedOnDate().isAfter(rejectDate)) {
final String errorMessage = "The client is active or The client rejetDate cannot be before the client SubmittedDate.";
throw new InvalidClientStateTransitionException("rejected", "date.cannot.before.client.submitted.date", errorMessage,
if (client.isNotPending()) {
final String errorMessage = "Only clients pending activation may be withdrawn.";
throw new InvalidClientStateTransitionException("rejection", "on.account.not.in.pending.activation.status", errorMessage,
rejectDate, client.getSubmittedOnDate());
} else if (client.getSubmittedOnDate().isAfter(rejectDate)) {
final String errorMessage = "The client rejection date cannot be before the client submitted date.";
throw new InvalidClientStateTransitionException("rejection", "date.cannot.before.client.submitted.date", errorMessage,
rejectDate, client.getSubmittedOnDate());
} else {
client.reject(currentUser, rejectReason, rejectDate.toDate());
this.clientRepository.saveAndFlush(client);
}
client.reject(currentUser, rejectReason, rejectDate.toDate());
this.clientRepository.saveAndFlush(client);
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
@@ -641,17 +641,17 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
final CodeValue withdrawReason = this.codeValueRepository.findOneByCodeNameAndIdWithNotFoundDetection(
ClientApiConstants.CLIENT_WITHDRAW_REASON, withdrawReasonId);
if (ClientStatus.fromInt(client.getStatus()).isRejected()) {
final String errorMessage = "Client is already Withdrawn.";
throw new InvalidClientStateTransitionException("withdrawn", "is.already.withdrawn", errorMessage);
} else if (client.isNotPending() || client.getSubmittedOnDate().isAfter(withdrawDate)) {
final String errorMessage = "The client is active or The client withdrawDate cannot be before the client SubmittedDate.";
throw new InvalidClientStateTransitionException("withdrawn", "date.cannot.before.client.submitted.date", errorMessage,
if (client.isNotPending()) {
final String errorMessage = "Only clients pending activation may be withdrawn.";
throw new InvalidClientStateTransitionException("withdrawal", "on.account.not.in.pending.activation.status", errorMessage,
withdrawDate, client.getSubmittedOnDate());
} else if (client.getSubmittedOnDate().isAfter(withdrawDate)) {
final String errorMessage = "The client withdrawal date cannot be before the client submitted date.";
throw new InvalidClientStateTransitionException("withdrawal", "date.cannot.before.client.submitted.date", errorMessage,
withdrawDate, client.getSubmittedOnDate());
} else {
client.withdraw(currentUser, withdrawReason, withdrawDate.toDate());
this.clientRepository.saveAndFlush(client);
}
client.withdraw(currentUser, withdrawReason, withdrawDate.toDate());
this.clientRepository.saveAndFlush(client);
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
@@ -659,7 +659,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
.withEntityId(entityId) //
.build();
}
@Override
public CommandProcessingResult reActivateClient(Long entityId, JsonCommand command) {
final AppUser currentUser = this.context.authenticatedUser();
@@ -667,15 +667,18 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
final Client client = this.clientRepository.findOneWithNotFoundDetection(entityId);
final LocalDate reactivateDate = command.localDateValueOfParameterNamed(ClientApiConstants.reactivationDateParamName);
if (ClientStatus.fromInt(client.getStatus()).isActive()) {
final String errorMessage = "Client is already activated.";
throw new InvalidClientStateTransitionException("activated", "is.already.activated", errorMessage);
} else if (client.isClosed()) {
client.reActivate(currentUser, reactivateDate.toDate());
this.clientRepository.saveAndFlush(client);
}
if (!client.isClosed()) {
final String errorMessage = "only closed clients may be reactivated.";
throw new InvalidClientStateTransitionException("reactivation", "on.nonclosed.account", errorMessage);
} else if (client.getClosureDate().isAfter(reactivateDate)) {
final String errorMessage = "The client reactivation date cannot be before the client closed date.";
throw new InvalidClientStateTransitionException("reactivation", "date.cannot.before.client.closed.date", errorMessage,
reactivateDate, client.getClosureDate());
}
client.reActivate(currentUser, reactivateDate.toDate());
this.clientRepository.saveAndFlush(client);
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
.withClientId(entityId) //
@@ -1,52 +0,0 @@
ALTER TABLE `m_client`
ADD COLUMN `reject_reason_cv_id` INT(11) NULL DEFAULT NULL AFTER `client_classification_cv_id`,
ADD COLUMN `rejectedon_date` DATE NULL DEFAULT NULL AFTER `reject_reason_cv_id`,
ADD COLUMN `rejectedon_userid` BIGINT(20) NULL DEFAULT NULL AFTER `rejectedon_date`,
ADD COLUMN `withdraw_reason_cv_id` INT(11) NULL DEFAULT NULL AFTER `rejectedon_userid`,
ADD COLUMN `withdrawn_on_date` DATE NULL DEFAULT NULL AFTER `withdraw_reason_cv_id`,
ADD COLUMN `withdraw_on_userid` BIGINT(20) NULL DEFAULT NULL AFTER `withdrawn_on_date`,
ADD CONSTRAINT `FK_m_client_type_mcode_value_reject` FOREIGN KEY (`reject_reason_cv_id`) REFERENCES `m_code_value` (`id`),
ADD CONSTRAINT `FK_m_client_type_m_code_value_withdraw` FOREIGN KEY (`withdraw_reason_cv_id`) REFERENCES `m_code_value` (`id`);
SELECT `DEFAULT_COLLATION_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`='mifostenant-default';
SHOW TABLE STATUS FROM `mifostenant-default`;
SHOW FUNCTION STATUS WHERE `Db`='mifostenant-default';
SHOW PROCEDURE STATUS WHERE `Db`='mifostenant-default';
SHOW TRIGGERS FROM `mifostenant-default`;
SHOW EVENTS FROM `mifostenant-default`;
SHOW CREATE TABLE `mifostenant-default`.`m_client`;
/* Entering session "mifosx" */
ALTER TABLE `m_client`
ADD COLUMN `updated_by` BIGINT(20) NULL DEFAULT NULL AFTER `closedon_date`,
ADD COLUMN `updated_on` DATE NULL DEFAULT NULL AFTER `updated_by`;
INSERT INTO `m_permission` ( `grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ( 'portfolio', 'REJECT_CLIENT', 'CLIENT', 'REJECT', 1);
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ( 'portfolio', 'REJECT_CLIENT_CHECKER', 'CLIENT', 'REJECT_CHECKER', 0);
INSERT INTO `m_permission` ( `grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ( 'portfolio', 'WITHDRAW_CLIENT', 'CLIENT', 'WITHDRAW', 1);
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'WITHDRAW_CLIENT_CHECKER', 'CLIENT', 'WITHDRAW_CHECKER', 0);
INSERT INTO `m_code` ( `code_name`, `is_system_defined`) VALUES ( 'ClientRejectReason', 1);
INSERT INTO `m_code_value` ( `code_id`, `code_value`, `order_position`, `code_score`) VALUES ( (SELECT id from m_code where code_name = 'ClientRejectReason') , 'Client Rejected', 1, NULL);
INSERT INTO `m_code` ( `code_name`, `is_system_defined`) VALUES ( 'ClientWithdrawReason', 1);
INSERT INTO `m_code_value` ( `code_id`, `code_value`, `order_position`, `code_score`) VALUES ( (SELECT id from m_code where code_name = 'ClientWithdrawReason') , 'Client Withdrawn', 1, NULL);
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ( 'portfolio', 'REACTIVATE_CLIENT', 'CLIENT', 'REACTIVATE', 1);
INSERT INTO `m_permission` ( `grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ( 'portfolio', 'REACTIVATE_CLIENT_CHECKER', 'CLIENT', 'REACTIVATE_CHECKER', 0);
ALTER TABLE `m_client`
ADD COLUMN `reactivated_on_date` DATE NULL AFTER `withdraw_on_userid`,
ADD COLUMN `reactivated_on_userid` BIGINT(20) NULL AFTER `reactivated_on_date`;