diff options
author | 2019-04-02 15:23:33 +0900 | |
---|---|---|
committer | 2019-04-02 15:23:50 +0900 | |
commit | 976775a6d9877d5df437f6b06073dee32198a10d (patch) | |
tree | 8011b6d2c8e651455f8f6769e95171e2c1ac7a67 /src/main/java/org/onap | |
parent | 0429a71c2ca41cd311473c9485fa98bbcadaa542 (diff) |
Implement builder pattern
Issue-ID: DCAEGEN2-1379
Change-Id: I7e9a98dcc12ef88a067fdf2837437d859ee65851
Signed-off-by: Arindam Mondal <arind.mondal@samsung.com>
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r-- | src/main/java/org/onap/dcae/controller/AccessController.java | 22 | ||||
-rw-r--r-- | src/main/java/org/onap/dcae/controller/PersistentEventConnection.java | 113 |
2 files changed, 98 insertions, 37 deletions
diff --git a/src/main/java/org/onap/dcae/controller/AccessController.java b/src/main/java/org/onap/dcae/controller/AccessController.java index 226ead5..1c78d99 100644 --- a/src/main/java/org/onap/dcae/controller/AccessController.java +++ b/src/main/java/org/onap/dcae/controller/AccessController.java @@ -165,15 +165,19 @@ public class AccessController { for (int j = 0; j < eventlists.length(); j++) { JSONObject event = eventlists.getJSONObject(j); String name = event.get("event_name").toString(); - PersistentEventConnection conn = new PersistentEventConnection(name, - event.get("event_description").toString(), - Boolean.parseBoolean(event.get("event_sseventUrlEmbed").toString()), - event.get("event_sseventsField").toString(), - event.get("event_sseventsUrl").toString(), - event.get("event_subscriptionTemplate").toString(), - event.get("event_unSubscriptionTemplate").toString(), - event.get("event_ruleId").toString(), - this); + PersistentEventConnection conn = + new PersistentEventConnection.PersistentEventConnectionBuilder().setEventName(name) + .setEventDescription(event.get("event_description").toString()) + .setEventSseventUrlEmbed( + Boolean.parseBoolean(event.get("event_sseventUrlEmbed").toString())) + .setEventSseventsField(event.get("event_sseventsField").toString()) + .setEventSseventsUrl(event.get("event_sseventsUrl").toString()) + .setEventSubscriptionTemplate( + event.get("event_subscriptionTemplate").toString()) + .setEventUnSubscriptionTemplate( + event.get("event_unSubscriptionTemplate").toString()) + .setEventRuleId(event.get("event_ruleId").toString()).setParentCtrllr(this) + .createPersistentEventConnection(); eventList.put(name, conn); executor.execute(conn); diff --git a/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java b/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java index 047936d..860c0c9 100644 --- a/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java +++ b/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java @@ -61,34 +61,91 @@ public class PersistentEventConnection implements Runnable { private AccessController parentCtrllr; private Map<String, String> eventParaMap; - public PersistentEventConnection(String event_name, - String event_description, - boolean event_sseventUrlEmbed, - String event_sseventsField, - String event_sseventsUrl, - String event_subscriptionTemplate, - String event_unSubscriptionTemplate, - String event_ruleId, - AccessController parentCtrllr) { - this.event_name = event_name; - this.event_description = event_description; - this.event_sseventUrlEmbed = event_sseventUrlEmbed; - this.event_sseventsField = event_sseventsField; - this.event_sseventsUrl = event_sseventsUrl; - this.event_subscriptionTemplate = event_subscriptionTemplate; - this.event_unSubscriptionTemplate = event_unSubscriptionTemplate; - this.event_ruleId = event_ruleId; - this.state = EventConnectionState.INIT; - - this.ctx = new RestConfContext(); - for (String s : parentCtrllr.getCtx().getAttributeKeySet()) { - this.ctx.setAttribute(s, ctx.getAttribute(s)); - } - this.parentCtrllr = parentCtrllr; - this.eventParaMap = new HashMap<>(); - this.eventParaMap.putAll(parentCtrllr.getParaMap()); - printEventParamMap(); - log.info("New persistent connection created " + event_name); + + public static class PersistentEventConnectionBuilder { + private String event_name; + private String event_description; + private boolean event_sseventUrlEmbed; + private String event_sseventsField; + private String event_sseventsUrl; + private String event_subscriptionTemplate; + private String event_unSubscriptionTemplate; + private String event_ruleId; + private AccessController parentCtrllr; + + public PersistentEventConnectionBuilder setEventName(String event_name) { + this.event_name = event_name; + return this; + } + + public PersistentEventConnectionBuilder setEventDescription(String event_description) { + this.event_description = event_description; + return this; + } + + public PersistentEventConnectionBuilder setEventSseventUrlEmbed(boolean event_sseventUrlEmbed) { + this.event_sseventUrlEmbed = event_sseventUrlEmbed; + return this; + } + + public PersistentEventConnectionBuilder setEventSseventsField(String event_sseventsField) { + this.event_sseventsField = event_sseventsField; + return this; + } + + public PersistentEventConnectionBuilder setEventSseventsUrl(String event_sseventsUrl) { + this.event_sseventsUrl = event_sseventsUrl; + return this; + } + + public PersistentEventConnectionBuilder setEventSubscriptionTemplate(String event_subscriptionTemplate) { + this.event_subscriptionTemplate = event_subscriptionTemplate; + return this; + } + + public PersistentEventConnectionBuilder setEventUnSubscriptionTemplate(String event_unSubscriptionTemplate) { + this.event_unSubscriptionTemplate = event_unSubscriptionTemplate; + return this; + } + + public PersistentEventConnectionBuilder setEventRuleId(String event_ruleId) { + this.event_ruleId = event_ruleId; + return this; + } + + public PersistentEventConnectionBuilder setParentCtrllr(AccessController parentCtrllr) { + this.parentCtrllr = parentCtrllr; + return this; + } + + public PersistentEventConnection createPersistentEventConnection() { + return new PersistentEventConnection(this); + } + } + + + private PersistentEventConnection(PersistentEventConnectionBuilder builder){ + + this.event_name = builder.event_name; + this.event_description = builder.event_description; + this.event_sseventUrlEmbed = builder.event_sseventUrlEmbed; + this.event_sseventsField = builder.event_sseventsField; + this.event_sseventsUrl = builder.event_sseventsUrl; + this.event_subscriptionTemplate = builder.event_subscriptionTemplate; + this.event_unSubscriptionTemplate = builder.event_unSubscriptionTemplate; + this.event_ruleId = builder.event_ruleId; + this.state = EventConnectionState.INIT; + + this.ctx = new RestConfContext(); + for (String s : builder.parentCtrllr.getCtx().getAttributeKeySet()) { + this.ctx.setAttribute(s, ctx.getAttribute(s)); + } + this.parentCtrllr = builder.parentCtrllr; + this.eventParaMap = new HashMap<>(); + this.eventParaMap.putAll(builder.parentCtrllr.getParaMap()); + printEventParamMap(); + log.info("New persistent connection created " + event_name); + } @Override |