def buildInsertMessage(ontology, data, queryType, sessionKey, serialize = True): ''' Builds an INSERT SSAP message. Keyword arguments: ontology -- the target ontology of the INSERT operation. data -- a string containing the JSON instance or a SQL-like INSERT statement. queryType -- the type of the query (native or SQL-like) sessionKey -- the identifier of the session. serialize -- indicates if a JSON object or a serialized JSON object must be returned. ''' jsonObj = _SSAPMessageFactory.__buildMessageStructure(SSAP_MESSAGE_TYPE.INSERT, sessionKey) jsonObj["body"]["query"] = None jsonObj["ontology"] = ontology jsonObj["body"]["queryType"] = SSAP_QUERY_TYPE.toString(queryType) if (queryType == SSAP_QUERY_TYPE.NATIVE) : jsonObj["body"]["data"] = data jsonObj["body"]["query"] = None else : jsonObj["body"]["data"] = None jsonObj["body"]["query"] = data if (serialize): return _SSAPMessageFactory.__serializeMessage(jsonObj) else: return jsonObj
def buildSubscribeMessage(ontology, query, queryType, refreshTimeMillis, sessionKey): ''' Builds a SUBSCRIBE SSAP message. Keyword arguments: ontology -- the target ontology of the SUBSCRIBE operation. query -- the query that filters the ontology instance that will trigger INDICATION messages. refreshTimeMillis -- the period of time that separates two consecutive notification sequences (in milliseconds). queryType -- the type of the query (native or SQL-like). sessionKey -- the identifier of the session. ''' jsonObj = _SSAPMessageFactory.__buildMessageStructure(SSAP_MESSAGE_TYPE.SUBSCRIBE, sessionKey) jsonObj["body"]["query"] = query jsonObj["body"]["queryType"] = SSAP_QUERY_TYPE.toString(queryType) jsonObj["body"]["msRefresh"] = refreshTimeMillis jsonObj["ontology"] = ontology return _SSAPMessageFactory.__serializeMessage(jsonObj)
def buildQueryMessage(ontology, query, queryType, queryParams, sessionKey): ''' Builds a QUERY SSAP message. Keyword arguments: ontology -- the target ontology of the QUERY operation. query -- que query to perform. queryType -- the type of the query (native, SQL-like, configuration database, historical database). queryParams -- an object containing the parameters of the query. sessionKey -- the identifier of the session. ''' jsonObj = _SSAPMessageFactory.__buildMessageStructure(SSAP_MESSAGE_TYPE.QUERY, sessionKey) jsonObj["body"]["query"] = query jsonObj["body"]["queryParams"] = queryParams jsonObj["body"]["queryType"] = SSAP_QUERY_TYPE.toString(queryType) jsonObj["ontology"] = ontology return _SSAPMessageFactory.__serializeMessage(jsonObj)
def buildDeleteMessage(ontology, query, queryType, sessionKey, serialize = True): ''' Builds a DELETE ssap message. Keyword arguments: ontology -- the target ontology of the DELETE operation. query -- the query that selects the instances that will be deleted. queryType -- the type of the query (native or SQL-like). sessionKey -- the identifier of the session. serialize -- indicates if a JSON object or a serialized JSON object must be returned. ''' jsonObj = _SSAPMessageFactory.__buildMessageStructure(SSAP_MESSAGE_TYPE.DELETE, sessionKey) jsonObj["body"]["data"] = None jsonObj["body"]["query"] = query jsonObj["body"]["queryType"] = SSAP_QUERY_TYPE.toString(queryType) if (serialize): return _SSAPMessageFactory.__serializeMessage(jsonObj) else: return jsonObj
def buildUpdateMessage(ontology, query, queryType, data, sessionKey, serialize = True): ''' Builds an UPDATE ssap message. Keyword arguments: ontology -- the target ontology of the UPDATE operation. query -- the query that selects the instances that will be updated. queryType -- the type of the query (native or SQL-like). data -- an expression that updates parts of the selected instances. sessionKey -- the identifier of the session. ''' jsonObj = _SSAPMessageFactory.__buildMessageStructure(SSAP_MESSAGE_TYPE.UPDATE, sessionKey) jsonObj["body"]["query"] = query jsonObj["body"]["data"] = data jsonObj["body"]["queryType"] = SSAP_QUERY_TYPE.toString(queryType) jsonObj["ontology"] = ontology if (serialize): return _SSAPMessageFactory.__serializeMessage(jsonObj) else: return jsonObj