예제 #1
0
Response* FakeConnection::doPost(const std::string& pathAndQuerystring,const IDocumentContent& payload) {
  TIMED_FUNC(FakeConnection_doPost);
  Response* response = new Response;

  response->setResponseCode(ResponseCode::OK); // otherwise blank

  return response;
}
예제 #2
0
Response* FakeConnection::doGet(const std::string& pathAndQuerystring) {
  TIMED_FUNC(FakeConnection_doGet);
  Response* response = new Response;

  response->setResponseCode(ResponseCode::OK); // otherwise blank

  return response;
}
예제 #3
0
Response* FakeConnection::doDelete(const std::string& pathAndQuerystring) {
  TIMED_FUNC(FakeConnection_doDelete);
  Response* response = new Response;

  response->setResponseCode(ResponseCode::NO_CONTENT); // otherwise blank

  return response;
}
예제 #4
0
Response* FakeConnection::getDocument(const std::string& uri) {
  TIMED_FUNC(FakeConnection_getDocument);
  LOG(DEBUG) << "  Entering FakeConnection::getDocument";

  LOG(DEBUG) << "    Fetching document with URI: " << uri;
  std::map<std::string,IDocumentContent*>::iterator it;
  it = mImpl->documents.find(uri);
  std::string ct("");
  std::string mime("");
  if (mImpl->documents.end() != it) {
    LOG(DEBUG) << "    Found document with URI: " << uri;
    IDocumentContent* docPtr = it->second;
    ct = docPtr->getContent();
    mime = docPtr->getMimeType();
  }
  //IDocumentContent& value = mImpl->documents[uri.c_str()];

  //LOG(DEBUG) << "    pointer value: " << value;

  Response* response = new Response;
  LOG(DEBUG) << "  Setting response code";


  LOG(DEBUG) << "  Setting response content ptr";
  //std::unique_ptr<std::string> content(new std::string(ct));
  //response->setContent(std::move(content));
  response->setContent(new std::string(ct));
  LOG(DEBUG) << "  Setting response headers";
  if (0 == ct.compare("")) {
    // not found
    response->setResponseCode(ResponseCode::NOT_FOUND);
    response->setResponseType(ResponseType::UNKNOWN_TYPE);
  } else {
    // found
    HttpHeaders headers;
    headers.setHeader("Content-type",mime);
    response->setResponseHeaders(headers);
    response->setResponseCode(ResponseCode::OK);
    if (0 == mime.compare("application/json")) {
      response->setResponseType(ResponseType::JSON);
    } else if (0 == mime.compare("application/xml") ) {
      response->setResponseType(ResponseType::XML);
    } else if (0 == mime.compare("text/plain")) {
      response->setResponseType(ResponseType::TEXT);
    } else {
      response->setResponseType(ResponseType::BINARY);
    }
  }

  LOG(DEBUG) << "  returning response ";
  return response;
}
예제 #5
0
Response* FakeConnection::saveDocumentContent(const std::string& uri,const IDocumentContent& payload) {
  TIMED_FUNC(FakeConnection_saveDocumentContent);
  LOG(DEBUG) << "  Entering FakeConnection::saveDocumentContent";

  IDocumentContent* dp = &(const_cast<IDocumentContent&>(payload));
  mImpl->documents.insert(std::pair<std::string,IDocumentContent*>(uri,dp));

  Response* response = new Response;

  response->setResponseCode(ResponseCode::CREATED); // otherwise blank
  response->setResponseType(ResponseType::UNKNOWN_TYPE); // explicit

  return response;
}
예제 #6
0
Response* FakeConnection::search(const SearchDescription& desc) {
  TIMED_FUNC(FakeConnection_search);
  LOG(DEBUG) << "  Entering FakeConnection::search";

  Response* response = new Response;

  response->setResponseCode(ResponseCode::OK);
  HttpHeaders headers;
  headers.setHeader("Content-type","application/json");
  response->setResponseHeaders(headers);
  std::ostringstream cos;
  cos <<
      "{\"response\": {" <<
        "\"start\": 1, \"page-length\": ";

  // return 10 or documents.length, whichever is smaller
  if (mImpl->documents.size() < 10) {
    cos << mImpl->documents.size();
  } else {
    cos << 10;
  }
  cos << ", \"results\": [";

  // loop over documents in map
  std::map<std::string,IDocumentContent*>::iterator it;
  int count = 0;
  for (it = mImpl->documents.begin();it != mImpl->documents.end() && count < 10;++it) {
    ++count; // iterate first as MarkLogic responses are 1 indexed, not 0 indexed
    if (count > 1) {
      cos << ",";
    }
    cos << "{\"index\": " << count << " , \"uri\": \"" << (it->first)
        << "\", \"score\": \"43648\" \"confidence\":\"0.418356\" \"fitness\":\"0.50947\"}";
  }

  cos << "] } }";
  //std::unique_ptr<std::string> cPtr(new std::string(cos.str()));
  //response->setContent(std::move(cPtr));
  response->setContent(new std::string(cos.str()));
  response->setResponseType(ResponseType::JSON);

  return response;
}
예제 #7
0
Response* FakeConnection::deleteDocument(const std::string& uri) {
  TIMED_FUNC(FakeConnection_deleteDocument);
  LOG(DEBUG) << "  Entering FakeConnection::deleteDocument";

  std::map<std::string,IDocumentContent*>::iterator it;
  it = mImpl->documents.find(uri.c_str());
  if (mImpl->documents.end() != it) {
    // delete if found
    LOG(DEBUG) << "   URI found: " << uri;
    mImpl->documents.erase(it);
  } else {
    LOG(DEBUG) << "   URI not found: " << uri;
  }

  Response* response = new Response;

  response->setResponseCode(ResponseCode::NO_CONTENT); // 204 = DELETED too and NO_CONTENT

  return response;
}
예제 #8
0
Angle Lidar::bestAvailableHeading(Angle desiredHeading){
  TIMED_FUNC(timerobj);
  Angle best_heading = -1;
  double best_heuristic = -1;
  ReadingContainer used_reading;
  if(configuration.data["pathfinding"]["lidar"]["perform_growth"]){
    used_reading = performObstactleGrowth();
  }
  else{
    used_reading = readings;
  }
  for(auto it = used_reading.begin(); it != used_reading.end();++it){
        double heuristic_value = rayHeuristic(desiredHeading,it->first,it->second);
        if(heuristic_value > best_heuristic || best_heuristic == -1){
          best_heading = it->first;
          best_heuristic = heuristic_value;
        }
  }
  CLOG(INFO,"lidar") << "Computed best heading: " << best_heading;
  return best_heading;
}
예제 #9
0
Response* Connection::search(const SearchDescription& desc) {
  TIMED_FUNC(Connection_search);
  return mImpl->proxy.postSync(mImpl->serverUrl,"/v1/search?format=json", *desc.getPayload());
}
예제 #10
0
Response* Connection::deleteDocument(const std::string& uri) {
  TIMED_FUNC(Connection_deleteDocument);
  return mImpl->proxy.deleteSync(mImpl->serverUrl,
      "/v1/documents?uri=" + uri // TODO directory (non uri) version // TODO check for URL parsing // TODO fix JSON hard coding here
      );
}
예제 #11
0
// TODO XML version
Response* Connection::saveDocument(const std::string& uri,const IDocumentContent& payload) {
  TIMED_FUNC(Connection_saveDocument);
  return mImpl->proxy.putSync(mImpl->serverUrl,
      "/v1/documents?uri=" + uri, // TODO directory (non uri) version // TODO check for URL parsing // TODO fix JSON hard coding here
      payload);
}
예제 #12
0
Response* Connection::getDocument(const std::string& uri) {
  TIMED_FUNC(Connection_getDocument);
  return mImpl->proxy.getSync(mImpl->serverUrl, "/v1/documents?uri=" + uri); // TODO escape URI for URL rules
}
예제 #13
0
// TODO multipart payload
Response* Connection::doDelete(const std::string& path) {
  TIMED_FUNC(Connection_doDelete);
  return mImpl->proxy.deleteSync(mImpl->serverUrl,path);
}
예제 #14
0
Response* Connection::doPost(const std::string& pathAndQuerystring,const IDocumentContent& payload) {
  TIMED_FUNC(Connection_doPost);
  return mImpl->proxy.postSync(mImpl->serverUrl,
      "/v1/search",
      payload);
}
예제 #15
0
// BASIC commands allowing re-use of this connection, perhaps for URLs we don't yet wrap
Response* Connection::doGet(const std::string& pathAndQuerystring) {
  TIMED_FUNC(Connection_doGet);
  return mImpl->proxy.getSync(mImpl->serverUrl, pathAndQuerystring);
}