its respective raml file doest not support either PUT or POST.
Providing the request and response information from raml to simulated resource,
so it can validate the requests it can support whenever it receives one from client.
Change-Id: I42ea78d963dd2c11e7ab945cb6a75bb8e3cd0864
Signed-off-by: spurthi.segu <spurthi.segu@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4259
Reviewed-by: RadhaBhavani <radha.p@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
try
{
SimulatorResourceModelSP rep = std::make_shared<SimulatorResourceModel>();
- std::string value = "off";
+ bool value = false;
rep->add("power", value);
- rep->add("intensity", 5);
+ rep->add("intensity", 15);
resource->put(std::map <std::string, std::string>(), rep, callback);
std::cout << "PUT is successful!" << std::endl;
try
{
SimulatorResourceModelSP rep = std::make_shared<SimulatorResourceModel>();
- std::string value = "on";
+ bool value = true;
rep->add("power", value);
- rep->add("intensity", 7);
+ rep->add("intensity", 17);
resource->post(std::map <std::string, std::string>(), rep, callback);
std::cout << "POST is successful!" << std::endl;
m_resModel = resModel;
}
+void SimulatorCollectionResourceImpl::setActionType(std::map<RAML::ActionType, RAML::ActionPtr> &actionType)
+{
+ m_actionTypes = actionType;
+}
+
std::vector<ObserverInfo> SimulatorCollectionResourceImpl::getObserversList()
{
return m_observersList;
std::shared_ptr<OC::OCResourceRequest> request)
{
std::shared_ptr<OC::OCResourceResponse> response;
+
+ RAML::ActionType type = getActionType(request->getRequestType());
+
+ if (!m_actionTypes.empty())
+ {
+ if (m_actionTypes.end() == m_actionTypes.find(type))
+ return response;
+ }
+
if ("GET" == request->getRequestType())
{
// Construct the representation
{
std::lock_guard<std::mutex> lock(m_childResourcesLock);
std::shared_ptr<OC::OCResourceResponse> response;
+
+ RAML::ActionType type = getActionType(request->getRequestType());
+
+ if (!m_actionTypes.empty())
+ {
+ if (m_actionTypes.end() == m_actionTypes.find(type))
+ return response;
+ }
+
if ("GET" == request->getRequestType())
{
// Construct the representation
}
}
}
+
+RAML::ActionType SimulatorCollectionResourceImpl::getActionType(std::string requestType)
+{
+ if (!requestType.compare("GET"))
+ return RAML::ActionType::GET;
+
+ if (!requestType.compare("PUT"))
+ return RAML::ActionType::PUT;
+
+ if (!requestType.compare("POST"))
+ return RAML::ActionType::POST;
+
+ if (!requestType.compare("DELETE"))
+ return RAML::ActionType::DELETE;
+
+ return RAML::ActionType::NONE;
+}
\ No newline at end of file
#define SIMULATOR_COLLECTION_RESOURCE_IMPL_H_
#include "simulator_collection_resource.h"
+#include "RamlParser.h"
class SimulatorResourceFactory;
class SimulatorCollectionResourceImpl : public SimulatorCollectionResource
void setResourceModel(const SimulatorResourceModel &resModel);
+ void setActionType(std::map<RAML::ActionType, RAML::ActionPtr> &actionType);
+
+ RAML::ActionType getActionType(std::string requestType);
+
private:
SimulatorCollectionResourceImpl();
std::vector<ObserverInfo> m_observersList;
ObserverCallback m_observeCallback;
ResourceModelChangedCallback m_modelCallback;
+ std::map<RAML::ActionType , RAML::ActionPtr> m_actionTypes;
OCResourceProperty m_property;
OCResourceHandle m_resourceHandle;
\r
name = ramlResource->getDisplayName();\r
uri = ramlResource->getResourceUri();\r
+ std::map<RAML::ActionType, RAML::ActionPtr> actionType = ramlResource->getActions();\r
\r
RAML::RequestResponseBodyPtr successResponseBody = getRAMLResponseBody(\r
ramlResource, RAML::ActionType::GET, "200");\r
collectionRes->setResourceType(resourceType);\r
collectionRes->setInterface(interfaceType);\r
collectionRes->setURI(ResourceURIFactory::getInstance()->constructURI(uri));\r
+ collectionRes->setActionType(actionType);\r
\r
collectionRes->setResourceModel(successResponseModel);\r
simResource = std::dynamic_pointer_cast<SimulatorResource>(collectionRes);\r
singleRes->setResourceType(resourceType);\r
singleRes->setInterface(interfaceType);\r
singleRes->setURI(ResourceURIFactory::getInstance()->constructURI(uri));\r
+ singleRes->setActionType(actionType);\r
\r
singleRes->setResourceModel(successResponseModel);\r
singleRes->setPutErrorResponseModel(putErrorResponseModel);\r
m_postErrorResModel = resModel;
}
+void SimulatorSingleResourceImpl::setActionType(std::map<RAML::ActionType, RAML::ActionPtr> &actionType)
+{
+ m_actionTypes = actionType;
+}
+
void SimulatorSingleResourceImpl::notifyApp(SimulatorResourceModel &resModel)
{
if (m_modelCallback)
<< " request received. \n**Payload details**\n" << payload)
}
- // Handover the request to appropriate interface handler
- std::string interfaceType(OC::DEFAULT_INTERFACE);
- OC::QueryParamsMap queryParams = request->getQueryParameters();
- if (queryParams.end() != queryParams.find("if"))
- interfaceType = queryParams["if"];
+ // TODO: Handover the request to appropriate interface handler
std::shared_ptr<OC::OCResourceResponse> response;
- if (interfaceType == OC::DEFAULT_INTERFACE)
- {
- response = requestOnBaseLineInterface(request);
- }
+ response = requestOnBaseLineInterface(request);
// Send response if the request handled by resource
if (response)
std::shared_ptr<OC::OCResourceRequest> request)
{
std::shared_ptr<OC::OCResourceResponse> response;
+
+ RAML::ActionType type = getActionType(request->getRequestType());
+
+ if (!m_actionTypes.empty())
+ {
+ if (m_actionTypes.end() == m_actionTypes.find(type))
+ return response;
+ }
+
if ("GET" == request->getRequestType())
{
OC::OCRepresentation ocRep = m_resModel.getOCRepresentation();
if (m_observeCallback)
m_observeCallback(m_uri, ObservationStatus::UNREGISTER, observerList[index]);
}
-}
\ No newline at end of file
+}
+
+RAML::ActionType SimulatorSingleResourceImpl::getActionType(std::string requestType)
+{
+ if (!requestType.compare("GET"))
+ return RAML::ActionType::GET;
+
+ if (!requestType.compare("PUT"))
+ return RAML::ActionType::PUT;
+
+ if (!requestType.compare("POST"))
+ return RAML::ActionType::POST;
+
+ if (!requestType.compare("DELETE"))
+ return RAML::ActionType::DELETE;
+
+ return RAML::ActionType::NONE;
+}
#include "simulator_single_resource.h"
#include "resource_update_automation_mngr.h"
+#include "RamlParser.h"
class SimulatorResourceFactory;
class SimulatorSingleResourceImpl : public SimulatorSingleResource
void setResourceModel(const SimulatorResourceModel &resModel);
void setPutErrorResponseModel(const SimulatorResourceModel &resModel);
void setPostErrorResponseModel(const SimulatorResourceModel &resModel);
+ void setActionType(std::map<RAML::ActionType, RAML::ActionPtr> &actionType);
+ RAML::ActionType getActionType(std::string requestType);
void notifyApp();
void notifyApp(SimulatorResourceModel &resModel);
ObserverCallback m_observeCallback;
UpdateAutomationMngr m_updateAutomationMgr;
std::vector<ObserverInfo> m_observersList;
+ std::map<RAML::ActionType , RAML::ActionPtr> m_actionTypes;
OCResourceProperty m_property;
OCResourceHandle m_resourceHandle;