From 08a8b8cff086c0706854961f409b2903abf21286 Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Sat, 15 Dec 2012 22:15:21 +0000 Subject: [PATCH] fix issue with updating root office details. --- .../mifosplatform/infrastructure/core/api/JsonCommand.java | 2 +- .../mifosplatform/organisation/office/domain/Office.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/JsonCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/JsonCommand.java index 13239e9b6..e9c2b8bd3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/JsonCommand.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/JsonCommand.java @@ -133,7 +133,7 @@ public final class JsonCommand { return differenceExists; } - private boolean parameterExists(final String parameterName) { + public boolean parameterExists(final String parameterName) { return this.fromApiJsonHelper.parameterExists(parameterName, parsedCommand); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/domain/Office.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/domain/Office.java index ff668176f..df1c67648 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/domain/Office.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/domain/Office.java @@ -101,7 +101,12 @@ public class Office extends AbstractAuditableCustom { final String localeAsInput = command.locale(); final String parentIdParamName = "parentId"; - if (command.isChangeInLongParameterNamed(parentIdParamName, this.parent.getId())) { + + if (command.parameterExists(parentIdParamName) && this.parent == null) { + throw new RootOfficeParentCannotBeUpdated(); + } + + if (this.parent != null && command.isChangeInLongParameterNamed(parentIdParamName, this.parent.getId())) { final Long newValue = command.longValueOfParameterNamed(parentIdParamName); actualChanges.put(parentIdParamName, newValue); }