use of org.apache.apex.malhar.lib.appdata.schemas.SchemaQuery in project apex-malhar by apache.
the class SchemaQueryDeserializer method deserializeHelper.
private Message deserializeHelper(String json, Class<? extends Message> message, Object context) throws Exception {
JSONObject schemaJO = new JSONObject(json);
String type = schemaJO.getString(Query.FIELD_TYPE);
if (!type.equals(SchemaQuery.TYPE)) {
LOG.error("The given type {} is invalid.", type);
return null;
}
String id = schemaJO.getString(Query.FIELD_ID);
Map<String, String> contextKeysMap = null;
Map<String, String> schemaKeysMap = null;
if (schemaJO.has(SchemaQuery.FIELD_CONTEXT)) {
JSONObject contextJO = schemaJO.getJSONObject(SchemaQuery.FIELD_CONTEXT);
if (contextJO.length() == 0) {
LOG.error("The context cannot be empty");
return null;
}
if (contextJO.has(SchemaQuery.FIELD_CONTEXT_KEYS)) {
JSONObject keys = contextJO.getJSONObject(SchemaQuery.FIELD_CONTEXT_KEYS);
contextKeysMap = SchemaUtils.extractMap(keys);
if (contextKeysMap.isEmpty()) {
contextKeysMap = null;
}
}
if (contextJO.has(SchemaQuery.FIELD_SCHEMA_KEYS)) {
JSONObject schemaKeys = contextJO.getJSONObject(SchemaQuery.FIELD_SCHEMA_KEYS);
schemaKeysMap = SchemaUtils.extractMap(schemaKeys);
if (schemaKeysMap.isEmpty()) {
schemaKeysMap = null;
}
}
}
SchemaQuery sq = new SchemaQuery(id, schemaKeysMap, contextKeysMap);
return sq;
}
use of org.apache.apex.malhar.lib.appdata.schemas.SchemaQuery in project apex-malhar by apache.
the class AbstractAppDataSnapshotServer method processQuery.
/**
* process the query send.
* provide this method to give sub class a chance to override.
* @param queryJSON
*/
protected void processQuery(String queryJSON) {
LOG.debug("query {}", queryJSON);
Message query = null;
try {
query = queryDeserializerFactory.deserialize(queryJSON);
} catch (IOException ex) {
LOG.error("Error parsing query: {}", queryJSON);
LOG.error("{}", ex);
return;
}
if (query instanceof SchemaQuery) {
SchemaResult schemaResult = schemaRegistry.getSchemaResult((SchemaQuery) query);
if (schemaResult != null) {
LOG.debug("queueing {}", schemaResult);
schemaQueue.add(schemaResult);
}
} else if (query instanceof DataQuerySnapshot) {
queryProcessor.enqueue((DataQuerySnapshot) query, null, null);
}
}
Aggregations