コード例 #1
0
/* ****************************************************************************
*
* addContextProviderAttribute -
*
* The limitReached parameter is to prevent the addition of new entities, which is needed in the case of the pagination
* limit has been reached with local entities.
*
*/
void addContextProviderAttribute
(
  ContextElementResponseVector&   cerV,
  EntityId*                       enP,
  ContextRegistrationAttribute*   craP,
  const ProvidingApplication&     pa,
  bool                            limitReached
)
{
  for (unsigned int ix = 0; ix < cerV.size(); ++ix)
  {
    if ((cerV.get(ix)->contextElement.entityId.id != enP->id) ||
        (cerV.get(ix)->contextElement.entityId.type != enP->type))
    {
     continue;
    }

    for (unsigned int jx = 0; jx < cerV.get(ix)->contextElement.contextAttributeVector.size(); ++jx)
    {
      std::string attrName = cerV.get(ix)->contextElement.contextAttributeVector.get(jx)->name;
      if (attrName == craP->name)
      {
        /* In this case, the attribute has been already found in local database. CPr is unnecessary */
        return;
      }
    }
    /* Reached this point, no attribute was found, so adding it with corresponding CPr info */
    ContextAttribute* caP = new ContextAttribute(craP->name, "", "");
    caP->providingApplication = pa;
    cerV.get(ix)->contextElement.contextAttributeVector.push_back(caP);
    return;

  }

  if (!limitReached)
  {
    /* Reached this point, it means that the cerV doesn't contain a proper CER, so we create it */
    ContextElementResponse* cerP            = new ContextElementResponse();
    cerP->contextElement.entityId.id        = enP->id;
    cerP->contextElement.entityId.type      = enP->type;
    cerP->contextElement.entityId.isPattern = "false";

    cerP->statusCode.fill(SccOk);

    ContextAttribute* caP = new ContextAttribute(craP->name, "", "");
    caP->providingApplication = pa;
    cerP->contextElement.contextAttributeVector.push_back(caP);

    cerV.push_back(cerP);
  }
}
コード例 #2
0
/* ****************************************************************************
*
* present -
*
* Just to exercise the code, nothing to be expected here ...
*/
TEST(ContextElementResponseVector, present)
{
  ContextElementResponseVector  cerv;
  ContextElementResponse        cer;

  utInit();

  cer.contextElement.entityId.id         = "ID";
  cer.contextElement.entityId.type       = "Type";
  cer.contextElement.entityId.isPattern  = "false";
  cer.statusCode.fill(SccOk, "details");
  cerv.push_back(&cer);

  cerv.present("");

  utExit();
}
コード例 #3
0
/* ****************************************************************************
*
* addContextProviderEntity -
*
*/
void addContextProviderEntity(ContextElementResponseVector& cerV, EntityId* enP, ProvidingApplication pa)
{
  for (unsigned int ix = 0; ix < cerV.size(); ++ix)
  {
    if (cerV.get(ix)->contextElement.entityId.id == enP->id && cerV.get(ix)->contextElement.entityId.type == enP->type)
    {
      cerV.get(ix)->contextElement.providingApplicationList.push_back(pa);
      return;    /* by construction, no more than one CER with the same entity information should exist in the CERV) */
    }
  }

  /* Reached this point, it means that the cerV doesn't contain a proper CER, so we create it */
  ContextElementResponse* cerP            = new ContextElementResponse();
  cerP->contextElement.entityId.id        = enP->id;
  cerP->contextElement.entityId.type      = enP->type;
  cerP->contextElement.entityId.isPattern = "false";
  cerP->contextElement.providingApplicationList.push_back(pa);

  cerP->statusCode.fill(SccOk);
  cerV.push_back(cerP);

}
コード例 #4
0
/* ****************************************************************************
*
* check - 
*/
TEST(ContextElementResponseVector, check)
{
  ContextElementResponseVector  cerv;
  ContextElementResponse        cer;
  std::string                   out;
  ConnectionInfo                ci;

  utInit();

  out = cerv.check(&ci, UpdateContext, "", "", 0);
  EXPECT_STREQ("OK", out.c_str());

  cer.contextElement.entityId.id         = "ID";
  cer.contextElement.entityId.type       = "Type";
  cer.contextElement.entityId.isPattern  = "false";
  cer.statusCode.fill(SccOk, "details");

  cerv.push_back(&cer);
  out = cerv.check(&ci, UpdateContext, "", "", 0);
  EXPECT_STREQ("OK", out.c_str());

  utExit();
}
コード例 #5
0
/* ****************************************************************************
*
* foundAndNotFoundAttributeSeparation - 
*
* Examine the response from mongo to find out what has really happened ...
*
*/
static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, UpdateContextRequest* upcrP, ConnectionInfo* ciP)
{
  ContextElementResponseVector  notFoundV;

  for (unsigned int cerIx = 0; cerIx < upcrsP->contextElementResponseVector.size(); ++cerIx)
  {
    ContextElementResponse* cerP = upcrsP->contextElementResponseVector[cerIx];

    //
    // All attributes with found == false?
    //
    int noOfFounds    = 0;
    int noOfNotFounds = 0;
    for (unsigned int aIx = 0; aIx < cerP->contextElement.contextAttributeVector.size(); ++aIx)
    {
      if (cerP->contextElement.contextAttributeVector[aIx]->found == true)
      {
        ++noOfFounds;
      }
      else
      {
        ++noOfNotFounds;
      }
    }

    //
    // Now, if we have ONLY FOUNDS, then things stay the way they are, one response with '200 OK'
    // If we have ONLY NOT-FOUNDS, the we have one response with '404 Not Found'
    // If we have a mix, then we need to add a response for the not founds, with '404 Not Found'
    //
    if ((noOfFounds == 0) && (noOfNotFounds > 0))
    {
      if ((cerP->statusCode.code == SccOk) || (cerP->statusCode.code == SccNone))
      {
        cerP->statusCode.fill(SccContextElementNotFound, cerP->contextElement.entityId.id);
      }
    }
    else if ((noOfFounds > 0) && (noOfNotFounds > 0))
    {
      // Adding a ContextElementResponse for the 'Not-Founds'

      ContextElementResponse* notFoundCerP = new ContextElementResponse(&cerP->contextElement.entityId, NULL);

      //
      // Filling in StatusCode (SccContextElementNotFound) for NotFound
      //
      notFoundCerP->statusCode.fill(SccContextElementNotFound, cerP->contextElement.entityId.id);

      //
      // Setting StatusCode to OK for Found
      //
      cerP->statusCode.fill(SccOk);

      //
      // And, pushing to NotFound-vector 
      //
      notFoundV.push_back(notFoundCerP);


      // Now moving the not-founds to notFoundCerP
      std::vector<ContextAttribute*>::iterator iter;
      for (iter = cerP->contextElement.contextAttributeVector.vec.begin(); iter < cerP->contextElement.contextAttributeVector.vec.end();)
      {
        if ((*iter)->found == false)
        {
          // 1. Push to notFoundCerP
          notFoundCerP->contextElement.contextAttributeVector.push_back(*iter);

          // 2. remove from cerP
          iter = cerP->contextElement.contextAttributeVector.vec.erase(iter);
        }
        else
        {
          ++iter;
        }
      }
    }

    //
    // Add EntityId::id to StatusCode::details if 404, but only if StatusCode::details is empty
    //
    if ((cerP->statusCode.code == SccContextElementNotFound) && (cerP->statusCode.details == ""))
    {
      cerP->statusCode.details = cerP->contextElement.entityId.id;
    }
  }

  //
  // Now add the contextElementResponses for 404 Not Found
  //
  if (notFoundV.size() != 0)
  {
    for (unsigned int ix = 0; ix < notFoundV.size(); ++ix)
    {
      upcrsP->contextElementResponseVector.push_back(notFoundV[ix]);
    }
  }


  //
  // If nothing at all in response vector, mark as not found (but not if DELETE request)
  //
  if (ciP->method != "DELETE")
  {
    if (upcrsP->contextElementResponseVector.size() == 0)
    {
      if (upcrsP->errorCode.code == SccOk)
      {
        upcrsP->errorCode.fill(SccContextElementNotFound, upcrP->contextElementVector[0]->entityId.id);
      }
    }
  }

  
  //
  // Add entityId::id to details if Not Found and only one element in response.
  // And, if 0 elements in response, take entityId::id from the request.
  //
  if (upcrsP->errorCode.code == SccContextElementNotFound)
  {
    if (upcrsP->contextElementResponseVector.size() == 1)
    {
      upcrsP->errorCode.details = upcrsP->contextElementResponseVector[0]->contextElement.entityId.id;
    }
    else if (upcrsP->contextElementResponseVector.size() == 0)
    {
      upcrsP->errorCode.details = upcrP->contextElementVector[0]->entityId.id;
    }
  }
}