Search in sources :

Example 1 with SchemaQuery

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;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) SchemaQuery(org.apache.apex.malhar.lib.appdata.schemas.SchemaQuery)

Example 2 with SchemaQuery

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);
    }
}
Also used : SchemaResult(org.apache.apex.malhar.lib.appdata.schemas.SchemaResult) Message(org.apache.apex.malhar.lib.appdata.schemas.Message) DataQuerySnapshot(org.apache.apex.malhar.lib.appdata.schemas.DataQuerySnapshot) IOException(java.io.IOException) SchemaQuery(org.apache.apex.malhar.lib.appdata.schemas.SchemaQuery)

Aggregations

SchemaQuery (org.apache.apex.malhar.lib.appdata.schemas.SchemaQuery)2 IOException (java.io.IOException)1 DataQuerySnapshot (org.apache.apex.malhar.lib.appdata.schemas.DataQuerySnapshot)1 Message (org.apache.apex.malhar.lib.appdata.schemas.Message)1 SchemaResult (org.apache.apex.malhar.lib.appdata.schemas.SchemaResult)1 JSONObject (org.codehaus.jettison.json.JSONObject)1