diff --git a/server/jsonrpc/actionhandler.cpp b/server/jsonrpc/actionhandler.cpp index 1070e33c..777e01b5 100644 --- a/server/jsonrpc/actionhandler.cpp +++ b/server/jsonrpc/actionhandler.cpp @@ -37,6 +37,15 @@ ActionHandler::ActionHandler(QObject *parent) : returns.insert("errorMessage", "string"); setReturns("ExecuteAction", returns); + params.clear(); returns.clear(); + setDescription("GetActionType", "Get the ActionType for the given ActionTypeId"); + params.insert("actionTypeId", "uuid"); + setParams("GetActionType", params); + returns.insert("success", "bool"); + returns.insert("errorMessage", "string"); + returns.insert("o:actionType", JsonTypes::actionTypeDescription()); + setReturns("GetActionType", returns); + connect(GuhCore::instance()->deviceManager(), &DeviceManager::actionExecutionFinished, this, &ActionHandler::actionExecuted); } @@ -69,6 +78,26 @@ JsonReply* ActionHandler::ExecuteAction(const QVariantMap ¶ms) return createReply(returns); } +JsonReply *ActionHandler::GetActionType(const QVariantMap ¶ms) const +{ + ActionTypeId actionTypeId(params.value("actionTypeId").toString()); + foreach (const DeviceClass &deviceClass, GuhCore::instance()->deviceManager()->supportedDevices()) { + foreach (const ActionType &actionType, deviceClass.actions()) { + if (actionType.id() == actionTypeId) { + QVariantMap data; + data.insert("success", true); + data.insert("errorMessage", QString()); + data.insert("actionType", JsonTypes::packActionType(actionType)); + return createReply(data); + } + } + } + QVariantMap data; + data.insert("success", false); + data.insert("errorMessage", QString("No ActionType with id %1.").arg(actionTypeId.toString())); + return createReply(data); +} + void ActionHandler::actionExecuted(const ActionId &id, DeviceManager::DeviceError status, const QString &errorMessage) { if (!m_asyncActionExecutions.contains(id)) { diff --git a/server/jsonrpc/actionhandler.h b/server/jsonrpc/actionhandler.h index 151feaa8..9288e040 100644 --- a/server/jsonrpc/actionhandler.h +++ b/server/jsonrpc/actionhandler.h @@ -32,6 +32,8 @@ public: Q_INVOKABLE JsonReply* ExecuteAction(const QVariantMap ¶ms); + Q_INVOKABLE JsonReply* GetActionType(const QVariantMap ¶ms) const; + private slots: void actionExecuted(const ActionId &id, DeviceManager::DeviceError status, const QString &errorMessage); diff --git a/tests/auto/actions/testactions.cpp b/tests/auto/actions/testactions.cpp index bd4bc41f..c5826404 100644 --- a/tests/auto/actions/testactions.cpp +++ b/tests/auto/actions/testactions.cpp @@ -37,6 +37,9 @@ private slots: void executeAction_data(); void executeAction(); + void getActionTypes_data(); + void getActionTypes(); + }; void TestActions::executeAction_data() @@ -115,6 +118,31 @@ void TestActions::executeAction() } +void TestActions::getActionTypes_data() +{ + QTest::addColumn("actionTypeId"); + QTest::addColumn("success"); + + QTest::newRow("valid actiontypeid") << mockActionIdWithParams << true; + QTest::newRow("invalid actiontypeid") << ActionTypeId::createActionTypeId() << false; +} + +void TestActions::getActionTypes() +{ + QFETCH(ActionTypeId, actionTypeId); + QFETCH(bool, success); + + QVariantMap params; + params.insert("actionTypeId", actionTypeId.toString()); + QVariant response = injectAndWait("Actions.GetActionType", params); + + verifySuccess(response, success); + + if (success) { + QVERIFY2(ActionTypeId(response.toMap().value("params").toMap().value("actionType").toMap().value("id").toString()) == actionTypeId, "Didnt get reply for same actionTypeId as requested."); + } +} + #include "testactions.moc" QTEST_MAIN(TestActions) diff --git a/tests/scripts/getactiontype.sh b/tests/scripts/getactiontype.sh new file mode 100755 index 00000000..d215f63c --- /dev/null +++ b/tests/scripts/getactiontype.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if [ -z $2 ]; then + echo "usage: $0 host actionTypeId" +else + (echo '{"id":1, "method":"Actions.GetActionType", "params":{"actionTypeId":"'$2'"}}'; sleep 1) | nc $1 1234 +fi