diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/hooks/domain/Hook.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/hooks/domain/Hook.java index 595138000..6c68ede7e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/hooks/domain/Hook.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/hooks/domain/Hook.java @@ -47,28 +47,22 @@ public class Hook extends AbstractAuditableCustom { private HookTemplate template; @ManyToOne(optional = true) - @JoinColumn(name = "ugd_template_id", referencedColumnName = "id", nullable = false) + @JoinColumn(name = "ugd_template_id", referencedColumnName = "id", nullable = true) private Template ugdTemplate; protected Hook() { // } - public static Hook fromJson(final JsonCommand command, - final HookTemplate template, final Set config, + public static Hook fromJson(final JsonCommand command, final HookTemplate template, final Set config, final Set events, final Template ugdTemplate) { - final String displayName = command - .stringValueOfParameterNamed(displayNameParamName); - Boolean isActive = command - .booleanObjectValueOfParameterNamed(isActiveParamName); - if (isActive == null) - isActive = false; - return new Hook(template, displayName, isActive, config, events, - ugdTemplate); + final String displayName = command.stringValueOfParameterNamed(displayNameParamName); + Boolean isActive = command.booleanObjectValueOfParameterNamed(isActiveParamName); + if (isActive == null) isActive = false; + return new Hook(template, displayName, isActive, config, events, ugdTemplate); } - private Hook(final HookTemplate template, final String displayName, - final Boolean isActive, final Set config, + private Hook(final HookTemplate template, final String displayName, final Boolean isActive, final Set config, final Set events, final Template ugdTemplate) { this.template = template; @@ -89,16 +83,14 @@ public class Hook extends AbstractAuditableCustom { this.ugdTemplate = ugdTemplate; } - private Set associateConfigWithThisHook( - final Set config) { + private Set associateConfigWithThisHook(final Set config) { for (final HookConfiguration hookConfiguration : config) { hookConfiguration.update(this); } return config; } - private Set associateEventsWithThisHook( - final Set events) { + private Set associateEventsWithThisHook(final Set events) { for (final HookResource hookResource : events) { hookResource.update(this); } @@ -114,7 +106,11 @@ public class Hook extends AbstractAuditableCustom { } public Long getUgdTemplateId() { - return this.ugdTemplate.getId(); + Long templateId = null; + if (this.ugdTemplate != null) { + templateId = this.ugdTemplate.getId(); + } + return templateId; } public Set getHookConfig() { @@ -125,33 +121,26 @@ public class Hook extends AbstractAuditableCustom { final Map actualChanges = new LinkedHashMap<>(5); - if (command.isChangeInStringParameterNamed(displayNameParamName, - this.name)) { - final String newValue = command - .stringValueOfParameterNamed(displayNameParamName); + if (command.isChangeInStringParameterNamed(displayNameParamName, this.name)) { + final String newValue = command.stringValueOfParameterNamed(displayNameParamName); actualChanges.put(displayNameParamName, newValue); this.name = newValue; } - if (command.isChangeInBooleanParameterNamed(isActiveParamName, - this.isActive)) { - final Boolean newValue = command - .booleanObjectValueOfParameterNamed(isActiveParamName); + if (command.isChangeInBooleanParameterNamed(isActiveParamName, this.isActive)) { + final Boolean newValue = command.booleanObjectValueOfParameterNamed(isActiveParamName); actualChanges.put(isActiveParamName, newValue); this.isActive = newValue; } - if (command.isChangeInLongParameterNamed(templateIdParamName, - getUgdTemplateId())) { - final Long newValue = command - .longValueOfParameterNamed(templateIdParamName); + if (command.isChangeInLongParameterNamed(templateIdParamName, getUgdTemplateId())) { + final Long newValue = command.longValueOfParameterNamed(templateIdParamName); actualChanges.put(templateIdParamName, newValue); } // events if (command.hasParameter(eventsParamName)) { - final JsonArray jsonArray = command - .arrayOfParameterNamed(eventsParamName); + final JsonArray jsonArray = command.arrayOfParameterNamed(eventsParamName); if (jsonArray != null) { actualChanges.put(eventsParamName, jsonArray); } @@ -159,8 +148,7 @@ public class Hook extends AbstractAuditableCustom { // config if (command.hasParameter(configParamName)) { - final JsonElement element = command.parsedJson().getAsJsonObject() - .get(configParamName); + final JsonElement element = command.parsedJson().getAsJsonObject().get(configParamName); if (element != null) { actualChanges.put(configParamName, element); } @@ -170,9 +158,7 @@ public class Hook extends AbstractAuditableCustom { } public boolean updateEvents(final Set newHookEvents) { - if (newHookEvents == null) { - return false; - } + if (newHookEvents == null) { return false; } if (this.events == null) { this.events = new HashSet<>(); @@ -183,9 +169,7 @@ public class Hook extends AbstractAuditableCustom { } public boolean updateConfig(final Set newHookConfig) { - if (newHookConfig == null) { - return false; - } + if (newHookConfig == null) { return false; } if (this.config == null) { this.config = new HashSet<>(); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/hooks/service/HookWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/hooks/service/HookWritePlatformServiceJpaRepositoryImpl.java index daa5c3fb3..c9373d2f1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/hooks/service/HookWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/hooks/service/HookWritePlatformServiceJpaRepositoryImpl.java @@ -197,7 +197,7 @@ public class HookWritePlatformServiceJpaRepositoryImpl private Hook retrieveHookBy(final Long hookId) { final Hook hook = this.hookRepository.findOne(hookId); if (hook == null) { - throw new HookNotFoundException(hookId.toString()); + throw new HookNotFoundException(hookId); } return hook; }