/* ****************************************************************************
*
* mongoUpdateContext - 
*/
HttpStatusCode mongoUpdateContext
(
  UpdateContextRequest*                 requestP,
  UpdateContextResponse*                responseP,
  const std::string&                    tenant,
  const std::vector<std::string>&       servicePathV,
  std::map<std::string, std::string>&   uriParams,    // FIXME P7: we need this to implement "restriction-based" filters
  const std::string&                    xauthToken,
  const std::string&                    apiVersion,
  bool                                  checkEntityExistance
)
{
    bool reqSemTaken;

    reqSemTake(__FUNCTION__, "ngsi10 update request", SemWriteOp, &reqSemTaken);

    /* Check that the service path vector has only one element, returning error otherwise */
    if (servicePathV.size() > 1)
    {
        LM_W(("Bad Input (service path length %d is greater than the one in update)", servicePathV.size()));
        responseP->errorCode.fill(SccBadRequest, "service path length greater than one in update");
    }
    else
    {
        /* Process each ContextElement */
        for (unsigned int ix = 0; ix < requestP->contextElementVector.size(); ++ix)
        {
          processContextElement(requestP->contextElementVector.get(ix),
                                responseP,
                                requestP->updateActionType.get(),
                                tenant,
                                servicePathV,
                                uriParams,
                                xauthToken,
                                apiVersion,
                                checkEntityExistance);
        }

        /* Note that although individual processContextElements() invocations return ConnectionError, this
           error gets "encapsulated" in the StatusCode of the corresponding ContextElementResponse and we
           consider the overall mongoUpdateContext() as OK. */
        responseP->errorCode.fill(SccOk);
    }    
    reqSemGive(__FUNCTION__, "ngsi10 update request", reqSemTaken);
    
    return SccOk;
}
Esempio n. 2
0
/* ****************************************************************************
*
* mongoNotifyContext -
*/
HttpStatusCode mongoNotifyContext(NotifyContextRequest* requestP, NotifyContextResponse* responseP, const std::string& tenant) {

    reqSemTake(__FUNCTION__, "ngsi10 notification");

    /* We ignore "subscriptionId" and "originator" in the request, as we don't have anything interesting
     * to do with them */

    /* Process each ContextElement */
    for (unsigned int ix = 0; ix < requestP->contextElementResponseVector.size(); ++ix) {
        /* We use 'ucr' to conform processContextElement signature but we are not doing anything with that */
        UpdateContextResponse ucr;

        // FIXME P10: we need to pass an empty service path vector in order to fulfill the processContextElement signature(). To review,
        // once we implement service path also for subscriptions/notifications
        std::vector<std::string> servicePathV;        

        processContextElement(&requestP->contextElementResponseVector.get(ix)->contextElement, &ucr, "append", tenant, servicePathV);
    }

    reqSemGive(__FUNCTION__, "ngsi10 notification");
    responseP->responseCode.fill(SccOk);

    return SccOk;
}