You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by js...@apache.org on 2023/05/03 07:46:38 UTC

[unomi] branch UNOMI-775-add-validation-endpoint updated (67f24d660 -> 2bea48114)

This is an automated email from the ASF dual-hosted git repository.

jsinovassinnaik pushed a change to branch UNOMI-775-add-validation-endpoint
in repository https://gitbox.apache.org/repos/asf/unomi.git


 discard 67f24d660 remove eventType from ValidationException
     new 2bea48114 remove eventType from ValidationException

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (67f24d660)
            \
             N -- N -- N   refs/heads/UNOMI-775-add-validation-endpoint (2bea48114)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 itests/src/test/java/org/apache/unomi/itests/JSONSchemaIT.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[unomi] 01/01: remove eventType from ValidationException

Posted by js...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jsinovassinnaik pushed a commit to branch UNOMI-775-add-validation-endpoint
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 2bea481148fe8027041912031e459bd20136d89b
Author: jsinovassin <js...@jahia.com>
AuthorDate: Tue May 2 17:07:14 2023 +0200

    remove eventType from ValidationException
---
 .../unomi/schema/api/ValidationException.java      | 15 ------------
 .../unomi/schema/impl/SchemaServiceImpl.java       | 28 ++++++++++------------
 .../java/org/apache/unomi/itests/JSONSchemaIT.java |  2 +-
 3 files changed, 13 insertions(+), 32 deletions(-)

diff --git a/extensions/json-schema/services/src/main/java/org/apache/unomi/schema/api/ValidationException.java b/extensions/json-schema/services/src/main/java/org/apache/unomi/schema/api/ValidationException.java
index c5481da83..58610b285 100644
--- a/extensions/json-schema/services/src/main/java/org/apache/unomi/schema/api/ValidationException.java
+++ b/extensions/json-schema/services/src/main/java/org/apache/unomi/schema/api/ValidationException.java
@@ -23,17 +23,10 @@ package org.apache.unomi.schema.api;
  */
 public class ValidationException extends Exception {
 
-    private String eventType;
-
     public ValidationException(String message) {
         super(message);
     }
 
-    public ValidationException(String message, String eventType) {
-        super(message);
-        this.eventType = eventType;
-    }
-
     public ValidationException(Throwable throwable) {
         super(throwable);
     }
@@ -41,12 +34,4 @@ public class ValidationException extends Exception {
     public ValidationException(String message, Throwable throwable) {
         super(message, throwable);
     }
-
-    public void setEventType(String eventType) {
-        this.eventType = eventType;
-    }
-
-    public String getEventType() {
-        return eventType;
-    }
 }
diff --git a/extensions/json-schema/services/src/main/java/org/apache/unomi/schema/impl/SchemaServiceImpl.java b/extensions/json-schema/services/src/main/java/org/apache/unomi/schema/impl/SchemaServiceImpl.java
index 5adcbc010..ca54fd243 100644
--- a/extensions/json-schema/services/src/main/java/org/apache/unomi/schema/impl/SchemaServiceImpl.java
+++ b/extensions/json-schema/services/src/main/java/org/apache/unomi/schema/impl/SchemaServiceImpl.java
@@ -124,10 +124,14 @@ public class SchemaServiceImpl implements SchemaService {
         Map<String, Set<ValidationError>> errorsPerEventType = new HashMap<>();
         JsonNode eventsNodes = parseData(events);
         eventsNodes.forEach(event -> {
+            String eventType = null;
             try {
-                Set<ValidationError> errors = validateNodeEvent(event);
+                eventType = extractEventType(event);
+                JsonSchemaWrapper eventSchema = getSchemaForEventType(eventType);
+                JsonSchema jsonSchema = getJsonSchema(eventSchema.getItemId());
+
+                Set<ValidationError> errors = validate(event, jsonSchema);
                 if (!errors.isEmpty()) {
-                    String eventType = event.get("eventType").asText();
                     if (errorsPerEventType.containsKey(eventType)) {
                         errorsPerEventType.get(eventType).addAll(errors);
                     } else {
@@ -136,11 +140,11 @@ public class SchemaServiceImpl implements SchemaService {
                 }
             } catch (ValidationException e) {
                 Set<ValidationError> errors = buildCustomErrorMessage(e.getMessage());
-                String eventType = e.getEventType() != null ? e.getEventType() : GENERIC_ERROR_KEY;
-                if (errorsPerEventType.containsKey(eventType)) {
-                    errorsPerEventType.get(eventType).addAll(errors);
+                String eventTypeOrErrorKey = eventType != null ? eventType : GENERIC_ERROR_KEY;
+                if (errorsPerEventType.containsKey(eventTypeOrErrorKey)) {
+                    errorsPerEventType.get(eventTypeOrErrorKey).addAll(errors);
                 } else {
-                    errorsPerEventType.put(eventType, errors);
+                    errorsPerEventType.put(eventTypeOrErrorKey, errors);
                 }
             }
         });
@@ -154,14 +158,6 @@ public class SchemaServiceImpl implements SchemaService {
         return errors;
     }
 
-    private Set<ValidationError> validateNodeEvent(JsonNode event) throws ValidationException {
-        String eventType = extractEventType(event);
-        JsonSchemaWrapper eventSchema = getSchemaForEventType(eventType);
-        JsonSchema jsonSchema = getJsonSchema(eventSchema.getItemId());
-
-        return validate(event, jsonSchema);
-    }
-
     @Override
     public JsonSchemaWrapper getSchema(String schemaId) {
         return schemasById.get(schemaId);
@@ -182,7 +178,7 @@ public class SchemaServiceImpl implements SchemaService {
     @Override
     public JsonSchemaWrapper getSchemaForEventType(String eventType) throws ValidationException {
         if (StringUtils.isEmpty(eventType)) {
-            throw new ValidationException("eventType missing", eventType);
+            throw new ValidationException("eventType missing");
         }
 
         return schemasById.values().stream()
@@ -192,7 +188,7 @@ public class SchemaServiceImpl implements SchemaService {
                                 jsonSchemaWrapper.getName() != null &&
                                 jsonSchemaWrapper.getName().equals(eventType))
                 .findFirst()
-                .orElseThrow(() -> new ValidationException("Schema not found for event type: " + eventType, eventType));
+                .orElseThrow(() -> new ValidationException("Schema not found for event type: " + eventType));
     }
 
     @Override
diff --git a/itests/src/test/java/org/apache/unomi/itests/JSONSchemaIT.java b/itests/src/test/java/org/apache/unomi/itests/JSONSchemaIT.java
index cd4373b48..366f3ece5 100644
--- a/itests/src/test/java/org/apache/unomi/itests/JSONSchemaIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/JSONSchemaIT.java
@@ -269,7 +269,7 @@ public class JSONSchemaIT extends BaseIT {
         keepTrying("No error should have been detected",
                 () -> {
                     try {
-                        return schemaService.validateEvents(listEvents.toString()).get("flattened").isEmpty();
+                        return schemaService.validateEvents(listEvents.toString()).isEmpty();
                     } catch (Exception e) {
                         return false;
                     }