fixed tests and bump api
This commit is contained in:
parent
6bd8983ec2
commit
0603b8a3b7
@ -1,3 +1,21 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* This file is part of guh. *
|
||||||
|
* *
|
||||||
|
* Guh is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation, version 2 of the License. *
|
||||||
|
* *
|
||||||
|
* Guh is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "ruleaction.h"
|
#include "ruleaction.h"
|
||||||
|
|
||||||
RuleAction::RuleAction(const ActionTypeId &actionTypeId, const DeviceId &deviceId) :
|
RuleAction::RuleAction(const ActionTypeId &actionTypeId, const DeviceId &deviceId) :
|
||||||
|
|||||||
@ -1,3 +1,21 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* This file is part of guh. *
|
||||||
|
* *
|
||||||
|
* Guh is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation, version 2 of the License. *
|
||||||
|
* *
|
||||||
|
* Guh is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#ifndef RULEACTION_H
|
#ifndef RULEACTION_H
|
||||||
#define RULEACTION_H
|
#define RULEACTION_H
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,8 @@
|
|||||||
* \sa Param, */
|
* \sa Param, */
|
||||||
RuleActionParam::RuleActionParam(const Param ¶m) :
|
RuleActionParam::RuleActionParam(const Param ¶m) :
|
||||||
m_name(param.name()),
|
m_name(param.name()),
|
||||||
m_value(param.value())
|
m_value(param.value()),
|
||||||
|
m_eventTypeId(EventTypeId())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -44,7 +44,7 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#define JSON_PROTOCOL_VERSION 15
|
#define JSON_PROTOCOL_VERSION 16
|
||||||
|
|
||||||
JsonRPCServer::JsonRPCServer(QObject *parent):
|
JsonRPCServer::JsonRPCServer(QObject *parent):
|
||||||
JsonHandler(parent),
|
JsonHandler(parent),
|
||||||
|
|||||||
@ -104,7 +104,7 @@ void JsonTypes::init()
|
|||||||
// RuleActionParam
|
// RuleActionParam
|
||||||
s_ruleActionParam.insert("name", basicTypeToString(String));
|
s_ruleActionParam.insert("name", basicTypeToString(String));
|
||||||
s_ruleActionParam.insert("o:value", basicTypeRef());
|
s_ruleActionParam.insert("o:value", basicTypeRef());
|
||||||
s_ruleActionParam.insert("o:eventId", basicTypeToString(Uuid));
|
s_ruleActionParam.insert("o:eventTypeId", basicTypeToString(Uuid));
|
||||||
|
|
||||||
// ParamDescriptor
|
// ParamDescriptor
|
||||||
s_paramDescriptor.insert("name", basicTypeToString(String));
|
s_paramDescriptor.insert("name", basicTypeToString(String));
|
||||||
@ -355,8 +355,13 @@ QVariantMap JsonTypes::packRuleActionParam(const RuleActionParam &ruleActionPara
|
|||||||
{
|
{
|
||||||
QVariantMap variantMap;
|
QVariantMap variantMap;
|
||||||
variantMap.insert("name", ruleActionParam.name());
|
variantMap.insert("name", ruleActionParam.name());
|
||||||
variantMap.insert("value", ruleActionParam.value());
|
|
||||||
variantMap.insert("eventTypeId", ruleActionParam.eventTypeId());
|
// if this ruleaction param has a valid EventTypeId, there is no value
|
||||||
|
if (ruleActionParam.eventTypeId() != EventTypeId()) {
|
||||||
|
variantMap.insert("eventTypeId", ruleActionParam.eventTypeId());
|
||||||
|
} else {
|
||||||
|
variantMap.insert("value", ruleActionParam.value());
|
||||||
|
}
|
||||||
return variantMap;
|
return variantMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -843,6 +848,18 @@ QPair<bool, QString> JsonTypes::validateVariant(const QVariant &templateVariant,
|
|||||||
qDebug() << "param types not matching";
|
qDebug() << "param types not matching";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
} else if (refName == ruleActionRef()) {
|
||||||
|
QPair<bool, QString> result = validateMap(ruleActionDescription(), variant.toMap());
|
||||||
|
if (!result.first) {
|
||||||
|
qDebug() << "ruleAction type not matching";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} else if (refName == ruleActionParamRef()) {
|
||||||
|
QPair<bool, QString> result = validateMap(ruleActionParamDescription(), variant.toMap());
|
||||||
|
if (!result.first) {
|
||||||
|
qDebug() << "ruleActionParam type not matching";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
} else if (refName == actionTypeRef()) {
|
} else if (refName == actionTypeRef()) {
|
||||||
QPair<bool, QString> result = validateMap(actionTypeDescription(), variant.toMap());
|
QPair<bool, QString> result = validateMap(actionTypeDescription(), variant.toMap());
|
||||||
if (!result.first) {
|
if (!result.first) {
|
||||||
|
|||||||
@ -50,11 +50,11 @@ RulesHandler::RulesHandler(QObject *parent) :
|
|||||||
params.insert("o:eventDescriptor", JsonTypes::eventDescriptorRef());
|
params.insert("o:eventDescriptor", JsonTypes::eventDescriptorRef());
|
||||||
params.insert("o:eventDescriptorList", QVariantList() << JsonTypes::eventDescriptorRef());
|
params.insert("o:eventDescriptorList", QVariantList() << JsonTypes::eventDescriptorRef());
|
||||||
params.insert("o:stateEvaluator", JsonTypes::stateEvaluatorRef());
|
params.insert("o:stateEvaluator", JsonTypes::stateEvaluatorRef());
|
||||||
params.insert("o:exitActions", QVariantList() << JsonTypes::actionRef());
|
params.insert("o:exitActions", QVariantList() << JsonTypes::ruleActionRef());
|
||||||
params.insert("o:enabled", JsonTypes::basicTypeToString(JsonTypes::Bool));
|
params.insert("o:enabled", JsonTypes::basicTypeToString(JsonTypes::Bool));
|
||||||
params.insert("name", JsonTypes::basicTypeToString(JsonTypes::String));
|
params.insert("name", JsonTypes::basicTypeToString(JsonTypes::String));
|
||||||
QVariantList actions;
|
QVariantList actions;
|
||||||
actions.append(JsonTypes::actionRef());
|
actions.append(JsonTypes::ruleActionRef());
|
||||||
params.insert("actions", actions);
|
params.insert("actions", actions);
|
||||||
setParams("AddRule", params);
|
setParams("AddRule", params);
|
||||||
returns.insert("ruleError", JsonTypes::ruleErrorRef());
|
returns.insert("ruleError", JsonTypes::ruleErrorRef());
|
||||||
@ -173,13 +173,14 @@ JsonReply* RulesHandler::AddRule(const QVariantMap ¶ms)
|
|||||||
// We have an eventTypeId
|
// We have an eventTypeId
|
||||||
if (eventDescriptorList.isEmpty()) {
|
if (eventDescriptorList.isEmpty()) {
|
||||||
QVariantMap returns;
|
QVariantMap returns;
|
||||||
qWarning() << "RuleAction" << ruleAction.actionTypeId() << "contains an eventTypeId, but there areno eventDescriptors.";
|
qWarning() << "RuleAction" << ruleAction.actionTypeId() << "contains an eventTypeId, but there are no eventDescriptors.";
|
||||||
returns.insert("ruleErorr", JsonTypes::ruleErrorToString(RuleEngine::RuleErrorInvalidRuleActionPatameter));
|
returns.insert("ruleErorr", JsonTypes::ruleErrorToString(RuleEngine::RuleErrorInvalidRuleActionPatameter));
|
||||||
return createReply(returns);
|
return createReply(returns);
|
||||||
}
|
}
|
||||||
// now check if this eventType is in the eventDescriptorList of this rule
|
// now check if this eventType is in the eventDescriptorList of this rule
|
||||||
foreach (const EventDescriptor eventDescriptor, eventDescriptorList) {
|
foreach (const EventDescriptor eventDescriptor, eventDescriptorList) {
|
||||||
if (eventDescriptor.eventTypeId() == ruleActionParam.eventTypeId()) {
|
if (eventDescriptor.eventTypeId() == ruleActionParam.eventTypeId()) {
|
||||||
|
// TODO: check if they match
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
// the given eventTypeId is not in the eventDescriptorList
|
// the given eventTypeId is not in the eventDescriptorList
|
||||||
@ -207,7 +208,7 @@ JsonReply* RulesHandler::AddRule(const QVariantMap ¶ms)
|
|||||||
foreach (const QVariant &actionVariant, exitActionList) {
|
foreach (const QVariant &actionVariant, exitActionList) {
|
||||||
QVariantMap actionMap = actionVariant.toMap();
|
QVariantMap actionMap = actionVariant.toMap();
|
||||||
RuleAction action(ActionTypeId(actionMap.value("actionTypeId").toString()), DeviceId(actionMap.value("deviceId").toString()));
|
RuleAction action(ActionTypeId(actionMap.value("actionTypeId").toString()), DeviceId(actionMap.value("deviceId").toString()));
|
||||||
qDebug() << "params from json" << actionMap.value("ruleActionParams");
|
qDebug() << "params from json" << actionMap.value("ruleActionParams");
|
||||||
action.setRuleActionParams(JsonTypes::unpackRuleActionParams(actionMap.value("ruleActionParams").toList()));
|
action.setRuleActionParams(JsonTypes::unpackRuleActionParams(actionMap.value("ruleActionParams").toList()));
|
||||||
qDebug() << "params in action" << action.ruleActionParams();
|
qDebug() << "params in action" << action.ruleActionParams();
|
||||||
exitActions.append(action);
|
exitActions.append(action);
|
||||||
|
|||||||
@ -139,7 +139,7 @@ RuleEngine::RuleEngine(QObject *parent) :
|
|||||||
foreach (QString paramNameString, settings.childGroups()) {
|
foreach (QString paramNameString, settings.childGroups()) {
|
||||||
if (paramNameString.startsWith("RuleActionParam-")) {
|
if (paramNameString.startsWith("RuleActionParam-")) {
|
||||||
settings.beginGroup(paramNameString);
|
settings.beginGroup(paramNameString);
|
||||||
RuleActionParam param(paramNameString.remove(QRegExp("^RuleActionParam-")), settings.value("value"));
|
RuleActionParam param(paramNameString.remove(QRegExp("^RuleActionParam-")), settings.value("value",QVariant()), EventTypeId(settings.value("eventTypeId", EventTypeId()).toString()));
|
||||||
params.append(param);
|
params.append(param);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
@ -354,6 +354,7 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QString &n
|
|||||||
settings.setValue("actionTypeId", action.actionTypeId());
|
settings.setValue("actionTypeId", action.actionTypeId());
|
||||||
foreach (const RuleActionParam ¶m, action.ruleActionParams()) {
|
foreach (const RuleActionParam ¶m, action.ruleActionParams()) {
|
||||||
settings.beginGroup("RuleActionParam-" + param.name());
|
settings.beginGroup("RuleActionParam-" + param.name());
|
||||||
|
settings.setValue("eventTypeId", param.eventTypeId());
|
||||||
settings.setValue("value", param.value());
|
settings.setValue("value", param.value());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
@ -362,7 +363,7 @@ RuleEngine::RuleError RuleEngine::addRule(const RuleId &ruleId, const QString &n
|
|||||||
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.beginGroup("exitActions");
|
settings.beginGroup("ruleExitActions");
|
||||||
foreach (const RuleAction &action, rule.exitActions()) {
|
foreach (const RuleAction &action, rule.exitActions()) {
|
||||||
settings.beginGroup(action.actionTypeId().toString());
|
settings.beginGroup(action.actionTypeId().toString());
|
||||||
settings.setValue("deviceId", action.deviceId());
|
settings.setValue("deviceId", action.deviceId());
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
15
|
16
|
||||||
{
|
{
|
||||||
"methods": {
|
"methods": {
|
||||||
"Actions.ExecuteAction": {
|
"Actions.ExecuteAction": {
|
||||||
@ -277,7 +277,7 @@
|
|||||||
"description": "Add a rule. You can describe rules by one or many EventDesciptors and a StateEvaluator. Note that onlyone of either eventDescriptor or eventDescriptorList may be passed at a time. A rule can be created but left disabled,meaning it won't actually be executed until set to enabled. If not given, enabled defaults to true.",
|
"description": "Add a rule. You can describe rules by one or many EventDesciptors and a StateEvaluator. Note that onlyone of either eventDescriptor or eventDescriptorList may be passed at a time. A rule can be created but left disabled,meaning it won't actually be executed until set to enabled. If not given, enabled defaults to true.",
|
||||||
"params": {
|
"params": {
|
||||||
"actions": [
|
"actions": [
|
||||||
"$ref:Action"
|
"$ref:RuleAction"
|
||||||
],
|
],
|
||||||
"name": "String",
|
"name": "String",
|
||||||
"o:enabled": "Bool",
|
"o:enabled": "Bool",
|
||||||
@ -286,7 +286,7 @@
|
|||||||
"$ref:EventDescriptor"
|
"$ref:EventDescriptor"
|
||||||
],
|
],
|
||||||
"o:exitActions": [
|
"o:exitActions": [
|
||||||
"$ref:Action"
|
"$ref:RuleAction"
|
||||||
],
|
],
|
||||||
"o:stateEvaluator": "$ref:StateEvaluator"
|
"o:stateEvaluator": "$ref:StateEvaluator"
|
||||||
},
|
},
|
||||||
@ -572,19 +572,31 @@
|
|||||||
],
|
],
|
||||||
"Rule": {
|
"Rule": {
|
||||||
"actions": [
|
"actions": [
|
||||||
"$ref:Action"
|
"$ref:RuleAction"
|
||||||
],
|
],
|
||||||
"enabled": "Bool",
|
"enabled": "Bool",
|
||||||
"eventDescriptors": [
|
"eventDescriptors": [
|
||||||
"$ref:EventDescriptor"
|
"$ref:EventDescriptor"
|
||||||
],
|
],
|
||||||
"exitActions": [
|
"exitActions": [
|
||||||
"$ref:Action"
|
"$ref:RuleAction"
|
||||||
],
|
],
|
||||||
"id": "Uuid",
|
"id": "Uuid",
|
||||||
"name": "String",
|
"name": "String",
|
||||||
"stateEvaluator": "$ref:StateEvaluator"
|
"stateEvaluator": "$ref:StateEvaluator"
|
||||||
},
|
},
|
||||||
|
"RuleAction": {
|
||||||
|
"actionTypeId": "Uuid",
|
||||||
|
"deviceId": "Uuid",
|
||||||
|
"o:ruleActionParams": [
|
||||||
|
"$ref:RuleActionParam"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"RuleActionParam": {
|
||||||
|
"name": "String",
|
||||||
|
"o:eventTypeId": "Uuid",
|
||||||
|
"o:value": "$ref:BasicType"
|
||||||
|
},
|
||||||
"RuleError": [
|
"RuleError": [
|
||||||
"RuleErrorNoError",
|
"RuleErrorNoError",
|
||||||
"RuleErrorInvalidRuleId",
|
"RuleErrorInvalidRuleId",
|
||||||
@ -594,7 +606,8 @@
|
|||||||
"RuleErrorActionTypeNotFound",
|
"RuleErrorActionTypeNotFound",
|
||||||
"RuleErrorInvalidParameter",
|
"RuleErrorInvalidParameter",
|
||||||
"RuleErrorInvalidRuleFormat",
|
"RuleErrorInvalidRuleFormat",
|
||||||
"RuleErrorMissingParameter"
|
"RuleErrorMissingParameter",
|
||||||
|
"RuleErrorInvalidRuleActionPatameter"
|
||||||
],
|
],
|
||||||
"SetupMethod": [
|
"SetupMethod": [
|
||||||
"SetupMethodJustAdd",
|
"SetupMethodJustAdd",
|
||||||
|
|||||||
@ -126,22 +126,22 @@ void TestRules::addRemoveRules_data()
|
|||||||
QVariantMap validActionNoParams;
|
QVariantMap validActionNoParams;
|
||||||
validActionNoParams.insert("actionTypeId", mockActionIdNoParams);
|
validActionNoParams.insert("actionTypeId", mockActionIdNoParams);
|
||||||
validActionNoParams.insert("deviceId", m_mockDeviceId);
|
validActionNoParams.insert("deviceId", m_mockDeviceId);
|
||||||
validActionNoParams.insert("params", QVariantList());
|
validActionNoParams.insert("ruleActionParams", QVariantList());
|
||||||
|
|
||||||
QVariantMap invalidAction;
|
QVariantMap invalidAction;
|
||||||
invalidAction.insert("actionTypeId", ActionTypeId());
|
invalidAction.insert("actionTypeId", ActionTypeId());
|
||||||
invalidAction.insert("deviceId", m_mockDeviceId);
|
invalidAction.insert("deviceId", m_mockDeviceId);
|
||||||
invalidAction.insert("params", QVariantList());
|
invalidAction.insert("ruleActionParams", QVariantList());
|
||||||
|
|
||||||
QVariantMap validExitActionNoParams;
|
QVariantMap validExitActionNoParams;
|
||||||
validExitActionNoParams.insert("actionTypeId", mockActionIdNoParams);
|
validExitActionNoParams.insert("actionTypeId", mockActionIdNoParams);
|
||||||
validExitActionNoParams.insert("deviceId", m_mockDeviceId);
|
validExitActionNoParams.insert("deviceId", m_mockDeviceId);
|
||||||
validExitActionNoParams.insert("params", QVariantList());
|
validExitActionNoParams.insert("ruleActionParams", QVariantList());
|
||||||
|
|
||||||
QVariantMap invalidExitAction;
|
QVariantMap invalidExitAction;
|
||||||
invalidExitAction.insert("actionTypeId", ActionTypeId());
|
invalidExitAction.insert("actionTypeId", ActionTypeId());
|
||||||
invalidExitAction.insert("deviceId", m_mockDeviceId);
|
invalidExitAction.insert("deviceId", m_mockDeviceId);
|
||||||
invalidExitAction.insert("params", QVariantList());
|
invalidExitAction.insert("ruleActionParams", QVariantList());
|
||||||
|
|
||||||
QVariantMap stateDescriptor;
|
QVariantMap stateDescriptor;
|
||||||
stateDescriptor.insert("stateTypeId", mockIntStateId);
|
stateDescriptor.insert("stateTypeId", mockIntStateId);
|
||||||
@ -363,7 +363,7 @@ void TestRules::loadStoreConfig()
|
|||||||
QVariantMap action1;
|
QVariantMap action1;
|
||||||
action1.insert("actionTypeId", mockActionIdNoParams);
|
action1.insert("actionTypeId", mockActionIdNoParams);
|
||||||
action1.insert("deviceId", m_mockDeviceId);
|
action1.insert("deviceId", m_mockDeviceId);
|
||||||
action1.insert("params", QVariantList());
|
action1.insert("ruleActionParams", QVariantList());
|
||||||
|
|
||||||
QVariantMap action2;
|
QVariantMap action2;
|
||||||
action2.insert("actionTypeId", mockActionIdWithParams);
|
action2.insert("actionTypeId", mockActionIdWithParams);
|
||||||
@ -378,7 +378,7 @@ void TestRules::loadStoreConfig()
|
|||||||
action2Param2.insert("name", "mockActionParam2");
|
action2Param2.insert("name", "mockActionParam2");
|
||||||
action2Param2.insert("value", true);
|
action2Param2.insert("value", true);
|
||||||
action2Params.append(action2Param2);
|
action2Params.append(action2Param2);
|
||||||
action2.insert("params", action2Params);
|
action2.insert("ruleActionParams", action2Params);
|
||||||
|
|
||||||
// First rule
|
// First rule
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
@ -454,6 +454,10 @@ void TestRules::loadStoreConfig()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVariantList replyActions = rule1.value("actions").toList();
|
QVariantList replyActions = rule1.value("actions").toList();
|
||||||
|
qDebug() << "----------------------------------------------";
|
||||||
|
qDebug() << rule1;
|
||||||
|
qDebug() << "----------------------------------------------";
|
||||||
|
|
||||||
foreach (const QVariant &actionVariant, actions) {
|
foreach (const QVariant &actionVariant, actions) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
foreach (const QVariant &replyActionVariant, replyActions) {
|
foreach (const QVariant &replyActionVariant, replyActions) {
|
||||||
|
|||||||
Reference in New Issue
Block a user