MIFOSX-2047
This commit is contained in:
+24
-40
@@ -47,28 +47,22 @@ public class Hook extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
private HookTemplate template;
|
private HookTemplate template;
|
||||||
|
|
||||||
@ManyToOne(optional = true)
|
@ManyToOne(optional = true)
|
||||||
@JoinColumn(name = "ugd_template_id", referencedColumnName = "id", nullable = false)
|
@JoinColumn(name = "ugd_template_id", referencedColumnName = "id", nullable = true)
|
||||||
private Template ugdTemplate;
|
private Template ugdTemplate;
|
||||||
|
|
||||||
protected Hook() {
|
protected Hook() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Hook fromJson(final JsonCommand command,
|
public static Hook fromJson(final JsonCommand command, final HookTemplate template, final Set<HookConfiguration> config,
|
||||||
final HookTemplate template, final Set<HookConfiguration> config,
|
|
||||||
final Set<HookResource> events, final Template ugdTemplate) {
|
final Set<HookResource> events, final Template ugdTemplate) {
|
||||||
final String displayName = command
|
final String displayName = command.stringValueOfParameterNamed(displayNameParamName);
|
||||||
.stringValueOfParameterNamed(displayNameParamName);
|
Boolean isActive = command.booleanObjectValueOfParameterNamed(isActiveParamName);
|
||||||
Boolean isActive = command
|
if (isActive == null) isActive = false;
|
||||||
.booleanObjectValueOfParameterNamed(isActiveParamName);
|
return new Hook(template, displayName, isActive, config, events, ugdTemplate);
|
||||||
if (isActive == null)
|
|
||||||
isActive = false;
|
|
||||||
return new Hook(template, displayName, isActive, config, events,
|
|
||||||
ugdTemplate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Hook(final HookTemplate template, final String displayName,
|
private Hook(final HookTemplate template, final String displayName, final Boolean isActive, final Set<HookConfiguration> config,
|
||||||
final Boolean isActive, final Set<HookConfiguration> config,
|
|
||||||
final Set<HookResource> events, final Template ugdTemplate) {
|
final Set<HookResource> events, final Template ugdTemplate) {
|
||||||
|
|
||||||
this.template = template;
|
this.template = template;
|
||||||
@@ -89,16 +83,14 @@ public class Hook extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
this.ugdTemplate = ugdTemplate;
|
this.ugdTemplate = ugdTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<HookConfiguration> associateConfigWithThisHook(
|
private Set<HookConfiguration> associateConfigWithThisHook(final Set<HookConfiguration> config) {
|
||||||
final Set<HookConfiguration> config) {
|
|
||||||
for (final HookConfiguration hookConfiguration : config) {
|
for (final HookConfiguration hookConfiguration : config) {
|
||||||
hookConfiguration.update(this);
|
hookConfiguration.update(this);
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<HookResource> associateEventsWithThisHook(
|
private Set<HookResource> associateEventsWithThisHook(final Set<HookResource> events) {
|
||||||
final Set<HookResource> events) {
|
|
||||||
for (final HookResource hookResource : events) {
|
for (final HookResource hookResource : events) {
|
||||||
hookResource.update(this);
|
hookResource.update(this);
|
||||||
}
|
}
|
||||||
@@ -114,7 +106,11 @@ public class Hook extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Long getUgdTemplateId() {
|
public Long getUgdTemplateId() {
|
||||||
return this.ugdTemplate.getId();
|
Long templateId = null;
|
||||||
|
if (this.ugdTemplate != null) {
|
||||||
|
templateId = this.ugdTemplate.getId();
|
||||||
|
}
|
||||||
|
return templateId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<HookConfiguration> getHookConfig() {
|
public Set<HookConfiguration> getHookConfig() {
|
||||||
@@ -125,33 +121,26 @@ public class Hook extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
|
|
||||||
final Map<String, Object> actualChanges = new LinkedHashMap<>(5);
|
final Map<String, Object> actualChanges = new LinkedHashMap<>(5);
|
||||||
|
|
||||||
if (command.isChangeInStringParameterNamed(displayNameParamName,
|
if (command.isChangeInStringParameterNamed(displayNameParamName, this.name)) {
|
||||||
this.name)) {
|
final String newValue = command.stringValueOfParameterNamed(displayNameParamName);
|
||||||
final String newValue = command
|
|
||||||
.stringValueOfParameterNamed(displayNameParamName);
|
|
||||||
actualChanges.put(displayNameParamName, newValue);
|
actualChanges.put(displayNameParamName, newValue);
|
||||||
this.name = newValue;
|
this.name = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.isChangeInBooleanParameterNamed(isActiveParamName,
|
if (command.isChangeInBooleanParameterNamed(isActiveParamName, this.isActive)) {
|
||||||
this.isActive)) {
|
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isActiveParamName);
|
||||||
final Boolean newValue = command
|
|
||||||
.booleanObjectValueOfParameterNamed(isActiveParamName);
|
|
||||||
actualChanges.put(isActiveParamName, newValue);
|
actualChanges.put(isActiveParamName, newValue);
|
||||||
this.isActive = newValue;
|
this.isActive = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.isChangeInLongParameterNamed(templateIdParamName,
|
if (command.isChangeInLongParameterNamed(templateIdParamName, getUgdTemplateId())) {
|
||||||
getUgdTemplateId())) {
|
final Long newValue = command.longValueOfParameterNamed(templateIdParamName);
|
||||||
final Long newValue = command
|
|
||||||
.longValueOfParameterNamed(templateIdParamName);
|
|
||||||
actualChanges.put(templateIdParamName, newValue);
|
actualChanges.put(templateIdParamName, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// events
|
// events
|
||||||
if (command.hasParameter(eventsParamName)) {
|
if (command.hasParameter(eventsParamName)) {
|
||||||
final JsonArray jsonArray = command
|
final JsonArray jsonArray = command.arrayOfParameterNamed(eventsParamName);
|
||||||
.arrayOfParameterNamed(eventsParamName);
|
|
||||||
if (jsonArray != null) {
|
if (jsonArray != null) {
|
||||||
actualChanges.put(eventsParamName, jsonArray);
|
actualChanges.put(eventsParamName, jsonArray);
|
||||||
}
|
}
|
||||||
@@ -159,8 +148,7 @@ public class Hook extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
|
|
||||||
// config
|
// config
|
||||||
if (command.hasParameter(configParamName)) {
|
if (command.hasParameter(configParamName)) {
|
||||||
final JsonElement element = command.parsedJson().getAsJsonObject()
|
final JsonElement element = command.parsedJson().getAsJsonObject().get(configParamName);
|
||||||
.get(configParamName);
|
|
||||||
if (element != null) {
|
if (element != null) {
|
||||||
actualChanges.put(configParamName, element);
|
actualChanges.put(configParamName, element);
|
||||||
}
|
}
|
||||||
@@ -170,9 +158,7 @@ public class Hook extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateEvents(final Set<HookResource> newHookEvents) {
|
public boolean updateEvents(final Set<HookResource> newHookEvents) {
|
||||||
if (newHookEvents == null) {
|
if (newHookEvents == null) { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.events == null) {
|
if (this.events == null) {
|
||||||
this.events = new HashSet<>();
|
this.events = new HashSet<>();
|
||||||
@@ -183,9 +169,7 @@ public class Hook extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateConfig(final Set<HookConfiguration> newHookConfig) {
|
public boolean updateConfig(final Set<HookConfiguration> newHookConfig) {
|
||||||
if (newHookConfig == null) {
|
if (newHookConfig == null) { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.config == null) {
|
if (this.config == null) {
|
||||||
this.config = new HashSet<>();
|
this.config = new HashSet<>();
|
||||||
|
|||||||
+1
-1
@@ -197,7 +197,7 @@ public class HookWritePlatformServiceJpaRepositoryImpl
|
|||||||
private Hook retrieveHookBy(final Long hookId) {
|
private Hook retrieveHookBy(final Long hookId) {
|
||||||
final Hook hook = this.hookRepository.findOne(hookId);
|
final Hook hook = this.hookRepository.findOne(hookId);
|
||||||
if (hook == null) {
|
if (hook == null) {
|
||||||
throw new HookNotFoundException(hookId.toString());
|
throw new HookNotFoundException(hookId);
|
||||||
}
|
}
|
||||||
return hook;
|
return hook;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user