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); }