MIFOSX-213: center, group and clients api for activating entity to move from pending to active status.

This commit is contained in:
Keith Woodlock
2013-04-21 23:57:10 +01:00
parent 500767a400
commit ea0ee84967
8 changed files with 48 additions and 100 deletions
+3 -1
View File
@@ -2050,7 +2050,9 @@ GET https://DomainName/api/v1/clients
<div class="method-section">
<div class="method-description">
<h4>Update a Client</h4>
<p>You can update any attribute of a client except for its association with <i>groups</i>. The relationship between a client and a group must be removed through the <b>Groups</b> API.</p>
<p><b>Note:</b>You can update any of the basic attributes of a client using this API but not its associations.</p>
<p>Chaning the relationship between a client and its office is not supported through this API. An API specific to handling <b>transfers</b> of clients between offices will be introduced for this.</p>
<p>The relationship between a client and a group must be removed through the <b>Groups</b> API.</p>
</div>
<div class="method-example">
<code class="method-declaration">
@@ -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<String> CLIENT_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(localeParamName,
public static final Set<String> CLIENT_CREATE_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(localeParamName,
dateFormatParamName, groupIdParamName, accountNoParamName, externalIdParamName, firstnameParamName, middlenameParamName,
lastnameParamName, fullnameParamName, officeIdParamName, staffIdParamName, activeParamName, activationDateParamName));
lastnameParamName, fullnameParamName, officeIdParamName, activeParamName, activationDateParamName));
public static final Set<String> CLIENT_UPDATE_REQUEST_DATA_PARAMETERS = new HashSet<String>(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<String> CLIENT_RESPONSE_DATA_PARAMETERS = new HashSet<String>(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<String> ACTIVATION_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(localeParamName,
dateFormatParamName, activationDateParamName));
@@ -42,7 +42,7 @@ public final class ClientDataValidator {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.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<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
@@ -87,7 +87,7 @@ public final class ClientDataValidator {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.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<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
@@ -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()) {
@@ -187,29 +187,6 @@ public final class Client extends AbstractPersistable<Long> {
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<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
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<Long> {
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<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
dataValidationErrors.add(error);
@@ -231,7 +208,7 @@ public final class Client extends AbstractPersistable<Long> {
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<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
dataValidationErrors.add(error);
@@ -285,11 +262,6 @@ public final class Client extends AbstractPersistable<Long> {
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<Long> {
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<Long> {
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;
}
@@ -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();
@@ -176,14 +176,6 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
final Map<String, Object> 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);
@@ -54,7 +54,7 @@ public class GroupingTypesApiConstants {
*/
public static final Set<String> CENTER_RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(idParamName, nameParamName,
externalIdParamName, officeIdParamName, officeNameParamName, staffIdParamName, staffNameParamName, hierarchyParamName,
"officeOptions", "staffOptions"));
officeOptionsParamName, staffOptionsParamName));
public static final Set<String> CENTER_GROUP_RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(idParamName, nameParamName,
externalIdParamName, officeIdParamName, officeNameParamName, staffIdParamName, staffNameParamName, hierarchyParamName,
@@ -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) {