jkevan commented on code in PR #426:
URL: https://github.com/apache/unomi/pull/426#discussion_r879572204
##########
extensions/json-schema/services/src/main/java/org/apache/unomi/schema/impl/SchemaServiceImpl.java:
##########
@@ -50,86 +48,99 @@ public class SchemaServiceImpl implements SchemaService {
ObjectMapper objectMapper = new ObjectMapper();
- private final Map<String, JsonSchemaWrapper> predefinedUnomiJSONSchemaById
= new HashMap<>();
- private Map<String, JsonSchemaWrapper> schemasById = new HashMap<>();
+ /**
+ * Schemas provided by Unomi runtime bundles in /META-INF/cxs/schemas/...
+ */
+ private final ConcurrentMap<String, JsonSchemaWrapper>
predefinedUnomiJSONSchemaById = new ConcurrentHashMap<>();
+ /**
+ * All Unomi schemas indexed by URI
+ */
+ private final ConcurrentMap<String, JsonSchemaWrapper> schemasById = new
ConcurrentHashMap<>();
+ /**
+ * Available extensions indexed by key:schema URI to be extended, value:
list of schema extension URIs
+ */
+ private final ConcurrentMap<String, Set<String>> extensions = new
ConcurrentHashMap<>();
private Integer jsonSchemaRefreshInterval = 1000;
private ScheduledFuture<?> scheduledFuture;
- private BundleContext bundleContext;
private PersistenceService persistenceService;
- private SchedulerService schedulerService;
private JsonSchemaFactory jsonSchemaFactory;
+ // TODO UNOMI-572: when fixing UNOMI-572 please remove the usage of the
custom ScheduledExecutorService and re-introduce the Unomi Scheduler Service
+ private ScheduledExecutorService scheduler;
+ //private SchedulerService schedulerService;
- @Override
- public PartialList<Metadata> getJsonSchemaMetadatas(int offset, int size,
String sortBy) {
- PartialList<JsonSchemaWrapper> items =
persistenceService.getAllItems(JsonSchemaWrapper.class, offset, size, sortBy);
- List<Metadata> details = new LinkedList<>();
- for (JsonSchemaWrapper definition : items.getList()) {
- details.add(definition.getMetadata());
- }
- return new PartialList<>(details, items.getOffset(),
items.getPageSize(), items.getTotalSize(), items.getTotalSizeRelation());
- }
@Override
public boolean isValid(String data, String schemaId) {
- JsonSchema jsonSchema = null;
- JsonNode jsonNode = null;
+ JsonSchema jsonSchema;
+ JsonNode jsonNode;
try {
jsonNode = objectMapper.readTree(data);
jsonSchema = jsonSchemaFactory.getSchema(new URI(schemaId));
} catch (Exception e) {
- logger.error("Failed to process data to validate because {} - Set
SchemaServiceImpl at DEBUG level for more detail ", e.getMessage());
+ logger.error("Schema validation failed because: Error during data
reading and initial schema lookup - Set SchemaServiceImpl at DEBUG level for
more detail ");
logger.debug("full error",e);
return false;
}
if (jsonNode == null) {
- logger.warn("No data to validate");
+ // no data to validate
return false;
}
if (jsonSchema == null) {
- logger.warn("No schema found for {}", schemaId);
+ logger.warn("Schema validation failed because: Schema not found -
Set SchemaServiceImpl at DEBUG level for more detail ");
Review Comment:
I reduce the logs during validation to 0, nothing will be logged in case of
errors or validation fail.
Validation process is now completely silent and will only log stuff in DEBUG
mode
##########
extensions/json-schema/services/src/main/java/org/apache/unomi/schema/impl/SchemaServiceImpl.java:
##########
@@ -50,86 +48,99 @@ public class SchemaServiceImpl implements SchemaService {
ObjectMapper objectMapper = new ObjectMapper();
- private final Map<String, JsonSchemaWrapper> predefinedUnomiJSONSchemaById
= new HashMap<>();
- private Map<String, JsonSchemaWrapper> schemasById = new HashMap<>();
+ /**
+ * Schemas provided by Unomi runtime bundles in /META-INF/cxs/schemas/...
+ */
+ private final ConcurrentMap<String, JsonSchemaWrapper>
predefinedUnomiJSONSchemaById = new ConcurrentHashMap<>();
+ /**
+ * All Unomi schemas indexed by URI
+ */
+ private final ConcurrentMap<String, JsonSchemaWrapper> schemasById = new
ConcurrentHashMap<>();
+ /**
+ * Available extensions indexed by key:schema URI to be extended, value:
list of schema extension URIs
+ */
+ private final ConcurrentMap<String, Set<String>> extensions = new
ConcurrentHashMap<>();
private Integer jsonSchemaRefreshInterval = 1000;
private ScheduledFuture<?> scheduledFuture;
- private BundleContext bundleContext;
private PersistenceService persistenceService;
- private SchedulerService schedulerService;
private JsonSchemaFactory jsonSchemaFactory;
+ // TODO UNOMI-572: when fixing UNOMI-572 please remove the usage of the
custom ScheduledExecutorService and re-introduce the Unomi Scheduler Service
+ private ScheduledExecutorService scheduler;
+ //private SchedulerService schedulerService;
- @Override
- public PartialList<Metadata> getJsonSchemaMetadatas(int offset, int size,
String sortBy) {
- PartialList<JsonSchemaWrapper> items =
persistenceService.getAllItems(JsonSchemaWrapper.class, offset, size, sortBy);
- List<Metadata> details = new LinkedList<>();
- for (JsonSchemaWrapper definition : items.getList()) {
- details.add(definition.getMetadata());
- }
- return new PartialList<>(details, items.getOffset(),
items.getPageSize(), items.getTotalSize(), items.getTotalSizeRelation());
- }
@Override
public boolean isValid(String data, String schemaId) {
- JsonSchema jsonSchema = null;
- JsonNode jsonNode = null;
+ JsonSchema jsonSchema;
+ JsonNode jsonNode;
try {
jsonNode = objectMapper.readTree(data);
jsonSchema = jsonSchemaFactory.getSchema(new URI(schemaId));
} catch (Exception e) {
- logger.error("Failed to process data to validate because {} - Set
SchemaServiceImpl at DEBUG level for more detail ", e.getMessage());
+ logger.error("Schema validation failed because: Error during data
reading and initial schema lookup - Set SchemaServiceImpl at DEBUG level for
more detail ");
logger.debug("full error",e);
return false;
}
if (jsonNode == null) {
- logger.warn("No data to validate");
+ // no data to validate
return false;
}
if (jsonSchema == null) {
- logger.warn("No schema found for {}", schemaId);
+ logger.warn("Schema validation failed because: Schema not found -
Set SchemaServiceImpl at DEBUG level for more detail ");
+ logger.warn("Schema not found: {}", schemaId);
+ return false;
+ }
+
+ Set<ValidationMessage> validationMessages;
+ try {
+ validationMessages = jsonSchema.validate(jsonNode);
+ } catch (Exception e) {
+ logger.error("Schema validation failed because: Error during
validation - Set SchemaServiceImpl at DEBUG level for more detail ");
Review Comment:
I reduce the logs during validation to 0, nothing will be logged in case of
errors or validation fail.
Validation process is now completely silent and will only log stuff in DEBUG
mode
##########
extensions/json-schema/services/src/main/java/org/apache/unomi/schema/impl/SchemaServiceImpl.java:
##########
@@ -50,86 +48,99 @@ public class SchemaServiceImpl implements SchemaService {
ObjectMapper objectMapper = new ObjectMapper();
- private final Map<String, JsonSchemaWrapper> predefinedUnomiJSONSchemaById
= new HashMap<>();
- private Map<String, JsonSchemaWrapper> schemasById = new HashMap<>();
+ /**
+ * Schemas provided by Unomi runtime bundles in /META-INF/cxs/schemas/...
+ */
+ private final ConcurrentMap<String, JsonSchemaWrapper>
predefinedUnomiJSONSchemaById = new ConcurrentHashMap<>();
+ /**
+ * All Unomi schemas indexed by URI
+ */
+ private final ConcurrentMap<String, JsonSchemaWrapper> schemasById = new
ConcurrentHashMap<>();
+ /**
+ * Available extensions indexed by key:schema URI to be extended, value:
list of schema extension URIs
+ */
+ private final ConcurrentMap<String, Set<String>> extensions = new
ConcurrentHashMap<>();
private Integer jsonSchemaRefreshInterval = 1000;
private ScheduledFuture<?> scheduledFuture;
- private BundleContext bundleContext;
private PersistenceService persistenceService;
- private SchedulerService schedulerService;
private JsonSchemaFactory jsonSchemaFactory;
+ // TODO UNOMI-572: when fixing UNOMI-572 please remove the usage of the
custom ScheduledExecutorService and re-introduce the Unomi Scheduler Service
+ private ScheduledExecutorService scheduler;
+ //private SchedulerService schedulerService;
- @Override
- public PartialList<Metadata> getJsonSchemaMetadatas(int offset, int size,
String sortBy) {
- PartialList<JsonSchemaWrapper> items =
persistenceService.getAllItems(JsonSchemaWrapper.class, offset, size, sortBy);
- List<Metadata> details = new LinkedList<>();
- for (JsonSchemaWrapper definition : items.getList()) {
- details.add(definition.getMetadata());
- }
- return new PartialList<>(details, items.getOffset(),
items.getPageSize(), items.getTotalSize(), items.getTotalSizeRelation());
- }
@Override
public boolean isValid(String data, String schemaId) {
- JsonSchema jsonSchema = null;
- JsonNode jsonNode = null;
+ JsonSchema jsonSchema;
+ JsonNode jsonNode;
try {
jsonNode = objectMapper.readTree(data);
jsonSchema = jsonSchemaFactory.getSchema(new URI(schemaId));
} catch (Exception e) {
- logger.error("Failed to process data to validate because {} - Set
SchemaServiceImpl at DEBUG level for more detail ", e.getMessage());
+ logger.error("Schema validation failed because: Error during data
reading and initial schema lookup - Set SchemaServiceImpl at DEBUG level for
more detail ");
logger.debug("full error",e);
return false;
}
if (jsonNode == null) {
- logger.warn("No data to validate");
+ // no data to validate
return false;
}
if (jsonSchema == null) {
- logger.warn("No schema found for {}", schemaId);
+ logger.warn("Schema validation failed because: Schema not found -
Set SchemaServiceImpl at DEBUG level for more detail ");
+ logger.warn("Schema not found: {}", schemaId);
+ return false;
+ }
+
+ Set<ValidationMessage> validationMessages;
+ try {
+ validationMessages = jsonSchema.validate(jsonNode);
+ } catch (Exception e) {
+ logger.error("Schema validation failed because: Error during
validation - Set SchemaServiceImpl at DEBUG level for more detail ");
+ logger.debug("full error", e);
return false;
}
- Set<ValidationMessage> validationMessages =
jsonSchema.validate(jsonNode);
if (validationMessages == null || validationMessages.isEmpty()) {
return true;
+ } else {
+ logger.error("Schema validation found {} errors while validating
against schema: {} - Set SchemaServiceImpl at DEBUG level for more detail ",
validationMessages.size(), schemaId);
Review Comment:
I reduce the logs during validation to 0, nothing will be logged in case of
errors or validation fail.
Validation process is now completely silent and will only log stuff in DEBUG
mode
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]