aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorBruno Sakoto <bruno.sakoto@bell.ca>2021-07-15 08:55:54 -0400
committerBruno Sakoto <bruno.sakoto@bell.ca>2021-07-20 16:00:13 -0400
commit092d4a0b4eb6011b16d223f0c1d5072fdb5f6abb (patch)
tree610f223d10a531928a239077be07b643d799cb47 /src/main/java/org
parent097707d886a8f59b8c5f994274f6347985ac8c6f (diff)
Add failing event to invalid event exception
Also avoid unecessary null checks when validating the event Issue-ID: CPS-494 Signed-off-by: Bruno Sakoto <bruno.sakoto@bell.ca> Change-Id: I199fcf42928253bb4f44b204f72a4f46c1cc1eef
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/cps/temporal/controller/event/listener/exception/InvalidEventEnvelopException.java10
-rw-r--r--src/main/java/org/onap/cps/temporal/controller/event/listener/kafka/DataUpdatedEventListener.java15
2 files changed, 16 insertions, 9 deletions
diff --git a/src/main/java/org/onap/cps/temporal/controller/event/listener/exception/InvalidEventEnvelopException.java b/src/main/java/org/onap/cps/temporal/controller/event/listener/exception/InvalidEventEnvelopException.java
index df4e756..1d8269a 100644
--- a/src/main/java/org/onap/cps/temporal/controller/event/listener/exception/InvalidEventEnvelopException.java
+++ b/src/main/java/org/onap/cps/temporal/controller/event/listener/exception/InvalidEventEnvelopException.java
@@ -25,17 +25,21 @@ import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
+import org.onap.cps.event.model.CpsDataUpdatedEvent;
/**
* Class representing an invalid event envelop exception.
+ * It refers to the invalid event and details the invalid fields it has.
*/
@Getter
public class InvalidEventEnvelopException extends EventListenerException {
+ private final CpsDataUpdatedEvent cpsDataUpdatedEvent;
private final List<InvalidField> invalidFields = new ArrayList<>();
- public InvalidEventEnvelopException(final String message) {
+ public InvalidEventEnvelopException(final String message, final CpsDataUpdatedEvent cpsDataUpdatedEvent) {
super(message);
+ this.cpsDataUpdatedEvent = cpsDataUpdatedEvent;
}
public void addInvalidField(final InvalidField invalidField) {
@@ -48,7 +52,9 @@ public class InvalidEventEnvelopException extends EventListenerException {
@Override
public String getMessage() {
- return String.format("%s. invalidFields: %s", super.getMessage(), this.invalidFields.toString());
+ return
+ String.format("%s. Event: %s. Invalid fields: %s",
+ super.getMessage(), this.cpsDataUpdatedEvent, this.invalidFields.toString());
}
@AllArgsConstructor
diff --git a/src/main/java/org/onap/cps/temporal/controller/event/listener/kafka/DataUpdatedEventListener.java b/src/main/java/org/onap/cps/temporal/controller/event/listener/kafka/DataUpdatedEventListener.java
index 79c9d92..2e4b88e 100644
--- a/src/main/java/org/onap/cps/temporal/controller/event/listener/kafka/DataUpdatedEventListener.java
+++ b/src/main/java/org/onap/cps/temporal/controller/event/listener/kafka/DataUpdatedEventListener.java
@@ -89,9 +89,10 @@ public class DataUpdatedEventListener {
private void validateEventEnvelop(final CpsDataUpdatedEvent cpsDataUpdatedEvent) {
- final var invalidEventEnvelopException = new InvalidEventEnvelopException("Validation failure");
+ final var invalidEventEnvelopException =
+ new InvalidEventEnvelopException("Validation failure", cpsDataUpdatedEvent);
- // Schema
+ // Validate schema
if (cpsDataUpdatedEvent.getSchema() == null) {
invalidEventEnvelopException.addInvalidField(
new InvalidEventEnvelopException.InvalidField(
@@ -99,22 +100,22 @@ public class DataUpdatedEventListener {
CpsDataUpdatedEvent.Schema.URN_CPS_ORG_ONAP_CPS_DATA_UPDATED_EVENT_SCHEMA_1_1_0_SNAPSHOT
.value()));
}
- // Id
+ // Validate id
if (!StringUtils.hasText(cpsDataUpdatedEvent.getId())) {
invalidEventEnvelopException.addInvalidField(
new InvalidEventEnvelopException.InvalidField(
MISSING, "id", null, null));
}
- // Source
- if (cpsDataUpdatedEvent.getSource() == null || !cpsDataUpdatedEvent.getSource().equals(EVENT_SOURCE)) {
+ // Validate source
+ if (!EVENT_SOURCE.equals(cpsDataUpdatedEvent.getSource())) {
invalidEventEnvelopException.addInvalidField(
new InvalidEventEnvelopException.InvalidField(
UNEXPECTED, "source",
cpsDataUpdatedEvent.getSource() != null
? cpsDataUpdatedEvent.getSource().toString() : null, EVENT_SOURCE.toString()));
}
- // Type
- if (cpsDataUpdatedEvent.getType() == null || !cpsDataUpdatedEvent.getType().equals(EVENT_TYPE)) {
+ // Validate type
+ if (!EVENT_TYPE.equals(cpsDataUpdatedEvent.getType())) {
invalidEventEnvelopException.addInvalidField(
new InvalidEventEnvelopException.InvalidField(
UNEXPECTED, "type", cpsDataUpdatedEvent.getType(), EVENT_TYPE));