You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2021/10/12 12:43:47 UTC
[unomi] branch draft-json-schema-integration updated: JSON Schema
integration
This is an automated email from the ASF dual-hosted git repository.
shuber pushed a commit to branch draft-json-schema-integration
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/draft-json-schema-integration by this push:
new 9e8dad5 JSON Schema integration
9e8dad5 is described below
commit 9e8dad56488deeb2fd4bb600224ff42ecfceae51
Author: Serge Huber <sh...@jahia.com>
AuthorDate: Tue Oct 12 14:43:42 2021 +0200
JSON Schema integration
---
.../services/impl/events/EventServiceImpl.java | 13 +++++++----
.../impl/events/EventTypeRegistryImpl.java | 27 ++++++++++------------
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/services/src/main/java/org/apache/unomi/services/impl/events/EventServiceImpl.java b/services/src/main/java/org/apache/unomi/services/impl/events/EventServiceImpl.java
index ced1351..b831e05 100644
--- a/services/src/main/java/org/apache/unomi/services/impl/events/EventServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/impl/events/EventServiceImpl.java
@@ -31,11 +31,7 @@ import org.apache.unomi.api.ValueType;
import org.apache.unomi.api.actions.ActionPostExecutor;
import org.apache.unomi.api.conditions.Condition;
import org.apache.unomi.api.query.Query;
-import org.apache.unomi.api.services.DefinitionsService;
-import org.apache.unomi.api.services.EventListenerService;
-import org.apache.unomi.api.services.EventService;
-import org.apache.unomi.api.services.EventTypeRegistry;
-import org.apache.unomi.api.services.SourceService;
+import org.apache.unomi.api.services.*;
import org.apache.unomi.persistence.spi.PersistenceService;
import org.apache.unomi.persistence.spi.aggregate.TermsAggregate;
import org.apache.unomi.services.impl.ParserHelper;
@@ -70,6 +66,8 @@ public class EventServiceImpl implements EventService {
private EventTypeRegistry eventTypeRegistry;
+ private SchemaRegistry schemaRegistry;
+
private Set<String> predefinedEventTypeIds = new LinkedHashSet<String>();
private Set<String> restrictedEventTypeIds = new LinkedHashSet<String>();
@@ -121,6 +119,10 @@ public class EventServiceImpl implements EventService {
this.eventTypeRegistry = eventTypeRegistry;
}
+ public void setSchemaRegistry(SchemaRegistry schemaRegistry) {
+ this.schemaRegistry = schemaRegistry;
+ }
+
public void setPersistenceService(PersistenceService persistenceService) {
this.persistenceService = persistenceService;
}
@@ -145,6 +147,7 @@ public class EventServiceImpl implements EventService {
}
public boolean isEventValid(Event event) {
+ this.schemaRegistry.isValid(event, "https://unomi.apache.org/schemas/json/events/" + event.getEventType() + ".json");
return this.eventTypeRegistry.isValid(event);
}
diff --git a/services/src/main/java/org/apache/unomi/services/impl/events/EventTypeRegistryImpl.java b/services/src/main/java/org/apache/unomi/services/impl/events/EventTypeRegistryImpl.java
index 5676380..a6327a0 100644
--- a/services/src/main/java/org/apache/unomi/services/impl/events/EventTypeRegistryImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/impl/events/EventTypeRegistryImpl.java
@@ -37,9 +37,9 @@ public class EventTypeRegistryImpl implements EventTypeRegistry, SynchronousBund
private static final Logger logger = LoggerFactory.getLogger(EventTypeRegistryImpl.class.getName());
- private Map<Long, List<PluginType>> pluginTypes = new HashMap<>();
+ private final Map<Long, List<EventType>> eventTypesByBundle = new HashMap<>();
- private Map<String, EventType> eventTypes = new LinkedHashMap<>();
+ private final Map<String, EventType> eventTypesById = new LinkedHashMap<>();
private BundleContext bundleContext;
@@ -78,11 +78,11 @@ public class EventTypeRegistryImpl implements EventTypeRegistry, SynchronousBund
}
public EventType get(String typeName) {
- return eventTypes.get(typeName);
+ return eventTypesById.get(typeName);
}
public void register(EventType eventType) {
- eventTypes.put(eventType.getType(), eventType);
+ eventTypesById.put(eventType.getType(), eventType);
}
@Override
@@ -213,7 +213,7 @@ public class EventTypeRegistryImpl implements EventTypeRegistry, SynchronousBund
}
public Collection<EventType> getAll() {
- return this.eventTypes.values();
+ return this.eventTypesById.values();
}
private void loadPredefinedEventTypes(BundleContext bundleContext) {
@@ -221,7 +221,7 @@ public class EventTypeRegistryImpl implements EventTypeRegistry, SynchronousBund
if (predefinedEventTypes == null) {
return;
}
- ArrayList<PluginType> pluginTypeArrayList = (ArrayList<PluginType>) pluginTypes.get(bundleContext.getBundle().getBundleId());
+ List<EventType> bundleEventTypes = this.eventTypesByBundle.get(bundleContext.getBundle().getBundleId());
while (predefinedEventTypes.hasMoreElements()) {
URL predefinedEventTypeURL = predefinedEventTypes.nextElement();
@@ -231,7 +231,7 @@ public class EventTypeRegistryImpl implements EventTypeRegistry, SynchronousBund
EventType eventType = CustomObjectMapper.getObjectMapper().readValue(predefinedEventTypeURL, EventType.class);
eventType.setPluginId(bundleContext.getBundle().getBundleId());
register(eventType);
- pluginTypeArrayList.add(eventType);
+ bundleEventTypes.add(eventType);
} catch (Exception e) {
logger.error("Error while loading event type definition " + predefinedEventTypeURL, e);
}
@@ -243,7 +243,7 @@ public class EventTypeRegistryImpl implements EventTypeRegistry, SynchronousBund
if (bundleContext == null) {
return;
}
- pluginTypes.put(bundleContext.getBundle().getBundleId(), new ArrayList<PluginType>());
+ eventTypesByBundle.put(bundleContext.getBundle().getBundleId(), new ArrayList<>());
loadPredefinedEventTypes(bundleContext);
}
@@ -251,13 +251,10 @@ public class EventTypeRegistryImpl implements EventTypeRegistry, SynchronousBund
if (bundleContext == null) {
return;
}
- List<PluginType> types = pluginTypes.remove(bundleContext.getBundle().getBundleId());
- if (types != null) {
- for (PluginType type : types) {
- if (type instanceof EventType) {
- EventType eventType = (EventType) type;
- eventTypes.remove(eventType.getType());
- }
+ List<EventType> eventTypes = eventTypesByBundle.remove(bundleContext.getBundle().getBundleId());
+ if (eventTypes != null) {
+ for (EventType eventType : eventTypes) {
+ eventTypesById.remove(eventType.getType());
}
}
}