Package org.apache.unomi.schema.impl
Class SchemaServiceImpl
- java.lang.Object
-
- org.apache.unomi.schema.impl.SchemaServiceImpl
-
- All Implemented Interfaces:
SchemaService
public class SchemaServiceImpl extends Object implements SchemaService
-
-
Constructor Summary
Constructors Constructor Description SchemaServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
deleteSchema(String schemaId)
Delete a schema according to its idvoid
destroy()
Set<String>
getInstalledJsonSchemaIds()
Get the list of installed Json Schema IdsJsonSchemaWrapper
getSchema(String schemaId)
Get a schema matching by a schema idJsonSchemaWrapper
getSchemaForEventType(String eventType)
Get the schema that is able to validate the specific event typeList<JsonSchemaWrapper>
getSchemasByTarget(String target)
Get a list aJsonSchemaWrapper
void
init()
boolean
isEventValid(String event)
Verify if the event is valid (This method is fail safe, if unexpected errors happens it will returns false)boolean
isEventValid(String event, String eventType)
Deprecate (since 2.2.0).boolean
isValid(String data, String schemaId)
Verify if a jsonNode is valid against a schema (This method is fail safe, if unexpected errors happens it will returns false)void
loadPredefinedSchema(InputStream schemaStream)
Load a predefined schema into memoryvoid
refreshJSONSchemas()
Refresh the JSON schemasvoid
saveSchema(String schema)
Save a new schema or update a schemavoid
setJsonSchemaRefreshInterval(Integer jsonSchemaRefreshInterval)
void
setPersistenceService(PersistenceService persistenceService)
void
setScopeService(ScopeService scopeService)
boolean
unloadPredefinedSchema(InputStream schemaStream)
Unload a predefined schema into memorySet<ValidationError>
validateEvent(String event)
perform a validation on the given eventMap<String,Set<ValidationError>>
validateEvents(String events)
perform a validation of a list of the given events
-
-
-
Method Detail
-
isValid
public boolean isValid(String data, String schemaId)
Description copied from interface:SchemaService
Verify if a jsonNode is valid against a schema (This method is fail safe, if unexpected errors happens it will returns false)- Specified by:
isValid
in interfaceSchemaService
- Parameters:
data
- to validateschemaId
- id of the schema used for the validation- Returns:
- true is the object is valid, false otherwise, false also in case of unexpected errors !
-
isEventValid
public boolean isEventValid(String event, String eventType)
Description copied from interface:SchemaService
Deprecate (since 2.2.0). the eventType is now directly extracted from the event source You can directly use sibling function: isEventValid(String event)- Specified by:
isEventValid
in interfaceSchemaService
-
isEventValid
public boolean isEventValid(String event)
Description copied from interface:SchemaService
Verify if the event is valid (This method is fail safe, if unexpected errors happens it will returns false)- Specified by:
isEventValid
in interfaceSchemaService
- Parameters:
event
- the event to check validity- Returns:
- true is the event is valid, false otherwise, false also in case of unexpected errors !
-
validateEvent
public Set<ValidationError> validateEvent(String event) throws ValidationException
Description copied from interface:SchemaService
perform a validation on the given event- Specified by:
validateEvent
in interfaceSchemaService
- Parameters:
event
- the event to validate- Returns:
- The list of validation errors in case there is some, empty list otherwise
- Throws:
ValidationException
- in case something goes wrong and validation could not be performed.
-
validateEvents
public Map<String,Set<ValidationError>> validateEvents(String events) throws ValidationException
Description copied from interface:SchemaService
perform a validation of a list of the given events- Specified by:
validateEvents
in interfaceSchemaService
- Parameters:
events
- the events to validate- Returns:
- The Map of validation errors group per event type in case there is some, empty map otherwise
- Throws:
ValidationException
- in case something goes wrong and validation could not be performed.
-
getSchema
public JsonSchemaWrapper getSchema(String schemaId)
Description copied from interface:SchemaService
Get a schema matching by a schema id- Specified by:
getSchema
in interfaceSchemaService
- Parameters:
schemaId
- Id of the schema- Returns:
- A JSON schema
-
getInstalledJsonSchemaIds
public Set<String> getInstalledJsonSchemaIds()
Description copied from interface:SchemaService
Get the list of installed Json Schema Ids- Specified by:
getInstalledJsonSchemaIds
in interfaceSchemaService
- Returns:
- A Set of JSON schema ids
-
getSchemasByTarget
public List<JsonSchemaWrapper> getSchemasByTarget(String target)
Description copied from interface:SchemaService
Get a list aJsonSchemaWrapper
- Specified by:
getSchemasByTarget
in interfaceSchemaService
- Parameters:
target
- to filter the schemas- Returns:
- a list of JSONSchema
-
getSchemaForEventType
public JsonSchemaWrapper getSchemaForEventType(String eventType) throws ValidationException
Description copied from interface:SchemaService
Get the schema that is able to validate the specific event type- Specified by:
getSchemaForEventType
in interfaceSchemaService
- Parameters:
eventType
- the eventType- Returns:
- The JSON Schema able to validate the given event type or null if not found.
- Throws:
ValidationException
-
saveSchema
public void saveSchema(String schema)
Description copied from interface:SchemaService
Save a new schema or update a schema- Specified by:
saveSchema
in interfaceSchemaService
- Parameters:
schema
- as a String value
-
deleteSchema
public boolean deleteSchema(String schemaId)
Description copied from interface:SchemaService
Delete a schema according to its id- Specified by:
deleteSchema
in interfaceSchemaService
- Parameters:
schemaId
- id of the schema to delete- Returns:
- true if the schema has been deleted
-
loadPredefinedSchema
public void loadPredefinedSchema(InputStream schemaStream) throws IOException
Description copied from interface:SchemaService
Load a predefined schema into memory- Specified by:
loadPredefinedSchema
in interfaceSchemaService
- Parameters:
schemaStream
- inputStream of the schema- Throws:
IOException
-
unloadPredefinedSchema
public boolean unloadPredefinedSchema(InputStream schemaStream)
Description copied from interface:SchemaService
Unload a predefined schema into memory- Specified by:
unloadPredefinedSchema
in interfaceSchemaService
- Parameters:
schemaStream
- inputStream of the schema to delete- Returns:
- true if the schema has been deleted
-
refreshJSONSchemas
public void refreshJSONSchemas()
Description copied from interface:SchemaService
Refresh the JSON schemas- Specified by:
refreshJSONSchemas
in interfaceSchemaService
-
init
public void init()
-
destroy
public void destroy()
-
setPersistenceService
public void setPersistenceService(PersistenceService persistenceService)
-
setScopeService
public void setScopeService(ScopeService scopeService)
-
setJsonSchemaRefreshInterval
public void setJsonSchemaRefreshInterval(Integer jsonSchemaRefreshInterval)
-
-