diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 7a19b3987..224f6296a 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -196,7 +196,7 @@
Clients can be rejected when client is in pending status. This API exists to reject a client .
-If the client is any other status results in error.
+Clients can be rejected when client is in pending for activation status.
+If the client is any other status, this API throws an error.
+Mandatory Fields |
+
| rejectDate, rejectReasonId + |
+
POST https://Domain Name/api/v1/clients/{clientId}?command=reject
POST clients/1?command=reject
@@ -3572,8 +3582,17 @@ Request Body:
Withdraw a Client
- Clients can be withdrawn when client is in pending status. This API exists to withdraw a client .
- If the client is any other status results in error.
+ Client applications can be withdrawn when client is in a pending for activation status.
+ If the client is any other status, this API throws an error.
+
+
+ Mandatory Fields
+
+
+ withdrawDate, withdrawReasonId
+
+
+
POST https://Domain Name/api/v1/clients/{clientId}?command=withdraw
@@ -3601,9 +3620,18 @@ Request Body:
- Reactivating a Client
- Clients can be reactivated when client is in closed status. This API exists to reactivate a client .
- If the client is any other status results in error.
+ Reactivate a Client
+ Clients can be reactivated after they have been closed.
+ Trying to reactivate a client in any other state throws an error.
+
+
+ Mandatory Fields
+
+
+ reactivationDate
+
+
+
POST https://Domain Name/api/v1/clients/{clientId}?command=reactivate
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java
index 98ffb7802..8b3f3327a 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java
@@ -156,7 +156,7 @@ public final class Client extends AbstractPersistable {
@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 {
@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 {
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 {
this.status = ClientStatus.WITHDRAWN.getValue();
}
+
public void reActivate(AppUser currentUser, Date reactivateDate) {
this.reactivateDate = reactivateDate;
this.reactivatedBy = currentUser;
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java
index 7694bf4b9..eb8d50ad0 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java
@@ -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) //
diff --git a/mifosng-provider/src/main/resources/sql/migrations/core_db/V220__Client_Lifecycle_Adding_Statuses.sql b/mifosng-provider/src/main/resources/sql/migrations/core_db/V220__Client_Lifecycle_Adding_Statuses.sql
deleted file mode 100644
index c0b838ac0..000000000
--- a/mifosng-provider/src/main/resources/sql/migrations/core_db/V220__Client_Lifecycle_Adding_Statuses.sql
+++ /dev/null
@@ -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`;
\ No newline at end of file