From ea0ee849673168f21b560e0961ba6a593319aa32 Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Sun, 21 Apr 2013 23:57:10 +0100 Subject: [PATCH] MIFOSX-213: center, group and clients api for activating entity to move from pending to active status. --- api-docs/apiLive.htm | 4 +- .../client/api/ClientApiConstants.java | 19 +++-- .../client/data/ClientDataValidator.java | 10 +-- .../portfolio/client/domain/Client.java | 83 +++++-------------- ...WritePlatformServiceJpaRepositoryImpl.java | 2 +- ...WritePlatformServiceJpaRepositoryImpl.java | 18 ++-- .../group/api/GroupingTypesApiConstants.java | 2 +- ...WritePlatformServiceJpaRepositoryImpl.java | 10 ++- 8 files changed, 48 insertions(+), 100 deletions(-) diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 829bc7968..1f97a4954 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -2050,7 +2050,9 @@ GET https://DomainName/api/v1/clients

Update a Client

-

You can update any attribute of a client except for its association with groups. The relationship between a client and a group must be removed through the Groups API.

+

Note:You can update any of the basic attributes of a client using this API but not its associations.

+

Chaning the relationship between a client and its office is not supported through this API. An API specific to handling transfers of clients between offices will be introduced for this.

+

The relationship between a client and a group must be removed through the Groups API.

diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientApiConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientApiConstants.java index 880478375..18b063aa8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientApiConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientApiConstants.java @@ -24,7 +24,6 @@ public class ClientApiConstants { public static final String lastnameParamName = "lastname"; public static final String fullnameParamName = "fullname"; public static final String officeIdParamName = "officeId"; - public static final String staffIdParamName = "staffId"; public static final String activeParamName = "active"; public static final String activationDateParamName = "activationDate"; @@ -33,20 +32,22 @@ public class ClientApiConstants { public static final String hierarchyParamName = "hierarchy"; public static final String displayNameParamName = "displayName"; public static final String officeNameParamName = "officeName"; - public static final String staffNameParamName = "staffName"; public static final String imageKeyParamName = "imageKey"; public static final String imagePresentParamName = "imagePresent"; // associations related part of response - public static final String parentGroupsParamName = "groups"; + public static final String groupsParamName = "groups"; // template related part of response public static final String officeOptionsParamName = "officeOptions"; - public static final String staffOptionsParamName = "staffOptions"; - public static final Set CLIENT_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, + public static final Set CLIENT_CREATE_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, dateFormatParamName, groupIdParamName, accountNoParamName, externalIdParamName, firstnameParamName, middlenameParamName, - lastnameParamName, fullnameParamName, officeIdParamName, staffIdParamName, activeParamName, activationDateParamName)); + lastnameParamName, fullnameParamName, officeIdParamName, activeParamName, activationDateParamName)); + + public static final Set CLIENT_UPDATE_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, + dateFormatParamName, accountNoParamName, externalIdParamName, firstnameParamName, middlenameParamName, + lastnameParamName, fullnameParamName, activeParamName, activationDateParamName)); /** * These parameters will match the class level parameters of @@ -54,9 +55,9 @@ public class ClientApiConstants { * match those of request parameters. */ public static final Set CLIENT_RESPONSE_DATA_PARAMETERS = new HashSet(Arrays.asList(idParamName, accountNoParamName, - externalIdParamName, statusParamName, firstnameParamName, middlenameParamName, lastnameParamName, fullnameParamName, - displayNameParamName, officeIdParamName, officeNameParamName, staffIdParamName, staffNameParamName, hierarchyParamName, - officeOptionsParamName, staffOptionsParamName)); + externalIdParamName, statusParamName, activeParamName, activationDateParamName, firstnameParamName, middlenameParamName, + lastnameParamName, fullnameParamName, displayNameParamName, officeIdParamName, officeNameParamName, hierarchyParamName, + imageKeyParamName, imagePresentParamName, groupsParamName, officeOptionsParamName)); public static final Set ACTIVATION_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, dateFormatParamName, activationDateParamName)); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientDataValidator.java index aff0d51d5..23d2e90aa 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientDataValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientDataValidator.java @@ -42,7 +42,7 @@ public final class ClientDataValidator { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); - fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, ClientApiConstants.CLIENT_REQUEST_DATA_PARAMETERS); + fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, ClientApiConstants.CLIENT_CREATE_REQUEST_DATA_PARAMETERS); final JsonElement element = fromApiJsonHelper.parse(json); final List dataValidationErrors = new ArrayList(); @@ -87,7 +87,7 @@ public final class ClientDataValidator { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); - fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, ClientApiConstants.CLIENT_REQUEST_DATA_PARAMETERS); + fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, ClientApiConstants.CLIENT_UPDATE_REQUEST_DATA_PARAMETERS); final JsonElement element = fromApiJsonHelper.parse(json); final List dataValidationErrors = new ArrayList(); @@ -124,12 +124,6 @@ public final class ClientDataValidator { atLeastOneParameterPassedForUpdate = true; } - if (fromApiJsonHelper.parameterExists(ClientApiConstants.officeIdParamName, element)) { - atLeastOneParameterPassedForUpdate = true; - final Long officeId = fromApiJsonHelper.extractLongNamed(ClientApiConstants.officeIdParamName, element); - baseDataValidator.reset().parameter(ClientApiConstants.officeIdParamName).value(officeId).notNull().integerGreaterThanZero(); - } - final Boolean active = fromApiJsonHelper.extractBooleanNamed(ClientApiConstants.activeParamName, element); if (active != null) { if (active.booleanValue()) { 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 70a2af00d..dde06235b 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 @@ -187,29 +187,6 @@ public final class Client extends AbstractPersistable { return getId().equals(clientId); } - public void changeOffice(final Office newOffice) { - if (isNotAMemberOfAGroup()) { - this.office = newOffice; - } else { - cannotUpdateOfficeOfClientThatBelongsInGroupException(newOffice); - } - } - - private boolean isNotAMemberOfAGroup() { - return this.groups == null || this.groups.isEmpty(); - } - - private void cannotUpdateOfficeOfClientThatBelongsInGroupException(final Office newOffice) { - final String defaultUserMessage = "Cannot update office of client that is member of a group."; - final ApiParameterError error = ApiParameterError.parameterError("error.msg.client.member.of.group.and.cannot.update.office", - defaultUserMessage, ClientApiConstants.officeIdParamName, newOffice.getId(), newOffice.getName()); - - final List dataValidationErrors = new ArrayList(); - dataValidationErrors.add(error); - - throw new PlatformApiDataValidationException(dataValidationErrors); - } - public void updateAccountNo(final String accountIdentifier) { this.accountNumber = accountIdentifier; this.accountNumberRequiresAutoGeneration = false; @@ -219,7 +196,7 @@ public final class Client extends AbstractPersistable { if (isActive()) { final String defaultUserMessage = "Cannot activate client. Client is already active."; final ApiParameterError error = ApiParameterError.parameterError("error.msg.clients.already.active", defaultUserMessage, - "activationDate", activationLocalDate.toString(formatter)); + ClientApiConstants.activationDateParamName, activationLocalDate.toString(formatter)); final List dataValidationErrors = new ArrayList(); dataValidationErrors.add(error); @@ -231,7 +208,7 @@ public final class Client extends AbstractPersistable { final String defaultUserMessage = "Activation date cannot be in the future."; final ApiParameterError error = ApiParameterError.parameterError("error.msg.clients.activationDate.in.the.future", - defaultUserMessage, "activationDate", activationLocalDate); + defaultUserMessage, ClientApiConstants.activationDateParamName, activationLocalDate); final List dataValidationErrors = new ArrayList(); dataValidationErrors.add(error); @@ -285,11 +262,6 @@ public final class Client extends AbstractPersistable { this.externalId = StringUtils.defaultIfEmpty(newValue, null); } - if (command.isChangeInLongParameterNamed(ClientApiConstants.officeIdParamName, this.office.getId())) { - final Long newValue = command.longValueOfParameterNamed(ClientApiConstants.officeIdParamName); - actualChanges.put(ClientApiConstants.officeIdParamName, newValue); - } - if (command.isChangeInStringParameterNamed(ClientApiConstants.firstnameParamName, this.firstname)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.firstnameParamName); actualChanges.put(ClientApiConstants.firstnameParamName, newValue); @@ -341,32 +313,35 @@ public final class Client extends AbstractPersistable { if (StringUtils.isNotBlank(this.fullname)) { - baseDataValidator.reset().parameter("firstname").value(this.firstname) - .mustBeBlankWhenParameterProvided("fullname", this.fullname); + baseDataValidator.reset().parameter(ClientApiConstants.firstnameParamName).value(this.firstname) + .mustBeBlankWhenParameterProvided(ClientApiConstants.fullnameParamName, this.fullname); - baseDataValidator.reset().parameter("middlename").value(this.middlename) - .mustBeBlankWhenParameterProvided("fullname", this.fullname); + baseDataValidator.reset().parameter(ClientApiConstants.middlenameParamName).value(this.middlename) + .mustBeBlankWhenParameterProvided(ClientApiConstants.fullnameParamName, this.fullname); - baseDataValidator.reset().parameter("lastname").value(this.lastname) - .mustBeBlankWhenParameterProvided("fullname", this.fullname); + baseDataValidator.reset().parameter(ClientApiConstants.lastnameParamName).value(this.lastname) + .mustBeBlankWhenParameterProvided(ClientApiConstants.fullnameParamName, this.fullname); } if (StringUtils.isBlank(this.fullname)) { - baseDataValidator.reset().parameter("firstname").value(this.firstname).notBlank().notExceedingLengthOf(50); - baseDataValidator.reset().parameter("middlename").value(this.middlename).ignoreIfNull().notExceedingLengthOf(50); - baseDataValidator.reset().parameter("lastname").value(this.lastname).notBlank().notExceedingLengthOf(50); + baseDataValidator.reset().parameter(ClientApiConstants.firstnameParamName).value(this.firstname).notBlank() + .notExceedingLengthOf(50); + baseDataValidator.reset().parameter(ClientApiConstants.middlenameParamName).value(this.middlename).ignoreIfNull() + .notExceedingLengthOf(50); + baseDataValidator.reset().parameter(ClientApiConstants.lastnameParamName).value(this.lastname).notBlank() + .notExceedingLengthOf(50); } if (this.activationDate != null) { if (office.isOpeningDateAfter(getActivationLocalDate())) { final String defaultUserMessage = "Client activation date cannot be a date before the office opening date."; final ApiParameterError error = ApiParameterError.parameterError( - "error.msg.clients.activationDate.cannot.be.before.office.activation.date", defaultUserMessage, "activationDate", - getActivationLocalDate()); + "error.msg.clients.activationDate.cannot.be.before.office.activation.date", defaultUserMessage, + ClientApiConstants.activationDateParamName, getActivationLocalDate()); dataValidationErrors.add(error); } - } + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } @@ -404,31 +379,11 @@ public final class Client extends AbstractPersistable { return this.office.identifiedBy(officeId); } - public Office getOffice() { - return office; - } - - public String getFirstName() { - return firstname; - } - - public String getLastName() { - return lastname; - } - - public Date getJoiningDate() { - return activationDate; - } - - public String getExternalId() { - return externalId; - } - - public String getImageKey() { + public String imageKey() { return imageKey; } - public void setImageKey(final String imageKey) { + public void updateImageKey(final String imageKey) { this.imageKey = imageKey; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientIdentifierWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientIdentifierWritePlatformServiceJpaRepositoryImpl.java index b8a0bd3b0..4cbae1985 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientIdentifierWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientIdentifierWritePlatformServiceJpaRepositoryImpl.java @@ -79,7 +79,7 @@ public class ClientIdentifierWritePlatformServiceJpaRepositoryImpl implements Cl return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // - .withOfficeId(client.getOffice().getId()) // + .withOfficeId(client.officeId()) // .withClientId(clientId) // .withEntityId(clientIdentifier.getId()) // .build(); 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 79f5e83fd..0bc4fb35f 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 @@ -176,14 +176,6 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP final Map changes = clientForUpdate.update(command); - if (changes.containsKey(ClientApiConstants.officeIdParamName)) { - final Long officeId = (Long) changes.get(ClientApiConstants.officeIdParamName); - final Office newOffice = this.officeRepository.findOne(officeId); - if (newOffice == null) { throw new OfficeNotFoundException(officeId); } - - clientForUpdate.changeOffice(newOffice); - } - if (!changes.isEmpty()) { this.clientRepository.saveAndFlush(clientForUpdate); } @@ -252,8 +244,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId); // delete image from the file system - if (StringUtils.isNotEmpty(client.getImageKey())) { - FileUtils.deleteClientImage(clientId, client.getImageKey()); + if (StringUtils.isNotEmpty(client.imageKey())) { + FileUtils.deleteClientImage(clientId, client.imageKey()); } return updateClientImage(clientId, client, null); } @@ -278,8 +270,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP final String imageUploadLocation = FileUtils.generateClientImageParentDirectory(clientId); // delete previous image from the file system - if (StringUtils.isNotEmpty(client.getImageKey())) { - FileUtils.deleteClientImage(clientId, client.getImageKey()); + if (StringUtils.isNotEmpty(client.imageKey())) { + FileUtils.deleteClientImage(clientId, client.imageKey()); } /** Recursively create the directory if it does not exist **/ @@ -290,7 +282,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP } private CommandProcessingResult updateClientImage(final Long clientId, final Client client, final String imageLocation) { - client.setImageKey(imageLocation); + client.updateImageKey(imageLocation); this.clientRepository.save(client); return new CommandProcessingResult(clientId); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupingTypesApiConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupingTypesApiConstants.java index a296a9044..b6d55653e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupingTypesApiConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupingTypesApiConstants.java @@ -54,7 +54,7 @@ public class GroupingTypesApiConstants { */ public static final Set CENTER_RESPONSE_DATA_PARAMETERS = new HashSet(Arrays.asList(idParamName, nameParamName, externalIdParamName, officeIdParamName, officeNameParamName, staffIdParamName, staffNameParamName, hierarchyParamName, - "officeOptions", "staffOptions")); + officeOptionsParamName, staffOptionsParamName)); public static final Set CENTER_GROUP_RESPONSE_DATA_PARAMETERS = new HashSet(Arrays.asList(idParamName, nameParamName, externalIdParamName, officeIdParamName, officeNameParamName, staffIdParamName, staffNameParamName, hierarchyParamName, diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/note/service/NoteWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/note/service/NoteWritePlatformServiceJpaRepositoryImpl.java index dbca4202f..0753a6565 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/note/service/NoteWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/note/service/NoteWritePlatformServiceJpaRepositoryImpl.java @@ -67,7 +67,9 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(newNote.getId()) // - .withClientId(client.getId()).withOfficeId(client.getOffice().getId()).build(); + .withClientId(client.getId()) // + .withOfficeId(client.officeId()) // + .build(); } @@ -207,8 +209,10 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(noteForUpdate.getId()) // - .withClientId(client.getId()).withOfficeId(client.getOffice().getId()).with(changes).build(); - + .withClientId(client.getId()) // + .withOfficeId(client.officeId()) // + .with(changes) // + .build(); } private CommandProcessingResult updateGroupNote(final JsonCommand command) {